Forum rules: Do not post bugs or feature requests here! Report bugs to our Issue Tracker and suggestions to Suggest a Feature.

This site is not for solicitation of services or 'purchasing' development. Please do not post requesting side mods/plugins and so on. Your thread will be removed, and you will receive a warning.
User avatar
By Zuaro
#137243 Hello, I'm currently working on a project to add to my server.

I want to implement a class system (Thanks a ton for the new breeding system) to my server that allows players to join a class and complete specific tasks for rewards.

For example: There will be a daycare class, the daycare class levels up Pokemon for other players that cannot, or are too lazy, to do it themselves. However, in order to do that, they will need that player's Pokemon. So, there will need to be trading involved.

Now, I want to make it so that, only members of the Daycare class will be able to craft Trading machines. I know there is some way to do it, it's a vital part of some servers, like Tekkit (Donating to be able to use specific items). However, I'm clueless about it. I was curious as to if you guys can help me with this.

Do you know of any plugins that restrict the crafting of items to, and only to players or groups with a specific permissions node?

Thanks for your time,
Zuaro

User avatar
By JamieS1211
#137280 This should do the trick (The class is called "AntiCraft")

Code: Select allpackage me.TJP.plugin;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;

@SuppressWarnings("unused")
public class AntiCraft extends JavaPlugin
implements Listener
{
protected final Logger log = Logger.getLogger("Minecraft");

private PluginManager pm;
public ConsoleCommandSender console;

public void onEnable()
{
   getConfig().options().copyDefaults(true);
   saveConfig();
   getServer().getPluginManager().registerEvents(this, this);
   this.pm = getServer().getPluginManager();
   this.log.info("[" + getDescription().getFullName() + "] is now enabled!");
}

public void onDisable()
{
   this.log.info(getDescription().getFullName() + " is now disabled!");
}

private final List<Integer> noMove = Arrays.asList(4098,4103);

@SuppressWarnings("deprecation")
@EventHandler
public void onItemMove(InventoryClickEvent event) {

   
    HumanEntity player = event.getWhoClicked();

    if (player.hasPermission("craft.bypass")) {
        return;
    }
    if (event.getView().getTopInventory().getType() == InventoryType.CRAFTING) {
        return;
    }
    ItemStack moved;
    if (event.getAction().name().contains("HOTBAR")) {
        moved = event.getView().getBottomInventory().getItem(event.getHotbarButton());
    } else {
        moved = event.getCurrentItem();
    }
    if (moved == null) {
        return;
    }
    if (noMove.contains(moved.getTypeId())) {
        event.setCancelled(true);
    }
}

@SuppressWarnings("deprecation")
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
  Player player = event.getPlayer();
 
  if (player.hasPermission("craft.drop.bypass"))
  {
     return;
  }
  if (noMove.contains(event.getItemDrop().getItemStack().getTypeId()))
    {
     event.setCancelled(true);
    }
}

}


Before you compile it place the item ids that you want to prevent people crafting in this section

Code: Select allprivate final List<Integer> noMove = Arrays.asList(4098,4103);


I was trying to get it to load from a config but it was playing up but that will still work. I have in there it set to trade machienes and pokeballs but your item ids may be different. This will stop players without the permission node "craft.bypass" from moving the items in any inventory screen other then their player inventory. This will prevent them crafting the items or transferring the items via placing in chests and breaking the chest. Also all players without "craft.drop.bypass" will be unable to drop the items to give them to another user. Good luck!
User avatar
By JamieS1211
#137281 Almost forgot to give you the plugin yml!
Here it is

Code: Select allname: AntiCraft
main: me.TJP.plugin.AntiCraft
version: 1.7.10
author: TJP
description: Prevents players crafting curtain items
permissions:
  craft.bypass:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass:
    description: Allows player to bypass the drop restrictions
    default: op
User avatar
By JamieS1211
#137295
Zuaro » 14 Sep 2014 16:13 wrote:Trying it now, thanks a lot!

I actually just added some new code to alert admins on problems and load from a config file.

Anyway if you want to compile it yourself this is the code

plugin.yml
Code: Select allname: AntiCraft
main: me.TJP.plugin.AntiCraft
version: 1.7.10
author: TJP
description: Prevents players crafting curtain items
permissions:
  craft.bypass:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass:
    description: Allows player to bypass the drop restrictions
    default: op
  craft.alert:
    description: Get message when player tries to break restrictions
    default: op


