Skip to content

Commit

Permalink
Add /crazycrates force-open back (#715)
Browse files Browse the repository at this point in the history
* open-others shouldn't be usable by everyone
* add second prize to AdvancedExample.yml
* add back /crazycrates forceopen
  • Loading branch information
ryderbelserion committed May 16, 2024
1 parent 33f92a4 commit 46e6dba
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ protected void takeKey(@NotNull final CommandSender sender, @Nullable final Offl
* @param type the keytype to check.
* @return the keytype or virtual key if none found.
*/
protected @NotNull final KeyType getKeyType(@NotNull final String type, boolean openOthers) {
protected @NotNull final KeyType getKeyType(@NotNull final String type) {
if (type.isEmpty()) return KeyType.virtual_key;

KeyType keyType = KeyType.getFromName(type);

if (keyType == null || keyType == KeyType.free_key && !openOthers) {
if (keyType == null || keyType == KeyType.free_key) {
return KeyType.virtual_key;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void give(CommandSender sender, @Suggestion("keys") String type, @Suggest
return;
}

final KeyType keyType = getKeyType(type, false);
final KeyType keyType = getKeyType(type);

if (amount <= 0) {
sender.sendRichMessage(Messages.not_a_number.getMessage(sender, "{number}", String.valueOf(amount)));
Expand Down Expand Up @@ -68,7 +68,7 @@ public void all(CommandSender sender, @Suggestion("keys") String type, @Suggesti
return;
}

final KeyType keyType = getKeyType(type, false);
final KeyType keyType = getKeyType(type);

if (amount <= 0) {
sender.sendRichMessage(Messages.not_a_number.getMessage(sender, "{number}", String.valueOf(amount)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void open(Player player, @Suggestion("crates") String crateName, @Suggest
return;
}

KeyType keyType = getKeyType(type, false);
KeyType keyType = getKeyType(type);

boolean hasKey = this.config.getProperty(ConfigKeys.virtual_accepts_physical_keys) && keyType == KeyType.physical_key ? this.userManager.getTotalKeys(player.getUniqueId(), crate.getName()) >= 1 : this.userManager.getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1;

Expand Down Expand Up @@ -113,7 +113,7 @@ public void open(Player player, @Suggestion("crates") String crateName, @Suggest

@Command("open-others")
@Permission(value = "crazycrates.open-others", def = PermissionDefault.OP)
public void others(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("players") Player player, @Suggestion("admin-keys") String type) {
public void others(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("players") Player player, @Suggestion("keys") String type) {
// If the command is cancelled.
if (isCancelled(player, crateName)) return;

Expand Down Expand Up @@ -150,17 +150,17 @@ public void others(CommandSender sender, @Suggestion("crates") String crateName,
return;
}

KeyType keyType = getKeyType(type, true);
KeyType keyType = getKeyType(type);

if (sender == player && keyType != KeyType.free_key) {
if (sender == player) {
open(player, crate.getName(), type);

return;
}

boolean hasKey = this.config.getProperty(ConfigKeys.virtual_accepts_physical_keys) && keyType == KeyType.physical_key ? this.userManager.getTotalKeys(player.getUniqueId(), crate.getName()) >= 1 : this.userManager.getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1;

if (!hasKey && keyType != KeyType.free_key) {
if (!hasKey) {
//todo() convert this to a bean property!
if (this.config.getProperty(ConfigKeys.need_key_sound_toggle)) {
Sound sound = Sound.sound(Key.key(this.config.getProperty(ConfigKeys.need_key_sound)), Sound.Source.PLAYER, 1f, 1f);
Expand All @@ -183,6 +183,56 @@ public void others(CommandSender sender, @Suggestion("crates") String crateName,
player.sendRichMessage(Messages.opened_a_crate.getMessage(player, placeholders));
}


@Command("forceopen")
@Permission(value = "crazycrates.forceopen", def = PermissionDefault.OP)
public void forceopen(CommandSender sender, @Suggestion("crates") String crateName, @Suggestion("players") Player player) {
// If the command is cancelled.
if (isCancelled(player, crateName)) return;

// Get the crate.
Crate crate = getCrate(player, crateName, false);

// If crate is null, return.
if (crate == null) {
player.sendRichMessage(Messages.not_a_crate.getMessage(player, "{crate}", crateName));

return;
}

CrateType crateType = crate.getCrateType();

// If crate type is null, we return.
if (crateType == null) {
player.sendRichMessage(Messages.internal_error.getMessage(player));

this.plugin.getLogger().severe("An error has occurred: The crate type is null for the crate named " + crate.getName());

return;
}

// Prevent it from working with these crate types.
if (crateType == CrateType.crate_on_the_go || crateType == CrateType.quick_crate || crateType == CrateType.fire_cracker || crateType == CrateType.quad_crate) {
final Map<String, String> placeholders = new HashMap<>();

placeholders.put("{cratetype}", crate.getCrateType().getName());
placeholders.put("{crate}", crate.getName());

player.sendRichMessage(Messages.cant_be_a_virtual_crate.getMessage(player, placeholders));

return;
}

this.crateManager.openCrate(player, crate, KeyType.free_key, player.getLocation(), true, false);

Map<String, String> placeholders = new HashMap<>();

placeholders.put("{crate}", crate.getName());
placeholders.put("{player}", player.getName());

player.sendRichMessage(Messages.opened_a_crate.getMessage(player, placeholders));
}

@Command("mass-open")
@Permission(value = "crazycrates.massopen", def = PermissionDefault.OP)
public void mass(Player player, @Suggestion("crates") String crateName, @Suggestion("keys") String type, @Suggestion("numbers") int amount) {
Expand Down Expand Up @@ -222,7 +272,7 @@ public void mass(Player player, @Suggestion("crates") String crateName, @Suggest
return;
}

final KeyType keyType = getKeyType(type, false);
final KeyType keyType = getKeyType(type);

int keys = keyType == KeyType.physical_key ? this.userManager.getPhysicalKeys(player.getUniqueId(), crate.getName()) : this.userManager.getVirtualKeys(player.getUniqueId(), crate.getName());
int used = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void take(CommandSender sender, @Suggestion("keys") String type, @Suggest
return;
}

final KeyType keyType = getKeyType(type, false);
final KeyType keyType = getKeyType(type);

final Crate crate = getCrate(sender, crateName, false);

Expand Down
19 changes: 18 additions & 1 deletion paper/src/main/resources/crates/AdvancedExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,21 @@ Crate:
- "give %player% gold_nugget 16"
# Alternatively, instead of commands. You can have an Items section which functions the same as the Items section above.
Items:
- "Item:gold_nugget, Amount:16"
- "Item:gold_nugget, Amount:16"
'2':
# The enchants to be stored on the book.
DisplayEnchantments:
- "protection:5"
- "unbreaking:3"
# The item to display in the gui.
# The enchanted book will function with the enchants properly in an anvil.
DisplayItem: "enchanted_book"
# The amount to display in the gui.
DisplayAmount: 3
# The lore of the item.
Lore:
- "<gradient:#8fcfa0:#32a852>A gradient lore!"
# The max range i.e. 25/100 = 15% chance to win.
MaxRange: 100
# The chance to win i.e. 25%
Chance: 25

0 comments on commit 46e6dba

Please sign in to comment.