Solved Prevent players from putting on armor?

Discussion in 'Plugin Development' started by ZeusAllMighty11, Nov 4, 2012.

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

    ZeusAllMighty11

    I tried and I get the right item slot but I can't check if they actually put it on.
     
  2. Offline

    fireblast709

    ZeusAllMighty11 check for
    Code:java
    1. InventoryType.SlotType.ARMOR

    you can get this in the InventoryClickEvent:
    Code:java
    1. onClick(InventoryClickEvent event)
    2. {
    3. if(event.getSlotType() == InventoryType.SlotType.ARMOR)
    4. {
    5. // Do whatever
    6. }
    7. }
     
  3. Offline

    ZeusAllMighty11

    Problem solved. Thanks for help, I was being dumb
     
  4. Offline

    JJSfluffyduck

    Maybe but this should be it try making your chain mail var in one line
     
  5. Offline

    fireblast709

    Code:java
    1. package me.zeus.GuardManager;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.inventory.InventoryClickEvent;
    10. import org.bukkit.event.inventory.InventoryType;
    11. import org.bukkit.event.inventory.InventoryType.SlotType;
    12. import org.bukkit.inventory.ItemStack;
    13.  
    14. public class Guards implements Listener {
    15.  
    16. @EventHandler
    17. public void onGuardCreate(final InventoryClickEvent e) {
    18. final Player guard = (Player) e.getWhoClicked();
    19.  
    20. final ItemStack chainboots = new ItemStack((Material.CHAINMAIL_BOOTS),
    21. 1);
    22. final ItemStack chainhelmet = new ItemStack(
    23. (Material.CHAINMAIL_HELMET), 1);
    24. final ItemStack chainleggings = new ItemStack(
    25. (Material.CHAINMAIL_LEGGINGS), 1);
    26. final ItemStack chainchestplate = new ItemStack(
    27. (Material.CHAINMAIL_CHESTPLATE), 1);
    28.  
    29. if(e.getSlotType() == InventoryType.SlotType.ARMOR)
    30. {
    31. Material cursor = e.getCursor().getType();
    32. if ((cursor == Material.CHAINMAIL_BOOTS)
    33. || (cursor == Material.CHAINMAIL_LEGGINGS)
    34. || (cursor == Material.CHAINMAIL_CHESTPLATE)
    35. || (cursor == Material.CHAINMAIL_HELMET)) {
    36.  
    37. Bukkit.broadcastMessage(ChatColor.RED
    38. + " Someone put on chain !");
    39.  
    40. } else{
    41. System.out.println("something else");
    42. }
    43. }
    44. }
    45. }

    No clue why you wanted a scheduled task :3. Untested
     
  6. Offline

    ZeusAllMighty11

    Another thread said scheduled task 0_0
     
  7. Offline

    fireblast709

    ZeusAllMighty11 well if this works why do it the hard way ;3? (unless you need a scheduler). Btw I made it so you can remove the final ItemStack objects
     
  8. Offline

    ZeusAllMighty11

    I didn't even need itemstacks, I just compared materials :p
     
  9. Offline

    fireblast709

    ZeusAllMighty11 that source was originally yours right? And that compaired ItemStacks...
     
  10. Offline

    ZeusAllMighty11

    ?


    I own all this source code, I wrote it myself...

    I only took the scheduler, then I removed it. (scheduler was from a plugin dev help post on here)
     
  11. Offline

    fireblast709

    ZeusAllMighty11 I mean that the source code I used, I got from you (I think... at least the package name would make sense). And in that code I found the final ItemStack vars and comparison done with .equals(). Not that it matters though x3
     
Thread Status:
Not open for further replies.

Share This Page