geforkt von Mirrors/HeadDB
Make it possible to rearrange the categories menu through the config file.
Dieser Commit ist enthalten in:
Ursprung
0c2b6bdc3c
Commit
9301d08472
@ -11,25 +11,26 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public enum Category {
|
||||
|
||||
ALPHABET("alphabet", ChatColor.YELLOW),
|
||||
ANIMALS("animals", ChatColor.DARK_AQUA),
|
||||
BLOCKS("blocks", ChatColor.DARK_GRAY),
|
||||
DECORATION("decoration", ChatColor.LIGHT_PURPLE),
|
||||
FOOD_DRINKS("food-drinks", ChatColor.GOLD),
|
||||
HUMANS("humans", ChatColor.DARK_BLUE),
|
||||
HUMANOID("humanoid", ChatColor.AQUA),
|
||||
MISCELLANEOUS("miscellaneous", ChatColor.DARK_GREEN),
|
||||
MONSTERS("monsters", ChatColor.RED),
|
||||
PLANTS("plants", ChatColor.GREEN);
|
||||
ALPHABET("alphabet", ChatColor.YELLOW, 20),
|
||||
ANIMALS("animals", ChatColor.DARK_AQUA, 21),
|
||||
BLOCKS("blocks", ChatColor.DARK_GRAY, 22),
|
||||
DECORATION("decoration", ChatColor.LIGHT_PURPLE, 23),
|
||||
FOOD_DRINKS("food-drinks", ChatColor.GOLD, 24),
|
||||
HUMANS("humans", ChatColor.DARK_BLUE, 29),
|
||||
HUMANOID("humanoid", ChatColor.AQUA, 30),
|
||||
MISCELLANEOUS("miscellaneous", ChatColor.DARK_GREEN, 31),
|
||||
MONSTERS("monsters", ChatColor.RED, 32),
|
||||
PLANTS("plants", ChatColor.GREEN, 33);
|
||||
|
||||
private final String name;
|
||||
private final ChatColor color;
|
||||
private final int location;
|
||||
private final Map<Category, Head> item = new HashMap<>();
|
||||
|
||||
Category(String name, ChatColor color) {
|
||||
Category(String name, ChatColor color, int location) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -40,6 +41,10 @@ public enum Category {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
if (item.containsKey(this)) {
|
||||
return item.get(this).getItemStack();
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import tsp.headdb.HeadDB;
|
||||
import tsp.headdb.api.Head;
|
||||
import tsp.headdb.api.HeadAPI;
|
||||
@ -14,13 +15,28 @@ import tsp.headdb.api.LocalHead;
|
||||
import tsp.headdb.database.Category;
|
||||
import tsp.headdb.util.Utils;
|
||||
import tsp.headdb.util.XMaterial;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InventoryUtils {
|
||||
private static final Map<String, Integer> uiLocation = new HashMap<>();
|
||||
|
||||
public static int uiGetLocation(String category, int slot) {
|
||||
// Try to use the cached value first; then the config; then the given default.
|
||||
if (!uiLocation.containsKey(category)) {
|
||||
if (HeadDB.getInstance().getCfg().contains("ui.category." + category + ".location")) {
|
||||
uiLocation.put(category, HeadDB.getInstance().getCfg().getInt("ui.category." + category + ".location"));
|
||||
} else {
|
||||
uiLocation.put(category, slot);
|
||||
}
|
||||
}
|
||||
return uiLocation.get(category);
|
||||
}
|
||||
|
||||
public static void openLocalMenu(Player player) {
|
||||
PagedPane pane = new PagedPane(4, 6, Utils.colorize("&c&lHeadDB &8- &aLocal Heads"));
|
||||
@ -143,7 +159,6 @@ public class InventoryUtils {
|
||||
public static void openDatabase(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")"));
|
||||
|
||||
fill(inventory, new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
|
||||
for (Category category : Category.getCategories()) {
|
||||
ItemStack item = category.getItem();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -152,11 +167,11 @@ public class InventoryUtils {
|
||||
lore.add(Utils.colorize("&e" + HeadAPI.getHeads(category).size() + " heads"));
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inventory.addItem(item);
|
||||
inventory.setItem(uiGetLocation(category.getName(), category.getLocation()), item);
|
||||
}
|
||||
|
||||
if (player.hasPermission("headdb.favorites")) {
|
||||
inventory.setItem(39, buildButton(
|
||||
inventory.setItem(uiGetLocation("favorites", 39), buildButton(
|
||||
XMaterial.BOOK.parseItem(),
|
||||
"&eFavorites",
|
||||
"",
|
||||
@ -165,7 +180,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
if (player.hasPermission("headdb.search")) {
|
||||
inventory.setItem(40, buildButton(
|
||||
inventory.setItem(uiGetLocation("search", 40), buildButton(
|
||||
XMaterial.DARK_OAK_SIGN.parseItem(),
|
||||
"&9Search",
|
||||
"",
|
||||
@ -174,7 +189,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
if (player.hasPermission("headdb.local")) {
|
||||
inventory.setItem(41, buildButton(
|
||||
inventory.setItem(uiGetLocation("local", 41), buildButton(
|
||||
XMaterial.COMPASS.parseItem(),
|
||||
"&aLocal",
|
||||
"",
|
||||
@ -182,27 +197,21 @@ public class InventoryUtils {
|
||||
));
|
||||
}
|
||||
|
||||
fill(inventory, new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public static void fill(Inventory inv, ItemStack item) {
|
||||
int size = inv.getSize();
|
||||
int[] ignored = new int[]{20, 21, 22, 23, 24, 29, 30, 31, 32, 33};
|
||||
|
||||
// Fill
|
||||
// Fill any non-empty inventory slots with the given item.
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!contains(i, ignored)) {
|
||||
ItemStack slotItem = inv.getItem(i);
|
||||
if (slotItem == null || slotItem.getType() == Material.AIR) {
|
||||
inv.setItem(i, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean contains(int n, int... array) {
|
||||
return Arrays.binarySearch(array, n) > -1;
|
||||
}
|
||||
|
||||
private static ItemStack buildButton(ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
@ -23,5 +23,35 @@ economy:
|
||||
plants: 100
|
||||
local: 1000
|
||||
|
||||
# UI customization options.
|
||||
ui:
|
||||
category:
|
||||
alphabet:
|
||||
location: 20
|
||||
animals:
|
||||
location: 21
|
||||
blocks:
|
||||
location: 22
|
||||
decoration:
|
||||
location: 23
|
||||
food-drinks:
|
||||
location: 24
|
||||
humans:
|
||||
location: 29
|
||||
humanoid:
|
||||
location: 30
|
||||
miscellaneous:
|
||||
location: 31
|
||||
monsters:
|
||||
location: 32
|
||||
plants:
|
||||
location: 33
|
||||
favorites:
|
||||
location: 39
|
||||
search:
|
||||
location: 40
|
||||
local:
|
||||
location: 41
|
||||
|
||||
# Debug Mode
|
||||
debug: false
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren