Skip to content

Commit

Permalink
update the additem format
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Sep 5, 2024
1 parent 2fc40dd commit 99c8d14
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 18 deletions.
10 changes: 4 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
76 changes: 64 additions & 12 deletions src/main/java/com/badbones69/crazycrates/api/objects/Crate.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<Component> 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<String> list = section.getStringList(items);
if (this.config.getProperty(ConfigKeys.item_editor_toggle)) {
final List<ItemStack> 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<String> 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<String> enchantments = new ArrayList<>();

for (Map.Entry<Enchantment, Integer> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> 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<Boolean> 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",
Expand Down

0 comments on commit 99c8d14

Please sign in to comment.