Make it possible to change the category menu items through the config file.

Dieser Commit ist enthalten in:
Leandro 2021-07-04 20:37:18 -03:00
Ursprung 9301d08472
Commit 7b377655ea
2 geänderte Dateien mit 27 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -14,7 +14,6 @@ import tsp.headdb.api.HeadAPI;
import tsp.headdb.api.LocalHead; import tsp.headdb.api.LocalHead;
import tsp.headdb.database.Category; import tsp.headdb.database.Category;
import tsp.headdb.util.Utils; import tsp.headdb.util.Utils;
import tsp.headdb.util.XMaterial;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
@ -25,6 +24,7 @@ import java.util.Map;
public class InventoryUtils { public class InventoryUtils {
private static final Map<String, Integer> uiLocation = new HashMap<>(); private static final Map<String, Integer> uiLocation = new HashMap<>();
private static final Map<String, ItemStack> uiItem = new HashMap<>();
public static int uiGetLocation(String category, int slot) { public static int uiGetLocation(String category, int slot) {
// Try to use the cached value first; then the config; then the given default. // Try to use the cached value first; then the config; then the given default.
@ -38,6 +38,25 @@ public class InventoryUtils {
return uiLocation.get(category); return uiLocation.get(category);
} }
public static ItemStack uiGetItem(String category, ItemStack item) {
// Try to use the cached value first; then the config; then the given default.
if (!uiItem.containsKey(category)) {
if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".item")) {
String cfg = HeadDB.getInstance().getCfg().getString("ui.category." + category + ".item");
Material mat = Material.matchMaterial(cfg);
if (mat == null || mat == Material.AIR) {
// Material set in config is invalid, use the given default.
uiItem.put(category, item);
} else {
uiItem.put(category, new ItemStack(mat));
}
} else {
uiItem.put(category, item);
}
}
return uiItem.get(category);
}
public static void openLocalMenu(Player player) { public static void openLocalMenu(Player player) {
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &aLocal Heads")); PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &aLocal Heads"));
@ -160,7 +179,7 @@ public class InventoryUtils {
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")")); Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")"));
for (Category category : Category.getCategories()) { for (Category category : Category.getCategories()) {
ItemStack item = category.getItem(); ItemStack item = uiGetItem(category.getName(), category.getItem());
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Utils.colorize(category.getColor() + "&l" + category.getName().toUpperCase())); meta.setDisplayName(Utils.colorize(category.getColor() + "&l" + category.getName().toUpperCase()));
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
@ -172,7 +191,7 @@ public class InventoryUtils {
if (player.hasPermission("headdb.favorites")) { if (player.hasPermission("headdb.favorites")) {
inventory.setItem(uiGetLocation("favorites", 39), buildButton( inventory.setItem(uiGetLocation("favorites", 39), buildButton(
XMaterial.BOOK.parseItem(), uiGetItem("favorites", new ItemStack(Material.BOOK)),
"&eFavorites", "&eFavorites",
"", "",
"&8Click to view your favorites") "&8Click to view your favorites")
@ -181,7 +200,7 @@ public class InventoryUtils {
if (player.hasPermission("headdb.search")) { if (player.hasPermission("headdb.search")) {
inventory.setItem(uiGetLocation("search", 40), buildButton( inventory.setItem(uiGetLocation("search", 40), buildButton(
XMaterial.DARK_OAK_SIGN.parseItem(), uiGetItem("search", new ItemStack(Material.DARK_OAK_SIGN)),
"&9Search", "&9Search",
"", "",
"&8Click to open search menu" "&8Click to open search menu"
@ -190,7 +209,7 @@ public class InventoryUtils {
if (player.hasPermission("headdb.local")) { if (player.hasPermission("headdb.local")) {
inventory.setItem(uiGetLocation("local", 41), buildButton( inventory.setItem(uiGetLocation("local", 41), buildButton(
XMaterial.COMPASS.parseItem(), uiGetItem("local", new ItemStack(Material.COMPASS)),
"&aLocal", "&aLocal",
"", "",
"&8Heads from any players that have logged on the server" "&8Heads from any players that have logged on the server"

Datei anzeigen

@ -48,10 +48,13 @@ ui:
location: 33 location: 33
favorites: favorites:
location: 39 location: 39
item: BOOK
search: search:
location: 40 location: 40
item: DARK_OAK_SIGN
local: local:
location: 41 location: 41
item: COMPASS
# Debug Mode # Debug Mode
debug: false debug: false