Could not pass event error

Discussion in 'Plugin Development' started by hayhaycrusher, Apr 5, 2013.

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

    hayhaycrusher

    Here is my code.

    Code:
    package co.uk.mchgamerz.src;
     
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.FireworkEffect;
    import org.bukkit.FireworkEffect.Type;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.Firework;
    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.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryOpenEvent;
    import org.bukkit.event.inventory.InventoryType.SlotType;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    @SuppressWarnings("deprecation")
    public final class CoreMain extends JavaPlugin implements Listener {
       
       
        public static Inventory inv;
        public static Inventory inv1;
       
     
        private ItemStack setName(ItemStack is, String name, List<String> lore){
            ItemMeta im = is.getItemMeta();
            if(name != null){
                im.setDisplayName(name);
            }
            if(lore != null){
                im.setLore(lore);
            }
           
            is.setItemMeta(im);
            return is;
        }
       
        @EventHandler
        public void onPlayerDropItem(PlayerDropItemEvent event) {
        Player p = event.getPlayer();
       
        if (event.getItemDrop().getItemStack().getType() == Material.EYE_OF_ENDER) {
        event.setCancelled(true);
        }
        }
       
     
        @EventHandler
        public void onInventoryOpen(InventoryOpenEvent event){
           
        }
       
        @EventHandler
        public void onInventoryClickEvent(InventoryClickEvent event){
            List<String> ls= new ArrayList<String>();
            String a = "Spawn";
            String b = "Survival Games";
            String c = "Trouble in Minecraftia";
            String d = "Survival Games";
            String f = "Survival Games";
            String ab = ChatColor.GREEN + "Click to Teleport";
           
            ls.add(ab);
           
           
           
           
           
            Player player = (Player) event.getWhoClicked();
           
           
            if (event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(a)){
               
               
                World world = player.getWorld();
               
                Location loc = new Location(player.getWorld(), 270.50, 7, 574.50);
               
                player.teleport(loc);
               
            }
            if (event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(b)){
               
               
                World world = player.getWorld();
               
                Location loc = new Location(player.getWorld(), 350.50, 7, 658.50);
               
                player.teleport(loc);
               
            }
            if (event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(c)){
               
               
                World world = player.getWorld();
               
                Location loc = new Location(player.getWorld(), 441.50, 7, 574.50);
               
                player.teleport(loc);
               
            }
            if (event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(b)){
       
       
                World world = player.getWorld();
       
                Location loc = new Location(player.getWorld(), 350.50, 7, 658.50);
       
                player.teleport(loc);
       
            }
          if (event.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(b)){
       
       
                World world = player.getWorld();
       
                Location loc = new Location(player.getWorld(), 439.50, 7, 574.50);
       
                player.teleport(loc);
           
            }
           
        }
       
        public void onEnable() {
            inv = Bukkit.createInventory(null, 9, ChatColor.ITALIC + "Select an item to teleport.");
            inv1 = Bukkit.createInventory(null, 9, ChatColor.ITALIC + "Owner Heads");
           
           
            getServer().getPluginManager().registerEvents(this, this);
        }
     
     
        public void onDisable() {
           
        }
       
           
       
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            List<String> ld= new ArrayList<String>();
            List<String> lp= new ArrayList<String>();
           
           
            Player player = event.getPlayer();
            PlayerInventory inventory = player.getInventory();
            String d = "Teleport Panel";
     
           
           
     
            String ab = ChatColor.GREEN + "Click to open the Teleport Panel";
           
            ld.add(ab);
     
            inventory.clear();
            ItemStack itemstack = (setName(new ItemStack(Material.EYE_OF_ENDER, 1), d, ld));
     
            inventory.addItem(itemstack);
        }
       
       
       
        private void shootFireworks() {
            for (Player player : Bukkit.getOnlinePlayers()){
                Firework fw = (Firework) player.getWorld().spawn(player.getLocation(), Firework.class);
                FireworkMeta fm = fw.getFireworkMeta();
                Random r = new Random();
                int fType = r.nextInt(5) + 1;
                Type type = null;
                switch (fType) {
                default:
                case 1:
                    type = Type.BALL;
                    break;
                case 2:
                    type = Type.BALL_LARGE;
                    break;
                case 3:
                    type = Type.BURST;
                    break;
                case 4:
                    type = Type.CREEPER;
                    break;
                case 5:
                    type = Type.STAR;
                }
                int c1 = r.nextInt(17) + 1;
                int c2 = r.nextInt(17) + 1;
            }
           
        }
     
       
       
        @EventHandler
        public void onPlayerInteract (PlayerInteractEvent event){
            Player player = event.getPlayer();
            Action action = event.getAction();
            String p = "Teleport Panel";
            String t = "Owner Heads";
            List<String> ls= new ArrayList<String>();
        if (action.equals(Action.RIGHT_CLICK_BLOCK) || action.equals(Action.RIGHT_CLICK_AIR)){
       
        if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(p)){
           
            event.setCancelled(true);
            String a = "Spawn";
            String c = "Trouble in Minecraftia";
            String ab = ChatColor.GREEN + "Click to Teleport";
           
            ls.add(ab);
           
            String b = "Survival Games";
           
            ItemStack skull1 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta = skull1.getItemMeta();
            ((SkullMeta)itemMeta).setOwner("hayhaycrusher");
            skull1.setItemMeta(itemMeta);
            inv.clear();
            inv.addItem(setName(new ItemStack(skull1), c, ls));
            inv.addItem(new ItemStack(Material.GLASS));
            inv.addItem(new ItemStack(Material.ANVIL, 1));
            inv.addItem(new ItemStack(Material.THIN_GLASS));
            inv.addItem(setName(new ItemStack(Material.NETHER_STAR, 1), a, ls));
            inv.addItem(new ItemStack(Material.GLASS_BOTTLE, 1));
            inv.addItem(setName(new ItemStack(Material.BOW, 1), b, ls));
            inv.addItem(new ItemStack(Material.TORCH, 1));
            inv.addItem(new ItemStack(Material.BAKED_POTATO, 1));
            inv.removeItem(new ItemStack(Material.THIN_GLASS));
            inv.removeItem(new ItemStack(Material.GLASS));
            inv.removeItem(new ItemStack(Material.GLASS_BOTTLE));
            inv.removeItem(new ItemStack(Material.TORCH));
            player.openInventory(inv);
        }
       
        if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(t)){
           
            event.setCancelled(true);
            String a = "Hayhaycrusher";
            String b = "MylesAbraham";
            String c = "CheniceAmelia_X";
            String d = "Juhooligan878";
            String f = "DominicJack";
            String ab = ChatColor.GREEN + "Click to Teleport";
           
            ls.add(ab);
           
           
            ItemStack skull1 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta1 = skull1.getItemMeta();
            ((SkullMeta)itemMeta1).setOwner("hayhaycrusher");
            skull1.setItemMeta(itemMeta1);
           
            ItemStack skull2 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta2 = skull2.getItemMeta();
            ((SkullMeta)itemMeta2).setOwner("MylesAbraham");
            skull2.setItemMeta(itemMeta2);
           
            ItemStack skull3 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta3 = skull3.getItemMeta();
            ((SkullMeta)itemMeta3).setOwner("juhooligan878");
            skull3.setItemMeta(itemMeta3);
     
            ItemStack skull4 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta4 = skull4.getItemMeta();
            ((SkullMeta)itemMeta4).setOwner("CheniceAmelia_X");
            skull4.setItemMeta(itemMeta4);
           
            ItemStack skull5 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            ItemMeta itemMeta5 = skull5.getItemMeta();
            ((SkullMeta)itemMeta5).setOwner("DominicJack");
            skull5.setItemMeta(itemMeta5);
           
           
            inv1.clear();
            inv1.addItem(setName(new ItemStack(skull3), d, null));
            inv1.addItem(new ItemStack(Material.GLASS));
            inv1.addItem(setName(new ItemStack(skull4), c, null));
            inv1.addItem(new ItemStack(Material.THIN_GLASS));
            inv1.addItem(setName(new ItemStack(skull1), a, null));
            inv1.addItem(new ItemStack(Material.GLASS_BOTTLE, 1));
            inv1.addItem(setName(new ItemStack(skull2), b, null));
            inv1.addItem(new ItemStack(Material.TORCH, 1));
            inv1.addItem(setName(new ItemStack(skull5), f, null));
            inv1.removeItem(new ItemStack(Material.THIN_GLASS));
            inv1.removeItem(new ItemStack(Material.GLASS));
            inv1.removeItem(new ItemStack(Material.GLASS_BOTTLE));
            inv1.removeItem(new ItemStack(Material.TORCH));
            player.openInventory(inv1);
        }
        }
       
        }
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
     
            if(commandLabel.equalsIgnoreCase("headitem")){
                if(sender instanceof Player){
                   
                    List<String> ld= new ArrayList<String>();
                    List<String> lp= new ArrayList<String>();
                   
                   
                    Player player = (Player) sender;
                    PlayerInventory inventory = player.getInventory();
                    String d = "Teleport Panel";
                   
                    String p = "Owner Heads";
                   
                   
                    String ap = ChatColor.GREEN + "Click to open the Owner Heads Panel";
                    String ab = ChatColor.GREEN + "Click to open the Teleport Panel";
                   
                    ld.add(ab);
                    lp.add(ap);
               
                    ItemStack itemstack2 = (setName(new ItemStack(Material.SKULL_ITEM, 1), p, lp));
                    inventory.addItem(itemstack2);
                }
           
            List<String> ls= new ArrayList<String>();
            if(commandLabel.equalsIgnoreCase("core")){
                if(sender instanceof Player){
                   
                   
     
                    String a = "Spawn";
                    String c = "Trouble in Minecraftia";
                    String ab = ChatColor.GREEN + "Click to Teleport";
                   
                    ls.add(ab);
                   
                    String b = "Survival Games";
                   
                    ItemStack skull1 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
                    ItemMeta itemMeta = skull1.getItemMeta();
                    ((SkullMeta)itemMeta).setOwner("hayhaycrusher");
                    skull1.setItemMeta(itemMeta);
                    inv.clear();
                    inv.addItem(setName(new ItemStack(skull1), c, ls));
                    inv.addItem(new ItemStack(Material.GLASS));
                    inv.addItem(new ItemStack(Material.ANVIL, 1));
                    inv.addItem(new ItemStack(Material.THIN_GLASS));
                    inv.addItem(setName(new ItemStack(Material.NETHER_STAR, 1), a, ls));
                    inv.addItem(new ItemStack(Material.GLASS_BOTTLE, 1));
                    inv.addItem(setName(new ItemStack(Material.BOW, 1), b, ls));
                    inv.addItem(new ItemStack(Material.TORCH, 1));
                    inv.addItem(new ItemStack(Material.BAKED_POTATO, 1));
                    inv.removeItem(new ItemStack(Material.THIN_GLASS));
                    inv.removeItem(new ItemStack(Material.GLASS));
                    inv.removeItem(new ItemStack(Material.GLASS_BOTTLE));
                    inv.removeItem(new ItemStack(Material.TORCH));
                    ((Player) sender).openInventory(inv);
                }
               
                if(cmd.getName().equalsIgnoreCase("head")){
                    Player s = (Player) sender;
                    Player target = s.getServer().getPlayer(args[0]);
                    if (target == null) {
                        s.sendMessage(ChatColor.DARK_RED + "[Core] " + ChatColor.GREEN + "That player is not online!");
                        return true;
                    } else {
                       
                        String a = "Spawn";
                        String c = "Trouble in Minecraftia";
                        String ab = ChatColor.GREEN + "Click to Teleport";
                       
                        ls.add(ab);
                       
                        String b = "Survival Games";
                       
                        ItemStack skull1 = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
                        ItemMeta itemMeta = skull1.getItemMeta();
                        ((SkullMeta)itemMeta).setOwner(target.getName());
                        skull1.setItemMeta(itemMeta);
                       
                        ((Inventory) s).addItem(setName(new ItemStack(skull1), null, null));
                       
                        return true;
                    }
                }
               
           
           
     
           
           
               
           
       
           
    }
            return false;
    }
     
            return false;
    }
    }
    

    if i right click with any item apart from the 2 im creating an event for i get this error.

    Code:
    19:56:49 [SEVERE] Could not pass event PlayerInteractEvent to Core vAlpha v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:181)
            at net.minecraft.server.v1_5_R2.PlayerInteractManager.interact(PlayerInt
    eractManager.java:376)
            at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java
    :635)
            at net.minecraft.server.v1_5_R2.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292
    )
            at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java
    :113)
            at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:5
    80)
            at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:2
    25)
            at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:4
    76)
            at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java
    :409)
            at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at co.uk.mchgamerz.src.CoreMain.onPlayerInteract(CoreMain.java:231)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.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.ja
    va:425)
            ... 16 more
    >

    If i click in my inventory when its not the items im creating an event for i get this error.

    Code:
    19:56:49 [SEVERE] Could not pass event PlayerInteractEvent to Core vAlpha v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:181)
            at net.minecraft.server.v1_5_R2.PlayerInteractManager.interact(PlayerInt
    eractManager.java:376)
            at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java
    :635)
            at net.minecraft.server.v1_5_R2.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292
    )
            at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java
    :113)
            at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:5
    80)
            at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:2
    25)
            at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:4
    76)
            at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java
    :409)
            at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at co.uk.mchgamerz.src.CoreMain.onPlayerInteract(CoreMain.java:231)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.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.ja
    va:425)
            ... 16 more
    >
     
  2. Offline

    Tamewolf

    The same line of your code is creating an error (Line 231), from pasting it into something I could get the lines from, it's this line in particular (but you may want to double check):

    Code:java
    1. if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(p)){


    NullPointerExceptions are my favorite. Just have to figure out what is returning null and fix it.
     
  3. Offline

    hayhaycrusher

    Do you have any idea of whats returning null?
     
  4. Offline

    ZeusAllMighty11


    And what is returning null is: Not all items have item meta or display name, and not all items in hand are items.
     
Thread Status:
Not open for further replies.

Share This Page