Console error

Discussion in 'Spigot Plugin Development' started by MaxKrissigo, May 12, 2016.

  1. So, I'm getting this error in my console, but can't find anything wrong with my code. I believe it has something to do with my Main class and Cosmetic class. I'll post the code you need! Thanks Max.
    Code (Text):
    [05:44:30 ERROR]: Error occurred while enabling MainPlugin v1.0 (Is it up to date?)
        at me.MaxKrissigo.MainPlugin.Cosmetic.<init>( ~[?:?]
        at me.MaxKrissigo.MainPlugin.Main.onEnable( ~[?:?]
        at ~[spigot.jar:git-Spigot-e6f93f4-935f18b]
        at [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.Bukkit.reload( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.command.defaults.ReloadCommand.execute( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.command.SimpleCommandMap.dispatch( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at net.minecraft.server.v1_9_R1.DedicatedServer.aL( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C( [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at [spigot.jar:git-Spigot-e6f93f4-935f18b]
        at [?:1.8.0_92]
  2. java.lang.NullPointerException
    at me.MaxKrissigo.MainPlugin.Cosmetic.<init>( ~[?:?]
    at me.MaxKrissigo.MainPlugin.Main.onEnable( ~[?:?]

    Show us your code, specify these lines
  3. This is the relevant code in the Main class:
    Code (Text):

        private Menu menu;
        private Cosmetic cosmetic;
        private Kit kit;
        private Enchant enchant;
        HashMap<String, Scoreboard> playerSb = new HashMap<String,Scoreboard>();
        public void onEnable() {
                menu = new Menu(this);
                kit = new Kit(this);
                enchant = new Enchant(this);
                cosmetic = new Cosmetic(this); //this is line 42
                Bukkit.getServer().getPluginManager().registerEvents(this, this);
                if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
                    getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
                    getLogger().severe("*** This plugin will be disabled. ***");

    And this is the relevant code of the cosmetic class.
    Code (Text):
        HashMap<String, Boolean> Hologram = new HashMap<String, Boolean>();
            private Inventory inv;
            private Inventory inv1;
            private Inventory inv2;
            private ItemStack killMessage, killDisplay, hologram;
            public Cosmetic(Plugin p) {
                    inv1 = Bukkit.getServer().createInventory(null, 45, "Kill Messages");
                    inv2 = Bukkit.getServer().createInventory(null, 45, "Kill Displays");
                    inv = Bukkit.getServer().createInventory(null, 45, "Cosmetic");
                    if (Hologram.get(p.getName())) { //this is line 39
                        hologram = createItem2(Material.DIAMOND, ChatColor.GOLD + "Hologram " + ChatColor.GREEN + "[ENABLED]");
                    } else if (!Hologram.get(p.getName())) {
                        hologram = createItem2(Material.DIAMOND, ChatColor.GOLD + "Hologram " + ChatColor.RED +  "[DISABLED]");
                    killMessage = createItem(Material.DIAMOND_SWORD, ChatColor.GOLD + "Kill Message");
                    killDisplay = createItem1(Material.GLASS, ChatColor.RED + "Kill Display");
                    inv2.setItem(12, hologram);
                    inv.setItem(20, killMessage);
                    inv.setItem(24, killDisplay);
                    Bukkit.getServer().getPluginManager().registerEvents(this, p);
  4. Can you show the which is line 39 in your cosmetic class?
  5. Ok, first of all this is your constructor, I am pretty sure you didn't mean to put all that code in the constructor :p

    if (Hologram.get(p.getName())) { //this is line 39

    You don't have a player object, or if you do, it is null.
    If you are trying to listen to clicks in your GUI, use InventoryClickEvent
  6. How would I get this to return true, so to check if the player is true? I've set up a hash map to store the players.

    EDIT: Basically check whether the boolean is true or not for that player.
  7. Code (Text):

        private Main plugin;
        public Cosmetic (Main pl){
            plugin = pl;
    This is what you want inside your constructor I guess. Not all that code, all that code should go to here:

    Code (Text):
    public void onInventoryClick(InventoryClickEvent e){
    //your code inside your constructor
    Get the player from your hashmap if you want but you can get who clicked by e.getWhoClicked();
  8. So I've added this to my InventoryClickEvent, but it isn't doing anything.
    Code (Text):
            public void onInventoryClick(InventoryClickEvent e) {
                    if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
                    if (e.getCurrentItem().getItemMeta() == null) return;
                    if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Hologram")) {
                        Player p = (Player) e.getWhoClicked();
                        if (Hologram.get(p.getName())) {
                            hologram = createItem2(Material.DIAMOND, ChatColor.GOLD + "Hologram " + ChatColor.RED +  "[DISABLED]");
                            Hologram.put(p.getName(), false);
                        } else if (!Hologram.get(p.getName())) {

                            hologram = createItem2(Material.DIAMOND, ChatColor.GOLD + "Hologram " + ChatColor.GREEN + "[ENABLED]");
                            Hologram.put(p.getName(), true);
  9. Debug your code by sending the player some messages. Anything on the console?
  10. No nothing on the console.
  11. Send some messages here and there and see where the code doesn't work, then try to fix it.
  12. I have no idea how to fix it, but the code which checks whether the hologram item has clicked is not working.