AsyncPlayerChatEvent is not working

Discussion in 'Spigot Plugin Development' started by theminerrick, Jun 2, 2015.

  1. hello guys i am making a anticurse plugin only the asyncplayerchatevent is not working i tryed to debug it but with no results. here is my code:

    Code (Text):
    package eu.thenlterms.chathelper;

    import java.util.HashMap;

    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import eu.thenlterms.chathelper.configs.BlackListedWords;

    public class CurseListener implements Listener {

        BlackListedWords b = BlackListedWords.getInstance();
        HashMap<String, String> lastmessage = new HashMap<String, String>();

        public Main plugin;
        public CurseListener(Main instance) {

        public void oncurse(AsyncPlayerChatEvent e){
                String message  = plugin.getConfig().getString("disabledchat");
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
                if(plugin.getConfig().getBoolean("anticurse") ==true){
                    for (String word : e.getMessage().split(" ")){
                        String message  = plugin.getConfig().getString("forbiddenword");
                        e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
                if(lastmessage.containsKey(e.getPlayer().getUniqueId()) && lastmessage.containsValue(e.getMessage())){
                    String message  = plugin.getConfig().getString("antispammessage");
                    e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
    someone any idea's how i can fix it
  2. clip


    Did you register the event onEnable?
  3. Yes i did.
  4. ==true. wat.

    On topic:
    Are you getting any stacktraces in console?
  5. nope i don't get any stacktraces
  6. Do you know if the function is called at all?
    Like if you add a debug message at the start of the method.
  7. i tried but i didn't get the message
  8. Then there must be something wrong with registering your events.
  9. i don't really know what can be the fault
    here is my main code:

    Code (Text):
    package eu.thenlterms.chathelper;

    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginManager;

    import eu.thenlterms.chathelper.configs.BlackListedWords;

    public class Main extends JavaPlugin{

        public Logger log = Logger.getLogger("Minecraft");

        public void onEnable() {"[ChatHelper] " + this.getDescription().getVersion() + " Has been loaded.");
        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(new CurseListener(this), this);
        getCommand("togglechat").setExecutor(new CommandToggleChat(this));
        public void onDisable() {
  "[ChatHelper] " + this.getDescription().getVersion() + " Has been Unloaded.");
  10. Do you have a plugin.yml that points to the correct main class?
  11. yes
  12."[ChatHelper] " + this.getDescription().getVersion() + " Has been loaded.");
    And this does get triggered?
  13. yes
  14. Is togglechat enabled in your config?

    and are you OP?
  15. yes and i tried with op and without op
  16. Alright, I want you to try something,
    Delete everything, or comment it out of that function, and replace it with this.
    And tell me if it shows up in your console:

    Code (Text):
    public void oncurse(AsyncPlayerChatEvent e) {
  17. this works
  18. Alright, so the onCurse function does get triggered. That's good.
    We're getting somewhere.

    What I should try to do, is debug every thing you are testing, see what returns false.

    Just check which one returns false ;)
  19. the last one returns false also when run /togglechat
  20. Well, then I should start looking at the ChatStates.isState method ;)