Need help - PlayerDropItemEvent

Discussion in 'Spigot Plugin Development' started by augesrob.com, May 19, 2016.

  1. Download Link
    https://www.spigotmc.org/resources/social-jump.21466/

    Could not pass event PlayerDropItemEvent to SocialJump v1.3
    org.bukkit.event.EventException

    Compiled in 1.8 for version 1.9.4

    Code (Text):
    package me.socialclubz.com;


    import java.util.ArrayList;
    import java.util.HashMap;
    import org.bukkit.Bukkit;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.FoodLevelChangeEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.util.Vector;

    public class Listeners
      implements Listener
    {
      private SocialJump plugin;
      public String prefix = "[SocialJump] ";
      public String noperm = SocialJump.m7;
      public String help = "For Help: /SocialJump help";

      public Listeners(SocialJump SocialJump)
      {
        this.plugin = SocialJump;
        this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
      }

      @EventHandler
      public void onFeed(FoodLevelChangeEvent e)
      {
        if ((e.getEntity() instanceof Player))
        {
          Player p = (Player)e.getEntity();
          if (this.plugin.InGame.contains(p.getName())) {
            e.setCancelled(true);
          }
        }
      }

      @EventHandler
      public void ItemPickup(PlayerPickupItemEvent e)
      {
        if (this.plugin.InGame.contains(e.getPlayer().getName())) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void ItemDrop(PlayerDropItemEvent e)
      {
        if (this.plugin.InGame.contains(e.getPlayer().getName())) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void CommandsDeny(PlayerCommandPreprocessEvent e)
      {
        if ((this.plugin.InGame.contains(e.getPlayer().getName())) &&
          (!e.getMessage().contains("/socialjump")))
        {
          e.setCancelled(true);
          e.getPlayer().sendMessage(this.plugin.prefix + SocialJump.m8);
        }
      }

      @EventHandler
      public void PlayerDeny(EntityDamageEvent e)
      {
        if ((e.getEntity() instanceof Player))
        {
          Player p = (Player)e.getEntity();
          if (this.plugin.InGame.contains(p.getName())) {
            e.setCancelled(true);
          }
        }
      }

      @EventHandler
      public void onQuit(PlayerQuitEvent e)
      {
        this.plugin.leaveArena(e.getPlayer());
      }

      @EventHandler
      public void onBlockBreak(BlockBreakEvent e)
      {
        if (this.plugin.InGame.contains(e.getPlayer().getName())) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void BlockPlace(BlockPlaceEvent e)
      {
        if (this.plugin.InGame.contains(e.getPlayer().getName())) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void onDamage(EntityDamageEvent e)
      {
        if ((e.getEntity() instanceof Player))
        {
          Player p = (Player)e.getEntity();
          if (this.plugin.InGame.contains(p.getName())) {
            e.setCancelled(true);
          }
        }
      }

      @EventHandler
      public void PlayerMove(PlayerMoveEvent e)
      {
        if (this.plugin.InGame.contains(e.getPlayer().getName()))
        {
          Player p = e.getPlayer();
          Block b = p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
          if (b.getType() == Material.SEA_LANTERN)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 100.0F, 500.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 10));
          }
          if (b.getType() == Material.DIAMOND_BLOCK)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 100.0F, 500.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2500, 10));
          }
          if (b.getType() == Material.SAND)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 100.0F, 500.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 10));
          }
          if (b.getType() == Material.SOUL_SAND)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 100.0F, 500.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 10));
          }
          if (b.getType() == Material.OBSIDIAN) {
            teleportToSpawn(p);
          }
          if (b.getType() == Material.STATIONARY_WATER) {
            teleportToSpawn(p);
          }
          if (b.getType() == Material.STATIONARY_LAVA) {
            teleportToSpawn(p);
          }
          if (b.getType() == Material.EMERALD_ORE)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 3.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 80, 2));
          }
          if (b.getType() == Material.EMERALD_BLOCK)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 3.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 80, 10));
          }
          if (b.getType() == Material.BEDROCK)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 3.0F);
            p.removePotionEffect(PotionEffectType.REGENERATION);
            p.removePotionEffect(PotionEffectType.SPEED);
            p.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
            p.removePotionEffect(PotionEffectType.POISON);
            p.removePotionEffect(PotionEffectType.HEALTH_BOOST);
            p.removePotionEffect(PotionEffectType.NIGHT_VISION);
            p.removePotionEffect(PotionEffectType.WEAKNESS);
            p.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
            p.removePotionEffect(PotionEffectType.SLOW);
            p.removePotionEffect(PotionEffectType.JUMP);
            p.removePotionEffect(PotionEffectType.HARM);
            p.removePotionEffect(PotionEffectType.WATER_BREATHING);
            p.removePotionEffect(PotionEffectType.INVISIBILITY);
            p.removePotionEffect(PotionEffectType.ABSORPTION);
            p.removePotionEffect(PotionEffectType.BLINDNESS);
            p.removePotionEffect(PotionEffectType.CONFUSION);
            p.removePotionEffect(PotionEffectType.FAST_DIGGING);
            p.removePotionEffect(PotionEffectType.HUNGER);
            p.removePotionEffect(PotionEffectType.SATURATION);
            p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
            p.removePotionEffect(PotionEffectType.WITHER);
          }
          if (b.getType() == Material.BEACON)
          {
            this.plugin.InGame.remove(p.getName());
         
            p.getInventory().clear();
            ItemStack[] old = (ItemStack[])this.plugin.oldItems.get(p.getName());
            p.getInventory().setContents(old);
            p.updateInventory();
         
            Location loc = (Location)this.plugin.oldLoc.get(p.getName());
            p.teleport(loc);
         
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 2.0F);
            p.playEffect(p.getLocation(), Effect.FIREWORKS_SPARK, 1);
            p.sendMessage(this.plugin.prefix + SocialJump.m9);
            p.performCommand("socialjumpmenu");
          }
          if ((p.getLocation().getBlock().getType() == Material.AIR) &&
            (p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().getType() == Material.IRON_BLOCK))
          {
            Vector v = p.getLocation().getDirection().multiply(3.0D).setY(0.8D);
            p.setVelocity(v);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 0.0D, 0.0D), Effect.INSTANT_SPELL, 1);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 0.5D, 0.0D), Effect.INSTANT_SPELL, 1);
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 500.0F, 500.0F);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 1.5D, 0.0D), Effect.INSTANT_SPELL, 1);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 2.0D, 0.0D), Effect.INSTANT_SPELL, 1);
          }
          if ((p.getLocation().getBlock().getType() == Material.AIR) &&
            (p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().getType() == Material.SLIME_BLOCK))
          {
            Vector v2 = p.getLocation().getDirection().multiply(0.0D).setY(1.0D);
            p.setVelocity(v2);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 0.0D, 0.0D), Effect.COLOURED_DUST, 1);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 0.5D, 0.0D), Effect.COLOURED_DUST, 1);
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 500.0F, 500.0F);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 1.5D, 0.0D), Effect.COLOURED_DUST, 1);
            p.getWorld().playEffect(p.getLocation().add(0.0D, 2.0D, 0.0D), Effect.COLOURED_DUST, 1);
          }
          if (b.getType() == Material.LAPIS_BLOCK)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 3.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 80, 2));
          }
          if (b.getType() == Material.PACKED_ICE)
          {
            p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 3.0F);
            p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000, 2));
          }
        }
      }

      @EventHandler
      public void onDrop(PlayerDropItemEvent e)
      {
        if (e.getItemDrop() == null) {
          return;
        }
        if (e.getItemDrop().getItemStack().getItemMeta().getDisplayName().equalsIgnoreCase(SocialJump.m14)) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void teleportToSpawn(Player p)
      {
        FileConfiguration cfg = this.plugin.getConfig();
     
        String world = cfg.getString("Start.World");
        double x = cfg.getDouble("Start.PosX");
        double y = cfg.getDouble("Start.PosY");
        double z = cfg.getDouble("Start.PosZ");
        double yaw = cfg.getDouble("Start.PosYaw");
        double pitch = cfg.getDouble("Start.PosPitch");
        Location loc = new Location(Bukkit.getWorld(world), x, y, z);
        loc.setPitch((float)pitch);
        loc.setYaw((float)yaw);
     
        p.teleport(loc);
     
        p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 500.0F, 500.0F);
        p.sendMessage(this.plugin.prefix + SocialJump.m10);
      }

      @EventHandler
      public void onClick(InventoryClickEvent e)
      {
        if (e.getCurrentItem() == null) {
          return;
        }
        if (!e.getCurrentItem().hasItemMeta()) {
          return;
        }
        if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(SocialJump.m14)) {
          e.setCancelled(true);
        }
      }

      @EventHandler
      public void onInteract(PlayerInteractEvent e)
      {
        Player p = e.getPlayer();
        if (e.getItem() == null) {
          return;
        }
        if (!e.getItem().hasItemMeta()) {
          return;
        }
        if ((this.plugin.InGame.contains(p.getName())) &&
          (e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(SocialJump.m14)))
        {
          p.getInventory().clear();
          ItemStack[] old = (ItemStack[])this.plugin.oldItems.get(p.getName());
          p.getInventory().setContents(old);
          this.plugin.InGame.remove(p.getName());
          p.updateInventory();
       
          Location loc = (Location)this.plugin.oldLoc.get(p.getName());
          p.teleport(loc);
       
          p.playSound(p.getLocation(), Sound.BLOCK_WOOD_FALL, 3.0F, 2.0F);
          p.sendMessage(this.plugin.prefix + SocialJump.m4);
        }
      }

      @EventHandler
      public void onPlayerSignInteract(PlayerInteractEvent e)
      {
        Player p = e.getPlayer();
        if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
        {
          Block i = e.getClickedBlock();
          if ((i.getState() instanceof Sign))
          {
            BlockState stateBlock = i.getState();
            Sign sign = (Sign)stateBlock;
            if ((sign.getLine(0).equalsIgnoreCase("[SJ]")) && (sign.getLine(1).equalsIgnoreCase("Join")))
            {
              sign.setLine(0, "- SJ -");
              sign.setLine(1, SocialJump.m23);
              sign.setLine(2, SocialJump.m22);
              sign.setLine(3, SocialJump.m24);
              sign.update(true);
            }
            if (sign.getLine(0).equalsIgnoreCase("- SJ -")) {
              p.performCommand("socialjump join");
            }
          }
        }
      }

      @EventHandler
      public void createrJoin(PlayerJoinEvent event)
      {
        Player player = event.getPlayer();
        if (player.getPlayerListName().equalsIgnoreCase("EnderFrancy")) {
          player.sendMessage(" ");
        }
      }

      @EventHandler
      public void Inventory(InventoryClickEvent event)
      {
        Player p = (Player)event.getWhoClicked();
        if (event.getInventory().getName().equalsIgnoreCase(SocialJump.m18))
        {
          event.setCancelled(true);
          if (event.getCurrentItem().getType() == Material.IRON_INGOT)
          {
            p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_HURT, 5.0F, 5.0F);
            p.sendMessage(this.prefix + SocialJump.m11);
            SocialJump.m19.replaceAll("%player%", p.getName());
            Bukkit.dispatchCommand(p, SocialJump.m19.replaceAll("%player%", p.getName()));
            event.getView().close();
          }
          event.setCancelled(true);
          if (event.getCurrentItem().getType() == Material.GOLD_INGOT)
          {
            p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_HURT, 5.0F, 5.0F);
            p.sendMessage(this.prefix + SocialJump.m12);
            SocialJump.m20.replaceAll("%player%", p.getName());
            Bukkit.dispatchCommand(p, SocialJump.m20.replaceAll("%player%", p.getName()));
            event.getView().close();
          }
          event.setCancelled(true);
          if (event.getCurrentItem().getType() == Material.DIAMOND)
          {
            p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_HURT, 5.0F, 5.0F);
            p.sendMessage(this.prefix + SocialJump.m13);
            SocialJump.m21.replaceAll("%player%", p.getName());
            Bukkit.dispatchCommand(p, SocialJump.m21.replaceAll("%player%", p.getName()));
            event.getView().close();
          }
        }
      }
    }

    Code (Text):

    [23:39:05 ERROR]: Could not pass event PlayerDropItemEvent to SocialJump v1.3
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.EntityHuman.a(EntityHuman.java:560) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.EntityHuman.drop(EntityHuman.java:516) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.CommandGive.execute(SourceFile:75) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.craftbukkit.v1_9_R2.command.VanillaCommandWrapper.dispatchVanillaCommand(VanillaCommandWrapper.java:108) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.craftbukkit.v1_9_R2.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:43) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:645) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.Bukkit.dispatchCommand(Bukkit.java:580) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at me.socialclubz.com.Listeners.Inventory(Listeners.java:404) [Social-Jump.jar:?]
            at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1851) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at me.socialclubz.com.Listeners.onDrop(Listeners.java:272) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-4e19de1]
            ... 31 more

     
     
    #1 augesrob.com, May 19, 2016
    Last edited: May 19, 2016
  2. You are receiving a NPE, so one of those variables are null.
     
  3. You need to check:
    1. If the Item has ItemMeta
    2. If the Item has a display name
    3. That you correctly initialized 'm14' of the SocialJump class
    EDIT: