Development Assistance ChatListener Not working.

Discussion in 'Plugin Help/Development/Requests' started by x_Jake_s, Dec 13, 2014.

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

    x_Jake_s

    My ChatListener:

    Code:
    package me.jacob.abc;
    
    import java.util.List;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    
    public class ChatListener implements Listener
    {
    
          public AnonymousBroadcaster plugin;
    
        @EventHandler
          public void onPlayerChat(AsyncPlayerChatEvent event)
          {
            Player player = event.getPlayer();
            if (!player.hasPermission("abc.swear.ignore"))
            {
              List<String> list = this.plugin.getConfig().getStringList("list");
              String msg = event.getMessage();
              for (int x = 0; x < list.toArray().length; x++)
              {
                String word = (String)list.toArray()[x];
                word = word.toLowerCase();
                if (msg.contains(word))
                {
                  if (this.plugin.getConfig().getBoolean("REPLACE_WORDS")) {
                    event.setMessage(event.getMessage().toLowerCase().replaceAll(word.toLowerCase(), this.plugin.getConfig().getString("NEW_MESSAGE")));
                    player.sendMessage("You cannot use that word.");
                  
                  }
    
                  }
                }
              }
            }
          }
    My Main Code(OnEnable, OnDisable Section)

    Code:
    public class AnonymousBroadcaster
      extends JavaPlugin
    {
      public Logger log = getLogger();
      public AnonymousBroadcaster plugin;
      public static final ChatListener cl = new ChatListener();
      @SuppressWarnings({ "unchecked", "rawtypes" })
      private List<String> broadcasts = new ArrayList();
      private int interval = 180;
      private int line = 0;
      @Override
      public void onDisable()
      {
        getLogger().info("ABC by x_jake_s is now disabled!");
      }
      @SuppressWarnings({ "unchecked", "rawtypes" })
      @Override
      public void onEnable()
       {
        getServer().getPluginManager().registerEvents(cl, this);
        getLogger().info("ABC by x_jake_s is now Enabled!");
        getConfig().options().copyDefaults(true);
        saveDefaultConfig();
        this.interval = getConfig().getInt("Interval");
        List<String> tempArray = getConfig()
          .getStringList("Broadcasts");
        List<String> bList = new ArrayList();
        for (String s : tempArray) {
          bList.add(ChatColor.translateAlternateColorCodes('&', s));
        }
        this.broadcasts = bList;
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this,
          new Runnable()
          {
            public void run()
            {
              AnonymousBroadcaster.this.broadcast();
            }
          }, 0L, this.interval * 20);
      }
    
      private void broadcast()
      {
        this.line += 1;
        if (this.line > this.broadcasts.size() - 1) {
          this.line = 0;
        }
        Bukkit.broadcastMessage((String)this.broadcasts.get(this.line));
      }
    Whenever i put this in my test server it loads find but when i type in my trigger word i put as a test it says
    [21:10:12 ERROR]: Could not pass event AsyncPlayerChatEvent to ABC v4.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[spigot.jar:git-Spigot-1571]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1571]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1571]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-1571]
    at net.minecraft.server.v1_7_R4.PlayerConnection.chat(PlayerConnection.java:932) [spigot.jar:git-Spigot-1571]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:872) [spigot.jar:git-Spigot-1571]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-Spigot-1571]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat$1.run(PacketPlayInChat.java:59) [spigot.jar:git-Spigot-1571]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_25]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_25]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_25]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
    at me.jacob.abc.ChatListener.onPlayerChat(ChatListener.java:21) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:296) ~[spigot.jar:git-Spigot-1571]
    ... 12 more
     
  2. Offline

    Skionz

    @x_Jake_s You never initialized 'plugin.'
     
  3. Offline

    x_Jake_s

    @Skionz where should it be initialized?

    still need help please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page