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

pom update & some refactoring

Dieser Commit ist enthalten in:
Silent 2021-07-05 23:18:29 +02:00
Ursprung b99192ba8e
Commit 6a7cffc10c
2 geänderte Dateien mit 18 neuen und 16 gelöschten Zeilen

10
pom.xml
Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>2.3.1</version> <version>2.4.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HeadDB</name> <name>HeadDB</name>
@ -38,9 +38,9 @@
<dependencies> <dependencies>
<!-- Paper API --> <!-- Paper API -->
<dependency> <dependency>
<groupId>com.destroystokyo.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version> <version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- json-simple --> <!-- json-simple -->
@ -92,8 +92,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>8</source> <source>16</source>
<target>8</target> <target>16</target>
</configuration> </configuration>
</plugin> </plugin>

Datei anzeigen

@ -23,10 +23,11 @@ import java.util.List;
import java.util.Map; 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<>(); private static final Map<String, ItemStack> uiItem = new HashMap<>();
public static int uiGetLocation(String category, int slot) { public static int getUILocation(String category, int slot) {
// Try to use the cached value first. // Try to use the cached value first.
if (uiLocation.containsKey(category)) return uiLocation.get(category); if (uiLocation.containsKey(category)) return uiLocation.get(category);
@ -41,7 +42,7 @@ public class InventoryUtils {
return slot; return slot;
} }
public static ItemStack uiGetItem(String category, ItemStack item) { public static ItemStack getUIItem(String category, ItemStack item) {
// Try to use the cached item first. // Try to use the cached item first.
if (uiItem.containsKey(category)) return uiItem.get(category); if (uiItem.containsKey(category)) return uiItem.get(category);
@ -194,19 +195,19 @@ 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 = uiGetItem(category.getName(), category.getItem()); ItemStack item = getUIItem(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<>();
lore.add(Utils.colorize("&e" + HeadAPI.getHeads(category).size() + " heads")); lore.add(Utils.colorize("&e" + HeadAPI.getHeads(category).size() + " heads"));
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
inventory.setItem(uiGetLocation(category.getName(), category.getLocation()), item); inventory.setItem(getUILocation(category.getName(), category.getLocation()), item);
} }
if (player.hasPermission("headdb.favorites")) { if (player.hasPermission("headdb.favorites")) {
inventory.setItem(uiGetLocation("favorites", 39), buildButton( inventory.setItem(getUILocation("favorites", 39), buildButton(
uiGetItem("favorites", new ItemStack(Material.BOOK)), getUIItem("favorites", new ItemStack(Material.BOOK)),
"&eFavorites", "&eFavorites",
"", "",
"&8Click to view your favorites") "&8Click to view your favorites")
@ -214,8 +215,8 @@ public class InventoryUtils {
} }
if (player.hasPermission("headdb.search")) { if (player.hasPermission("headdb.search")) {
inventory.setItem(uiGetLocation("search", 40), buildButton( inventory.setItem(getUILocation("search", 40), buildButton(
uiGetItem("search", new ItemStack(Material.DARK_OAK_SIGN)), getUIItem("search", new ItemStack(Material.DARK_OAK_SIGN)),
"&9Search", "&9Search",
"", "",
"&8Click to open search menu" "&8Click to open search menu"
@ -223,8 +224,8 @@ public class InventoryUtils {
} }
if (player.hasPermission("headdb.local")) { if (player.hasPermission("headdb.local")) {
inventory.setItem(uiGetLocation("local", 41), buildButton( inventory.setItem(getUILocation("local", 41), buildButton(
uiGetItem("local", new ItemStack(Material.COMPASS)), getUIItem("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"
@ -236,7 +237,7 @@ public class InventoryUtils {
} }
public static void fill(Inventory inv) { public static void fill(Inventory inv) {
ItemStack item = uiGetItem("fill", new ItemStack(Material.BLACK_STAINED_GLASS_PANE)); ItemStack item = getUIItem("fill", new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
// Do not bother filling the inventory if item to fill it with is AIR. // Do not bother filling the inventory if item to fill it with is AIR.
if (item == null || item.getType() == Material.AIR) return; if (item == null || item.getType() == Material.AIR) return;
@ -307,4 +308,5 @@ public class InventoryUtils {
item.setAmount(amount); item.setAmount(amount);
player.getInventory().addItem(item); player.getInventory().addItem(item);
} }
} }