Solved GUI ERROR

Discussion in 'Spigot Plugin Development' started by ilias2002, Jun 5, 2016.

  1. When i do right click inventory doesnt open :/

    Main
    Code (Text):
    package me.ilias2002gr.SkyPVP;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    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.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.ilias2002gr.Inventory.Menu;

    public class Main extends JavaPlugin implements Listener{
       
        private ItemStack menu;
        private Menu m;
       
          private ItemStack item(String itemName, Material itemMaterial) {
            ItemStack i = new ItemStack(itemMaterial);
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(itemName);
            i.setItemMeta(im);
            return i;
          }
       
      public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);

        System.out.println("[SkyPvp] !");
      }

      public void onDiable() {
        System.out.println("[SkyPvp] !");
      }
     
      @EventHandler
      public void OnJoin(PlayerJoinEvent e) {
        Player p = e.getPlayer();
        PlayerInventory pi = p.getInventory();
        pi.clear();
        this.menu = item(ChatColor.DARK_GRAY + "Kits", Material.ENCHANTED_BOOK);
        pi.setItem(4, this.menu);
       
      }
     
      @EventHandler
      public void onRightClick(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        if ((e.getItem().getType() == Material.ENCHANTED_BOOK) && (
          (e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)))
          this.m.show(p);
      }
    }
     
    Menu (Inventory)
    Code (Text):
    package me.ilias2002gr.Inventory;

    import java.util.Arrays;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;

    public class Menu implements Listener {
        private Inventory inv;
        private ItemStack kit;
        private ItemStack kit2;
        private ItemStack bow;

        public Menu(Plugin p) {
            this.inv = Bukkit.getServer().createInventory(null, 9, ChatColor.DARK_GRAY + "Kits");

            this.kit = item(ChatColor.GREEN + "PvP", Material.STONE_SWORD, ChatColor.GRAY + "The standard kit to", ChatColor.GRAY + "practice your skills.");
            this.kit2 = item(ChatColor.GREEN + "Archer", Material.BOW, ChatColor.GRAY + "Destroy all the enemys", ChatColor.GRAY + "with your infinity bow.");

            this.inv.setItem(0, this.kit);
            this.inv.setItem(1, this.kit2);
            Bukkit.getServer().getPluginManager().registerEvents(this, p);
          }

          private ItemStack item(String itemName, Material itemMaterial, String itemLore, String itemLore2) {
            ItemStack i = new ItemStack(itemMaterial);
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(itemName);
            im.setLore(Arrays.asList(new String[] { itemLore, itemLore2 }));
            i.setItemMeta(im);
            return i;
          }

          private ItemStack item2() {
            ItemStack i = new ItemStack(Material.BOW);
            ItemMeta im = i.getItemMeta();
            im.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
            i.setItemMeta(im);
            return i;
          }

          public void show(Player p) {
            p.openInventory(this.inv);
          }

          @EventHandler
          public void onClickInv(InventoryClickEvent e)
          {
            Player p = (Player)e.getWhoClicked();
            PlayerInventory pi = p.getInventory();
            if (!e.getInventory().equals(this.inv)) {
              return;
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("PvP")) {
              e.setCancelled(true);
              p.closeInventory();
              pi.clear();
              pi.addItem(new ItemStack[] { new ItemStack(Material.STONE_SWORD) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.FISHING_ROD) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.BOW) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE, 2) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.ARROW, 32) });
              pi.setHelmet(new ItemStack(Material.LEATHER_HELMET));
              pi.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
              pi.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
              pi.setBoots(new ItemStack(Material.GOLD_BOOTS));
              p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_DESTROY, 1.0F, 2.0F);
              p.sendMessage(ChatColor.GREEN + "You received your kit.");
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Archer")) {
              e.setCancelled(true);
              p.closeInventory();
              pi.clear();
              this.bow = item2();
              pi.addItem(new ItemStack[] { new ItemStack(this.bow) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE, 2) });
              pi.addItem(new ItemStack[] { new ItemStack(Material.ARROW, 32) });
              pi.setHelmet(new ItemStack(Material.LEATHER_HELMET));
              pi.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
              pi.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
              pi.setBoots(new ItemStack(Material.GOLD_BOOTS));
              p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_BREAK, 1.0F, 2.0F);
              p.sendMessage(ChatColor.GREEN + "You received your kit.");
            }
         
        }
    }
     
     
  2. please help me what i have do wrong ?

    Console error
    Code (Text):
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
        ... 17 more
    [14:56:14 ERROR]: Could not pass event PlayerInteractEvent to IMKits v2.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:193) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:189) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:682) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_65]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_65]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot-1.8.jar:git-Spigot-550ebac-7019900]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
    Caused by: java.lang.NullPointerException
        at me.ilias2002gr.SkyPVP.Main.onRightClick(Main.java:56) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot-1.8.jar:git-Spigot-550ebac-7019900]
        ... 17 more
     
  3. Code (Text):
      at me.ilias2002gr.SkyPVP.Main.onRightClick(Main.java:56) ~[?:?]
    Code (Text):
      @EventHandler
      public void onRightClick(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        if ((e.getItem().getType() == Material.ENCHANTED_BOOK) && (
          (e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)))
          this.m.show(p);
      }
    Error is here ;)
    Code (Text):
     this.m.show(p);
    m is null
     
  4. how i will fix it ? i will remove it ?
     
  5. You are never registring the Menu you created.
     
  6. .... i dont understand please tell me what i must add ?
     
  7. You have to register your menu in your variable m
     
  8. Code (Text):
       private Menu m;
    i have do this

    but where i will add it again ? in PlayerInteractEvent ?

    ????

    please tell me
     
    #8 ilias2002, Jun 5, 2016
    Last edited by a moderator: Jun 10, 2016
  9. I suggest you, to learn java first. Even if we would show you, what exactly you need to do, I doubt you will understand it.


    Also: STOP SPAMMING FOR F*** SAKE!!!
     
    • Agree Agree x 1
  10. You should really learn some java....
    ...especially if you don't even know how to fix a NullPointerException...
     
    • Agree Agree x 1
  11. @TheSilentHorizon
    if you want LEFT THIS THREAD RIGHT NOW
    i ask help no "NOON" people tell me this !

    i have some problems and i need help

    this is the reason why i post this thread And there are furoms for help

    help please error

    im.setDisplayName(ChatColor.WHITE + ((CreatureSpawner)e.getBlock().getState()).getSpawnedType() + "§fSpawner");

    create your own thread instead of bumping this. Be sure to include more information there, like maybe its a good idea to include the error you are talking about....
     
    #11 ilias2002, Jun 5, 2016
    Last edited by a moderator: Jun 10, 2016
    • Like Like x 1
  12. Alright, reported this thread. Enough spam is enough.
     
  13. and ?
    i ask help no people tell me GO LEAN JAVA
     
  14. you never set your menu in the variable m so when you call it the Null error appear
    also stop spam and you should learn java a litle bit before creating plugin'sx)
     
    • Winner Winner x 1