Skip to content

Commit

Permalink
refactor enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Sep 4, 2024
1 parent ffa4e01 commit e8d40fa
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 77 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import com.badbones69.crazycrates.listeners.BrokeLocationsListener;
import com.badbones69.crazycrates.listeners.CrateControlListener;
import com.badbones69.crazycrates.listeners.MiscListener;
import com.badbones69.crazycrates.listeners.crates.CosmicCrateListener;
import com.badbones69.crazycrates.listeners.crates.types.CosmicCrateListener;
import com.badbones69.crazycrates.listeners.crates.CrateOpenListener;
import com.badbones69.crazycrates.listeners.crates.MobileCrateListener;
import com.badbones69.crazycrates.listeners.crates.QuadCrateListener;
import com.badbones69.crazycrates.listeners.crates.WarCrateListener;
import com.badbones69.crazycrates.listeners.crates.types.MobileCrateListener;
import com.badbones69.crazycrates.listeners.crates.types.QuadCrateListener;
import com.badbones69.crazycrates.listeners.crates.types.WarCrateListener;
import com.badbones69.crazycrates.listeners.other.EntityDamageListener;
import com.badbones69.crazycrates.support.MetricsWrapper;
import com.badbones69.crazycrates.support.holograms.HologramManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.api.utils.ItemUtils;
import com.badbones69.crazycrates.api.utils.MiscUtils;
Expand Down Expand Up @@ -129,7 +129,7 @@ public InventoryBuilder build() {
.addLorePlaceholder("%keys_total%", NumberFormat.getNumberInstance().format(this.userManager.getTotalKeys(uuid, fileName)))
.addLorePlaceholder("%crate_opened%", NumberFormat.getNumberInstance().format(this.userManager.getCrateOpened(uuid, fileName)))
.addLorePlaceholder("%player%", getPlayer().getName())
.setPersistentString(PersistentKeys.crate_key.getNamespacedKey(), fileName);
.setPersistentString(Keys.crate_key.getNamespacedKey(), fileName);

inventory.setItem(slot, ItemUtils.getItem(section, builder, player).getStack());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.badbones69.crazycrates.api.builders.types;

import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.api.objects.Tier;
import com.badbones69.crazycrates.tasks.InventoryManager;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void run(InventoryClickEvent event) {

final PersistentDataContainerView container = item.getPersistentDataContainer();

if (container.has(PersistentKeys.main_menu_button.getNamespacedKey()) && this.config.getProperty(ConfigKeys.enable_crate_menu)) { // Clicked the menu button.
if (container.has(Keys.main_menu_button.getNamespacedKey()) && this.config.getProperty(ConfigKeys.enable_crate_menu)) { // Clicked the menu button.
if (this.inventoryManager.inCratePreview(player)) {
if (holder.overrideMenu()) return;

Expand All @@ -147,25 +147,25 @@ public void run(InventoryClickEvent event) {
return;
}

if (container.has(PersistentKeys.next_button.getNamespacedKey())) { // Clicked the next button.
if (container.has(Keys.next_button.getNamespacedKey())) { // Clicked the next button.
if (this.inventoryManager.getPage(player) < crate.getMaxPage()) {
crate.playSound(player, player.getLocation(), "click-sound","ui.button.click", Sound.Source.PLAYER);

this.inventoryManager.nextPage(player);

this.inventoryManager.openCratePreview(player, crate, container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING));
this.inventoryManager.openCratePreview(player, crate, container.get(Keys.crate_tier.getNamespacedKey(), PersistentDataType.STRING));
}

return;
}

if (container.has(PersistentKeys.back_button.getNamespacedKey())) { // Clicked the back button.
if (container.has(Keys.back_button.getNamespacedKey())) { // Clicked the back button.
if (this.inventoryManager.getPage(player) > 1 && this.inventoryManager.getPage(player) <= crate.getMaxPage()) {
crate.playSound(player, player.getLocation(), "click-sound","ui.button.click", Sound.Source.PLAYER);

this.inventoryManager.backPage(player);

this.inventoryManager.openCratePreview(player, crate, container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING));
this.inventoryManager.openCratePreview(player, crate, container.get(Keys.crate_tier.getNamespacedKey(), PersistentDataType.STRING));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ch.jalu.configme.SettingsManager;
import com.badbones69.crazycrates.api.builders.InventoryBuilder;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.api.objects.Tier;
import com.badbones69.crazycrates.config.ConfigManager;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void run(InventoryClickEvent event) {

final PersistentDataContainerView container = item.getPersistentDataContainer();

if (this.config.getProperty(ConfigKeys.enable_crate_menu) && container.has(PersistentKeys.main_menu_button.getNamespacedKey())) {
if (this.config.getProperty(ConfigKeys.enable_crate_menu) && container.has(Keys.main_menu_button.getNamespacedKey())) {
if (this.inventoryManager.inCratePreview(player)) {
if (holder.overrideMenu()) return;

Expand All @@ -73,10 +73,10 @@ public void run(InventoryClickEvent event) {
return;
}

if (container.has(PersistentKeys.crate_tier.getNamespacedKey())) {
if (container.has(Keys.crate_tier.getNamespacedKey())) {
crate.playSound(player, player.getLocation(), "click-sound", "ui.button.click", Sound.Source.PLAYER);

final String tierName = container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING);
final String tierName = container.get(Keys.crate_tier.getNamespacedKey(), PersistentDataType.STRING);

final Tier tier = crate.getTier(tierName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ch.jalu.configme.SettingsManager;
import ch.jalu.configme.properties.Property;
import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.misc.State;
import com.ryderbelserion.vital.common.utils.StringUtil;
import com.ryderbelserion.vital.paper.api.enums.Support;
import com.ryderbelserion.vital.paper.util.AdvUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.badbones69.crazycrates.api.enums;
package com.badbones69.crazycrates.api.enums.misc;

import com.badbones69.crazycrates.CrazyCrates;
import com.ryderbelserion.vital.paper.api.files.FileManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.badbones69.crazycrates.api.enums;
package com.badbones69.crazycrates.api.enums.misc;

import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataType;
import com.badbones69.crazycrates.CrazyCrates;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("rawtypes")
public enum PersistentKeys {
public enum Keys {

no_firework_damage("firework", PersistentDataType.BOOLEAN),
cosmic_mystery_crate("cosmic_mystery_crate", PersistentDataType.INTEGER),
Expand All @@ -25,7 +24,7 @@ public enum PersistentKeys {
private final String NamespacedKey;
private final PersistentDataType type;

PersistentKeys(@NotNull final String NamespacedKey, @NotNull final PersistentDataType type) {
Keys(@NotNull final String NamespacedKey, @NotNull final PersistentDataType type) {
this.NamespacedKey = NamespacedKey;
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.badbones69.crazycrates.api.enums;
package com.badbones69.crazycrates.api.enums.misc;

public enum State {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.badbones69.crazycrates.api.builders.types.CrateTierMenu;
import com.badbones69.crazycrates.api.crates.CrateHologram;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.config.ConfigManager;
import com.badbones69.crazycrates.config.impl.ConfigKeys;
import com.badbones69.crazycrates.tasks.BukkitUserManager;
Expand Down Expand Up @@ -111,7 +111,7 @@ public Crate(@NotNull final String name,
@NotNull final List<String> prizeMessage,
@NotNull final List<String> prizeCommands,
@NotNull final CrateHologram hologram) {
this.keyBuilder = key.setDisplayName(keyName).setPersistentString(PersistentKeys.crate_key.getNamespacedKey(), name);
this.keyBuilder = key.setDisplayName(keyName).setPersistentString(Keys.crate_key.getNamespacedKey(), name);
this.keyName = keyName;

this.file = file;
Expand Down Expand Up @@ -570,7 +570,7 @@ public final CrateType getCrateType() {
}

public final @Nullable Prize getPrize(@NotNull final ItemStack item) {
return getPrize(item.getPersistentDataContainer().get(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING));
return getPrize(item.getPersistentDataContainer().get(Keys.crate_prize.getNamespacedKey(), PersistentDataType.STRING));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.badbones69.crazycrates.api.objects;

import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.utils.ItemUtils;
import com.badbones69.crazycrates.api.utils.MiscUtils;
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;
Expand Down Expand Up @@ -140,7 +138,7 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName,
* @return the display item that is shown for the preview and the winning prize.
*/
public @NotNull final ItemStack getDisplayItem() {
return this.displayItem.setPersistentString(PersistentKeys.crate_prize.getNamespacedKey(), this.sectionName).getStack();
return this.displayItem.setPersistentString(Keys.crate_prize.getNamespacedKey(), this.sectionName).getStack();
}

/**
Expand Down Expand Up @@ -173,7 +171,7 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName,
this.displayItem.setDisplayLore(lore);
}

return this.displayItem.setPlayer(player).setPersistentString(PersistentKeys.crate_prize.getNamespacedKey(), this.sectionName).getStack();
return this.displayItem.setPlayer(player).setPersistentString(Keys.crate_prize.getNamespacedKey(), this.sectionName).getStack();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.badbones69.crazycrates.api.objects;

import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.builders.ItemBuilder;
import com.ryderbelserion.vital.common.utils.StringUtil;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -96,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).addLorePlaceholder("%chance%", this.getTotalChance()).setPersistentString(PersistentKeys.crate_tier.getNamespacedKey(), this.name).getStack();
return this.item.setDisplayName(this.coloredName).setDisplayLore(this.lore).addLorePlaceholder("%chance%", this.getTotalChance()).setPersistentString(Keys.crate_tier.getNamespacedKey(), this.name).getStack();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.badbones69.crazycrates.api.utils;

import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.ryderbelserion.vital.common.utils.StringUtil;
Expand Down Expand Up @@ -169,7 +169,7 @@ public static boolean isSimilar(@NotNull final ItemStack itemStack, @NotNull fin
* @return the {@link String}
*/
public static String getKey(@NotNull final PersistentDataContainerView container) {
return container.get(PersistentKeys.crate_key.getNamespacedKey(), PersistentDataType.STRING);
return container.get(Keys.crate_key.getNamespacedKey(), PersistentDataType.STRING);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void spawnFirework(@NotNull final Location location, @Nullable fin

PersistentDataContainer fireworkData = firework.getPersistentDataContainer();

fireworkData.set(PersistentKeys.no_firework_damage.getNamespacedKey(), PersistentDataType.BOOLEAN, true);
fireworkData.set(Keys.no_firework_damage.getNamespacedKey(), PersistentDataType.BOOLEAN, true);

plugin.getServer().getRegionScheduler().runDelayed(plugin, location, scheduledTask -> firework.detonate(), 3L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.badbones69.crazycrates.commands.crates.types.admin;

import com.badbones69.crazycrates.api.enums.Files;
import com.badbones69.crazycrates.api.enums.misc.Files;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.commands.crates.types.BaseCommand;
import dev.triumphteam.cmd.bukkit.annotation.Permission;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.badbones69.crazycrates.commands.crates.types.admin.crates;

import com.badbones69.crazycrates.api.enums.Files;
import com.badbones69.crazycrates.api.enums.misc.Files;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.api.utils.MsgUtils;
import com.badbones69.crazycrates.commands.crates.types.BaseCommand;
import dev.triumphteam.cmd.bukkit.annotation.Permission;
import dev.triumphteam.cmd.core.annotations.ArgName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.types.plugins;

import com.badbones69.crazycrates.api.enums.Files;
import com.badbones69.crazycrates.api.enums.misc.Files;
import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.ICrateMigrator;
import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.enums.MigrationType;
import com.ryderbelserion.vital.paper.api.files.CustomFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.configurationdata.CommentsConfiguration;
import ch.jalu.configme.properties.Property;
import com.badbones69.crazycrates.api.enums.State;
import com.ryderbelserion.vital.paper.api.enums.Support;
import com.badbones69.crazycrates.api.enums.misc.State;

import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.badbones69.crazycrates.listeners.crates;
package com.badbones69.crazycrates.listeners.crates.types;

import com.badbones69.crazycrates.api.events.PlayerPrizeEvent;
import com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent;
Expand Down Expand Up @@ -32,7 +32,7 @@
import us.crazycrew.crazycrates.api.enums.types.KeyType;
import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.builders.types.CratePrizeMenu;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.badbones69.crazycrates.api.utils.MiscUtils;
Expand Down Expand Up @@ -178,7 +178,7 @@ public void onMysteryBoxClick(InventoryClickEvent event) {
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();

// Check if it has the mystery crate key otherwise check picked key.
if (container.has(PersistentKeys.cosmic_mystery_crate.getNamespacedKey())) {
if (container.has(Keys.cosmic_mystery_crate.getNamespacedKey())) {
int size = cosmicCrateManager.getPrizes(player).size();

// Check if prizes is less than or equal to totalPrizes before we change any items.
Expand Down Expand Up @@ -212,7 +212,7 @@ public void onMysteryBoxClick(InventoryClickEvent event) {
// Play a sound to indicate they clicked a chest.
holder.getCrate().playSound(player, player.getLocation(), "click-sound","ui.button.click", Sound.Source.PLAYER);
}
} else if (container.has(PersistentKeys.cosmic_picked_crate.getNamespacedKey())) {
} else if (container.has(Keys.cosmic_picked_crate.getNamespacedKey())) {
final Tier tier = this.crateManager.getTier(player, pickedSlot);

// Get item builder.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.badbones69.crazycrates.listeners.crates;
package com.badbones69.crazycrates.listeners.crates.types;

import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.PrizeManager;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.badbones69.crazycrates.api.events.PlayerPrizeEvent;
import com.badbones69.crazycrates.api.objects.Crate;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void onCrateUse(PlayerInteractEvent event) {

final PersistentDataContainerView container = item.getPersistentDataContainer();

final NamespacedKey key = PersistentKeys.crate_key.getNamespacedKey();
final NamespacedKey key = Keys.crate_key.getNamespacedKey();

if (!container.has(key)) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.badbones69.crazycrates.listeners.crates;
package com.badbones69.crazycrates.listeners.crates.types;

import com.badbones69.crazycrates.api.PrizeManager;
import com.badbones69.crazycrates.api.utils.ItemUtils;
Expand All @@ -16,7 +16,7 @@
import com.badbones69.crazycrates.tasks.crates.other.quadcrates.SessionManager;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.api.objects.Prize;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.enums.misc.Keys;
import com.badbones69.crazycrates.api.enums.Messages;
import com.badbones69.crazycrates.api.ChestManager;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void onChestClick(PlayerInteractEvent event) {
final ItemMeta itemMeta = display.getItemMeta();

// Access the pdc and set "crazycrates-item"
itemMeta.getPersistentDataContainer().set(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "1");
itemMeta.getPersistentDataContainer().set(Keys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "1");

// Set the item meta.
display.setItemMeta(itemMeta);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.badbones69.crazycrates.listeners.crates;
package com.badbones69.crazycrates.listeners.crates.types;

import com.badbones69.crazycrates.api.events.PlayerPrizeEvent;
import com.badbones69.crazycrates.api.objects.Crate;
Expand Down
Loading

0 comments on commit e8d40fa

Please sign in to comment.