Chat Cooldown Help

Discussion in 'Plugin Development' started by Munnzeh, Jan 9, 2014.

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

    Munnzeh

    I am getting a series of Console errors when ever i send a message in Chat.
    Basically i am trying to create a Chat cooldown Timer to avoid potential spam within Chat.

    Code:java
    1. public class MGChatCooldown implements Listener {
    2.  
    3.  
    4. public MGV2Main plugin;
    5.  
    6. public MGChatCooldown(MGV2Main plugin) {
    7. this.plugin = plugin;
    8. }
    9.  
    10.  
    11.  
    12. public MGChatCooldown() {
    13. }
    14.  
    15.  
    16.  
    17. public static List<String> cooldown = new ArrayList<String>();
    18.  
    19. int cd = 5;
    20. int cdtimer = 5;
    21.  
    22. @EventHandler
    23. public void onCooldownChat(AsyncPlayerChatEvent e) {
    24. final Player p = e.getPlayer();
    25.  
    26. cd = plugin.getServer().getScheduler()
    27. .scheduleSyncRepeatingTask(plugin, new Runnable() {
    28. public void run() {
    29. if (cdtimer != -1) {
    30. if (cdtimer != 0) {
    31. Bukkit.broadcast(ChatColor.RED
    32. + "Chat Cooldown Debug.. processing.",
    33. "Admin.Debug");
    34. cdtimer--;
    35. }
    36. else if (cdtimer == 4) {
    37. cooldown.add(p.getName());
    38. }
    39.  
    40. else if (cdtimer == 0) {
    41. cooldown.remove(p.getName());
    42. Bukkit.getServer().getScheduler()
    43. .cancelTask(cd);
    44. }
    45. }
    46. }
    47.  
    48. }, 20, 100);
    49. }
    50.  
    51. }
    52.  


    Here are my console errors.

    Code:
    14:53:16 [SEVERE] Could not pass event AsyncPlayerChatEvent to Minigames v2.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:459)
            at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.j
    ava:891)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :842)
            at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R3.NetworkManager.i(NetworkManager.java:213
    )
            at net.minecraft.server.v1_6_R3.NetworkManager.c(NetworkManager.java:351
    )
            at net.minecraft.server.v1_6_R3.NetworkReaderThread.run(SourceFile:94)
    Caused by: java.lang.NullPointerException
            at me.Listeners.Munnzeh.MGChatCooldown.onCooldownChat(MGChatCooldown.jav
    a:40)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 9 more
     
  2. Offline

    Yonas

    You can use my CooldownManager if you want:
    http://snip.sweetcode.de/code/22

    Example:
    Code:
    public class TheCore extends JavaPlugin implements Listener {
        
        private CooldownManager cooldownManager;
        
        @EventHandler
        public void onEnable() { 
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            cooldownManager = new CooldownManager(5, Time.SECONDS);
        }
        
        @EventHandler
        public void onChat(AsyncPlayerChatEvent e) {
            if(!(cooldownManager.interact(e.getPlayer()))) {
                e.getPlayer().sendMessage("Please wait " + cooldownManager.timeLeft(e.getPlayer(), Time.SECONDS) + " Seconds");
                e.setCancelled(true);
                return;
            }
        }
    
    }
    
     
  3. Offline

    Jake6177

    Yonas I'm bookmarking that link. If I start making plugins again, that is going to be so ridiculously useful to me. >:)
     
    Yonas likes this.
Thread Status:
Not open for further replies.

Share This Page