From 4456935b9fbba7eab8f17a09b9e4bd738191ec73 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 19 Aug 2024 22:09:05 -0400 Subject: [PATCH] add %chance% --- CHANGELOG.md | 1 + .../crazycrates/api/objects/Prize.java | 26 +++++++++++++---- .../crazycrates/api/objects/Tier.java | 28 ++++++++++++++----- src/main/resources/crates/AdvancedExample.yml | 2 +- src/main/resources/crates/CrateExample.yml | 2 +- .../resources/crates/types/CasinoCrate.yml | 9 ++++-- .../resources/crates/types/CosmicCrate.yml | 13 +++++---- src/main/resources/crates/types/QuadCrate.yml | 4 +-- .../resources/crates/types/WonderCrate.yml | 2 +- 9 files changed, 62 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bafe433fa..81e287e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ Crate: ### Fixes: - Fixed a rare issue where you weren't able to open QuickCrate - Fixed a duplication issue with CosmicCrate +- Fixed an issue where CMI likely wouldn't be detected ### Changes: - Right click now opens the crate menu as well. diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java index 499d3ca1d..652008248 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -7,6 +7,7 @@ import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.api.builders.ItemBuilder; +import com.ryderbelserion.vital.common.utils.StringUtil; import com.ryderbelserion.vital.paper.api.enums.Support; import com.ryderbelserion.vital.paper.util.AdvUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; @@ -216,21 +217,34 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, public @NotNull final String getCrateName() { return this.crateName; } - + /** - * @return the chance the prize has of being picked. + * Get the total chance + * + * @return the total chance divided */ - public final int getChance() { - return this.chance; + public final String getTotalChance() { + return StringUtil.formatDouble((double) getChance() / getMaxRange() * 100) + "%"; } - + /** + * Get the max range + * * @return the max range of the prize. */ public final int getMaxRange() { return this.maxRange; } + /** + * Get the chance + * + * @return the chance the prize has of being picked. + */ + public final int getChance() { + return this.chance; + } + /** * @return true if a firework explosion is played and false if not. */ @@ -337,6 +351,8 @@ public void broadcast(final Crate crate) { builder.setDisplayLore(this.section.getStringList("Lore")); } + builder.addLorePlaceholder("%chance%", this.getTotalChance()); + builder.setGlowing(this.section.contains("Glowing") ? section.getBoolean("Glowing") : null); builder.setDamage(this.section.getInt("DisplayDamage", 0)); diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java b/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java index 61a3fe0a5..b9ef2ce56 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java @@ -2,6 +2,7 @@ import com.badbones69.crazycrates.api.enums.PersistentKeys; import com.badbones69.crazycrates.api.builders.ItemBuilder; +import com.ryderbelserion.vital.common.utils.StringUtil; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -54,21 +55,34 @@ public Tier(@NotNull final String tier, @NotNull final ConfigurationSection sect public @NotNull final ItemBuilder getItem() { return this.item; } - + /** - * @return the chance of being picked. + * Get the total chance + * + * @return the total chance divided */ - public final int getChance() { - return this.chance; + public final String getTotalChance() { + return StringUtil.formatDouble((double) getChance() / getMaxRange() * 100) + "%"; } - + /** - * @return the range of max possible chances. + * Get the max range + * + * @return the max range of the prize. */ public final int getMaxRange() { return this.maxRange; } + /** + * Get the chance + * + * @return the chance the prize has of being picked. + */ + public final int getChance() { + return this.chance; + } + /** * @return slot in the inventory. */ @@ -82,6 +96,6 @@ public final int getSlot() { public @NotNull final ItemStack getTierItem(final @Nullable Player target) { if (target != null) this.item.setPlayer(target); - return this.item.setDisplayName(this.coloredName).setDisplayLore(this.lore).setPersistentString(PersistentKeys.crate_tier.getNamespacedKey(), this.name).getStack(); + return this.item.setDisplayName(this.coloredName).setDisplayLore(this.lore).addLorePlaceholder("%chance%", this.getTotalChance()).setPersistentString(PersistentKeys.crate_tier.getNamespacedKey(), this.name).getStack(); } } \ No newline at end of file diff --git a/src/main/resources/crates/AdvancedExample.yml b/src/main/resources/crates/AdvancedExample.yml index 3b088433b..0669b44eb 100644 --- a/src/main/resources/crates/AdvancedExample.yml +++ b/src/main/resources/crates/AdvancedExample.yml @@ -159,7 +159,7 @@ Crate: # The lore of the item. DisplayLore: - "Win the warlord's set." - - "Chance: 40%" + - "Chance: %chance%" # The max range i.e. 40/100 = 40% chance to win. MaxRange: 100 # The chance to win i.e. 40% diff --git a/src/main/resources/crates/CrateExample.yml b/src/main/resources/crates/CrateExample.yml index 7140bd9f0..464d18c07 100644 --- a/src/main/resources/crates/CrateExample.yml +++ b/src/main/resources/crates/CrateExample.yml @@ -248,7 +248,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain Money." - - "Chance: 20%" + - "Chance: %chance%" # The max range i.e. 20/100 = 25% chance to win. MaxRange: 100 # The chance to win i.e. 20% diff --git a/src/main/resources/crates/types/CasinoCrate.yml b/src/main/resources/crates/types/CasinoCrate.yml index d232da9fa..bc2df1ffb 100644 --- a/src/main/resources/crates/types/CasinoCrate.yml +++ b/src/main/resources/crates/types/CasinoCrate.yml @@ -138,6 +138,7 @@ Crate: # The in-game lore of the tier. Lore: - "A basic tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -154,6 +155,7 @@ Crate: # The in-game lore of the tier. Lore: - "An uncommon tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -170,6 +172,7 @@ Crate: # The in-game lore of the tier. Lore: - "A rare tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "ender_chest" # The custom model data of the item, -1 is disabled. @@ -259,7 +262,7 @@ Crate: # The lore of the item. DisplayLore: - "Win the warlord's set." - - "Chance: 40%" + - "Chance: %chance%" # The max range i.e. 40/100 = 40% chance to win. MaxRange: 100 # The chance to win i.e. 40% @@ -356,7 +359,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a fancy pair of pants." - - "Chance: 4%" + - "Chance: %chance%" # The items to win. Items: - "Item:chainmail_leggings, Amount:1, Damage:75, Trim-Pattern:sentry, Trim-Material:lapis, Name:Fancy Pants, protection:2" @@ -385,7 +388,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a old classic sword." - - "Chance: 3.5%" + - "Chance: %chance%" # The max range i.e. 35/1000 = 3.5% chance to win. MaxRange: 1000 # The chance to win i.e. 3.5%. diff --git a/src/main/resources/crates/types/CosmicCrate.yml b/src/main/resources/crates/types/CosmicCrate.yml index b87658b02..8ca86b05c 100644 --- a/src/main/resources/crates/types/CosmicCrate.yml +++ b/src/main/resources/crates/types/CosmicCrate.yml @@ -137,6 +137,7 @@ Crate: # The in-game lore of the tier. Lore: - "A basic tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -153,6 +154,7 @@ Crate: # The in-game lore of the tier. Lore: - "An uncommon tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -169,6 +171,7 @@ Crate: # The in-game lore of the tier. Lore: - "A rare tier." + - "%chance%" # The item used for the secondary gui when you right-click for the preview. Item: "ender_chest" # The custom model data of the item, -1 is disabled. @@ -288,7 +291,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a cheap helmet." - - "Chance: 60%" + - "Chance: %chance%" # The tiers the prize can be won from. Tiers: - "Basic" @@ -315,7 +318,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain Money." - - "Chance: 20%" + - "Chance: %chance%" # If the prize should spawn fireworks. Firework: true # The tiers the prize can be won from. @@ -351,7 +354,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a crazy cool sword." - - "Chance: 10%" + - "Chance: %chance%" # The tiers the prize can be won from. Tiers: - "Rare" @@ -376,7 +379,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain a butt load of Money." - - "Chance: 20%" + - "Chance: %chance%" # If the prize should spawn fireworks. Firework: true # The tiers the prize can be won from. @@ -404,7 +407,7 @@ Crate: DisplayLore: - "A special Key" - "For a special Crate." - - "Chance: 1.0%" + - "Chance: %chance%" # If the prize should spawn fireworks. Firework: true # If the display item should glow. diff --git a/src/main/resources/crates/types/QuadCrate.yml b/src/main/resources/crates/types/QuadCrate.yml index 2729fb7c4..0537b7d60 100644 --- a/src/main/resources/crates/types/QuadCrate.yml +++ b/src/main/resources/crates/types/QuadCrate.yml @@ -194,7 +194,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a fancy pair of pants." - - "Chance: 4%" + - "Chance: %chance%" # The max range i.e. 40/1000 = 4% chance to win. MaxRange: 1000 # The chance to win i.e. 4% @@ -227,7 +227,7 @@ Crate: # The lore of the item. DisplayLore: - "Win a old classic sword." - - "Chance: 3.5%" + - "Chance: %chance%" # The max range i.e. 35/1000 = 3.5% chance to win. MaxRange: 1000 # The chance to win i.e. 3.5%. diff --git a/src/main/resources/crates/types/WonderCrate.yml b/src/main/resources/crates/types/WonderCrate.yml index 084b466bc..fd3fa268d 100644 --- a/src/main/resources/crates/types/WonderCrate.yml +++ b/src/main/resources/crates/types/WonderCrate.yml @@ -238,7 +238,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain Money." - - "Chance: 20%" + - "Chance: %chance%" # The max range i.e. 20/100 = 25% chance to win. MaxRange: 100 # The chance to win i.e. 20%