Solved StaffChat problem

Discussion in 'Plugin Development' started by mc_myster, Dec 28, 2015.

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

    mc_myster

    So i am creating a plugin for staff to be able to converse over but i am having a silly error where it sends the message 2 times to the sender. Have a look, my ArrayList only contains myself, im not in it 2 times and here is the code also:

    This is what happens:
    [​IMG]
    ArrayList Current Users:
    [​IMG]
    Code:
    Code:
    @EventHandler(priority=EventPriority.HIGH)
    public void StaffChat(AsyncPlayerChatEvent e){
         if(staffchat.contains(e.getPlayer().getName())){
             for(String s : staffchat){
                 e.setCancelled(true);
                 Bukkit.getPlayer(s).sendMessage("§7[§4§lStaff§7-§4§lChat§7] §f" + e.getPlayer().getName() + "§4§l > §e" +  e.getMessage());
             }
         }
    }
     
  2. Offline

    Xerox262

    Where are you registering your events? It looks as if you have done it twice.

    Also, you should move the e.setCancelled(true); outside of the for loop
     
  3. Offline

    Zombie_Striker

    @mc_myster
    You're not canceling the event, so you're sending a message, and then the server goes through with the original message.
     
  4. Offline

    Xerox262

    He's cancelling the event in the for loop.
     
  5. Offline

    mc_myster

    @Xerox262 I moved the cancelled event out of the loop and it still does it.
     
  6. Offline

    Xerox262

    You didn't read the other part of the message, can you show where you register the events? It looks like you've done it twice.
    Possibly registered in the onEnable and in a constructor if you're in a different class, can you show them so we can help more?

    All that moving the e.setCancelled(true); outside the for loop done was to make your server not waste time cancelling an event that you already cancelled.
     
  7. Offline

    mc_myster

    @Xerox262 Yeh for some reason on registered the events 2 times, i must of accidentally duplicated it when i was updating the code, thanks allot for the help :)
     
    Xerox262 likes this.
Thread Status:
Not open for further replies.

Share This Page