Solved Cancel Drops/Movement

Discussion in 'Plugin Development' started by Pink__Slime, May 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Pink__Slime

    So I'm trying to cancel the dropping of items in an ArrayList and the movement of armour in another ArrayList. I seem to be doing it wrong because I can't figure it out.

    Here's my code:

    Main:
    Code:java
    1.  
    2.  
    3. public final static ArrayList<Material> items = new ArrayList<Material>();
    4. public final static ArrayList<Material> armour = new ArrayList<Material>();
    5.  
    6. public void onEnable(){
    7. instance = this;
    8. log.info("Instance = this");
    9.  
    10. if (!setupEconomy() ) {
    11. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    12. getServer().getPluginManager().disablePlugin(this);
    13. return;
    14. }
    15.  
    16. PluginManager pm = getServer().getPluginManager();
    17. pm.registerEvents(this, this);
    18. pm.registerEvents(new MenuListener(this), this);
    19. pm.registerEvents(new KitEvents(this), this);
    20. pm.registerEvents(new Other(this), this);
    21. pm.registerEvents(new SignCreate(this), this);
    22. pm.registerEvents(new Stomper(this), this);
    23. getCommand("pvp").setExecutor(new Commands());
    24. getCommand("testmenu").setExecutor(new Commands());
    25.  
    26. getConfig().options().copyDefaults(true);
    27. saveConfig();
    28.  
    29. Methods.createMenu();
    30. Methods.createSelectMenu();
    31. Methods.banDrops();
    32. Methods.armour();
    33.  
    34. MenuListener.test();
    35. }
    36.  
    37. public void onDisable(){
    38. instance = null;
    39. log.info("Instance = null");
    40. }


    Methods:
    Code:java
    1. public static void banDrops(){
    2. Main.items.add(Material.DIAMOND_SWORD);
    3. Main.items.add(Material.IRON_SWORD);
    4. Main.items.add(Material.STONE_SWORD);
    5. Main.items.add(Material.GOLD_SWORD);
    6. Main.items.add(Material.WOOD_SWORD);
    7. Main.items.add(Material.IRON_AXE);
    8. Main.items.add(Material.BOW);
    9. Main.items.add(Material.DIAMOND_HOE);
    10. Main.items.add(Material.WOOD_HOE);
    11. Main.items.add(Material.BLAZE_ROD);
    12. Main.items.add(Material.SPIDER_EYE);
    13. Main.items.add(Material.SULPHUR);
    14. Main.items.add(Material.TNT);
    15. Main.items.add(Material.ENDER_PEARL);
    16. Main.items.add(Material.REDSTONE_TORCH_ON);
    17.  
    18. Main.items.add(Material.MUSHROOM_SOUP);
    19. }
    20.  
    21. public static void armour(){
    22. // Diamond
    23. Main.armour.add(Material.DIAMOND_HELMET);
    24. Main.armour.add(Material.DIAMOND_CHESTPLATE);
    25. Main.armour.add(Material.DIAMOND_LEGGINGS);
    26. Main.armour.add(Material.DIAMOND_BOOTS);
    27.  
    28. // Iron
    29. Main.armour.add(Material.IRON_HELMET);
    30. Main.armour.add(Material.IRON_CHESTPLATE);
    31. Main.armour.add(Material.IRON_LEGGINGS);
    32. Main.armour.add(Material.IRON_BOOTS);
    33.  
    34. // Gold
    35. Main.armour.add(Material.GOLD_HELMET);
    36. Main.armour.add(Material.GOLD_CHESTPLATE);
    37. Main.armour.add(Material.GOLD_LEGGINGS);
    38. Main.armour.add(Material.GOLD_BOOTS);
    39.  
    40. // Chain
    41. Main.armour.add(Material.CHAINMAIL_HELMET);
    42. Main.armour.add(Material.CHAINMAIL_CHESTPLATE);
    43. Main.armour.add(Material.CHAINMAIL_LEGGINGS);
    44. Main.armour.add(Material.CHAINMAIL_BOOTS);
    45.  
    46. // Leather
    47. Main.armour.add(Material.LEATHER_HELMET);
    48. Main.armour.add(Material.LEATHER_CHESTPLATE);
    49. Main.armour.add(Material.LEATHER_LEGGINGS);
    50. Main.armour.add(Material.LEATHER_BOOTS);
    51. }


    Listener:
    Code:java
    1. @EventHandler
    2. void onClickEvent(InventoryClickEvent e) {
    3.  
    4. if(e.getWhoClicked() instanceof Player){
    5. Player player = (Player)e.getWhoClicked();
    6. ItemStack it = e.getCurrentItem();
    7.  
    8. if(it != null && it.getItemMeta() != null && it.getItemMeta().getDisplayName() != null){
    9.  
    10.  
    11. if(e.getInventory().getType() == InventoryType.PLAYER){
    12. if(Main.armour.contains(it)){
    13. e.setCancelled(true);
    14. player.sendMessage(ChatColor.RED + "You can't move this");
    15. }
    16. }
    17. }
    18. }
    19. }
     
  2. Offline

    minoneer

    There is you problem. You are checking, if the ArrayList contains the ItemStack, but the ArrayList only contains Materials. Change that line to

    Code:java
    1. if (Main.armour.contains(it.getType())


    that should work
     
  3. Offline

    Pink__Slime

    minoneer
    Doesn't work still... Still no errors.

    Bump.
    I need to stop the movement of items in the armour ArrayList. I figured out the drops but every player gets the armour set and I want to avoid players from removing armour.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    Technius

    Pink__Slime
    Items are copied when they are set into the inventories. You could try cancelling InventoryClickEvents if they are clicking armor on their armor slots.
     
  5. Offline

    Pink__Slime

    So basically what I have without the check to see if it's a player's inventory?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  6. Offline

    minoneer

    Ok, instead of bunping every few hours, why don't you just add debug messages?
     
  7. Offline

    Pink__Slime

    1. I'm allowed to bump every 12 hours.
    2. Because I need help.
    3. Because I don't add them. Haven't thought about it.
     
  8. Offline

    minoneer

    1.: yes you are. But since when is it 12h from Today at 3:40 AM and Today at 8:14 AM ?

    3.: That's usually the first thing you do, before even asking others in a forum.
     
  9. Offline

    John Cameron

    Error message or some kind or error?
    They are there for a reason, we can't tell unless we know what the error is.
     
  10. Offline

    minoneer

    ^^
     
    Pink__Slime likes this.
  11. Offline

    Pink__Slime

    Exactly... I get home from school 2.5 hours, I'll add debug messages to see how far it works.

    Ok so I don't know what changed but it works now...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page