Solved Error but everything works?

Discussion in 'Spigot Plugin Development' started by TutForMinecraft, Jun 16, 2016.

  1. So I am working on a VERY simple death chest plugin for my server, everything is working but I am getting an error in the console. Just trying to figure out why.

    Classes:
    Main:
    Code (Text):
    package me.robert.dc;

    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class DeathChest extends JavaPlugin {

        private JavaPlugin plugin;
        private PluginManager pluginManager;

        public void onEnable() {
            this.plugin = this;
            this.pluginManager = this.getServer().getPluginManager();

            registerListeners();
        }

        private void registerListeners() {
            pluginManager.registerEvents(new PlayerDeathListener(), this);
        }

        public JavaPlugin getPlugin() {
            return plugin;
        }
    }
     
    Listener:

    Code (Text):
    package me.robert.dc;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.block.Chest;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    public class PlayerDeathListener implements Listener {

        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event) {
            Player player = event.getEntity();
            World world = player.getWorld();
            Inventory inventory = player.getInventory();
            Location deathLocation = player.getLocation();
            ItemStack[] drops = inventory.getContents();
            event.getDrops().clear();

            world.getBlockAt(deathLocation).setType(Material.CHEST);
            getNextAirBlock(world.getBlockAt(deathLocation));

            Chest chest = (Chest) world.getBlockAt(deathLocation).getState();
            player.sendMessage("Block Inventory: " + chest.getBlockInventory().getSize());
            player.sendMessage("Inventory: " + chest.getInventory().getSize());

            for (ItemStack itemStack : drops) {
                chest.getInventory().addItem(itemStack);
            }
        }

        private void getNextAirBlock(Block block) {
            if (block.getRelative(BlockFace.NORTH).getType().equals(Material.AIR)) {
                block.getRelative(BlockFace.NORTH).setType(Material.CHEST);
                return;
            } else if (block.getRelative(BlockFace.EAST).getType().equals(Material.AIR)) {
                block.getRelative(BlockFace.EAST).setType(Material.CHEST);
                return;
            } else if (block.getRelative(BlockFace.SOUTH).getType().equals(Material.AIR)) {
                block.getRelative(BlockFace.SOUTH).setType(Material.CHEST);
                return;
            } else if (block.getRelative(BlockFace.WEST).getType().equals(Material.AIR)) {
                block.getRelative(BlockFace.WEST).setType(Material.CHEST);
                return;
            } else {
                System.out.println("--- NO AIR ---");
            }
        }
    }
     
    ERROR:
    Code (Text):
    16.06 09:59:03 [Server] ERROR Could not pass event PlayerDeathEvent to DeathChest v2.0.0
    16.06 09:59:03 [Server] INFO org.bukkit.event.EventException
    16.06 09:59:03 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:409) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.EntityPlayer.die(EntityPlayer.java:409) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.EntityLiving.damageEntity(EntityLiving.java:901) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.EntityHuman.damageEntity(EntityHuman.java:772) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.EntityPlayer.damageEntity(EntityPlayer.java:500) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.EntityLiving.Q(EntityLiving.java:112) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.CommandKill.execute(SourceFile:35) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.command.VanillaCommandWrapper.dispatchVanillaCommand(VanillaCommandWrapper.java:108) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:43) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1296) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1156) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
    16.06 09:59:03 [Server] INFO at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:690) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:646) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 09:59:03 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:550) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]

    Send
     
    Any help as always is apreciated.
     
  2. Copy the full stack trace, including those after "Caused by ... ".
     
  3. What I posted is literally all I get in the console when a player dies, I cleared the console then used /kill and got this:
    Code (Text):
    16.06 11:16:43 [Server] ERROR Could not pass event PlayerDeathEvent to DeathChest v2.0.0
    16.06 11:16:43 [Server] INFO org.bukkit.event.EventException
    16.06 11:16:43 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:409) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.EntityPlayer.die(EntityPlayer.java:409) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.EntityLiving.damageEntity(EntityLiving.java:901) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.EntityHuman.damageEntity(EntityHuman.java:772) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.EntityPlayer.damageEntity(EntityPlayer.java:500) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.EntityLiving.Q(EntityLiving.java:112) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.CommandKill.execute(SourceFile:35) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.command.VanillaCommandWrapper.dispatchVanillaCommand(VanillaCommandWrapper.java:108) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:43) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1296) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1156) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
    16.06 11:16:43 [Server] INFO at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:690) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:646) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
    16.06 11:16:43 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:550) [craftbukkit_1.10.jar:git-Bukkit-fb568fd]
     
  4. I don't even see your class mentioned in the stack trace... Does removing the plugin prevents the exception?
     
  5. I thought that was weird too, I removed the plugin and yes it has made it so I don't get the exceptions.
     
  6. @TutForMinecraft
    Code (Java):
    player.sendMessage("Block Inventory: " + chest.getBlockInventory().getSize());
            player.sendMessage("Inventory: " + chest.getInventory().getSize());
    Is this being printed?
     
  7. Yes it prints out:
    Block Inventory: 27
    Inventory: 54
     
  8. @TutForMinecraft make a non-null check on the ItemStack in the drops for-loop. Some elements can be null
     
  9. I totally forgot about that! Thank you that fixed it.

    What I changed in case someone else needs to know
    Code (Text):
    for (ItemStack itemStack : drops) {
                if (!(itemStack == null))
                    chest.getInventory().addItem(itemStack);
            }