Chat events.

Discussion in 'Plugin Development' started by TheNoobiestCrafters, Nov 4, 2012.

Thread Status:
Not open for further replies.
  1. I saw a tutorial on how to do this, but I lost it.
    For example, if I type "heal" (without quotes) into the chat, it will do player.setHealth(0);
     
  2. Offline

    sensus12

    you need to register a listener and then into listener:

    Code:
    public void onChat(AsyncPlayerChatEvent event){
    Player player = null;
    String msg = event.getMessage().toLowerCase();
    if(msg.equals("heal"){
    player.setHealth(0);
    }
    }
     
  3. Offline

    fireblast709

    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent event)
    3. {
    4. Player p = event.getPlayer();
    5. String message = event.getMessage();
    6. if(message.contains("heal"))
    7. {
    8. p.setHealth(0);
    9. }
    10. }

    Don't forget to register your Listener class (the class this method is in)
     
  4. Offline

    Hoolean

    You do know player.setHealth(0); will kill them right? Not heal them XD
     
  5. Offline

    fireblast709

  6. you doing things that you shouldn't do, the async task is called mostly inside an async task, you never checkig it, and if its called inside an async task, you may break bukkit by accessing a bukkit methode, it shuld be better if you schedule an task to be sure its running on the main bukkit thread
     
Thread Status:
Not open for further replies.

Share This Page