onPlayerChat event timings

Discussion in 'Plugin Development' started by Godbrandont, Jul 22, 2015.

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

    Godbrandont

    Hello, I have recently been working on a plugin which detects if a player asks a certain question in chat and then display a message accordingly, however the actual answer pops up in chat before the player's chat message. I'd like this to be the other way around. Is there any way of doing this? An extract from my code is shown below:
    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e)
        {
            isPrivate = plugin.getConfig().getBoolean("private");
            Player p = e.getPlayer();
            String message = e.getMessage().toLowerCase();
            if(!p.hasPermission("helperbot.autoquestionexempt") && Cooldown.cooldown <= 0 || p.isOp())
            {
                //How do I leave spawn
                if(message.contains("how") && message.contains("do") && message.contains("i") && message.contains("start") || message.contains("how") && message.contains("leave") && message.contains("spawn") ||
                        message.contains("how") &&  message.contains("exit") && message.contains("spawn") || message.contains("how") &&  message.contains("depart") && message.contains("spawn") ||
                        message.contains("how") && message.contains("go out of") && message.contains("spawn") || message.contains("where") && message.contains("leave") && message.contains("spawn")
                        || message.contains("where") && message.contains("exit") && message.contains("spawn") || message.contains("where") && message.contains("depart") && message.contains("spawn")
                        || message.contains("where") && message.contains("go out of") && message.contains("spawn"))
                {
                    if(isPrivate == false)
                    {
                        Bukkit.broadcastMessage(Prefix.prefix() + " You can leave spawn via " + ChatColor.RED + "/portals " + ChatColor.AQUA + "or by simply just walking out.");
                        plugin.HelperBotCooldown();
                    }
                    else
                    {
                        p.sendMessage(Prefix.prefix() + " You can leave spawn via " + ChatColor.RED + "/portals " + ChatColor.AQUA + "or by simply just walking out.");
                        plugin.HelperBotCooldown();
                        e.setCancelled(true);
                    }
                }
                //Who is the owner
                else if(message.contains("who") && message.contains("are") && message.contains("owner") || message.contains("who") && message.contains("are") && message.contains("owna") || message.contains("hoo") && message.contains("is") && message.contains("owna") || message.contains("hoo") && message.contains("is") && message.contains("owner") || message.contains("who") && message.contains("is") && message.contains("owner") || message.contains("who") && message.contains("is") && message.contains("owna"))
                {
                    if(isPrivate == false)
                    {
                        Bukkit.broadcastMessage(Prefix.prefix() + " The owners of (server) are (owners).");
                        plugin.HelperBotCooldown();
                    }
                    else
                    {
                        p.sendMessage(Prefix.prefix() + " The owners of (server) are (owners).");
                        plugin.HelperBotCooldown();
                        e.setCancelled(true);
                    }
                }
    And this is what it currently looks like in chat.
    [​IMG]

    Any help would be appreciated on how to fix this problem. Preferably specific code. Thanks a lot.
     
  2. Send the message 1 tick later:
    new BukkitRunnable() {
    public void run() {
    //send message
    }
    }.runTaskLater(instanceOfMainClass, 1);
     
    Godbrandont likes this.
  3. Offline

    mine-care

    Compare booleans as: if(boolean) for true, and if(!boolean) for false.
    also your matching algorythm (line 29) isnt guaranteed to work... if i say "Who owns this server?" it will be bypassed.
    You may try with RegEx'es to find a more suitable one or just improve this one by doing a match level comparason :- )
     
  4. Offline

    Godbrandont

    Thanks a lot mate

    Yeah it's a work in progress, I have testers and such and it's nowhere near completion. Thanks for your feedback though

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  5. Offline

    mine-care

  6. Offline

    _Filip

    Oh hey Brandon

    I would just use the bukkit scheduler because it is quicker to write.

    Also instead of bool == false it is better to use !bool
     
    Last edited: Jul 22, 2015
  7. Offline

    Godbrandont

    Oh hey there, only just seen this.

    But yeah thanks, I always forget about using ! instead of == false, I've been doing a lot of python coding recently so I'm used to it.
     
Thread Status:
Not open for further replies.

Share This Page