config.yml
Code: Select all# AntiCraft
# Configuration file
# Below give a list of all items you wish to be uncraftable via item id.
# It should be in the form of a list below "noMove:" with a new line per id.
# Each line should start with a "-" followed by a space and then the id.
# Example "- [Item ID]"
noMove:
  - 4436
  - 4437
  - 4438
  - 4439
  - 4098


AntiCraft.java
Code: Select allpackage me.TJP.plugin;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;

@SuppressWarnings("unused")
public class AntiCraft extends JavaPlugin
implements Listener
{
protected final Logger log = Logger.getLogger("Minecraft");

private PluginManager pm;
public ConsoleCommandSender console;

public void onEnable()
{
   getConfig().options().copyDefaults(true);
   saveConfig();
   getServer().getPluginManager().registerEvents(this, this);
   this.pm = getServer().getPluginManager();
   this.log.info("[" + getDescription().getFullName() + "] is now enabled!");
}

public void onDisable()
{
   this.log.info(getDescription().getFullName() + " is now disabled!");
}

private final List<Integer> noMove = AntiCraft.this.getConfig().getIntegerList("noMove");

@SuppressWarnings("deprecation")
@EventHandler
public void onItemMove(InventoryClickEvent event) {

   HumanEntity user = event.getWhoClicked();
   Player player = (Player) user;

    if (player.hasPermission("craft.bypass")) {
        return;
    }
    if (event.getView().getTopInventory().getType() == InventoryType.CRAFTING) {
        return;
    }
    ItemStack moved;
    if (event.getAction().name().contains("HOTBAR")) {
        moved = event.getView().getBottomInventory().getItem(event.getHotbarButton());
    } else {
        moved = event.getCurrentItem();
    }
    if (moved == null) {
        return;
    }
    if (noMove.contains(moved.getTypeId())) {
        event.setCancelled(true);
        player.sendMessage("You can't move that item in this inventory!");
       
        for (Player admin : Bukkit.getOnlinePlayers())
        {
          if (admin.hasPermission("craft.alert")){
            admin.sendMessage(player.getName() + " tried to move an inventory item against restrictions!");
          }
        }
    }
}

@SuppressWarnings("deprecation")
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
  Player player = event.getPlayer();
 
  if (player.hasPermission("craft.drop.bypass"))
  {
     return;
  }
  if (noMove.contains(event.getItemDrop().getItemStack().getTypeId()))
    {
     event.setCancelled(true);
     player.sendMessage("You cannot drop that item!");
     
     for (Player admin : Bukkit.getOnlinePlayers())
       {
         if (admin.hasPermission("craft.alert")){
           admin.sendMessage(player.getName() + " tried to drop an item against restrictions!");
         }
       }
    }
}

}
User avatar
By Zuaro
#137299 It works like a charm for how it was built. However, I'm curious as to if there's any way to make it so that there are more nodes corresponding to new arrays.

Not sure if that made any sense, let me clarify.

Person A is in the Daycare group - They can make Trading Machines.
Person B is in the Trainer Group - They can make Pokeballs.

Is there a way to make it so that Person A will not be able to make Pokeballs, while Person B will not be able to make Trading Machines?

Currently it's set up so that they will need the node in order to use any item via array, so that would allow Person A and Person B to make both Trading Machines and Pokeballs.
User avatar
By JamieS1211
#137300
Zuaro » 14 Sep 2014 17:47 wrote:It works like a charm for how it was built. However, I'm curious as to if there's any way to make it so that there are more nodes corresponding to new arrays.

Not sure if that made any sense, let me clarify.

Person A is in the Daycare group - They can make Trading Machines.
Person B is in the Trainer Group - They can make Pokeballs.

Is there a way to make it so that Person A will not be able to make Pokeballs, while Person B will not be able to make Trading Machines?

Currently it's set up so that they will need the node in order to use any item via array, so that would allow Person A and Person B to make both Trading Machines and Pokeballs.


Yes of course. Just tell me how many nodes you want. I will make a list for each node in the config and then post the code so you can recompile it.
User avatar
By Zuaro
#137301 Alrighty.

craft.bypass.Gambler
craft.bypass.Ranger
craft.bypass.Daycare
craft.bypass.Breeder
craft.bypass.Fisherman

Thanks a lot for the help btw.
User avatar
By JamieS1211
#137310 This should be it. I have not tested it so can you. Let me know both ways and check each node on and off.

