3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-28 20:00:10 +01:00

Make it possible to change the default heads in the categories menu through the config.

Dieser Commit ist enthalten in:
Leandro 2021-07-04 21:35:50 -03:00
Ursprung 63ffca71fd
Commit d6cdde98c4
2 geänderte Dateien mit 36 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -39,23 +39,33 @@ public class InventoryUtils {
} }
public static ItemStack uiGetItem(String category, ItemStack item) { public static ItemStack uiGetItem(String category, ItemStack item) {
// Try to use the cached value first; then the config; then the given default. // Try to use the cached value first.
if (!uiItem.containsKey(category)) { if (uiItem.containsKey(category)) return uiItem.get(category);
// Try to get a head from the config file.
if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".head")) {
int id = HeadDB.getInstance().getCfg().getInt("ui.category." + category + ".head");
Head head = HeadAPI.getHeadByID(id);
if (head != null) {
uiItem.put(category, head.getItemStack());
return uiItem.get(category);
}
}
// Try to get an item from the config file.
if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".item")) { if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".item")) {
String cfg = HeadDB.getInstance().getCfg().getString("ui.category." + category + ".item"); String cfg = HeadDB.getInstance().getCfg().getString("ui.category." + category + ".item");
Material mat = Material.matchMaterial(cfg); Material mat = Material.matchMaterial(cfg);
if (mat == null || mat == Material.AIR) { 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)); uiItem.put(category, new ItemStack(mat));
}
} else {
uiItem.put(category, item);
}
}
return uiItem.get(category); return uiItem.get(category);
} }
}
// No valid head or item in the config file, return the given default.
uiItem.put(category, item);
return item;
}
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"));

Datei anzeigen

@ -26,26 +26,38 @@ economy:
# UI customization options. # UI customization options.
ui: ui:
category: category:
# Head categories.
alphabet: alphabet:
location: 20 location: 20
head: 1788
animals: animals:
location: 21 location: 21
head: 5741
blocks: blocks:
location: 22 location: 22
head: 8624
decoration: decoration:
location: 23 location: 23
head: 11046
food-drinks: food-drinks:
location: 24 location: 24
head: 17442
humans: humans:
location: 29 location: 29
head: 19361
humanoid: humanoid:
location: 30 location: 30
head: 28320
miscellaneous: miscellaneous:
location: 31 location: 31
head: 32746
monsters: monsters:
location: 32 location: 32
head: 34819
plants: plants:
location: 33 location: 33
head: 37278
# Meta categories, used for UI elements.
favorites: favorites:
location: 39 location: 39
item: BOOK item: BOOK