Page 2 of 2

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 02:08
by JamieS1211
Zuaro » 15 Sep 2014 01:19 wrote: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.


What about drops? I will be able to fix it tonight

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 12:34
by JamieS1211
This should have everything working. Let me know when you have tested it with everything working. If you recompile it using the same files however delete the contents of AntiCraft.java and replace it with below.

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 (daycare.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 (breeder.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 (fisherman.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!");
           }
        }
     }
  }
}

}

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 16:23
by Zuaro
Sorry, I was at school. Yeah, the drop feature worked. I'll test that one now.

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 17:03
by Zuaro
Tested it, worked fine. All three features did. The only issue I'm having now is that, players, when the item goes to their inventory (Not hotbar, to the inventory.) and the player shift-clicks the item to put it in their hotbar, it makes a duplicate of the item. This could be bad if, for example, a player gets an Old Rod from a boss or fisherman (Just an example), and they're not of the Fisherman rank, they can make a duplicate of the item. Or, if a player makes a Trading Machine and drops it for a non-daycare to use, they can duplicate the machine. Is there any way to make it so that the item cannot go into the player's inventory at all?

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 17:34
by JamieS1211
Zuaro » 15 Sep 2014 22:03 wrote:Tested it, worked fine. All three features did. The only issue I'm having now is that, players, when the item goes to their inventory (Not hotbar, to the inventory.) and the player shift-clicks the item to put it in their hotbar, it makes a duplicate of the item. This could be bad if, for example, a player gets an Old Rod from a boss or fisherman (Just an example), and they're not of the Fisherman rank, they can make a duplicate of the item. Or, if a player makes a Trading Machine and drops it for a non-daycare to use, they can duplicate the machine. Is there any way to make it so that the item cannot go into the player's inventory at all?

The issue you are talking about is to do with creative. If you exit creative then it should not happen. Also regarding pickup I can prevent players picking up curtain items however this won't stop them being able to gain an item via give etc. I can look into it to update their inventory if it check that there is a disallowed item in there. Let me know if you want both. You can also not give anyone the drop bypass nodes.

Re: Pixelmon Item Restrictions?

PostPosted: 15 Sep 2014 17:59
by JamieS1211
Also this will patch that issue with creative. If it is bugging you! Let me know about the pick-up etc.

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) || (event.getView().getTopInventory().getType() == InventoryType.CREATIVE)) {
        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 (daycare.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 (breeder.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 (fisherman.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!");
           }
        }
     }
  }
}

}