org.bukkit.command.CommandException when trying to open a GUI

Viewed 637

I am making a Minecraft Java Plugin, and my plugin worked fine 6 months ago. Now when I got back to my plugin, it does not work.

Here is an error given /play, which opens a GUI.

[14:07:28 INFO]: LucaForever issued server command: /play
[14:07:28 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'play' in plugin BlocksUtilities v1.6
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at java.base/java.lang.Thread.run(Thread.java:832) [?:?]
Caused by: java.lang.IllegalArgumentException: Title cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom$MinecraftInventory.<init>(CraftInventoryCustom.java:58) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom.<init>(CraftInventoryCustom.java:32) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.createInventory(CraftServer.java:1525) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.Bukkit.createInventory(Bukkit.java:938) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        at org.blocks.ui.GamesUI.GUI(GamesUI.java:24) ~[?:?]
        at org.blocks.commands.GameUICommand.onCommand(GameUICommand.java:33) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
        ... 15 more

Here is a part of the code that I think is faulty:

public class GamesUI 
{
    public static Inventory inv;
    public static String inventory_name;
    public static int inv_rows = 1 * 9;
    
    public static void initialaize()
    {
        inventory_name = Utils.chat("&6&lChoose a Game!");
        
        inv = Bukkit.createInventory(null, inv_rows);
    }
    
    public static Inventory GUI (Player p)
    {
        Inventory toReturn = Bukkit.createInventory(p, inv_rows, inventory_name); //i tried here p and 
                                                                                    null but none work
        
        Utils.createItem(inv, 166, 1, 2, "&cStaff World", "&bClick to join the staff world!", "&4Only staff allowed!");
        Utils.createItem(inv, 355, 1, 1, "&cBedwars", "&bClick to join bedwars!", "&70 players playing!");
        
        toReturn.setContents(inv.getContents());
        return toReturn;
    }
    
    public static void clicked(Player p, int slot, ItemStack clicked, Inventory inv)
    {
        if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&cBedwars")))
        {
            p.sendMessage(Utils.chat("&7Sending you to the bedwars server..."));
            p.performCommand("bedwars join");
        }
        
    }
}

Here is a part of utils too:

public static ItemStack createItem(Inventory inv, int materialId, int amount, int invSlot, String displayName, String... loreString)
    {
        ItemStack item;
        List<String> lore = new ArrayList();
        
        item = new ItemStack(Material.getMaterial(materialId), amount);
                
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(Utils.chat(displayName));
        for (String s : loreString)
        {
            lore.add(Utils.chat(s));
        }
        meta.setLore(lore);
        item.setItemMeta(meta);
        inv.setItem(invSlot - 1, item);
        return item;
    }

------------------> Part 2

The other commands, like /gmc, don't do anything. They don't display errors, just show that I executed the command and then nothing. IMAGE

Thank you, and hope to hear from someone.

1 Answers

I think the error appears because you have not set a title for your inventory. To fix it, you should assign a value to inventory_name:

public static String inventory_name = "name";

If you don't want a title, you can use:

Inventory toReturn = Bukkit.createInventory(p, inv_rows);

You can leave the rest of the code as it is. It should then look like this:

public class GamesUI 
{
    public static Inventory inv;
    public static String inventory_name;
    public static int inv_rows = 1 * 9;
    
    public static void initialaize()
    {
        inventory_name = Utils.chat("&6&lChoose a Game!");
        
        inv = Bukkit.createInventory(null, inv_rows);
    }
    
    public static Inventory GUI (Player p)
    {
        Inventory toReturn = Bukkit.createInventory(p, inv_rows, inventory_name); //i tried here p and 
                                                                                    null but none work
        
        Utils.createItem(inv, 166, 1, 2, "&cStaff World", "&bClick to join the staff world!", "&4Only staff allowed!");
        Utils.createItem(inv, 355, 1, 1, "&cBedwars", "&bClick to join bedwars!", "&70 players playing!");
        
        toReturn.setContents(inv.getContents());
        return toReturn;
    }
    
    public static void clicked(Player p, int slot, ItemStack clicked, Inventory inv)
    {
        if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&cBedwars")))
        {
            p.sendMessage(Utils.chat("&7Sending you to the bedwars server..."));
            p.performCommand("bedwars join");
        }
        
    }
}
Related