AntiCraft.java
Code: Select allpackage me.TJP.plugin;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;

@SuppressWarnings("unused")
public class AntiCraft extends JavaPlugin
implements Listener
{
protected final Logger log = Logger.getLogger("Minecraft");

private PluginManager pm;
public ConsoleCommandSender console;

public void onEnable()
{
   getConfig().options().copyDefaults(true);
   saveConfig();
   getServer().getPluginManager().registerEvents(this, this);
   this.pm = getServer().getPluginManager();
   this.log.info("[" + getDescription().getFullName() + "] is now enabled!");
}

public void onDisable()
{
   this.log.info(getDescription().getFullName() + " is now disabled!");
}

private final List<Integer> gambler = AntiCraft.this.getConfig().getIntegerList("gambler");
private final List<Integer> trainer = AntiCraft.this.getConfig().getIntegerList("trainer");
private final List<Integer> daycare = AntiCraft.this.getConfig().getIntegerList("daycare");
private final List<Integer> breeder = AntiCraft.this.getConfig().getIntegerList("breeder");
private final List<Integer> fisherman = AntiCraft.this.getConfig().getIntegerList("fisherman");


@SuppressWarnings("deprecation")
@EventHandler
public void onItemMove(InventoryClickEvent event) {

   HumanEntity user = event.getWhoClicked();
   Player player = (Player) user;

    if (event.getView().getTopInventory().getType() == InventoryType.CRAFTING) {
        return;
    }
    ItemStack moved;
    if (event.getAction().name().contains("HOTBAR")) {
        moved = event.getView().getBottomInventory().getItem(event.getHotbarButton());
    } else {
        moved = event.getCurrentItem();
    }
    if (moved == null) {
        return;
    }
   
    //gambler
    if (gambler.contains(moved.getTypeId())) {
       if (player.hasPermission("craft.bypass.gambler")) {
            return;
        } else {
           event.setCancelled(true);
           player.sendMessage("You can't move that item in this inventory, you are not a gambler!");
       
           for (Player admin : Bukkit.getOnlinePlayers())
           {
              if (admin.hasPermission("craft.alert")){
                 admin.sendMessage(player.getName() + " tried to move an gambler inventory item against restrictions!");
              }
           }
        }
    }
   
    //trainer
    if (trainer.contains(moved.getTypeId())) {
       if (player.hasPermission("craft.bypass.trainer")) {
            return;
        } else {
           event.setCancelled(true);
           player.sendMessage("You can't move that item in this inventory, you are not a trainer!");
       
           for (Player admin : Bukkit.getOnlinePlayers())
           {
              if (admin.hasPermission("craft.alert")){
                 admin.sendMessage(player.getName() + " tried to move an trainer inventory item against restrictions!");
              }
           }
        }
    }
   
    //daycare
    if (gambler.contains(moved.getTypeId())) {
       if (player.hasPermission("craft.bypass.daycare")) {
            return;
        } else {
           event.setCancelled(true);
           player.sendMessage("You can't move that item in this inventory, you are not a daycare!");
       
           for (Player admin : Bukkit.getOnlinePlayers())
           {
              if (admin.hasPermission("craft.alert")){
                 admin.sendMessage(player.getName() + " tried to move an daycare inventory item against restrictions!");
              }
           }
        }
    }
   
    //breeder
    if (gambler.contains(moved.getTypeId())) {
       if (player.hasPermission("craft.bypass.breeder")) {
            return;
        } else {
           event.setCancelled(true);
           player.sendMessage("You can't move that item in this inventory, you are not a breeder!");
       
           for (Player admin : Bukkit.getOnlinePlayers())
           {
              if (admin.hasPermission("craft.alert")){
                 admin.sendMessage(player.getName() + " tried to move an breeder inventory item against restrictions!");
              }
           }
        }
    }
   
    //fisherman
    if (gambler.contains(moved.getTypeId())) {
       if (player.hasPermission("craft.bypass.fisherman")) {
            return;
        } else {
           event.setCancelled(true);
           player.sendMessage("You can't move that item in this inventory, you are not a fisherman!");
       
           for (Player admin : Bukkit.getOnlinePlayers())
           {
              if (admin.hasPermission("craft.alert")){
                 admin.sendMessage(player.getName() + " tried to move an fisherman inventory item against restrictions!");
              }
           }
        }
    }
}

@SuppressWarnings("deprecation")
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
  Player player = event.getPlayer();
 
  //gambler
  if (gambler.contains(event.getItemDrop().getItemStack().getTypeId())) {
     if (player.hasPermission("craft.drop.bypass.gambler"))
     {
        return;
     } else {
        event.setCancelled(true);
        player.sendMessage("You cannot drop that item you are not a gambler!");
     
        for (Player admin : Bukkit.getOnlinePlayers())
        {
           if (admin.hasPermission("craft.alert")){
              admin.sendMessage(player.getName() + " tried to drop a gambler item against restrictions!");
           }
        }
     }
  }
 
  //trainer
  if (trainer.contains(event.getItemDrop().getItemStack().getTypeId())) {
     if (player.hasPermission("craft.drop.bypass.trainer"))
     {
        return;
     } else {
        event.setCancelled(true);
        player.sendMessage("You cannot drop that item you are not a trainer!");
     
        for (Player admin : Bukkit.getOnlinePlayers())
        {
           if (admin.hasPermission("craft.alert")){
              admin.sendMessage(player.getName() + " tried to drop a trainer item against restrictions!");
           }
        }
     }
  }
 
  //daycare
  if (daycare.contains(event.getItemDrop().getItemStack().getTypeId())) {
     if (player.hasPermission("craft.drop.bypass.daycare"))
     {
        return;
     } else {
        event.setCancelled(true);
        player.sendMessage("You cannot drop that item you are not a daycare!");
     
        for (Player admin : Bukkit.getOnlinePlayers())
        {
           if (admin.hasPermission("craft.alert")){
              admin.sendMessage(player.getName() + " tried to drop a daycare item against restrictions!");
           }
        }
     }
  }
 
  //breeder
  if (breeder.contains(event.getItemDrop().getItemStack().getTypeId())) {
     if (player.hasPermission("craft.drop.bypass.breeder"))
     {
        return;
     } else {
        event.setCancelled(true);
        player.sendMessage("You cannot drop that item you are not a breeder!");
     
        for (Player admin : Bukkit.getOnlinePlayers())
        {
           if (admin.hasPermission("craft.alert")){
              admin.sendMessage(player.getName() + " tried to drop a breeder item against restrictions!");
           }
        }
     }
  }
 
  //fisherman
  if (fisherman.contains(event.getItemDrop().getItemStack().getTypeId())) {
     if (player.hasPermission("craft.drop.bypass.fisherman"))
     {
        return;
     } else {
        event.setCancelled(true);
        player.sendMessage("You cannot drop that item you are not a fisherman!");
     
        for (Player admin : Bukkit.getOnlinePlayers())
        {
           if (admin.hasPermission("craft.alert")){
              admin.sendMessage(player.getName() + " tried to drop a fisherman item against restrictions!");
           }
        }
     }
  }
}

}


