Gui plugin not making a gui

Discussion in 'Plugin Development' started by NightmareFox, Apr 15, 2021.

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

    NightmareFox

    I have made a plugin for a custom GUI but it is not working.
    The plugin gets loaded on my server but when i run the command to open the GUI nothing happens.
    It does not even throw an error at all.

    This is the utils class.
    Code:
    
    package com.hn_hosting.gui.utils;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Utils {
       
       public static String chat (String s) {
         return ChatColor.translateAlternateColorCodes('&', s);
       }
       
       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;
         
       }
       
    public static ItemStack createItemByte(Inventory inv, int materialId, int byteId, int amount, int invSlot, String displayName, String... loreString) {
         
         ItemStack item;
         List<String> lore = new ArrayList();
         
         item = new ItemStack(Material.getMaterial(materialId), amount, (short) byteId);
         
         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;
         
       }
       
    }
    and this is the Ui class.

    Code:
    package com.hn_hosting.gui.ui;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    
    import com.hn_hosting.gui.utils.Utils;
    
    public class Ui {
       
       public static Inventory inv;
       public static String inventory_name;
       public static int inv_rows = 4 * 9;
       
       public static void initialize() {
         inventory_name = Utils.chat("&6&lTest");
         
         inv = Bukkit.createInventory(null, inv_rows);
       }
    
       public static Inventory GUI (Player p) {
         Inventory toReturn = Bukkit.createInventory(null,  inv_rows, inventory_name);
         
         Utils.createItem(inv, 4, 1, 1, "&cTest Item", "Just a test");
         
         toReturn.setContents(inv.getContents());
         return toReturn;
       }
       
       public static void clicked(Player p, int slot, ItemStack clicked, Inventory inv) {
         if (clicked.getItemMeta().equalsIgnoreCase(Utils.chat("&cTest Item"))) {
           p.setDisplayName(Utils.chat("ok then"));
         }
       }
    }
    
    I just need to know what i am doing wrong.
     
    Last edited by a moderator: Apr 15, 2021
  2. Offline

    timtower Administrator Administrator Moderator

    @NightmareFox You do realize that you never show the gui right?
     
  3. Offline

    NightmareFox

    That is because my Gui never pops up like it should
     
  4. Offline

    timtower Administrator Administrator Moderator

    You are not telling it to pop up either.
     
    davidclue likes this.
  5. Offline

    davidclue

    It's a method that you call using a player object, you have created your custom inventory with your custom items, now what you need to do is choose what players you want the gui to open for and use that method. You will find the method you are looking for here.
     
Thread Status:
Not open for further replies.

Share This Page