Solved PlayerInteractEvent problem

Discussion in 'Plugin Development' started by kreashenz, Aug 31, 2013.

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

    kreashenz

    So I am now completely stumped on this. I've got the event handler, I'm registering the event in the main class, I've got all that.. But this one thing isn't actually working out how it's supposed to.

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onInteractEvent(PlayerInteractEvent e){
    4. System.out.print("PlayerInteractEvent got called");
    5. final Player p = e.getPlayer();
    6. Block b = e.getClickedBlock();
    7. ItemStack item = e.getItem();
    8. if(item != null){
    9. if(plugin.kit.containsKey(p.getName())){
    10. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    11. if(item.hasItemMeta()){
    12. if(item.getType().equals(Material.BOOK)){
    13. if(item.getItemMeta().getDisplayName().equalsIgnoreCase("§6Book of Kits")){
    14. if(!(p.getGameMode().equals(GameMode.CREATIVE))){
    15. new ItemMenuHandler().openKits(p);
    16. } else Functions.tell(p, "§cYou can't be in creative to open this!");
    17. }
    18. }
    19.  
    20. if(item.equals(Material.LEATHER)){
    21. System.out.print("potato");
    22. if(item.hasItemMeta() && item.getItemMeta().getDisplayName().equalsIgnoreCase("§6Tail")){
    23. System.out.print("potato1");
    24. if(plugin.kit.get(p.getName()).equals(Kit.KANGAROO)){
    25. System.out.print("Kangaroo!");
    26. if(!(cooldown.contains(p.getName()))){
    27. System.out.print("potato2");
    28. if(timesRotated.containsKey(p.getName())){
    29. System.out.print("potato3");
    30. if(!(timesRotated.get(p.getName()) > 1)){
    31. System.out.print(timesRotated);
    32. timesRotated.put(p.getName(), 1);
    33. plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new BukkitRunnable(){
    34. @Override
    35. public void run() {
    36. System.out.print("scheduler is running");
    37. Location loc = p.getLocation();
    38. loc.setYaw(loc.getYaw() + 9);
    39. p.teleport(loc);
    40.  
    41. for(Entity ent : p.getNearbyEntities(6, 5, 6)){
    42. if(ent instanceof Player){
    43. Player pEnt = (Player)ent;
    44. pEnt.setVelocity(pEnt.getLocation().getDirection().multiply(-4));
    45. }
    46. }
    47. }
    48. }, 0L, 2L);
    49. new BukkitRunnable(){
    50. public void run(){
    51. timesRotated.remove(p.getName());
    52. Functions.tell(p, "§cYou're feeling better!");
    53. }
    54. }.runTaskLater(plugin, 300L);
    55. } else Functions.tell(p, "§cYou have to wait!");
    56. }
    57. }
    58. }
    59. }
    60. }
    61. }
    62. }
    63. }
    64. }
    65. }

    It's reading it, because I'm getting the "PlayerInteractEvent got called" message, but nothing else is coming up. So my problem is that it's not reading it, and I need a way to fix it. Hopefully someone knows what's going on here. Thanks!
     
  2. Offline

    Techy4198

    I can't see a problem, but I would like to ask, why are you using your own method to send a message to the player?
     
  3. Offline

    chasechocolate

    Probably so it can add a custom prefix.

    kreashenz do a debug message after every if-statement (lines 8-13).
     
  4. Offline

    kreashenz

    chasechocolate Ok, I've added debugs and it seems it stops when I'm checking, if(item.equals(Something)). What can be the problem there?

    Solved. I was checking item (ItemStack) equals a material. (if(item.equals(Material.LEATHER))){

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

Share This Page