Skip to content

Commit

Permalink
Merge branch 'Crazy-Crew:main' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Feb 11, 2024
2 parents 401e521 + 23dae4b commit 90a6467
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ Crate:
* Updated slot checks for menu items to rely on PersistentDataContainer.
* Re-organized the default /crate gui
* Check uuids for quad crate sessions over player objects.
* Update /cc additem to take input for tiers which only work for cosmic/casino, /cc additem <crate_name> <prize_number> [tier]
* Update /cc additem again to take input for custom chance, Note: The max range by default is still 100 so keep it under 100. /cc additem <crate_name> <prize_number> <chance> [tier]
* [tier] is an optional arg.

## Fixes:
* Fixed issues with crates being broken in worlds created by world plugins.
* Fixed a few other bugs I can't remember.
* Fixed a bug where the refund event needed to be fired sync.
* Fixed a bug with display damage where if you put a value that can't be parsed as an integer like 50f, It wouldn't just be empty durability.
* Fixed a bug where cc additem wouldn't add tiers to casino/cosmic crate.

## Other:
* [Feature Requests](https://github.com/Crazy-Crew/CrazyCrates/issues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ public void registerComments(CommentsConfiguration conf) {
public static final Property<List<String>> admin_help = newListProperty("Messages.Admin-Help", List.of(
"&c&lCrazy Crates Admin Help",
"",
"&6/cc additem <crate> <prize> &7- &eAdd items in-game to a prize in a crate.",
"&6/cc preview <crate> [player] &7- &eOpens the preview of a crate for a player.",
"&6/cc additem <crate_name> <prize_number> <chance> [tier] &7- &eAdd items in-game to a prize in a crate including Cosmic/Casino.",
"&6/cc preview <crate_name> [player] &7- &eOpens the preview of a crate for a player.",
"&6/cc list &7- &eLists all crates.",
"&6/cc open <crate> &7- &eTries to open a crate for you if you have a key.",
"&6/cc open-others <crate> [player] &7- &eTries to open a crate for a player if they have a key.",
"&6/cc transfer <crate> [player] [amount &7- &eTransfers keys to players you chose.",
"&6/cc open <crate_name> &7- &eTries to open a crate for you if you have a key.",
"&6/cc open-others <crate_name> [player] &7- &eTries to open a crate for a player if they have a key.",
"&6/cc transfer <crate_name> [player] [amount &7- &eTransfers keys to players you chose.",
"&6/cc debug &7- &eDebugs crates",
"&6/cc admin &7- &eShows admin menu",
"&6/cc forceopen <crate> [player] &7- &eOpens a crate for a player for free.",
"&6/cc mass-open <crate> <physical/virtual> [amount] &7- &eMass opens a set amount of crates.",
"&6/cc forceopen <crate_name> [player] &7- &eOpens a crate for a player for free.",
"&6/cc mass-open <crate_name> <physical/virtual> [amount] &7- &eMass opens a set amount of crates.",
"&6/cc tp <location> &7- &eTeleport to a Crate.",
"&6/cc give <physical/virtual> <crate> [amount] [player] &7- &eAllows you to take keys from a player.",
"&6/cc set <crate> &7- &eSet the block you are looking at as a crate.",
"&6/cc give <physical/virtual> <crate_name> [amount] [player] &7- &eAllows you to take keys from a player.",
"&6/cc set <crate_name> &7- &eSet the block you are looking at as a crate.",
"&6/cc set Menu &7- &eSet the block you are looking at to open the /cc menu.",
"&6/cc reload &7- &eReloads the config/data files.",
"&6/cc set1/set2 &7- &eSets position &c#1 &eor &c#2 for when making a new schematic for QuadCrates.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public int getNewPlayerKeys() {
* @param prize the prize the item is being added to.
* @param item the ItemStack that is being added.
*/
public void addEditorItem(String prize, ItemStack item) {
public void addEditorItem(String prize, ItemStack item, int chance) {
List<ItemStack> items = new ArrayList<>();
items.add(item);

Expand Down Expand Up @@ -572,7 +572,70 @@ public void addEditorItem(String prize, ItemStack item) {
this.file.set(path + ".DisplayItem", item.getType().name());
this.file.set(path + ".DisplayAmount", item.getAmount());
this.file.set(path + ".MaxRange", 100);
this.file.set(path + ".Chance", 50);
this.file.set(path + ".Chance", chance);
} else {
// Must be checked as getList will return null if nothing is found.
if (this.file.contains(path + ".Editor-Items")) this.file.getList(path + ".Editor-Items").forEach(listItem -> items.add((ItemStack) listItem));
}

this.file.set(path + ".Editor-Items", items);

File crates = new File(this.plugin.getDataFolder(), "crates");

File crateFile = new File(crates, this.name + ".yml");

try {
this.file.save(crateFile);
} catch (IOException exception) {
this.plugin.getLogger().log(Level.SEVERE, "Failed to save " + this.name + ".yml", exception);
}

this.fileManager.getFile(this.name).reloadFile();

this.plugin.getCrateManager().reloadCrate(this.plugin.getCrateManager().getCrateFromName(this.name));
}

/**
* Add a new editor item to a prize in the crate.
*
* @param prize the prize the item is being added to.
* @param item the ItemStack that is being added.
* @param tier the tier for the crate.
*/
public void addEditorItem(String prize, ItemStack item, Tier tier, int chance) {
List<ItemStack> items = new ArrayList<>();
items.add(item);

String path = "Crate.Prizes." + prize;

if (!this.file.contains(path)) {
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) this.file.set(path + ".DisplayName", item.getItemMeta().getDisplayName());
if (item.getItemMeta().hasLore()) this.file.set(path + ".Lore", item.getItemMeta().getLore());
}

NBTItem nbtItem = new NBTItem(item);

if (nbtItem.hasNBTData()) {
if (nbtItem.hasTag("Unbreakable") && nbtItem.getBoolean("Unbreakable")) this.file.set(path + ".Unbreakable", true);
}

List<String> enchantments = new ArrayList<>();

for (Enchantment enchantment : item.getEnchantments().keySet()) {
enchantments.add((enchantment.getKey().getKey() + ":" + item.getEnchantmentLevel(enchantment)));
}

if (!enchantments.isEmpty()) this.file.set(path + ".DisplayEnchantments", enchantments);

this.file.set(path + ".DisplayItem", item.getType().name());
this.file.set(path + ".DisplayAmount", item.getAmount());
this.file.set(path + ".MaxRange", 100);
this.file.set(path + ".Chance", chance);

this.file.set(path + ".Tiers", new ArrayList<>() {{
add(tier.getName());
}});
} else {
// Must be checked as getList will return null if nothing is found.
if (this.file.contains(path + ".Editor-Items")) this.file.getList(path + ".Editor-Items").forEach(listItem -> items.add((ItemStack) listItem));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ public Prize(String prizeName, String prizeNumber, ConfigurationSection section)
}

/**
* @return returns the name of the prize.
* @return the name of the prize.
*/
public String getPrizeName() {
return this.prizeName;
}


/**
* @return the prize number.
*/
public String getPrizeNumber() {
return this.prizeNumber;
}

/**
* @return returns the display item that is shown for the preview and the winning prize.
* @return the display item that is shown for the preview and the winning prize.
*/
public ItemStack getDisplayItem() {
if (this.itemStack == null) {
Expand All @@ -123,7 +130,7 @@ public ItemStack getDisplayItem() {
}

/**
* @return returns the ItemBuilder of the display item.
* @return the ItemBuilder of the display item.
*/
public ItemBuilder getDisplayItemBuilder() {
return this.displayItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public void load() {
this.bukkitCommandManager.registerSuggestion(SuggestionKey.of("prizes"), (sender, context) -> {
List<String> numbers = new ArrayList<>();

this.plugin.getCrateManager().getCrateFromName(context.getArgs().get(0)).getPrizes().forEach(prize -> numbers.add(prize.getPrizeName()));
this.plugin.getCrateManager().getCrateFromName(context.getArgs().get(0)).getPrizes().forEach(prize -> numbers.add(prize.getPrizeNumber()));

return numbers;
});

this.bukkitCommandManager.registerSuggestion(SuggestionKey.of("tiers"), (sender, context) -> {
List<String> numbers = new ArrayList<>();

this.plugin.getCrateManager().getCrateFromName(context.getArgs().get(0)).getTiers().forEach(tier -> numbers.add(tier.getName()));

return numbers;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private String getContext(String subCommand, String commandOrder) {
case "transfer" -> correctUsage = commandOrder + "<crate-name> <player-name> <amount>";
case "debug", "open", "set" -> correctUsage = commandOrder + "<crate-name>";
case "tp" -> correctUsage = commandOrder + "<id>";
case "additem" -> correctUsage = commandOrder + "<crate-name> <prize-number>";
case "additem" -> correctUsage = commandOrder + "<crate-name> <prize-number> <chance> [tier]";
case "preview", "open-others", "forceopen" -> correctUsage = commandOrder + "<crate-name> <player-name>";
case "mass-open" -> correctUsage = commandOrder + "<crate-name> <key-type> <amount>";
case "give-random" -> correctUsage = commandOrder + "<key-type> <amount> <player-name>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.builders.types.CrateTierMenu;
import com.badbones69.crazycrates.api.objects.Tier;
import dev.triumphteam.cmd.core.annotation.ArgName;
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.Default;
import dev.triumphteam.cmd.core.annotation.SubCommand;
import dev.triumphteam.cmd.core.annotation.Suggestion;
import dev.triumphteam.cmd.core.annotation.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -242,7 +238,7 @@ public void onAdminTeleport(Player player, @Suggestion("locations") String id) {

@SubCommand("additem")
@Permission(value = "crazycrates.command.admin.additem", def = PermissionDefault.OP)
public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crateName, @Suggestion("prizes") String prize) {
public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crateName, @Suggestion("prizes") String prize, @Suggestion("numbers") int chance, @Optional @Suggestion("tiers") String tier) {
ItemStack item = player.getInventory().getItemInMainHand();

if (item.getType() == Material.AIR) {
Expand All @@ -257,13 +253,12 @@ public void onAdminCrateAddItem(Player player, @Suggestion("crates") String crat
return;
}

if (crate.getCrateType() == CrateType.cosmic) {
player.sendMessage(Messages.failed_to_add_item.getString());
return;
}

try {
crate.addEditorItem(prize, item);
if (tier == null) {
crate.addEditorItem(prize, item, chance);
} else {
crate.addEditorItem(prize, item, crate.getTier(tier), chance);
}
} catch (Exception exception) {
this.plugin.getServer().getLogger().log(Level.WARNING, "Failed to add a new prize to the " + crate.getName() + " crate.", exception);

Expand Down

0 comments on commit 90a6467

Please sign in to comment.