Solved PlayerInteractEvent error

Discussion in 'Plugin Development' started by Lionhard, Dec 24, 2013.

Thread Status:
Not open for further replies.
  1. Hello dear users,

    I have accepted a request for someone and now I want to add so he can add custom items in the config.yml. It works on my other plugin, but not on this one... :D Idk what it wants, the console also doesn't tell ANYTHING about an error or something... I would really appreciate if someone would help me find this little bug. Here is the code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void PlayerInteract(PlayerInteractEvent event){
    4. Player player = event.getPlayer();
    5. Set<String> allItems = this.getConfig().getConfigurationSection("items").getKeys(false);
    6. player.sendMessage("Set allItems: " + allItems);
    7. for(String itemSection : allItems){
    8. int id = this.getConfig().getInt("items." + itemSection + ".id");
    9. player.sendMessage("int id: " + id);
    10. String command = this.getConfig().getString("items." + itemSection + ".command");
    11. player.sendMessage("String command: " + command);
    12. ItemStack item = new ItemStack(Material.getMaterial(id));
    13. if(event.getAction().equals(Action.LEFT_CLICK_AIR) && player.getInventory().getItemInHand().equals(new ItemStack(Material.getMaterial(item.getType().getId())))){
    14. player.performCommand(command);
    15. }
    16. }


    Thanks in advance, Lionhard98.

    P.S.: Those messages like "player.sendMessage("Set allItems: " + allItems);" I've just set up so I can see if those variables are right, but I dont even come to this (the plugin doesnt print it in the chat). First I thought the error was because I forgot to implement Listener, but when I added "implements Listener" to the class it still didn't work. :/
     
  2. Offline

    RainoBoy97

    Did you register it in the onEnable()?
     
    Lionhard likes this.
  3. Offline

    pope_on_dope

    did you register your events?


    ninja'd....
     
    Lionhard likes this.
  4. pope_on_dope It is in the same file, do I still have to register them? :D (Sorry if that was a stupid question :D)

    EDIT: Oh man I'm so stupid :D Thanks you both, it works now perfectly :D
     
  5. Offline

    RainoBoy97

    Lionhard
    Yes you do ;) No problem!

    Merry christmas! :>
     
Thread Status:
Not open for further replies.

Share This Page