Solved Enderpearl Cooldown Timer

Discussion in 'Plugin Development' started by HCMatt, Nov 21, 2018.

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

    HCMatt

    Okay so...

    I had this working, but i had it in the same plugin as many other things so I have split all the plugins into their own plugins. Ever since I did that, every other plugin works but this one and I can't figure out why. Here is the code:

    Code:
        
    //Hashmap
    private HashMap<Player, Integer> cooldownTime;
    private HashMap<Player, BukkitRunnable> cooldownTask;
    
    
    
    //Pearl Event
        @EventHandler
        public void onInteract(final PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            final Action a = e.getAction();
    
            if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getType() == Material.ENDER_PEARL) {
                   //Test Message p.sendMessage("pearl");
                    if (cooldownTime.containsKey(p)) {
                        e.setCancelled(true);
                        p.sendMessage(ChatColor.RED + "You can't pearl yet! Time Remaining: " + ChatColor.AQUA + cooldownTime.get(p));
                        return;
                    } else {
                        cooldownTime.put(p, getConfig().getInt("Revelation.Enderpearl Cooldown"));
                        cooldownTask.put(p, new BukkitRunnable() {
                            public void run() {
                                cooldownTime.put(p, cooldownTime.get(p) - 1);
                                if (cooldownTime.get(p) == 0) {
                                    cooldownTime.remove(p);
                                    cooldownTask.remove(p);
                                    cancel();
                                }
                            }
                        });
    
                        cooldownTask.get(p).runTaskTimer(this, 20, 20);
    
                        return;
                    }
                }
            }
            return;
        }

    Here is the error in console:

    Code:
    [18:59:15 ERROR]: Could not pass event PlayerInteractEvent to RevPearl v2.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[spigot-1.7.10.jar:git-Spigot-1592]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.7.10.jar:git-Spigot-1592]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.7.10.jar:git-Spigot-1592]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.7.10.jar:git-Spigot-1592]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:242) [spigot-1.7.10.jar:git-Spigot-1592]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:212) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:636) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a(SourceFile:60) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle(SourceFile:9) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot-1.7.10.jar:git-Spigot-1592]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot-1.7.10.jar:git-Spigot-1592]
    Caused by: java.lang.NullPointerException
            at rev.pearl.tizz.RevPearl.onInteract(RevPearl.java:46) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[spigot-1.7.10.jar:git-Spigot-1592]
            ... 15 more
    >
     
  2. Offline

    timtower Administrator Administrator Moderator

    @HCMatt getItemInHand can return null
     
  3. Offline

    HCMatt

    But the line that is throwing the error is : if (cooldownTime.containsKey(p)) {
     
  4. Offline

    timtower Administrator Administrator Moderator

    cooldownTime is null, you never initialize it.
     
  5. Offline

    HCMatt

    But this was all working before.. Why isnt it now? and would you know how i would go about fixing it
     
  6. Offline

    timtower Administrator Administrator Moderator

    private HashMap<Player, Integer> cooldownTime = new HashMap<Player, Integer>()
     
  7. Offline

    HCMatt

    Wait... Thats so obvious xD I feel so dumb... but I copied and pasted exactly what was in the old plugin so how did it work before? :S

    Anyway thanks it worked!!
     
  8. Offline

    timtower Administrator Administrator Moderator

    Maybe the old plugin used the onEnable to set the variable to something.
     
  9. Offline

    HCMatt

    You're completely right .-.!
    Thanks again
     
Thread Status:
Not open for further replies.

Share This Page