diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c20067b9..6b7d531d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,7 @@ - CSGO Crate animation was delayed by 1 tick, for some reason. ### Changes: -- Updated Vital API. -- use getOrDefault on PersistentDataContainer, to avoid some useless NPE checks. -- Added deprecation notices for `Editor-Items`, as I also do not want to maintain that anymore. - - `Editor-Items` should continue to work, however... no new items can be added with it. - - I cannot keep `Editor-Items`, if I don't keep legacy color codes which I don't want to keep. - - A different format may be supplied, if people don't like the base64, however there is tools to decode base64/bytes \ No newline at end of file +- Updated the /crates additem command + - CrazyCrates now supports MiniMessage, regardless of the item format used. + - This is only happening, as legacy colors have been removed and I did some research. +- Updated Vital API \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index 07c09b380..7028fa1de 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -1,5 +1,6 @@ package com.badbones69.crazycrates.api.objects; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.api.builders.types.CrateTierMenu; import com.badbones69.crazycrates.api.crates.CrateHologram; import com.badbones69.crazycrates.api.enums.misc.Keys; @@ -13,9 +14,11 @@ import com.ryderbelserion.vital.paper.util.DyeUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; import net.kyori.adventure.sound.Sound; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import net.kyori.adventure.text.Component; import org.bukkit.Color; import org.bukkit.Particle; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.Nullable; import org.bukkit.configuration.ConfigurationSection; @@ -34,6 +37,7 @@ import com.badbones69.crazycrates.api.utils.MiscUtils; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -85,6 +89,8 @@ public class Crate { private @NotNull final InventoryManager inventoryManager = this.plugin.getInventoryManager(); + private @NotNull final SettingsManager config = ConfigManager.getConfig(); + /** * @param name The name of the crate. * @param crateType The crate type of the crate. @@ -645,26 +651,72 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String section.set(getPath(prizeName, "MaxRange"), 100); } - //todo() add something for Editor-Items, I am no longer using it. + if (itemStack.hasItemMeta()) { + final ItemMeta itemMeta = itemStack.getItemMeta(); + + if (itemMeta.hasDisplayName()) { + final Component displayName = itemMeta.displayName(); - String toBase64 = ItemUtil.toBase64(itemStack); + if (displayName != null) { + section.set(getPath(prizeName, "DisplayName"), MiscUtils.convert(displayName)); + } + } - section.set(getPath(prizeName, "DisplayData"), toBase64); + if (itemMeta.hasLore()) { + final List lore = itemMeta.lore(); - final String items = getPath(prizeName, "Items"); + if (lore != null) { + section.set(getPath(prizeName, "DisplayLore"), MiscUtils.convert(lore)); + } + } + } - if (section.contains(items)) { - final List list = section.getStringList(items); + if (this.config.getProperty(ConfigKeys.item_editor_toggle)) { + final List editorItems = new ArrayList<>(); - list.add("Data:" + toBase64); + if (section.contains(prizeName + ".Editor-Items")) { + final List editors = section.getList(prizeName + ".Editor-Items"); - section.set(items, list); + if (editors != null) { + editors.forEach(item -> editorItems.add((ItemStack) item)); + } + } + + editorItems.add(itemStack); + + section.set(getPath(prizeName, "Editor-Items"), editorItems); } else { - section.set(items, new ArrayList<>() {{ - add("Data:" + toBase64); - }}); + String toBase64 = ItemUtil.toBase64(itemStack); + + section.set(getPath(prizeName, "DisplayData"), toBase64); + + final String items = getPath(prizeName, "Items"); + + if (section.contains(items)) { + final List list = section.getStringList(items); + + list.add("Data:" + toBase64); + + section.set(items, list); + } else { + section.set(items, new ArrayList<>() {{ + add("Data:" + toBase64); + }}); + } } + section.set(getPath(prizeName, "DisplayItem"), itemStack.getType().getKey().getKey()); + + section.set(getPath(prizeName, "DisplayAmount"), itemStack.getAmount()); + + List enchantments = new ArrayList<>(); + + for (Map.Entry enchantment : itemStack.getEnchantments().entrySet()) { + enchantments.add(enchantment.getKey().getKey().getKey() + ":" + enchantment.getValue()); + } + + if (!enchantments.isEmpty()) section.set(getPath(prizeName, "DisplayEnchantments"), enchantments); + section.set(getPath(prizeName, "Chance"), chance); // The section already contains a prize name, so we update the tiers. diff --git a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java index e3b8dfcad..8557ae1ee 100644 --- a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java +++ b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java @@ -61,6 +61,15 @@ public void registerComments(CommentsConfiguration conf) { @Comment("This option will let you test a different way of picking random numbers. If you have any issues, You can set it back to false.") public static final Property use_different_random = newProperty("root.use-different-random", false); + @Comment({ + "This option defines what in-game editor format is used in CrazyCrates", + "", + "true -> uses the old one", + "false -> uses the new one", + "" + }) + public static final Property item_editor_toggle = newProperty("root.use-old-editor", false); + @Comment({ "A recent change to permissions related to opening crates was made", "The way I assumed wildcard permissions worked isn't how they worked",