Solved Guard Confiscator

Discussion in 'Plugin Development' started by SeniorCluckers, Jul 29, 2014.

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

    SeniorCluckers

    Hey i made this plugin so guards cant take stuff away from prisoners. But when they use blaze rod they can take anything. And i know i have to use a array list for that but how would i set that up. And also they dont need to use blaze rod to take stuff from prisoners. They can use there hands and i dont want that. Can anyone help?

    Main Class:
    Code:java
    1. package me.cruz2000;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class ConfiscatorMain
    6. extends JavaPlugin
    7. {
    8. RightClickListener rightclick;
    9. static ConfiscatorMain plugin;
    10.  
    11. public void onEnable()
    12. {
    13. plugin = this;
    14. this.rightclick = new RightClickListener();
    15. }
    16. }
    17.  


    Listener Class:
    Code:java
    1. package me.cruz2000;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.EntityType;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerInteractEntityEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.inventory.PlayerInventory;
    12. import org.bukkit.plugin.PluginManager;
    13.  
    14. public class RightClickListener
    15. implements Listener
    16. {
    17. public RightClickListener()
    18. {
    19. Bukkit.getPluginManager().registerEvents(this, ConfiscatorMain.plugin);
    20. }
    21.  
    22. @EventHandler
    23. public void onRightClick(PlayerInteractEntityEvent e)
    24. {
    25. if (((e.getPlayer().hasPermission("prisonconfiscator.confiscate") & e.getRightClicked().getType() == EntityType.PLAYER)) && (!((Player)e.getRightClicked()).hasPermission("prisonconfiscator.noconfiscate")))
    26. {
    27. Player c = e.getPlayer();
    28. Player p = (Player)e.getRightClicked();
    29. ItemStack item = p.getItemInHand();
    30. p.setItemInHand(null);
    31. p.updateInventory();
    32. c.getInventory().addItem(new ItemStack[] { item });
    33. }
    34. }
    35. }
    36.  
     
  2. Offline

    drpk

    SeniorCluckers
    register your events in the Main class, not the listener class.
     
  3. Offline

    SeniorCluckers

    I did but not really answering my question..
     
  4. Offline

    fireblast709

    drpk both work fine
    SeniorCluckers just check the Material of the item in hand. Also, don't use static instances of your main class, use the constructor to pass around an instance of the main class.
     
  5. Offline

    SeniorCluckers

    Can you help me i haven't really read up on java im on the api docs but i have no idea what to do. I know i have to check the item the guard is holding to use that item to take away what the prisoner is holding.
     
  6. Offline

    fireblast709

    SeniorCluckers its the same as getting the item the prisoner is holding (but you call the method on the guard)
     
  7. Offline

    SeniorCluckers

    Code:java
    1. Player c = e.getPlayer();
    2. Player p = (Player)e.getRightClicked();
    3. ItemStack item = p.getItemInHand();
    4. p.setItemInHand(null);
    5. p.updateInventory();
    6. c.getInventory().addItem(new ItemStack[] { item });
    7. c.updateInventory();

    Umm still confused. Is it " e.getItemInHand(Material.BLAZE_ROD); " ??
     
  8. Offline

    fireblast709

    SeniorCluckers no you get the ItemStack (and that method takes no parameters), then get the type of that ItemStack, and check if it == Material.BLAZE_ROD
     
  9. Offline

    SeniorCluckers

    Im confused. Im sorry.
     
  10. Offline

    fireblast709

  11. Offline

    SeniorCluckers

    I cant get it to work. Am i over thinking it?
     
  12. Offline

    fireblast709

  13. Offline

    SeniorCluckers

    In your point of view rate in 1-10 how easy is this.

    And im not sure where where that line goes.

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

    fireblast709

    SeniorCluckers just after you define Player c, check if getItemInHand().getType() == Material.BLAZE_ROD
     
  15. Offline

    SeniorCluckers


    Code:java
    1. Player c = e.getPlayer().getItemInHand().getType() == Material.BLAZE_ROD));


    Like this??

    fireblast709
    Found out what i was doing wrong thanks so much!

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

Share This Page