Move createGuiItem methods to their own util class

This commit is contained in:
Chew 2021-09-26 17:48:17 -05:00
parent 9935ac68da
commit 2e06caca1f
No known key found for this signature in database
GPG Key ID: AF1472E56590998C
4 changed files with 80 additions and 83 deletions

View File

@ -1,7 +1,6 @@
package net.seanomik.energeticstorage.gui;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.seanomik.energeticstorage.EnergeticStorage;
import net.seanomik.energeticstorage.files.PlayersFile;
import net.seanomik.energeticstorage.objects.ESDrive;
import net.seanomik.energeticstorage.objects.ESSystem;
@ -17,9 +16,14 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import static net.seanomik.energeticstorage.utils.GUIHelper.createGuiItem;
public class ESDriveGUI implements InventoryHolder, Listener {
private final Inventory globalInv;
@ -65,34 +69,6 @@ public class ESDriveGUI implements InventoryHolder, Listener {
}
}
private ItemStack createGuiItem(Material material, String name, List<String> description) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(description);
item.setItemMeta(meta);
return item;
}
private ItemStack createGuiItem(Material material, List<String> description) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setLore(description);
item.setItemMeta(meta);
return item;
}
private ItemStack createGuiItem(Material material, String name) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
// You can open the inventory with this
public void openInventory(Player p, ESSystem esSystem) {
p.openInventory(globalInv);

View File

@ -18,10 +18,15 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static net.seanomik.energeticstorage.utils.GUIHelper.createGuiItem;
public class ESSystemSecurityGUI implements InventoryHolder, Listener {
private final Inventory inv;
@ -115,34 +120,6 @@ public class ESSystemSecurityGUI implements InventoryHolder, Listener {
}
}
private ItemStack createGuiItem(Material material, String name, List<String> description) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(description);
item.setItemMeta(meta);
return item;
}
private ItemStack createGuiItem(Material material, List<String> description) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setLore(description);
item.setItemMeta(meta);
return item;
}
private ItemStack createGuiItem(Material material, String name) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
public void openInventory(Player p, ESSystem esSystem) {
if (openSystems.containsKey(p)) {
openSystems.replace(p, esSystem);

View File

@ -10,8 +10,6 @@ import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -24,7 +22,15 @@ import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static net.seanomik.energeticstorage.utils.GUIHelper.createGuiItem;
public class ESTerminalGUI implements InventoryHolder, Listener {
private final Inventory globalInv;
@ -208,25 +214,6 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
}
}
private ItemStack createGuiItem(Material material, String name) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
item.setItemMeta(meta);
return item;
}
private ItemStack createGuiItem(Material material, String name, List<String> lore) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
private enum ClickType {
NONE,
SWAP,

View File

@ -0,0 +1,57 @@
package net.seanomik.energeticstorage.utils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GUIHelper {
/**
* Creates a GUI Item with a given material, display name, and optional lore
*
* @param material The material to use
* @param name The name of the item
* @param lore Optional lore to add to the item
* @return An item stack to be used in the GUI.
*/
public static ItemStack createGuiItem(Material material, String name, String... lore) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.RESET + name);
if (lore.length > 0) {
ArrayList<String> metaLore = new ArrayList<>(Arrays.asList(lore));
meta.setLore(metaLore);
}
item.setItemMeta(meta);
}
return item;
}
/**
* Creates a GUI item with given material, display name, and required lore
*
* @param material The material to use
* @param name The name of the item
* @param lore Optional lore to add to the item
* @return An item stack to be used in the GUI.
*/
public static ItemStack createGuiItem(Material material, String name, List<String> lore) {
ItemStack item = new ItemStack(material, 1);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.RESET + name);
meta.setLore(lore);
}
item.setItemMeta(meta);
return item;
}
}