Plugin error not understanding

Discussion in 'Plugin Development' started by linkrock4, Nov 27, 2012.

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

    linkrock4

    Hey, i'm having this plugin error and i'm not finding out why and i would just to know how to fix it :D

    ERROR:
    Code:
    [SEVERE] Could not pass event BlockPlaceEvent to Christmas v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(CraftEventFactory.java:99)
        at net.minecraft.server.ItemBlock.interactWith(ItemBlock.java:78)
        at net.minecraft.server.ItemStack.placeItem(ItemStack.java:87)
        at net.minecraft.server.ItemInWorldManager.interact(ItemInWorldManager.java:392)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:662)
        at net.minecraft.server.Packet15Place.handle(SourceFile:58)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:113)
        at net.minecraft.server.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
        at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: java.lang.NullPointerException
        at net.minecraft.server.ItemStack.setData(ItemStack.java:157)
        at net.minecraft.server.ItemStack.<init>(ItemStack.java:41)
        at org.bukkit.craftbukkit.inventory.CraftItemStack.<init>(CraftItemStack.java:61)
        at org.bukkit.craftbukkit.inventory.CraftItemStack.<init>(CraftItemStack.java:49)
        at org.bukkit.craftbukkit.inventory.CraftItemStack.<init>(CraftItemStack.java:27)
        at org.bukkit.craftbukkit.inventory.CraftInventory.firstPartial(CraftInventory.java:232)
        at org.bukkit.craftbukkit.inventory.CraftInventory.addItem(CraftInventory.java:258)
        at net.skydevs.src.Christmas.onBlockPlace(Christmas.java:51)
        at sun.reflect.GeneratedMethodAccessor3.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.java:339)
        ... 18 more
    
    CODE:
    Code:
    package net.skydevs.src;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.inventory.ItemStack;
    import java.util.Random;
     
    public class Christmas extends JavaPlugin implements Listener {
        Random rand = new Random();
        public String ChristmasMessage;
     
        public void onEnable() { // Server Starts
            getLogger().info("Christmas Plugin has been enabled!");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
     
        }
     
        public void onDisable() { // Server Stops
            getLogger().info("Christmas Plugin has been disabled!");
     
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String Label,
                String[] args) {
     
            if (cmd.getName().equalsIgnoreCase("Christmas")) {
                Bukkit.broadcastMessage(ChatColor.BLACK+ "["+ ChatColor.RED+ "Christmas"+ ChatColor.BLACK+ "] "+ ChatColor.GREEN+ "Happy "+ ChatColor.RED+ "Christmas "+ ChatColor.GREEN+ "everyone! We hope you enjoy the new features we have for you!");
     
            }
     
            return false;
        }
       
        @EventHandler
        @SuppressWarnings("deprecation")
        public void onBlockPlace(BlockPlaceEvent e) {
            Block b = e.getBlockPlaced();
            if (b.getTypeId() == 56) {
                int id = 0;
                id = rand.nextInt(400);
                e.getPlayer().sendMessage(ChatColor.BLACK + "[" + ChatColor.RED + "Christmas"+ ChatColor.BLACK + "] " + ChatColor.GREEN+ "Ho! Ho! Ho! " + ChatColor.RED+ "Merry Christmas! Enjoy your gift!");
                e.getPlayer().getInventory().addItem(new ItemStack(id, 1));
                e.getPlayer().updateInventory();
                e.getPlayer().getInventory().removeItem(new ItemStack(56, 1));
                e.getPlayer().updateInventory();
                e.setCancelled(true);
            }
        }
    }
    Thanks!
     
  2. Offline

    NoLiver92

    which is line 157 in ItemStack.java?
     
  3. Offline

    JazzaG

    You're giving the player an item with Id that could go as high as 400. Do blocks even go that high?
     
  4. Offline

    raGan.

    Yes, items follow after blocks, but there is a hole between those groups.
     
  5. Offline

    NoLiver92

    yes but not all values are used, if your code calls one that isnt used, you would get that error. what i would do is put the values you want into an array and then randomly pick an element in that array to give
     
  6. Offline

    linkrock4

    Cant you simply do (0-143, 256-396) Not sure if you guys got any ideas but umm idk how to do that cuz it dosent work :/
     
  7. Offline

    raGan.

    and MAYBE just check if it is null before you do stuff. thats how NPEs are usually avoided
     
  8. Offline

    linkrock4

    @raGan
    And how can i do that?
     
  9. Offline

    raGan.

    This appears to be true.

    Using if(whatYouWantToCheck != null) {
    //do stuff
    }
     
    kyran_ likes this.
  10. Offline

    linkrock4

    so....

    if(id != null) {
    bla bla
    } ?
     
  11. Offline

    raGan.

    if(Material.getMaterial(id) == null) {
    //add item
    }
     
  12. Offline

    linkrock4

    Thanks but theres just 1 problem...

    If (--->Material<---.getMaterial(id) == null) {

    }

    ...is an error... :confused: im not so sure why it should be working it worked in my other plugin so im not sure why....
     
  13. Offline

    raGan.

    import Material class(quick fix in Eclipe (I think Ctrl + 1))

    .getMaterial() is it's static method, it should always work
     
  14. Offline

    linkrock4

    It works!@ Is there a way to find out if the inventory is full and if it is than to do something?
     
  15. Offline

    kyran_

    Again with the avatars!
    raGan. you sneaky bastard, I bet you secretly enjoy seeing "This post has been edited 3 times." every time someone mentions you! The money we waste every year on new edit buttons... I bet there's a pile of them out back with squeaky hinges, worn out springs and faded letters.
     
  16. Offline

    Tirelessly

    addItem returns a map of items that couldn't be added, I believe..
     
  17. Offline

    linkrock4

    Well when i spam my diamondore on the floor it keeps going if the inventory is full... :/
     
Thread Status:
Not open for further replies.

Share This Page