Error on PlayerInteractEvent

Discussion in 'Plugin Development' started by MrGriefer_HGTech, Sep 20, 2015.

Thread Status:
Not open for further replies.
  1. Hello!

    I keep getting this console errors whenever a player click on saddle. The saddle must open up a GUI but whenever they click the saddle it gives me error on the console. Here is my code and the console error:

    Code for PlayerInteractEvent:
    Code:
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            if (event.getItem() != null
                    && event.getItem().hasItemMeta()
                    && event.getItem().getItemMeta().hasDisplayName()
                    && event.getItem().getItemMeta().getDisplayName().equals(String.valueOf(SettingsManager.getConfig().get("Mount-Item.Displayname"))
                            .replace("&", "§"))) {
                event.setCancelled(true);
                openMountsMenu(event.getPlayer());
            }
        }
    The error:
    HTML:
    [17:35:09] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to SimpleMounts v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
        at me.MrGriefer_.SM.MessageManager.getMessage(MessageManager.java:64) ~[?:?]
        at me.MrGriefer_.SM.Mounts.Mount.getMenuName(Mount.java:130) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.openMountsMenu(MenuListeners.java:103) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.onInteract(MenuListeners.java:45) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        ... 17 more
    [17:35:11] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to SimpleMounts v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:107) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:623) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
        at me.MrGriefer_.SM.MessageManager.getMessage(MessageManager.java:64) ~[?:?]
        at me.MrGriefer_.SM.Mounts.Mount.getMenuName(Mount.java:130) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.openMountsMenu(MenuListeners.java:103) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.onInteract(MenuListeners.java:45) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        ... 18 more
    [17:35:11] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to SimpleMounts v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
        at me.MrGriefer_.SM.MessageManager.getMessage(MessageManager.java:64) ~[?:?]
        at me.MrGriefer_.SM.Mounts.Mount.getMenuName(Mount.java:130) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.openMountsMenu(MenuListeners.java:103) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.onInteract(MenuListeners.java:45) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        ... 17 more
    [17:35:12] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to SimpleMounts v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:717) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
        at me.MrGriefer_.SM.MessageManager.getMessage(MessageManager.java:64) ~[?:?]
        at me.MrGriefer_.SM.Mounts.Mount.getMenuName(Mount.java:130) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.openMountsMenu(MenuListeners.java:103) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.onInteract(MenuListeners.java:45) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        ... 18 more
    [17:35:17] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to SimpleMounts v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:717) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    Caused by: java.lang.NullPointerException
        at me.MrGriefer_.SM.MessageManager.getMessage(MessageManager.java:64) ~[?:?]
        at me.MrGriefer_.SM.Mounts.Mount.getMenuName(Mount.java:130) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.openMountsMenu(MenuListeners.java:103) ~[?:?]
        at me.MrGriefer_.SM.Listeners.MenuListeners.onInteract(MenuListeners.java:45) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-fdc1440-53fac9f]
        ... 18 more
    [17:35:37] [Server thread/INFO]
    Thank for reading and helping! :)
     
  2. Offline

    finalblade1234

    Can I see MenuListeners.java?
     
  3. Here:

    Code:
    package me.MrGriefer_.SM.Listeners;
    
    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    import me.MrGriefer_.SM.Core;
    import me.MrGriefer_.SM.CustomPlayer;
    import me.MrGriefer_.SM.MessageManager;
    import me.MrGriefer_.SM.SettingsManager;
    import me.MrGriefer_.SM.Mounts.Mount;
    import me.MrGriefer_.SM.Util.ItemFactory;
    import net.minecraft.server.v1_8_R3.NBTTagCompound;
    import net.minecraft.server.v1_8_R3.NBTTagList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    
    public class MenuListeners implements Listener {
    
        private Core core;
        public MenuListeners(Core core) {
            this.core = core;
        }
       
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            if (event.getItem() != null
                    && event.getItem().hasItemMeta()
                    && event.getItem().getItemMeta().hasDisplayName()
                    && event.getItem().getItemMeta().getDisplayName().equals(String.valueOf(SettingsManager.getConfig().get("Mount-Item.Displayname"))
                            .replace("&", "§"))) {
                event.setCancelled(true);
                openMountsMenu(event.getPlayer());
            }
        }
       
        public static void openMountsMenu(Player player) {
            int listSize = 0;
            for (Mount m : Core.getMounts()) {
                if (!m.getType().isEnabled()) continue;
                listSize++;
            }
            int slotAmount = 54;
            if (listSize < 22)
                slotAmount = 54;
            if (listSize < 15)
                slotAmount = 45;
            if (listSize < 8)
                slotAmount = 36;
           
            Inventory inv = Bukkit.createInventory(null, slotAmount, MessageManager.getMessage("Menu.Mounts"));
           
            int i = 10;
            for (Mount m : Core.getMounts()) {
                if (!m.getType().isEnabled() && (boolean) SettingsManager.getConfig().get("Disabled-Items.Show-Custom-Disabled-Item")) {
                    Material material = Material.valueOf((String) SettingsManager.getConfig().get("Disabled-Items.Custom-Disabled-Item.Type"));
                    Byte data = Byte.valueOf(String.valueOf(SettingsManager.getConfig().get("Disabled-Items.Custom-Disabled-Item.Data")));
                    String name = String.valueOf(SettingsManager.getConfig().get("Disabled-Items.Custom-Disabled-Item.Name")).replace("&", "§");
                    inv.setItem(i, ItemFactory.create(material, data, name));
                    if (i == 25 || i == 34 || i == 16) {
                        i += 3;
                    } else {
                        i++;
                    }
                    continue;
                }
                if (!m.getType().isEnabled()) continue;
                if (SettingsManager.getConfig().get("No-Permission.Dont-Show-Item") != null)
                    if (!player.hasPermission(m.getType().getPermission()))
                        continue;
                if ((boolean) SettingsManager.getConfig().get("No-Permission.Custom-Item.enabled") && !player.hasPermission(m.getType().getPermission())) {
                    Material material = Material.valueOf((String) SettingsManager.getConfig().get("No-Permission.Custom-Item.Type"));
                    Byte data = Byte.valueOf(String.valueOf(SettingsManager.getConfig().get("No-Permission.Custom-Item.Data")));
                    String name = String.valueOf(SettingsManager.getConfig().get("No-Permission.Custom-Item.Name")).replace("&", "§");
                    inv.setItem(i, ItemFactory.create(material, data, name));
                    if (i == 25 || i == 34 || i == 16) {
                        i += 3;
                    } else {
                        i++;
                    }
                    continue;
                }
                String lore = null;
                if (SettingsManager.getConfig().get("No-Permission.Show-In-Lore") != null) {
                    lore = ChatColor.translateAlternateColorCodes('&', String.valueOf(SettingsManager.getConfig().get("No-Permission.Lore-Message-" + ((player.hasPermission(m.getType().getPermission()) ? "Yes" : "No")))));
                }
                String toggle = MessageManager.getMessage("Menu.Spawn");
                CustomPlayer cp = Core.getCustomPlayer(player);
                if (cp.currentMount != null && cp.currentMount.getType() == m.getType())
                    toggle = MessageManager.getMessage("Menu.Despawn");
                ItemStack is = ItemFactory.create(m.getMaterial(), m.getData(), toggle + " " + m.getMenuName(), (lore != null) ? lore : null);
                if (cp.currentMount != null && cp.currentMount.getType() == m.getType())
                    is = addGlow(is);
                inv.setItem(i, is);
                if (i == 25 || i == 34 || i == 16) {
                    i += 3;
                } else {
                    i++;
                }
            }
           
            inv.setItem(inv.getSize() - 5, ItemFactory.create(Material.TNT, (byte) 0x0, MessageManager.getMessage("Clear-Mounts")));
           
            player.openInventory(inv);
        }
       
        public static Mount.MountType getMountByName(String name) {
            for (Mount mount : Core.getMounts()) {
                if (mount.getMenuName().replace(" ", "").equals(name.replace(" ", ""))) {
                    return mount.getType();
                }
            }
            return null;
        }
       
        static List<Player> playerList = new ArrayList<>();
       
        public static void activateMountByType(Mount.MountType type, final Player player) {
            if (!player.hasPermission(type.getPermission())) {
                if (!playerList.contains(player)) {
                    player.sendMessage("§9Mount> §cYou don't have permission!");
                    playerList.add(player);
                    Bukkit.getScheduler().runTaskLaterAsynchronously(Core.getPlugin(), new Runnable() {
                        @Override
                        public void run() {
                            playerList.remove(player);
                        }
                    }, 1);
                }
                return;
            }
           
            for (Mount mount : Core.getMounts()) {
                if (mount.getType().isEnabled() && mount.getType() == type) {
                    Class mountClass = mount.getClass();
                   
                    Class[] cArg = new Class[1];
                    cArg[0] = UUID.class;
                   
                    UUID uuid = player.getUniqueId();
                   
                    try {
                        mountClass.getDeclaredConstructor(UUID.class).newInstance(uuid);
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
     
  4. Offline

    bwfcwalshy Retired Staff

    @MrGriefer_HGTech Just saying, that code will break every version. You may want to make it future compatibility. Also don't use § use ChatColor
     
  5. Offline

    RoboticPlayer

    Java Naming Conventions.
     
  6. So I need to make my package name in all-lowercase letters, but the error is telling that is from PlayerInteractEvent! I can't see anything wrong with my PlayerInteractEvent.
     
Thread Status:
Not open for further replies.

Share This Page