Solved Why I get no Inventory?

Discussion in 'Plugin Development' started by Kicksy, Dec 30, 2018.

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

    Kicksy

    Code:
    public Inventory invnt(int in) {
          
            Inventory inv = Bukkit.createInventory(null, 27,"Daily");
    inv.setItem(in, new ItemStack(Material.HOPPER));
    return inv;
    }
    Code:
    p.openInventory(inve.invnt(6));
     
  2. Offline

    Kevinzuman22

    Could you please explain the error you're experiencing, or include the error log that came with it. Otherwise we can not help you.
     
  3. Offline

    Kicksy

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'daily' in plugin Daily v1.0.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1385) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_191]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_191]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-596221b-9a1fc1e]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
            at me.Kicksy.de.main.onCommand(main.java:63) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
            ... 15 more
     
  4. Offline

    Kevinzuman22

    Something on line 63 in your 'main' class is null, which results in a NullPointerException. Could you post your full main class, as well as the class that contains the Inventory methods?
     
  5. Offline

    Kicksy

    Code:
    package me.Kicksy.de;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class inve implements Listener {
    
        private main plugin;
        private Spieler spieler;
    
        public inve(main main) {
            this.plugin = main;
            spieler = this.plugin.spieler;
        }
    
        public ItemStack item(int id, String title) {
            ItemStack item = new ItemStack(id, 1);
            ItemMeta im = item.getItemMeta();
            im.setDisplayName(title);
            item.setItemMeta(im);
            return item;
        }
    
        public Inventory invnt(int Tag, Player p) {
    
            Inventory inv = Bukkit.createInventory(p, 27, "Daily");
    
            for (int i = 0; i < 27; i++) {
                inv.setItem(i, new ItemStack(Material.STAINED_GLASS, 1));
            }
    
            inv.setItem(4, new ItemStack(Material.HOPPER));
    
            // if(Tag-- < 0 && Tag++ <= plugin.getConfig().getInt("Tage")) {
            if (spieler.spielerConfig.getInt("Spieler." + p.getUniqueId() + ".Tag") + 4 > plugin.getConfig()
                    .getInt("Tage")) {
    
                for (int i = 9; i < 17; i++) {
                    int count = 0;
                    count++;
                    int day = Tag - 9 + count;
                    if (day < 0) {
                        day *= -1;
                    }
                    inv.setItem(i, item(Integer.parseInt(plugin.getConfig().getString("Belohung." + day + ".item")),
                            plugin.getConfig().getString("Belohung." + Tag-- + ".titel")));
                }
                inv.setItem(12, item(Integer.parseInt(plugin.getConfig().getString("Belohung." + Tag-- + ".item")),
                        plugin.getConfig().getString("Belohung." + Tag-- + ".titel")));
                inv.setItem(13, item(Integer.parseInt(plugin.getConfig().getString("Belohung." + Tag + ".item")),
                        plugin.getConfig().getString("Belohung." + Tag + ".titel")));
                inv.setItem(14, item(Integer.parseInt(plugin.getConfig().getString("Belohung." + Tag++ + ".item")),
                        plugin.getConfig().getString("Belohung." + Tag++ + ".titel")));
            }
            return inv;
        }
    }
    
    Code:
    package me.Kicksy.de;
    
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin {
    
        String prefix = "[Daily] ";
        public Spieler spieler;
        private inve inve;
    
        public void loadConfiguration() {
            this.getConfig().addDefault("Tage", "10");
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
    
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new events(this), this);
            //getServer().getPluginManager().registerEvents(new events(new main()), this);
            //Bukkit.getPluginManager().registerEvents(new events(this), this);  
            loadConfiguration();
            int Tage = Integer.parseInt(this.getConfig().getString("Tage"));
            getConfig().set("Belohung." + 0 + ".int", 160);
            for (int i = 1; i < Tage + 1; i++) {
                if (getConfig().getString("Belohung." + i + ".type") == null) {
                    getConfig().set("Belohung." + i + ".item", i);
                    getConfig().set("Belohung." + i + ".titel", "10 coins");
                    getConfig().set("Belohung." + i + ".type", "Item");
                    getConfig().set("Belohung." + i + ".int", i);
                 
                    saveConfig();
                }
            }
         
            System.out.print(prefix + "Das Plugin wurde aktiviert!");
        }
    
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("daily")) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage("Du musst ein Spieler sein, um diesen Befehl ausfuehren zu k├Ânnen!");
                    return true;
                } else {
    
                    /*Inventory inv = Bukkit.createInventory(p, 27,"Daily");
                    for(int i = 0; i<27;i++) { 
                        inv.setItem(i, new ItemStack(Material.STAINED_GLASS,1));
                    }
                 
                    inv.setItem(4, new ItemStack(Material.HOPPER));
                    inv.setItem(13, new ItemStack(Integer.parseInt(getConfig().getString("Belohung." + "2" + ".item")),1));
                    */p.openInventory(inve.invnt(6,p)); //63 Line
                }
            }
            return true;
         
         
        }
    
    }
    
     
  6. Offline

    Kevinzuman22

    I'm assuming you're coding for a version close to 1.12.

    Defining a new ItemStack with the constructor 'ItemStack(Integer, Integer)', which you are using here
    Code:
    public ItemStack item(int id, String title) {
            ItemStack item = new ItemStack(id, 1);
            ItemMeta im = item.getItemMeta();
            im.setDisplayName(title);
            item.setItemMeta(im);
            return item;
        }
    does not exist. A Material is required to create an item. This should be the case, or you are coding for a version that's quite a bit older. Which version are you coding for, just to be sure?
     
  7. Offline

    Kicksy

    Also if I create only a empty inventory with no Items I get a error.
    And I can create a ItemStack only with a int.
     

    Attached Files:

    • 2.PNG
      2.PNG
      File size:
      10.5 KB
      Views:
      6
  8. Offline

    timtower Ninja on the waves Moderator

    What version are you building against?
     
  9. Offline

    Kicksy

    1.12

    I solved the the problem. I add to the onEnable method:
    Code:
    inve = new inve(this);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 31, 2018
Thread Status:
Not open for further replies.

Share This Page