Skip to content

Commit

Permalink
add %chance%
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 20, 2024
1 parent 4015958 commit 4456935
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/com/badbones69/crazycrates/api/objects/Prize.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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));
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/badbones69/crazycrates/api/objects/Tier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/crates/AdvancedExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win the warlord's set."
- "<bold><gold>Chance: <red>40%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 40/100 = 40% chance to win.
MaxRange: 100
# The chance to win i.e. 40%
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/crates/CrateExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Make it rain Money."
- "<bold><gold>Chance: <red>20%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 20/100 = 25% chance to win.
MaxRange: 100
# The chance to win i.e. 20%
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/crates/types/CasinoCrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<gray>A basic tier."
- "<red>%chance%</red>"
# 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.
Expand All @@ -154,6 +155,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<green>An uncommon tier."
- "<red>%chance%</red>"
# 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.
Expand All @@ -170,6 +172,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<red>A rare tier."
- "<red>%chance%</red>"
# 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.
Expand Down Expand Up @@ -259,7 +262,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win the warlord's set."
- "<bold><gold>Chance: <red>40%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 40/100 = 40% chance to win.
MaxRange: 100
# The chance to win i.e. 40%
Expand Down Expand Up @@ -356,7 +359,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a fancy pair of pants."
- "<bold><gold>Chance: <red>4%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The items to win.
Items:
- "Item:chainmail_leggings, Amount:1, Damage:75, Trim-Pattern:sentry, Trim-Material:lapis, Name:<bold><green>Fancy Pants</bold>, protection:2"
Expand Down Expand Up @@ -385,7 +388,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a old classic sword."
- "<bold><gold>Chance: <red>3.5%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 35/1000 = 3.5% chance to win.
MaxRange: 1000
# The chance to win i.e. 3.5%.
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/crates/types/CosmicCrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<gray>A basic tier."
- "<red>%chance%</red>"
# 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.
Expand All @@ -153,6 +154,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<green>An uncommon tier."
- "<red>%chance%</red>"
# 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.
Expand All @@ -169,6 +171,7 @@ Crate:
# The in-game lore of the tier.
Lore:
- "<red>A rare tier."
- "<red>%chance%</red>"
# 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.
Expand Down Expand Up @@ -288,7 +291,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a cheap helmet."
- "<bold><gold>Chance: <red>60%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The tiers the prize can be won from.
Tiers:
- "Basic"
Expand All @@ -315,7 +318,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Make it rain Money."
- "<bold><gold>Chance: <red>20%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# If the prize should spawn fireworks.
Firework: true
# The tiers the prize can be won from.
Expand Down Expand Up @@ -351,7 +354,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a crazy cool sword."
- "<bold><gold>Chance: <red>10%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The tiers the prize can be won from.
Tiers:
- "Rare"
Expand All @@ -376,7 +379,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Make it rain a butt load of Money."
- "<bold><gold>Chance: <red>20%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# If the prize should spawn fireworks.
Firework: true
# The tiers the prize can be won from.
Expand Down Expand Up @@ -404,7 +407,7 @@ Crate:
DisplayLore:
- "<gray>A special Key"
- "<gray>For a special Crate."
- "<bold><gold>Chance: <red>1.0%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# If the prize should spawn fireworks.
Firework: true
# If the display item should glow.
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/crates/types/QuadCrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a fancy pair of pants."
- "<bold><gold>Chance: <red>4%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 40/1000 = 4% chance to win.
MaxRange: 1000
# The chance to win i.e. 4%
Expand Down Expand Up @@ -227,7 +227,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Win a old classic sword."
- "<bold><gold>Chance: <red>3.5%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 35/1000 = 3.5% chance to win.
MaxRange: 1000
# The chance to win i.e. 3.5%.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/crates/types/WonderCrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Crate:
# The lore of the item.
DisplayLore:
- "<gray>Make it rain Money."
- "<bold><gold>Chance: <red>20%</bold>"
- "<bold><gold>Chance: <red>%chance%</bold>"
# The max range i.e. 20/100 = 25% chance to win.
MaxRange: 100
# The chance to win i.e. 20%
Expand Down

0 comments on commit 4456935

Please sign in to comment.