diff --git a/paper/run/server.properties b/paper/run/server.properties index 8255d6822..232c301fb 100644 --- a/paper/run/server.properties +++ b/paper/run/server.properties @@ -1,5 +1,5 @@ #Minecraft server properties -#Wed Feb 07 16:01:30 GMT-03:00 2024 +#Fri Feb 09 08:13:54 GMT-03:00 2024 enable-jmx-monitoring=false rcon.port=25575 level-seed= diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/ItemBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/ItemBuilder.java index 8a54bee01..ec97e5532 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/ItemBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/ItemBuilder.java @@ -7,7 +7,6 @@ import com.ryderbelserion.cluster.utils.DyeUtils; import de.tr7zw.changeme.nbtapi.NBTItem; import emanondev.itemedit.ItemEdit; -import emanondev.itemedit.storage.ServerStorage; import io.th0rgal.oraxen.api.OraxenItems; import org.bukkit.Color; import org.bukkit.DyeColor; @@ -45,7 +44,6 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.stream.Collectors; public class ItemBuilder { @@ -91,7 +89,7 @@ public class ItemBuilder { private boolean isLeatherArmor; // Enchantments - private HashMap enchantments; + private Map enchantments; // Shields private boolean isShield; @@ -399,38 +397,7 @@ public ItemStack build() { ItemStack item = this.itemStack; - // Custom Items (Oraxen, ItemEdit) - if (this.customMaterial != null && this.customMaterial.contains(":")) { - - String[] split = this.customMaterial.split(":"); - String identifier = split[0]; - String id = split[1]; - - if (!identifier.isBlank() && !id.isBlank()) { - - if (PluginSupport.ORAXEN.isPluginEnabled() && identifier.equals("or")) { - io.th0rgal.oraxen.items.ItemBuilder oraxenItem = OraxenItems.getItemById(id); - - if (oraxenItem != null && OraxenItems.exists(id)) { - item = oraxenItem.build(); - this.itemStack = item; - this.itemMeta = item.getItemMeta(); - this.itemName = item.getItemMeta().getDisplayName(); - } - } - - if (PluginSupport.ITEM_EDIT.isPluginEnabled() && identifier.equals("ie")) { - ServerStorage serverStorage = ItemEdit.get().getServerStorage(); - item = serverStorage.getItem(id); - if (item != null) { - this.itemStack = item; - this.itemMeta = item.getItemMeta(); - this.itemName = item.getItemMeta().getDisplayName(); - } - } - } - } - + setCustomItem(); if (item != null && item.getType() != Material.AIR) { if (this.isHead && (this.isHash)) { // Sauce: https://github.com/deanveloper/SkullCreator @@ -444,7 +411,9 @@ public ItemStack build() { item.setAmount(this.itemAmount); - if (this.itemMeta == null) this.itemMeta = item.getItemMeta(); + if (this.itemMeta == null) { + this.itemMeta = item.getItemMeta(); + } this.itemMeta.setDisplayName(getUpdatedName()); this.itemMeta.setLore(getUpdatedLore()); @@ -456,7 +425,9 @@ public ItemStack build() { if (this.isMap) { MapMeta mapMeta = (MapMeta) this.itemMeta; - if (this.mapColor != null) mapMeta.setColor(this.mapColor); + if (this.mapColor != null) { + mapMeta.setColor(this.mapColor); + } } if (this.itemMeta instanceof Damageable damageable && (this.damage >= 1)) { @@ -470,16 +441,22 @@ public ItemStack build() { if (this.isPotion && (this.potionType != null || this.potionColor != null)) { PotionMeta potionMeta = (PotionMeta) this.itemMeta; - if (this.potionType != null) potionMeta.setBasePotionData(new PotionData(this.potionType)); + if (this.potionType != null) { + potionMeta.setBasePotionData(new PotionData(this.potionType)); + } - if (this.potionColor != null) potionMeta.setColor(this.potionColor); + if (this.potionColor != null) { + potionMeta.setColor(this.potionColor); + } } if (this.material == Material.TIPPED_ARROW && this.potionType != null) { PotionMeta potionMeta = (PotionMeta) this.itemMeta; potionMeta.setBasePotionData(new PotionData(this.potionType)); - if (this.potionColor != null) potionMeta.setColor(this.potionColor); + if (this.potionColor != null) { + potionMeta.setColor(this.potionColor); + } } if (this.isLeatherArmor && this.armorColor != null) { @@ -500,7 +477,9 @@ public ItemStack build() { shieldMeta.setBlockState(banner); } - if (this.useCustomModelData) this.itemMeta.setCustomModelData(this.customModelData); + if (this.useCustomModelData) { + this.itemMeta.setCustomModelData(this.customModelData); + } this.itemFlags.forEach(this.itemMeta::addItemFlags); item.setItemMeta(this.itemMeta); @@ -510,13 +489,17 @@ public ItemStack build() { NBTItem nbt = new NBTItem(item); - if (this.isHead && !this.isHash) nbt.setString("SkullOwner", this.player); + if (this.isHead && !this.isHash) { + nbt.setString("SkullOwner", this.player); + } if (this.isMobEgg && (this.entityType != null)) { nbt.addCompound("EntityTag").setString("id", "minecraft:" + this.entityType.name()); } - if (!this.crateName.isEmpty()) nbt.setString("CrazyCrates-Crate", this.crateName); + if (!this.crateName.isEmpty()) { + nbt.setString("CrazyCrates-Crate", this.crateName); + } return nbt.getItem(); } else { @@ -524,6 +507,60 @@ public ItemStack build() { } } + public boolean isCustomItem() { + if (this.customMaterial == null || !this.customMaterial.contains(":")) { + return false; + } + + String[] split = this.customMaterial.split(":"); + if (split.length < 2 || split[0].isBlank() || split[1].isBlank()) { + return false; + } + + String identifier = split[0]; + String id = split[1]; + + return (PluginSupport.ORAXEN.isPluginEnabled() && "or".equals(identifier) && OraxenItems.exists(id)) || + (PluginSupport.ITEM_EDIT.isPluginEnabled() && "ie".equals(identifier) && ItemEdit.get().getServerStorage().getIds().contains(id)); + } + + public void setCustomItem() { + if (!isCustomItem()) { + return; + } + + String[] split = this.customMaterial.split(":"); + String identifier = split[0]; + String id = split[1]; + + if ("or".equals(identifier) && PluginSupport.ORAXEN.isPluginEnabled()) { + configureOraxenItem(id); + } else if ("ie".equals(identifier) && PluginSupport.ITEM_EDIT.isPluginEnabled()) { + configureItemEditItem(id); + } + } + + private void configureOraxenItem(String id) { + io.th0rgal.oraxen.items.ItemBuilder oraxenItem = OraxenItems.getItemById(id); + if (oraxenItem != null) { + updateItemStack(oraxenItem.build()); + } + } + + private void configureItemEditItem(String id) { + ItemStack item = ItemEdit.get().getServerStorage().getItem(id); + updateItemStack(item); + } + + private void updateItemStack(ItemStack item) { + if (item != null) { + this.itemStack = item; + this.itemMeta = item.getItemMeta(); + this.itemName = item.getItemMeta().getDisplayName(); + this.enchantments = item.getEnchantments(); + } + } + /* Class based extensions. */ @@ -618,13 +655,16 @@ public ItemBuilder setMaterial(@NotNull String material) { switch (this.material.name()) { case "PLAYER_HEAD" -> this.isHead = true; case "POTION", "SPLASH_POTION" -> this.isPotion = true; - case "LEATHER_HELMET", "LEATHER_CHESTPLATE", "LEATHER_LEGGINGS", "LEATHER_BOOTS", "LEATHER_HORSE_ARMOR" -> this.isLeatherArmor = true; + case "LEATHER_HELMET", "LEATHER_CHESTPLATE", "LEATHER_LEGGINGS", "LEATHER_BOOTS", "LEATHER_HORSE_ARMOR" -> + this.isLeatherArmor = true; case "BANNER" -> this.isBanner = true; case "SHIELD" -> this.isShield = true; case "FILLED_MAP" -> this.isMap = true; } - if (this.material.name().contains("BANNER")) this.isBanner = true; + if (this.material.name().contains("BANNER")) { + this.isBanner = true; + } return this; } @@ -871,7 +911,9 @@ public ItemBuilder setPlayerName(String playerName) { * @return The ItemBuilder with a list of updated enchantments. */ public ItemBuilder setEnchantments(HashMap enchantment) { - if (enchantment != null) this.enchantments = enchantment; + if (enchantment != null) { + this.enchantments = enchantment; + } return this; } @@ -1031,14 +1073,22 @@ public static ItemBuilder convertItemStack(ItemStack item) { if (item.hasItemMeta() && item.getItemMeta() != null) { ItemMeta itemMeta = item.getItemMeta(); - if (itemMeta.hasDisplayName()) itemBuilder.setName(itemMeta.getDisplayName()); - if (itemMeta.hasLore()) itemBuilder.setLore(itemMeta.getLore()); + if (itemMeta.hasDisplayName()) { + itemBuilder.setName(itemMeta.getDisplayName()); + } + if (itemMeta.hasLore()) { + itemBuilder.setLore(itemMeta.getLore()); + } NBTItem nbt = new NBTItem(item); - if (nbt.hasTag("Unbreakable")) itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable")); + if (nbt.hasTag("Unbreakable")) { + itemBuilder.setUnbreakable(nbt.getBoolean("Unbreakable")); + } - if (itemMeta instanceof org.bukkit.inventory.meta.Damageable damageable) itemBuilder.setDamage(damageable.getDamage()); + if (itemMeta instanceof org.bukkit.inventory.meta.Damageable damageable) { + itemBuilder.setDamage(damageable.getDamage()); + } } return itemBuilder; @@ -1063,7 +1113,6 @@ public static ItemBuilder convertItemStack(ItemStack item) { */ public static @NotNull ItemBuilder convertString(String itemString, String placeHolder) { ItemBuilder itemBuilder = new ItemBuilder(); - try { for (String optionString : itemString.split(", ")) { String option = optionString.split(":")[0]; @@ -1092,10 +1141,12 @@ public static ItemBuilder convertItemStack(ItemStack item) { if (value.isEmpty() || value.equalsIgnoreCase("true")) itemBuilder.setUnbreakable(true); } case "trim-pattern" -> { - if (!value.isEmpty()) itemBuilder.setTrimPattern(Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(value.toLowerCase()))); + if (!value.isEmpty()) + itemBuilder.setTrimPattern(Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(value.toLowerCase()))); } case "trim-material" -> { - if (!value.isEmpty()) itemBuilder.setTrimMaterial(Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(value.toLowerCase()))); + if (!value.isEmpty()) + itemBuilder.setTrimMaterial(Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(value.toLowerCase()))); } default -> { Enchantment enchantment = getEnchantment(option); @@ -1158,7 +1209,7 @@ public static List convertStringList(List itemStrings) { * @return The list of ItemBuilders. */ public static List convertStringList(@NotNull List itemStrings, String placeholder) { - return itemStrings.stream().map(itemString -> convertString(itemString, placeholder)).collect(Collectors.toList()); + return itemStrings.stream().map(itemString -> convertString(itemString, placeholder)).toList(); } /** @@ -1225,15 +1276,20 @@ private PotionType getPotionType(PotionEffectType type) { * @return The enchantment from the string. */ private static @Nullable Enchantment getEnchantment(String enchantmentName) { + if (enchantmentName == null || enchantmentName.isBlank()) { + return null; + } + enchantmentName = stripEnchantmentName(enchantmentName); for (Enchantment enchantment : Enchantment.values()) { try { - if (stripEnchantmentName(enchantment.getKey().getKey()).equalsIgnoreCase(enchantmentName)) return enchantment; + if (stripEnchantmentName(enchantment.getKey().getKey()).equalsIgnoreCase(enchantmentName)) + return enchantment; HashMap enchantments = getEnchantmentList(); if (stripEnchantmentName(enchantment.getName()).equalsIgnoreCase(enchantmentName) || (enchantments.get(enchantment.getName()) != null && - stripEnchantmentName(enchantments.get(enchantment.getName())).equalsIgnoreCase(enchantmentName))) + stripEnchantmentName(enchantments.get(enchantment.getName())).equalsIgnoreCase(enchantmentName))) return enchantment; } catch (Exception ignore) { } diff --git a/paper/src/main/java/com/badbones69/crazycrates/managers/crates/CrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/managers/crates/CrateManager.java index 4de2fb450..2583d1da1 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/managers/crates/CrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/managers/crates/CrateManager.java @@ -150,7 +150,9 @@ public void loadCrates() { purge(); // Removes all holograms so that they can be replaced. - if (this.holograms != null) this.holograms.removeAllHolograms(); + if (this.holograms != null) { + this.holograms.removeAllHolograms(); + } if (PluginSupport.DECENT_HOLOGRAMS.isPluginEnabled()) { this.holograms = new DecentHologramsSupport(); @@ -988,6 +990,7 @@ private ItemBuilder getDisplayItem(@NotNull FileConfiguration file, String prize this.plugin.getLogger().warning("The display item for the prize " + prize + " is null. Please check your config.yml file."); displayItem = "RED_TERRACOTTA"; } + try { itemBuilder.setMaterial(displayItem) .setAmount(file.getInt(path + "DisplayAmount", 1)) @@ -998,7 +1001,8 @@ private ItemBuilder getDisplayItem(@NotNull FileConfiguration file, String prize .hideItemFlags(file.getBoolean(path + "HideItemFlags")) .addItemFlags(file.getStringList(path + "Flags")) .addPatterns(file.getStringList(path + "Patterns")) - .setPlayerName(file.getString(path + "Player")); + .setPlayerName(file.getString(path + "Player")) + .setCustomItem(); if (file.contains(path + "DisplayDamage") && file.getInt(path + "DisplayDamage") >= 1) { itemBuilder.setDamage(file.getInt(path + "DisplayDamage"));