onPlayerChat (AsyncPlayerChat) not firing?

Discussion in 'Plugin Development' started by mysterypotatoguy, Dec 19, 2014.

Thread Status:
Not open for further replies.
  1. Hey, im trying to create a plugin for something that will respond to certain messages, but I don't think onPlayerChat is firing, I've added a system.out.println to it but it returns nothing in console, can anyone help?
    Code:
    @EventHandler
    public boolean onPlayerChat(AsyncPlayerChatEvent event) {
        System.out.println("test");
        Player p = event.getPlayer();
        String msg = event.getMessage();
        if (msg.toLowerCase().equals("potatobot")) {
            if (p.hasPermission("potatobot.use")){
            Player online = null;
            for (Entity en : Bukkit.getOnlinePlayers())
                if (en instanceof Player) {
                    online = (Player) en;
                    online.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "Yes, Master?");}
            }}
        if (msg.toLowerCase().startsWith("potatobot") && msg.toLowerCase().contains("tell a joke")) {
            if(p.hasPermission("potatobot.use")){
            Player onlinea = null;
            for (Entity en : Bukkit.getOnlinePlayers())
                if (en instanceof Player) {
                    onlinea = (Player) en;
                    Random rand = new Random();
                    int randomNumber = rand.nextInt(5);
                        //yes, ignore the really bad jokes, they came from the internet.
                        if (randomNumber == 1)
                            onlinea.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "Whats red and bad for your teeth? A brick!");       
                        if (randomNumber == 2)
                            onlinea.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "Why was 6 afraid of 7? Because 7 8 9!");       
                        if (randomNumber == 3)
                            onlinea.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "What do you call a pig that does karate? A Pork Chop!");       
                        if (randomNumber == 4)
                            onlinea.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "What do computers eat for lunch? Microchips!");                   
                        if (randomNumber == 5)
                            onlinea.sendMessage(Color.GRAY + "[" + Color.BLUE + "Robot" + Color.GRAY + "]" + Color.SILVER + "PotatoBot" + Color.WHITE + "How do trees access the internet? They log in!");                   
            }           
                }}
    
        return true;}}
     
  2. Rocoty likes this.
  3. @AdamQpzm I think so? where would I find it?
    EDIT: If you mean
    public final class PotatoBot extends JavaPlugin implements Listener {
    then yes
     
    Last edited: Dec 19, 2014
  4. Offline

    Rocoty

    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page