Solved PlayerInteractEvent triggers FOUR times

Discussion in 'Plugin Development' started by Blingdaddy1, Feb 9, 2014.

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

    Blingdaddy1

    I don't even know why it's triggering 4 times... Please help?
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onPlayerClickSlime(PlayerInteractEvent event) {
    4. Player player = event.getPlayer();
    5. Action action = event.getAction();
    6. if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
    7. if (player.getItemInHand().getType() == Material.SLIME_BALL) {
    8. for (Player players : Bukkit.getOnlinePlayers()) {
    9. player.hidePlayer(players);
    10. player.sendMessage(ChatColor.AQUA + "[" + ChatColor.GOLD + "TeamAFK" + ChatColor.AQUA + "]" + ChatColor.GREEN + " Hidden all players!");
    11. player.getItemInHand().setType(Material.MAGMA_CREAM);
    12. player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1, 1);
    13. player.playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 1);
    14. BarAPI.setMessage(player, ChatColor.GOLD + "Players hidden!", 10);
    15. }
    16. }
    17. if (player.getItemInHand().getType() == Material.MAGMA_CREAM) {
    18. for (Player players : Bukkit.getOnlinePlayers()) {
    19. player.showPlayer(players);
    20. player.sendMessage(ChatColor.AQUA + "[" + ChatColor.GOLD + "TeamAFK" + ChatColor.AQUA + "]" + ChatColor.GREEN + " Shown all players!");
    21. player.getItemInHand().setType(Material.SLIME_BALL);
    22. player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1, 1);
    23. player.playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 1);
    24. BarAPI.setMessage(player, ChatColor.GOLD + "Players shown!", 10);
    25. }
    26. }
    27. }
    28. }
     
  2. Offline

    Rocoty

    Did you register the listener four times?
     
  3. Offline

    Blingdaddy1

    No... All I did was
    Code:java
    1. Bukkit.getPluginManager().registerEvents(new Listeners(), this);
     
  4. Offline

    jthort

    Blingdaddy1 I had this problem, check your imports on all classes make sure it's not imported when it shouldn't be.

    Also I use this
    Code:
    PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
    I don't know if it makes a difference if you use \/ but give it a shot
     
  5. Offline

    Blingdaddy1

    I've found out that it's displaying the message once for every person on the server.... What?
     
  6. Offline

    RawCode

    for (Player players : Bukkit.getOnlinePlayers()) {

    learn2code
     
  7. Offline

    Blingdaddy1

    Yeah i've fixed this I should probably set this to solved xD Thanks everyone :D
     
Thread Status:
Not open for further replies.

Share This Page