[SOLVED] Cooldown code breaks PlayerInteractEvent

Discussion in 'Spigot Plugin Development' started by Derugo, Jul 3, 2015.

  1. I'm working on adding a cooldown on one of my plugins but have never made a cooldown and have no clue what I'm doing.

    I've been following a cooldown tutorial/template: https://bukkit.org/threads/simple-cooldown-event-easy-tutorial-coding-for-noobs-and-others-d.209990/

    If possible, please let me know what/where I've gone wrong. All and any help is appreciated! If you know what needs fixing please tell me!

    The error I get when interacting with the item(s):
    Code (Text):

    [11:36:19] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to LobbySpeed v1.7.3
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:740) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_31]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:712) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
        at me.lobbyspeed.Main.onUseItem(Main.java:120) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        ... 17 more
     
    My main class:
    Code (Text):

    package me.lobbyspeed;

    import java.io.File;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitTask;
    import me.lobbyspeed.CoolDownManager;

    public class Main
      extends JavaPlugin
      implements Listener
    {
       
        public CoolDownManager cooldown;
         HashMap<String, Integer> cooldown1;
         
         public final Logger logger = Logger.getLogger("Minecraft");
         public static Main plugin;
         
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
        this.saveDefaultConfig();
       
        BukkitTask Cooldown = new CoolDownManager(this).runTaskTimer(this, 20, 20);
       
        cooldown1 = new HashMap<String, Integer>();
        this.plugin = plugin;

      }
      @EventHandler
      public void onJoin(PlayerJoinEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
             event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
             ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
              ItemMeta im = disable.getItemMeta();
              im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
              im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
              disable.setItemMeta(im);
              event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
             event.getPlayer().updateInventory();
      } else {
         if(this.getConfig().getString("speed-enabled-by-default") == "false"){
         event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
         ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
          ItemMeta im = enable.getItemMeta();
          im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
          im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
          enable.setItemMeta(im);
          event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
         event.getPlayer().updateInventory();
      }
      }
         }
         }
      @EventHandler
      public void onRespawn(PlayerRespawnEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
                 event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
               ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                 ItemMeta im = disable.getItemMeta();
                 im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                 im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                 disable.setItemMeta(im);
                 event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
               event.getPlayer().updateInventory();
         } else {
             if(this.getConfig().getString("speed-enabled-by-default") == "false"){
             event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
             ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
             ItemMeta im = enable.getItemMeta();
             im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
             im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
             enable.setItemMeta(im);
             event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
             event.getPlayer().updateInventory();
         }
         }
         }
             }
         
      private int cooldowntime = 10;
      @EventHandler
      public void onUseItem(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
       
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
       
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
           
                        event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
                        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.enable-buff")), 2, 1);
                       
                        ItemStack disable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                        ItemMeta im = disable2.getItemMeta();
                        im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                        im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                        disable2.setItemMeta(im);
                        event.getPlayer().getInventory().setItemInHand(disable2);
                       event.getPlayer().updateInventory();
                       
                       if(this.getConfig().getString("messages.enable-buff.enabled").equals("true")){
                           event.getPlayer().sendMessage(this.getConfig().getString("messages.enable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                       } else {
                           //Do nothing
                       }
      }
            }
      }else{
         event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }
      @EventHandler
      public void onUseItem2(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
       
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
       
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
           
                        event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
                     event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.disable-buff")), 2, 1);
                       ItemStack enable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
                       ItemMeta im = enable2.getItemMeta();
                       im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
                       im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
                       enable2.setItemMeta(im);
                       event.getPlayer().getInventory().setItemInHand(enable2);
                     event.getPlayer().updateInventory();
                     
                     if(this.getConfig().getString("messages.disable-buff.enabled").equals("true")){
                         event.getPlayer().sendMessage(this.getConfig().getString("messages.disable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                     } else {
                         //Do nothing
                     }
      }
            }
      }else{
                    event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }


      @EventHandler
      public void onDrop(PlayerDropItemEvent event)
      {
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
        if ((event.getPlayer().getGameMode() == GameMode.SURVIVAL) || (event.getPlayer().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
         }
      }
      @EventHandler
      public void onMoveItem(InventoryClickEvent event)
      {
         if (event.getWhoClicked().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if ((event.getWhoClicked()).getGameMode() == GameMode.SURVIVAL || (event.getWhoClicked().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
      }
      }
      @EventHandler
      public void onEntityDeath(EntityDeathEvent event)
      {
       if (event.getEntity().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
            event.getDrops().clear();
        }
      }
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if ((cmd.getName().equalsIgnoreCase("lobbyspeed")))
        {
            if (args.length < 1)
            {
                 sender.sendMessage("§8§l§m====================================");
                 sender.sendMessage("§f ");
                 sender.sendMessage(" §9§lLobbySpeed v" + Bukkit.getServer().getPluginManager().getPlugin("LobbySpeed").getDescription().getVersion() + ": §7Developed by Derugo");
                 sender.sendMessage(" §eReload Configuration: §c/lobbyspeed reload");
                 sender.sendMessage("§f ");
                 sender.sendMessage("§8§l§m====================================");
            }
            else
            {
                if (sender.hasPermission("lobbyspeed.reload")){
                if (args[0] == "reload");
            reloadConfig();
            saveConfig();
            sender.sendMessage("§a§oLobbySpeed configuration reloaded.");
        }
        return false;
    }
        return false;
    }
        return false;
    }
    }
     
    CoolDownManager class:
    Code (Text):

    package me.lobbyspeed;


    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;


    public class CoolDownManager extends BukkitRunnable {

    public Main plugin;

    public CoolDownManager(Main plugin){
    this.plugin = plugin;
    }

    public void run() {

    for(Player player : Bukkit.getServer().getOnlinePlayers()) {

      try{
          plugin.cooldown1.put(player.getName(), plugin.cooldown1.get(player.getName()) - 1);
      }catch(Exception e){
          plugin.cooldown1.put(player.getName(), 0);
      }
    }
    }
    }

     
     
  2. What is the 120 line in your main class?
     
  3. Error says line 120.

    Code (Text):
    event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.enable-buff")), 2, 1);
    Only thing that makes sense in context is "item-sounds.enable-buff" sound is null. Check your config to be sure its there and spelled correctly (its case sensitive, too).
     
  4. oh and if i were making a cool down i would use the System.getMilliSeconds() method to get the current millseconds and add it to a hashmap with the key being the player's name, and whenever the player right clicks i would use the TimeUnit class to convert the time into seconds and check is the difference is more than or equal to the cooldown time, if it is i would run the code and set the new value as the System.getMilliSeconds() and so on.
     
  5. Why? The minecraft clock (ticks) is a better idea.
     
  6. @BillyGalbreath All string names in the config are spelled correctly. The plugin worked perfectly fine until I added the cooldown code.

    Here's the default config.yml:
    Code (Text):

    #should the speed buff be enabled by default
    speed-enabled-by-default: false

    #inventory slot the item is placed in
    slot: 8

    #level of speed buff to give
    level: 3

    #world the plugin is enabled in
    enabled-world: world

    #change items and item names
    items:
      enable-buff: SUGAR
      disable-buff: SULPHUR
    item-names:
      enable-buff: '&b&lSpeed Buff &7(Right Click)'
      disable-buff: '&b&lSpeed Buff &7(Right Click)'
    item-lore:
      enable-buff: '&cRight click to enable your speed'
      disable-buff: '&cRight click to disable your speed'

    #customise the sounds
    item-sounds:
      enable-buff: ORB_PICKUP
      disable-buff: ANVIL_LAND

    #customise or disable the messages in chat (use %n for a new line)
    messages:
      enable-buff:
        enabled: true
        message: '&a&oSpeed buff enabled...'
      disable-buff:
        enabled: true
        message: '&c&oSpeed buff disabled...'

     
     
  7. every one has their own way :p, i'm more comfortable with that :)
     
  8. Is this the code as it was when the error you pasted happened? The error specifically says line 120 of your main class, and the only thing that could possibly be null (given the event that its happening in, the player will never be null) is the sound stuff.
     
  9. As billy said unless the 120th line is something else, there's nothing that could be null other than the config path.
     
  10. I'm pretty sure it was, but here's the latest one. Same error, just re-exported the plugin.

    main class:
    Code (Text):

    package me.lobbyspeed;

    import java.io.File;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitTask;
    import me.lobbyspeed.CoolDownManager;

    public class Main
      extends JavaPlugin
      implements Listener
    {
     
        public CoolDownManager cooldown;
         HashMap<String, Integer> cooldown1;
       
         public final Logger logger = Logger.getLogger("Minecraft");
         public static Main plugin;
       
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
        this.saveDefaultConfig();
     
        BukkitTask Cooldown = new CoolDownManager(this).runTaskTimer(this, 20, 20);
     
        cooldown1 = new HashMap<String, Integer>();
        this.plugin = plugin;

      }
      @EventHandler
      public void onJoin(PlayerJoinEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
             event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
             ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
              ItemMeta im = disable.getItemMeta();
              im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
              im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
              disable.setItemMeta(im);
              event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
             event.getPlayer().updateInventory();
      } else {
         if(this.getConfig().getString("speed-enabled-by-default") == "false"){
         event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
         ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
          ItemMeta im = enable.getItemMeta();
          im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
          im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
          enable.setItemMeta(im);
          event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
         event.getPlayer().updateInventory();
      }
      }
         }
         }
      @EventHandler
      public void onRespawn(PlayerRespawnEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
                 event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
               ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                 ItemMeta im = disable.getItemMeta();
                 im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                 im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                 disable.setItemMeta(im);
                 event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
               event.getPlayer().updateInventory();
         } else {
             if(this.getConfig().getString("speed-enabled-by-default") == "false"){
             event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
             ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
             ItemMeta im = enable.getItemMeta();
             im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
             im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
             enable.setItemMeta(im);
             event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
             event.getPlayer().updateInventory();
         }
         }
         }
             }
       
      private int cooldowntime = 10;
      @EventHandler
      public void onUseItem(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
     
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
     
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
         
                        event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
                        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.enable-buff")), 2, 1);
                     
                        ItemStack disable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                        ItemMeta im = disable2.getItemMeta();
                        im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                        im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                        disable2.setItemMeta(im);
                        event.getPlayer().getInventory().setItemInHand(disable2);
                       event.getPlayer().updateInventory();
                     
                       if(this.getConfig().getString("messages.enable-buff.enabled").equals("true")){
                           event.getPlayer().sendMessage(this.getConfig().getString("messages.enable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                       } else {
                           //Do nothing
                       }
      }
            }
      }else{
         event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }
      @EventHandler
      public void onUseItem2(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
     
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
     
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
         
                        event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
                     event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.disable-buff")), 2, 1);
                       ItemStack enable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
                       ItemMeta im = enable2.getItemMeta();
                       im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
                       im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
                       enable2.setItemMeta(im);
                       event.getPlayer().getInventory().setItemInHand(enable2);
                     event.getPlayer().updateInventory();
                   
                     if(this.getConfig().getString("messages.disable-buff.enabled").equals("true")){
                         event.getPlayer().sendMessage(this.getConfig().getString("messages.disable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                     } else {
                         //Do nothing
                     }
      }
            }
      }else{
                    event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }


      @EventHandler
      public void onDrop(PlayerDropItemEvent event)
      {
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
        if ((event.getPlayer().getGameMode() == GameMode.SURVIVAL) || (event.getPlayer().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
         }
      }
      @EventHandler
      public void onMoveItem(InventoryClickEvent event)
      {
         if (event.getWhoClicked().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if ((event.getWhoClicked()).getGameMode() == GameMode.SURVIVAL || (event.getWhoClicked().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
      }
      }
      @EventHandler
      public void onEntityDeath(EntityDeathEvent event)
      {
       if (event.getEntity().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
            event.getDrops().clear();
        }
      }
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if ((cmd.getName().equalsIgnoreCase("lobbyspeed")))
        {
            if (args.length < 1)
            {
                 sender.sendMessage("§8§l§m====================================");
                 sender.sendMessage("§f ");
                 sender.sendMessage(" §9§lLobbySpeed v" + Bukkit.getServer().getPluginManager().getPlugin("LobbySpeed").getDescription().getVersion() + ": §7Developed by Derugo");
                 sender.sendMessage(" §eReload Configuration: §c/lobbyspeed reload");
                 sender.sendMessage("§f ");
                 sender.sendMessage("§8§l§m====================================");
            }
            else
            {
                if (sender.hasPermission("lobbyspeed.reload")){
                if (args[0] == "reload");
            reloadConfig();
            saveConfig();
            sender.sendMessage("§a§oLobbySpeed configuration reloaded.");
        }
        return false;
    }
        return false;
    }
        return false;
    }
    }
    error:
    Code (Text):

    [12:08:06] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to LobbySpeed v1.7.3
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:698) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_31]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:712) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-870264a-0a645a2]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.NullPointerException
        at me.lobbyspeed.Main.onUseItem(Main.java:118) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-870264a-0a645a2]
        ... 18 more
    This error says its line 118.
     
  11. Ok this one says line 118, which is:

    Code (Text):

    plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
     
    We know plugin, cooldown1, and the player are not null because of the check 2 lines above it. This leaves only the cooldowntime variable, which you declare it directly above this event method. Move it to the top of your class and see what happens. This may just be a scope/ordering issue.
     
  12. Moved it to the top, still says error is on line 118.
    Code (Text):

    package me.lobbyspeed;

    import java.io.File;
    import java.io.IOException;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitTask;
    import me.lobbyspeed.CoolDownManager;

    public class Main
      extends JavaPlugin
      implements Listener
    {
       
        public CoolDownManager cooldown;
         HashMap<String, Integer> cooldown1;
         
         public final Logger logger = Logger.getLogger("Minecraft");
         public static Main plugin;
         
         private int cooldowntime = 10;
         
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
        this.saveDefaultConfig();
       
        BukkitTask Cooldown = new CoolDownManager(this).runTaskTimer(this, 20, 20);
       
        cooldown1 = new HashMap<String, Integer>();
        this.plugin = plugin;

      }
      @EventHandler
      public void onJoin(PlayerJoinEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
             event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
             ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
              ItemMeta im = disable.getItemMeta();
              im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
              im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
              disable.setItemMeta(im);
              event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
             event.getPlayer().updateInventory();
      } else {
         if(this.getConfig().getString("speed-enabled-by-default") == "false"){
         event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
         ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
          ItemMeta im = enable.getItemMeta();
          im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
          im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
          enable.setItemMeta(im);
          event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
         event.getPlayer().updateInventory();
      }
      }
         }
         }
      @EventHandler
      public void onRespawn(PlayerRespawnEvent event){
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             if(this.getConfig().getString("speed-enabled-by-default").equals("true")){
                 event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
               ItemStack disable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                 ItemMeta im = disable.getItemMeta();
                 im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                 im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                 disable.setItemMeta(im);
                 event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, disable);
               event.getPlayer().updateInventory();
         } else {
             if(this.getConfig().getString("speed-enabled-by-default") == "false"){
             event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
             ItemStack enable = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
             ItemMeta im = enable.getItemMeta();
             im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
             im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
             enable.setItemMeta(im);
             event.getPlayer().getInventory().setItem(this.getConfig().getInt("slot")-1, enable);
             event.getPlayer().updateInventory();
         }
         }
         }
             }
      @EventHandler
      public void onUseItem(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
       
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
       
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
                       
                        event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, this.getConfig().getInt("level")-1));
                        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.enable-buff")), 2, 1);
                       
                        ItemStack disable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase()), 1);
                        ItemMeta im = disable2.getItemMeta();
                        im.setDisplayName(this.getConfig().getString("item-names.disable-buff").replaceAll("&" , "§"));
                        im.setLore(Arrays.asList(this.getConfig().getString("item-lore.disable-buff").replaceAll("&" , "§")));
                        disable2.setItemMeta(im);
                        event.getPlayer().getInventory().setItemInHand(disable2);
                       event.getPlayer().updateInventory();
                       
                       if(this.getConfig().getString("messages.enable-buff.enabled").equals("true")){
                           event.getPlayer().sendMessage(this.getConfig().getString("messages.enable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                       } else {
                           //Do nothing
                       }
      }
            }
      }else{
         event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }
      @EventHandler
      public void onUseItem2(PlayerInteractEvent event) {
         if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(event.getPlayer().getInventory().getItemInHand().getType() == Material.getMaterial(this.getConfig().getString("items.disable-buff").toUpperCase())){
               if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
             }
       
      if (plugin.cooldown1.get(event.getPlayer().getName()) <= 0) {
       
                        plugin.cooldown1.put(event.getPlayer().getName(), cooldowntime);
                       
                        event.getPlayer().removePotionEffect(PotionEffectType.SPEED);
                     event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.valueOf(this.getConfig().getString("item-sounds.disable-buff")), 2, 1);
                       ItemStack enable2 = new ItemStack(Material.getMaterial(this.getConfig().getString("items.enable-buff").toUpperCase()), 1);
                       ItemMeta im = enable2.getItemMeta();
                       im.setDisplayName(this.getConfig().getString("item-names.enable-buff").replaceAll("&" , "§"));
                       im.setLore(Arrays.asList(this.getConfig().getString("item-lore.enable-buff").replaceAll("&" , "§")));
                       enable2.setItemMeta(im);
                       event.getPlayer().getInventory().setItemInHand(enable2);
                     event.getPlayer().updateInventory();
                     
                     if(this.getConfig().getString("messages.disable-buff.enabled").equals("true")){
                         event.getPlayer().sendMessage(this.getConfig().getString("messages.disable-buff.message").replaceAll("&" , "§").replaceAll("%n", "\n"));
                     } else {
                         //Do nothing
                     }
      }
            }
      }else{
                    event.getPlayer().sendMessage(ChatColor.RED + "You must wait " + ChatColor.BLUE + plugin.cooldown1.get(event.getPlayer().getName()) + ChatColor.RED + " seconds to reuse this item!");
      }
         }


      @EventHandler
      public void onDrop(PlayerDropItemEvent event)
      {
         if (event.getPlayer().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
        if ((event.getPlayer().getGameMode() == GameMode.SURVIVAL) || (event.getPlayer().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
         }
      }
      @EventHandler
      public void onMoveItem(InventoryClickEvent event)
      {
         if (event.getWhoClicked().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
         if ((event.getWhoClicked()).getGameMode() == GameMode.SURVIVAL || (event.getWhoClicked().getGameMode() == GameMode.ADVENTURE)) {
          event.setCancelled(true);
    }
      }
      }
      @EventHandler
      public void onEntityDeath(EntityDeathEvent event)
      {
       if (event.getEntity().getWorld().getName().equals(this.getConfig().getString("enabled-world"))){
            event.getDrops().clear();
        }
      }
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if ((cmd.getName().equalsIgnoreCase("lobbyspeed")))
        {
            if (args.length < 1)
            {
                 sender.sendMessage("§8§l§m====================================");
                 sender.sendMessage("§f ");
                 sender.sendMessage(" §9§lLobbySpeed v" + Bukkit.getServer().getPluginManager().getPlugin("LobbySpeed").getDescription().getVersion() + ": §7Developed by Derugo");
                 sender.sendMessage(" §eReload Configuration: §c/lobbyspeed reload");
                 sender.sendMessage("§f ");
                 sender.sendMessage("§8§l§m====================================");
            }
            else
            {
                if (sender.hasPermission("lobbyspeed.reload")){
                if (args[0] == "reload");
            reloadConfig();
            saveConfig();
            sender.sendMessage("§a§oLobbySpeed configuration reloaded.");
        }
        return false;
    }
        return false;
    }
        return false;
    }
    }
     
  13. Do me a favor, and use pastebin so I can see line numbers exactly how you see them since your code isnt formatted.
     
  14. Found the problem.

    You never initialized the variable plugin so it's null. What you did is set plugin to plugin, which is basically null, you should to plugin = this; instead of this.plugin = plugin; or just straight up use this.cooldown1 instead of plugin.cooldown1
     
    • Winner Winner x 1
  15. http://pastebin.com/EbxGrjcY
     
  16. Edandre found it. ^_^

    Looking at the pastebin I am able to see that. When I copied your code into an editor the line numbers were different. Blame the forum software for that. :p
     
    • Like Like x 1
  17. Wow, thanks xD <3

    For some reason it's not showing the cooldown message, do you perhaps know what's gone wrong there? There's no error.
     
  18. Your else statement is at the wrong if statement's bracket ^_^
     
    • Like Like x 1
  19. Lol, forgot to change it back, thought that was the issue in the first place before posting this thread. Thank you so much @Edandre and @BillyGalbreath <3
     
    • Friendly Friendly x 1
  20. No problem, mark the thread as solved ;)