plugin.yml
Code: Select allname: AntiCraft
main: me.TJP.plugin.AntiCraft
version: 1.7.10
author: TJP
description: Prevents players crafting curtain items
permissions:
  craft.bypass.gambler:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.bypass.trainer:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.bypass.daycare:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.bypass.breeder:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.bypass.fisherman:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass.gambler:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass.trainer:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass.daycare:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass.breeder:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.drop.bypass.fisherman:
    description: Allows player to bypass the crafting restrictions
    default: op
  craft.alert:
    description: Get message when player tries to break restrictions
    default: op


config.yml
Code: Select all# AntiCraft
# Configuration file
# Below give a list of all items you wish to be uncraftable via item id.
# It should be in the form of a list below "noMove:" with a new line per id.
# Each line should start with a "-" followed by a space and then the id.
# Example "- [Item ID]"
# Each heading refers to its permision craft.bypass.[heading]
gambler:
  - 1
trainer:
  - 1
daycare:
  - 1
breeder:
  - 1
fisherman:
  - 1
User avatar
By Zuaro
#137344 After testing it with multiple items with the nodes, it worked for two.

With the Gambler, I made it so that only Gamblers can craft Normal Gems, it worked fine.
With the Trainer, I made it so that only Trainers can craft Ultra Balls, it worked fine.

However, with the other three,

With the Fisherman, I made it so that only Fishermen can craft Old Rods, all groups could craft.
With the Daycare, I made it so that only Daycare can craft Trade Machines, all groups could craft.
With the Breeder, I made it so that only Breeders can craft Pokedexes, all groups could craft.
JOIN THE TEAM