diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index 70c12532d..5771b3d65 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { api(projects.crazycratesCore) - compileOnly("cz.basicland:bLibs:2.0.0-WIP-b24") + compileOnly("cz.basicland:bLibs:2.0.0-WIP-b25") compileOnly ("org.projectlombok:lombok:1.18.32") annotationProcessor ("org.projectlombok:lombok:1.18.32") diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java index e20b35b8e..22b06b250 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -107,7 +107,7 @@ public Prize(String prizeNumber, String crateName, Tier tier, ItemStack stack, b if (updatedLore == null) updatedLore = new ArrayList<>(); updatedLore.addFirst(""); updatedLore.addFirst(type.name()); - display.setDisplayLore(updatedLore); + display.setDisplayLore(updatedLore.stream().map(s -> s.replace("§", "&")).toList()); this.displayItem = display; this.prizeItem = display; diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/DatabaseManager.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/DatabaseManager.java index b93d51bda..753d81ac8 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/DatabaseManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/DatabaseManager.java @@ -53,7 +53,7 @@ public DatabaseManager(List crateList) { CrateSettings settings = crate.getCrateSettings(); if (settings == null) continue; BannerPackage bannerPackage = settings.getBannerPackage(); - if (bannerPackage.isBannerActive()) { + if (bannerPackage.isBannerActive() || !bannerPackage.enabled()) { settings.loadItems(crate, crate.getPrizes(), this); } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/History.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/History.java index e8693a3f5..e3485b7c9 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/History.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/History.java @@ -11,28 +11,25 @@ import com.badbones69.crazycrates.api.objects.gacha.util.HSLColor; import com.badbones69.crazycrates.api.objects.gacha.util.Pair; import cz.basicland.blibs.spigot.utils.item.NBT; -import io.papermc.paper.adventure.PaperAdventure; -import net.kyori.adventure.key.Key; -import net.kyori.adventure.nbt.api.BinaryTagHolder; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.DataComponentValue; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; +import static net.kyori.adventure.text.Component.text; + public class History { private final DatabaseManager playerDataManager; private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); @@ -46,7 +43,7 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti PlayerProfile profile = playerDataManager.getPlayerProfile(target, crateSettings, true); if (profile == null) { - player.sendMessage(Component.text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); + player.sendMessage(text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); return; } @@ -54,7 +51,7 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti TextColor color = TextColor.fromHexString("#de7a00"); if (historyList.isEmpty()) { - player.sendMessage(Component.text("Nemáte žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); + player.sendMessage(text("Nemáte žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); return; } @@ -68,11 +65,11 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti int endIndex = Math.min(startIndex + HISTORY_PER_PAGE, size); int maxPage = (size / HISTORY_PER_PAGE) + (size % HISTORY_PER_PAGE == 0 ? 0 : 1); - Component header = Component.text() + Component header = text() .appendNewline() - .append(Component.text("Historie otevření ", color)) - .append(Component.text(crateSettings.getCrateName(), NamedTextColor.AQUA)) - .append(Component.text(" crate", color)) + .append(text("Historie otevření ", color)) + .append(text(crateSettings.getCrateName(), NamedTextColor.AQUA)) + .append(text(" crate", color)) .appendNewline() .build(); player.sendMessage(header); @@ -81,11 +78,11 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti Result history = historyList.get(size - i - 1); Rarity rarity = history.getRarity(); - Component component = Component.text() - .append(Component.text("» ", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)) - .append(LegacyComponentSerializer.legacy('&').deserialize(history.getItemName()).hoverEvent(showItem(getItem(history, rarity, crateSettings)))) - .append(Component.text(" - ", NamedTextColor.GRAY) - .append(Component.text(rarity.name(), rarity.getColor()).hoverEvent(HoverEvent.showText(getHoverText(history, crateSettings))))) + Component component = text() + .append(text("» ", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)) + .append(LegacyComponentSerializer.legacy('&').deserialize(history.getItemName()).hoverEvent(getHover(history, rarity, crateSettings))) + .append(text(" - ", NamedTextColor.GRAY) + .append(text(rarity.name(), rarity.getColor()).hoverEvent(HoverEvent.showText(getHoverText(history, crateSettings))))) .build(); player.sendMessage(component); } @@ -93,15 +90,15 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti int pageMinus = pageNumber - 1; int pagePlus = pageNumber + 1; - Component pages = Component.text() + Component pages = text() .appendNewline() - .append(Component.text("<<<<", NamedTextColor.DARK_GRAY, TextDecoration.BOLD) + .append(text("<<<<", NamedTextColor.DARK_GRAY, TextDecoration.BOLD) .clickEvent(ClickEvent.callback((clickEvent) -> sendHistory(player, target, pageMinus <= 0 ? maxPage : pageMinus, crateSettings))) - .hoverEvent(Component.text("Předchozí stránka", NamedTextColor.GRAY))) - .append(Component.text(" Strana " + pageNumber + "/" + maxPage + " ", color)) - .append(Component.text(">>>>", NamedTextColor.DARK_GRAY, TextDecoration.BOLD) + .hoverEvent(text("Předchozí stránka", NamedTextColor.GRAY))) + .append(text(" Strana " + pageNumber + "/" + maxPage + " ", color)) + .append(text(">>>>", NamedTextColor.DARK_GRAY, TextDecoration.BOLD) .clickEvent(ClickEvent.callback((clickEvent) -> sendHistory(player, target, pagePlus > maxPage ? 1 : pagePlus, crateSettings))) - .hoverEvent(Component.text("Další stránka", NamedTextColor.GRAY))) + .hoverEvent(text("Další stránka", NamedTextColor.GRAY))) .build(); player.sendMessage(pages); } @@ -110,15 +107,15 @@ public void sendPity(Player player, String target, CrateSettings crateSettings) PlayerProfile profile = playerDataManager.getPlayerProfile(target, crateSettings, true); if (profile == null) { - player.sendMessage(Component.text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); + player.sendMessage(text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED)); return; } - Component header = Component.text() + Component header = text() .appendNewline() - .append(Component.text("Pity pro ", NamedTextColor.GRAY)) - .append(Component.text(crateSettings.getCrateName(), NamedTextColor.AQUA)) - .append(Component.text(" crate", NamedTextColor.GRAY)) + .append(text("Pity pro ", NamedTextColor.GRAY)) + .append(text(crateSettings.getCrateName(), NamedTextColor.AQUA)) + .append(text(" crate", NamedTextColor.GRAY)) .appendNewline() .build(); player.sendMessage(header); @@ -129,18 +126,18 @@ public void sendPity(Player player, String target, CrateSettings crateSettings) ResultType won5050 = pair.second(); int color = getColor(pity); - Component component = Component.text() - .append(Component.text(rarity.name(), rarity.getColor())) - .append(Component.text(" pity: ", NamedTextColor.GRAY)) - .append(Component.text(pity, TextColor.color(color))) - .append(Component.text(" last 50/50: ", NamedTextColor.GRAY)) - .append(Component.text(won5050.name(), won5050.getColor())) + Component component = text() + .append(text(rarity.name(), rarity.getColor())) + .append(text(" pity: ", NamedTextColor.GRAY)) + .append(text(pity, TextColor.color(color))) + .append(text(" last 50/50: ", NamedTextColor.GRAY)) + .append(text(won5050.name(), won5050.getColor())) .build(); player.sendMessage(component); }); } - private ItemStack getItem(Result history, Rarity rarity, CrateSettings crateSettings) { + private @NotNull HoverEvent getHover(Result history, Rarity rarity, CrateSettings crateSettings) { Set items = crateSettings.getGachaType().equals(GachaType.OVERRIDE) ? crateSettings.getBoth(rarity) : new HashSet<>(history.isWon5050() ? crateSettings.getLimited() : crateSettings.getStandard()); items.removeIf(item -> item.getRarity() != rarity || !item.getSectionName().equals(history.getRewardName())); @@ -155,13 +152,9 @@ private ItemStack getItem(Result history, Rarity rarity, CrateSettings crateSett } } - return item; - } - - private HoverEvent showItem(ItemStack itemStack) { - NamespacedKey key = itemStack.getType().getKey(); - int itemCount = itemStack.getAmount(); - return HoverEvent.showItem(HoverEvent.ShowItem.showItem(key, itemCount, PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getComponentsPatch()))); + NamespacedKey key = item.getType().getKey(); + int itemCount = item.getAmount(); + return HoverEvent.showItem(HoverEvent.ShowItem.showItem(key, itemCount, new NBT(item).getNBTToMap())); } private Component getHoverText(Result history, CrateSettings crateSettings) { @@ -170,15 +163,15 @@ private Component getHoverText(Result history, CrateSettings crateSettings) { int color = getColor(history.getPity()); ResultType won5050 = history.getWon5050(); - return Component.text() - .append(Component.text("- čas: ", NamedTextColor.GRAY) - .append(Component.text(dateFormat.format(history.getTimestamp()), NamedTextColor.GOLD))) + return text() + .append(text("- čas: ", NamedTextColor.GRAY) + .append(text(dateFormat.format(history.getTimestamp()), NamedTextColor.GOLD))) .appendNewline() - .append(Component.text("- pity: ", NamedTextColor.GRAY) - .append(Component.text(history.getPity(), TextColor.color(color)))) + .append(text("- pity: ", NamedTextColor.GRAY) + .append(text(history.getPity(), TextColor.color(color)))) .append(raritySettings.is5050Enabled() ? - Component.newline().append(Component.text("- 50/50: ", NamedTextColor.GRAY)) - .append(Component.text(won5050.name(), won5050.getColor())) : + Component.newline().append(text("- 50/50: ", NamedTextColor.GRAY)) + .append(text(won5050.name(), won5050.getColor())) : Component.empty()) .build(); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/banners/BannerPackage.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/banners/BannerPackage.java index d85808a00..acbc207fd 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/banners/BannerPackage.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/banners/BannerPackage.java @@ -3,10 +3,10 @@ import java.time.Duration; import java.time.LocalDateTime; -public record BannerPackage(BannerData currentBanner, BannerData nextBanner) { +public record BannerPackage(BannerData currentBanner, BannerData nextBanner, boolean enabled) { public BannerData getBanner() { - return currentBanner.isBannerActive() ? currentBanner : nextBanner.isBannerActive() ? nextBanner : null; + return enabled ? currentBanner.isBannerActive() ? currentBanner : nextBanner.isBannerActive() ? nextBanner : null : null; } public boolean isBannerActive() { diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/data/CrateSettings.java b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/data/CrateSettings.java index 63132e115..65827951d 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/data/CrateSettings.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/objects/gacha/data/CrateSettings.java @@ -86,7 +86,7 @@ public CrateSettings(FileConfiguration config, String crateName, Crate crate) { CustomFile customFile = yamlManager.getCustomFile(bannerFile); if (customFile == null) { - bannerPackage = null; + bannerPackage = new BannerPackage(null, null, false); return; } @@ -95,7 +95,7 @@ public CrateSettings(FileConfiguration config, String crateName, Crate crate) { BannerData currentBanner = getBanner(yamlFile, "currentBanner"); BannerData nextBanner = getBanner(yamlFile, "nextBanner"); - bannerPackage = new BannerPackage(currentBanner, nextBanner); + bannerPackage = new BannerPackage(currentBanner, nextBanner, true); updateItems(); }