From a023bc607d2c8a3b843d59a2a46ae0fa99de0a4c Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Wed, 4 Sep 2024 02:49:51 -0400 Subject: [PATCH 01/18] add initial event changes to better handle crate management --- .../badbones69/crazycrates/CrazyCrates.java | 4 + .../api/enums/crates/CrateStatus.java | 19 ++ .../api/events/crates/CrateStatusEvent.java | 71 ++++++++ .../listeners/crates/CrateStatusListener.java | 72 ++++++++ .../tasks/crates/types/CsgoCrate.java | 165 ------------------ .../tasks/crates/types/v2/CsgoCrate.java | 132 ++++++++++++++ 6 files changed, 298 insertions(+), 165 deletions(-) create mode 100644 src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java create mode 100644 src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java create mode 100644 src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java delete mode 100644 src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java create mode 100644 src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java diff --git a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java index da8321be3..f04662087 100644 --- a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java +++ b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java @@ -12,6 +12,7 @@ import com.badbones69.crazycrates.listeners.BrokeLocationsListener; import com.badbones69.crazycrates.listeners.CrateControlListener; import com.badbones69.crazycrates.listeners.MiscListener; +import com.badbones69.crazycrates.listeners.crates.CrateStatusListener; import com.badbones69.crazycrates.listeners.crates.types.CosmicCrateListener; import com.badbones69.crazycrates.listeners.crates.CrateOpenListener; import com.badbones69.crazycrates.listeners.crates.types.MobileCrateListener; @@ -104,6 +105,9 @@ public void onEnable() { new CrateMainMenu(), new CrateTierMenu(), + // Crate Monitoring + new CrateStatusListener(), + // Other listeners. new BrokeLocationsListener(), new CrateControlListener(), diff --git a/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java b/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java new file mode 100644 index 000000000..230e24c41 --- /dev/null +++ b/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java @@ -0,0 +1,19 @@ +package com.badbones69.crazycrates.api.enums.crates; + +public enum CrateStatus { + + failed("Failed"), + ended("Ended"), + cycling("Cycling"), + opened("Opened"); + + private final String status; + + CrateStatus(final String status) { + this.status = status; + } + + public final String getStatus() { + return this.status; + } +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java b/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java new file mode 100644 index 000000000..674ceed8c --- /dev/null +++ b/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java @@ -0,0 +1,71 @@ +package com.badbones69.crazycrates.api.events.crates; + +import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.objects.Crate; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +public class CrateStatusEvent extends Event { + + private final Player player; + private final Crate crate; + + public CrateStatusEvent(@NotNull final Crate crate, @NotNull final Player player) { + this.status = CrateStatus.opened; + this.player = player; + this.crate = crate; + } + + private Inventory inventory; + private CrateStatus status; + private Location location; + + public void setInventory(final Inventory inventory) { + this.inventory = inventory; + } + + public final Inventory getInventory() { + return this.inventory; + } + + public void setLocation(final Location location) { + this.location = location != null ? location : this.player.getLocation(); + } + + public final Location getLocation() { + return this.location; + } + + public final CrateStatusEvent setStatus(final CrateStatus status) { + this.status = status; + + return this; + } + + public final CrateStatus getStatus() { + return this.status; + } + + public final Player getPlayer() { + return this.player; + } + + public final Crate getCrate() { + return this.crate; + } + + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public @NotNull HandlerList getHandlers() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java new file mode 100644 index 000000000..0efb060b5 --- /dev/null +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java @@ -0,0 +1,72 @@ +package com.badbones69.crazycrates.listeners.crates; + +import com.badbones69.crazycrates.CrazyCrates; +import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; +import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.tasks.crates.CrateManager; +import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; +import net.kyori.adventure.sound.Sound; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.java.JavaPlugin; + +public class CrateStatusListener implements Listener { + + private final CrazyCrates plugin = JavaPlugin.getPlugin(CrazyCrates.class); + + private final CrateManager crateManager = this.plugin.getCrateManager(); + + @EventHandler(priority = EventPriority.MONITOR) + public void onCrateStatus(CrateStatusEvent event) { + final CrateStatus status = event.getStatus(); + final Player player = event.getPlayer(); + final Crate crate = event.getCrate(); + + final Location location = player.getLocation(); + + switch (status) { + case ended, failed -> { + crate.playSound(player, location, "stop-sound", "entity.player.levelup", Sound.Source.PLAYER); + + switch (crate.getCrateType()) { + case quad_crate -> this.crateManager.endQuadCrate(player); + + case quick_crate -> this.crateManager.endQuickCrate(player, location, crate, false); + + default -> this.crateManager.endCrate(player); + } + + // Always remove thy player from thy opening list! + this.crateManager.removePlayerFromOpeningList(player); + + final Inventory inventory = event.getInventory(); + + // Close inventory, if the crate requires an inventory. + if (inventory != null) { + new FoliaRunnable(player.getScheduler(), null) { + @Override + public void run() { + if (player.getOpenInventory().getTopInventory().equals(inventory)) player.closeInventory(InventoryCloseEvent.Reason.UNLOADED); + } + }.runDelayed(plugin, 40); + } + } + + case cycling -> { + crate.playSound(player, location, "cycle-sound", "block.note_block.xylophone", Sound.Source.PLAYER); + } + + case opened -> { + + } + + default -> {} + } + } +} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java deleted file mode 100644 index 309d8233d..000000000 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.badbones69.crazycrates.tasks.crates.types; - -import com.badbones69.crazycrates.api.objects.Crate; -import com.badbones69.crazycrates.api.objects.Prize; -import com.badbones69.crazycrates.api.PrizeManager; -import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; -import net.kyori.adventure.sound.Sound; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import us.crazycrew.crazycrates.api.enums.types.KeyType; -import com.badbones69.crazycrates.api.builders.CrateBuilder; -import com.badbones69.crazycrates.api.utils.MiscUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -public class CsgoCrate extends CrateBuilder { - - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - - public CsgoCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { - super(crate, player, size); - } - - @Override - public void open(@NotNull final KeyType type, final boolean checkHand) { - // Crate event failed so we return. - if (isCrateEventValid(type, checkHand)) { - return; - } - - final Player player = getPlayer(); - final UUID uuid = player.getUniqueId(); - final Crate crate = getCrate(); - final String fileName = crate.getFileName(); - - final boolean keyCheck = this.userManager.takeKeys(uuid, fileName, type, crate.useRequiredKeys() ? crate.getRequiredKeys() : 1, checkHand); - - if (!keyCheck) { - // Remove from opening list. - this.crateManager.removePlayerFromOpeningList(player); - - return; - } - - // Set the glass/display items to the inventory. - populate(); - - // Open the inventory. - player.openInventory(getInventory()); - - addCrateTask(new FoliaRunnable(player.getScheduler(), null) { - int time = 1; - - int full = 0; - - int open = 0; - - @Override - public void run() { - if (this.full <= 50) { // When Spinning - moveItemsAndSetGlass(); - - playSound("cycle-sound", Sound.Source.PLAYER, "block.note_block.xylophone"); - } - - this.open++; - - if (this.open >= 5) { - player.openInventory(getInventory()); - - this.open = 0; - } - - this.full++; - - if (this.full > 51) { - if (MiscUtils.slowSpin(120, 15).contains(this.time)) { // When Slowing Down - moveItemsAndSetGlass(); - - playSound("cycle-sound", Sound.Source.PLAYER, "block.note_block.xylophone"); - } - - this.time++; - - if (this.time == 60) { // When done - playSound("stop-sound", Sound.Source.PLAYER, "entity.player.levelup"); - - crateManager.endCrate(player); - - final ItemStack itemStack = new ItemStack(Material.GRAY_STAINED_GLASS); - - setItem(4, itemStack); - setItem(22, itemStack); - - final ItemStack item = getInventory().getItem(13); - - if (item != null) { - final Prize prize = crate.getPrize(item); - - PrizeManager.givePrize(player, crate, prize); - } - - crateManager.removePlayerFromOpeningList(player); - - cancel(); - - new FoliaRunnable(player.getScheduler(), null) { - @Override - public void run() { - if (player.getOpenInventory().getTopInventory().equals(getInventory())) player.closeInventory(); - } - }.runDelayed(plugin, 40); - } else if (this.time > 60) { // Added this due reports of the prizes spamming when low tps. - cancel(); - } - } - } - }.runAtFixedRate(this.plugin, 1, 1)); - } - - private void populate() { - getBorder().forEach(this::setCustomGlassPane); - - // Set display items. - for (int index = 9; index > 8 && index < 18; index++) { - setItem(index, getCrate().pickPrize(getPlayer()).getDisplayItem(getPlayer())); - } - } - - private void moveItemsAndSetGlass() { - final List items = new ArrayList<>(); - - final Player player = getPlayer(); - final Crate crate = getCrate(); - - for (int i = 9; i > 8 && i < 17; i++) { - items.add(getInventory().getItem(i)); - } - - setItem(9, crate.pickPrize(player).getDisplayItem(player)); - - for (int i = 0; i < 8; i++) { - setItem(i + 10, items.get(i)); - } - - getBorder().forEach(this::setCustomGlassPane); - } - - @Override - public void run() { - - } - - private List getBorder() { - return Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26); - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java new file mode 100644 index 000000000..233d137d7 --- /dev/null +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java @@ -0,0 +1,132 @@ +package com.badbones69.crazycrates.tasks.crates.types.v2; + +import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; +import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.api.PrizeManager; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import us.crazycrew.crazycrates.api.enums.types.KeyType; +import com.badbones69.crazycrates.api.builders.CrateBuilder; +import com.badbones69.crazycrates.api.utils.MiscUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class CsgoCrate extends CrateBuilder { + + private final CrateStatusEvent event; + + public CsgoCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { + super(crate, player, size); + + this.event = new CrateStatusEvent(crate, player); + } + + private int time = 1; + private int full = 0; + private int open = 0; + + @Override + public void run() { + final Player player = getPlayer(); + final Crate crate = getCrate(); + + if (this.full <= 50) { // cycling + moveItemsAndSetGlass(); + + this.event.setStatus(CrateStatus.cycling).callEvent(); + } + + this.open++; + + if (this.open >= 5) { // opens the inventory + player.openInventory(getInventory()); + + this.open = 0; + } + + this.full++; + + if (this.full > 51) { // slowing down + if (MiscUtils.slowSpin(120, 15).contains(this.time)) { // cycling + moveItemsAndSetGlass(); + + this.event.setStatus(CrateStatus.cycling).callEvent(); + } + + this.time++; + + if (this.time >= 60) { // finished + this.event.setStatus(CrateStatus.ended).callEvent(); + + final ItemStack itemStack = new ItemStack(Material.GRAY_STAINED_GLASS); + + setItem(4, itemStack); + setItem(22, itemStack); + + final ItemStack item = getInventory().getItem(13); + + if (item != null) PrizeManager.givePrize(player, crate, crate.getPrize(item)); + + cancel(); + } + } + } + + @Override + public void open(@NotNull final KeyType type, final boolean checkHand) { + final Player player = getPlayer(); + final Crate crate = getCrate(); + + final UUID uuid = player.getUniqueId(); + final String fileName = crate.getFileName(); + + final boolean keyCheck = this.userManager.takeKeys(uuid, fileName, type, crate.useRequiredKeys() ? crate.getRequiredKeys() : 1, checkHand); + + if (!keyCheck) { + this.crateManager.removePlayerFromOpeningList(player); + + return; + } + + getBorder().forEach(this::setCustomGlassPane); + + // Set display items. + for (int index = 9; index > 8 && index < 18; index++) { + setItem(index, getCrate().pickPrize(getPlayer()).getDisplayItem(getPlayer())); + } + + // Open the inventory. + player.openInventory(getInventory()); + + // run the task, which uses the run method above. + runAtFixedRate(this.plugin, 1, 1); + } + + private void moveItemsAndSetGlass() { + final List items = new ArrayList<>(); + + final Player player = getPlayer(); + final Crate crate = getCrate(); + + for (int i = 9; i > 8 && i < 17; i++) { + items.add(getInventory().getItem(i)); + } + + setItem(9, crate.pickPrize(player).getDisplayItem(player)); + + for (int i = 0; i < 8; i++) { + setItem(i + 10, items.get(i)); + } + + getBorder().forEach(this::setCustomGlassPane); + } + + private List getBorder() { + return Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26); + } +} \ No newline at end of file From f6d6c9de3cc5d36239cd2dc34177590bd90f1823 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Wed, 4 Sep 2024 02:51:16 -0400 Subject: [PATCH 02/18] add annotations --- .../crazycrates/api/events/crates/CrateStatusEvent.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java b/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java index 674ceed8c..1f0ab3c70 100644 --- a/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java +++ b/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java @@ -8,6 +8,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.Inventory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class CrateStatusEvent extends Event { @@ -24,15 +25,15 @@ public CrateStatusEvent(@NotNull final Crate crate, @NotNull final Player player private CrateStatus status; private Location location; - public void setInventory(final Inventory inventory) { + public void setInventory(@Nullable final Inventory inventory) { this.inventory = inventory; } - public final Inventory getInventory() { + public @Nullable final Inventory getInventory() { return this.inventory; } - public void setLocation(final Location location) { + public void setLocation(@Nullable final Location location) { this.location = location != null ? location : this.player.getLocation(); } @@ -40,7 +41,7 @@ public final Location getLocation() { return this.location; } - public final CrateStatusEvent setStatus(final CrateStatus status) { + public final CrateStatusEvent setStatus(@NotNull final CrateStatus status) { this.status = status; return this; From bbf45451d996a03fbaa70764933613d11e3953ce Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Wed, 4 Sep 2024 14:01:02 -0400 Subject: [PATCH 03/18] update import --- .../com/badbones69/crazycrates/tasks/crates/CrateManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index bcf13dbe7..bf581c21e 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -16,7 +16,7 @@ import com.badbones69.crazycrates.tasks.crates.types.CasinoCrate; import com.badbones69.crazycrates.tasks.crates.types.CosmicCrate; import com.badbones69.crazycrates.tasks.crates.types.CrateOnTheGo; -import com.badbones69.crazycrates.tasks.crates.types.CsgoCrate; +import com.badbones69.crazycrates.tasks.crates.types.v2.CsgoCrate; import com.badbones69.crazycrates.tasks.crates.types.FireCrackerCrate; import com.badbones69.crazycrates.tasks.crates.types.QuadCrate; import com.badbones69.crazycrates.tasks.crates.types.QuickCrate; From c6dd78bce9e410e2c8c0ac4ce31b087733bcc062 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 12:14:59 -0400 Subject: [PATCH 04/18] remove isLegacy() --- gradle/libs.versions.toml | 3 +- .../badbones69/crazycrates/CrazyCrates.java | 7 -- .../api/builders/InventoryBuilder.java | 38 +++-------- .../crazycrates/api/enums/Messages.java | 48 +++---------- .../crazycrates/api/objects/Crate.java | 67 +++---------------- .../crazycrates/api/objects/Prize.java | 23 ------- .../crazycrates/api/utils/MsgUtils.java | 24 ++----- .../crazycrates/config/impl/ConfigKeys.java | 18 ----- .../listeners/crates/CrateOpenListener.java | 7 +- .../crates/types/CosmicCrateListener.java | 6 +- .../tasks/crates/types/QuickCrate.java | 7 +- 11 files changed, 36 insertions(+), 212 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4a352c0e5..c04f5d0a8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,7 +31,7 @@ vault = "1.7.1" triumph-cmd = "2.0.0-ALPHA-10" jetbrains = "24.1.0" adventure = "4.17.0" -vital = "2.7.4" +vital = "0.0.1" # Modrinth @@ -55,7 +55,6 @@ oraxen = { module = "io.th0rgal:oraxen", version.ref = "oraxen" } # Libraries triumph-cmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version.ref = "triumph-cmd" } -vital-common = { module = "com.ryderbelserion.vital:common", version.ref = "vital" } vital-paper = { module = "com.ryderbelserion.vital:paper", version.ref = "vital" } jetbrains = { module = "org.jetbrains:annotations", version.ref = "jetbrains" } diff --git a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java index f04662087..c386a30fb 100644 --- a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java +++ b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java @@ -7,8 +7,6 @@ import com.badbones69.crazycrates.api.objects.other.Server; import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.commands.CommandManager; -import com.badbones69.crazycrates.config.ConfigManager; -import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.listeners.BrokeLocationsListener; import com.badbones69.crazycrates.listeners.CrateControlListener; import com.badbones69.crazycrates.listeners.MiscListener; @@ -192,9 +190,4 @@ public void onDisable() { public @NotNull final Timer getTimer() { return this.timer; } - - @Override - public final boolean isLegacy() { - return !ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle); - } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/InventoryBuilder.java b/src/main/java/com/badbones69/crazycrates/api/builders/InventoryBuilder.java index 770eb2844..0b1ec2e66 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/InventoryBuilder.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/InventoryBuilder.java @@ -58,13 +58,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.title = title; this.size = size; - String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; + final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - if (this.plugin.isLegacy()) { - this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle)); - } else { - this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); - } + this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate) { @@ -74,13 +70,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; - String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; + final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - if (this.plugin.isLegacy()) { - this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle)); - } else { - this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); - } + this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, final int page, @NotNull final Crate crate) { @@ -91,13 +83,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; - String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; + final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - if (this.plugin.isLegacy()) { - this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle)); - } else { - this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); - } + this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate, @NotNull final List tiers) { @@ -108,13 +96,9 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; this.tiers = tiers; - String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; + final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - if (this.plugin.isLegacy()) { - this.inventory = this.server.createInventory(this, this.size, ItemUtil.color(inventoryTitle)); - } else { - this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); - } + this.inventory = this.server.createInventory(this, this.size, AdvUtil.parse(inventoryTitle)); } public InventoryBuilder() {} @@ -127,7 +111,7 @@ public boolean overrideMenu() { if (!commands.isEmpty()) { commands.forEach(value -> { - String command = value.replaceAll("%player%", quoteReplacement(this.player.getName())).replaceAll("%crate%", quoteReplacement(this.crate.getFileName())); + final String command = value.replaceAll("%player%", quoteReplacement(this.player.getName())).replaceAll("%crate%", quoteReplacement(this.crate.getFileName())); MiscUtils.sendCommand(command); }); @@ -197,10 +181,6 @@ public final boolean contains(@NotNull final String message) { } public void sendTitleChange() { - if (this.plugin.isLegacy()) { - return; - } - ServerPlayer entityPlayer = (ServerPlayer) ((CraftHumanEntity) getView().getPlayer()).getHandle(); int containerId = entityPlayer.containerMenu.containerId; MenuType windowType = CraftContainer.getNotchInventoryType(getView().getTopInventory()); diff --git a/src/main/java/com/badbones69/crazycrates/api/enums/Messages.java b/src/main/java/com/badbones69/crazycrates/api/enums/Messages.java index ee7d6475c..59c511276 100644 --- a/src/main/java/com/badbones69/crazycrates/api/enums/Messages.java +++ b/src/main/java/com/badbones69/crazycrates/api/enums/Messages.java @@ -182,14 +182,8 @@ public void sendActionBar(final CommandSender sender, final String placeholder, if (msg.isEmpty() || msg.isBlank()) return; - if (this.plugin.isLegacy()) { - if (sender instanceof Player player) { - player.sendActionBar(ItemUtil.color(msg)); - } - } else { - if (sender instanceof Player player) { - player.sendActionBar(AdvUtil.parse(msg)); - } + if (sender instanceof Player player) { + player.sendActionBar(AdvUtil.parse(msg)); } } @@ -198,14 +192,8 @@ public void sendActionBar(final CommandSender sender, final Map if (msg.isEmpty() || msg.isBlank()) return; - if (this.plugin.isLegacy()) { - if (sender instanceof Player player) { - player.sendActionBar(ItemUtil.color(msg)); - } - } else { - if (sender instanceof Player player) { - player.sendActionBar(AdvUtil.parse(msg)); - } + if (sender instanceof Player player) { + player.sendActionBar(AdvUtil.parse(msg)); } } @@ -214,14 +202,8 @@ public void sendActionBar(final CommandSender sender) { if (msg.isEmpty() || msg.isBlank()) return; - if (this.plugin.isLegacy()) { - if (sender instanceof Player player) { - player.sendActionBar(ItemUtil.color(msg)); - } - } else { - if (sender instanceof Player player) { - player.sendActionBar(AdvUtil.parse(msg)); - } + if (sender instanceof Player player) { + player.sendActionBar(AdvUtil.parse(msg)); } } @@ -230,11 +212,7 @@ public void sendRichMessage(final CommandSender sender, final String placeholder if (msg.isEmpty() || msg.isBlank()) return; - if (this.plugin.isLegacy()) { - sender.sendMessage(ItemUtil.color(msg)); - } else { - sender.sendRichMessage(msg); - } + sender.sendRichMessage(msg); } public void sendRichMessage(final CommandSender sender, final Map placeholders) { @@ -242,11 +220,7 @@ public void sendRichMessage(final CommandSender sender, final Map placeholders) { diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index fb917b967..2b978e111 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -15,8 +15,6 @@ import net.kyori.adventure.sound.Sound; import org.bukkit.Color; import org.bukkit.Particle; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.Nullable; import org.bukkit.configuration.ConfigurationSection; @@ -35,11 +33,9 @@ import com.badbones69.crazycrates.api.utils.MiscUtils; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; -@SuppressWarnings("deprecation") public class Crate { private ItemBuilder previewTierBorderItem; @@ -70,8 +66,6 @@ public class Crate { private int previewChestLines; private int newPlayerKeys; - private List itemStacks; - private List tiers; private CrateHologram hologram; @@ -646,67 +640,26 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String final String tiers = getPath(prizeName, "Tiers"); - final boolean useOldEditor = ConfigManager.getConfig().getProperty(ConfigKeys.item_editor_toggle); - if (!section.contains(prizeName)) { section.set(getPath(prizeName, "MaxRange"), 100); } - if (useOldEditor && !this.plugin.isLegacy()) { - final List editorItems = new ArrayList<>(); - - if (section.contains(prizeName + ".Editor-Items")) { - final List editors = section.getList(prizeName + ".Editor-Items"); - - if (editors != null) { - editors.forEach(item -> editorItems.add((ItemStack) item)); - } - } - - editorItems.add(itemStack); - - List enchantments = new ArrayList<>(); - - for (Map.Entry enchantment : itemStack.getEnchantments().entrySet()) { - enchantments.add(enchantment.getKey().getKey().getKey() + ":" + enchantment.getValue()); - } - - if (!enchantments.isEmpty()) section.set(getPath(prizeName, "DisplayEnchantments"), enchantments); + String toBase64 = ItemUtil.toBase64(itemStack); - if (itemStack.hasItemMeta()) { - final ItemMeta itemMeta = itemStack.getItemMeta(); + section.set(getPath(prizeName, "DisplayData"), toBase64); - if (itemMeta.hasDisplayName()) { - section.set(getPath(prizeName, "DisplayName"), itemMeta.getDisplayName()); - } + final String items = getPath(prizeName, "Items"); - if (itemMeta.hasLore()) { - section.set(getPath(prizeName, "DisplayLore"), itemMeta.getLore()); - } - } + if (section.contains(items)) { + final List list = section.getStringList(items); - section.set(getPath(prizeName, "DisplayItem"), itemStack.getType().getKey().getKey()); - section.set(getPath(prizeName, "DisplayAmount"), itemStack.getAmount()); + list.add("Data:" + toBase64); - section.set(getPath(prizeName, "Editor-Items"), editorItems); + section.set(items, list); } else { - String toBase64 = ItemUtil.toBase64(itemStack); - - section.set(getPath(prizeName, "DisplayData"), toBase64); - - final String items = getPath(prizeName, "Items"); - - if (section.contains(items)) { - final List list = section.getStringList(items); - - list.add("Data:" + toBase64); - - section.set(items, list); - } else { - section.set(items, new ArrayList<>() {{ - add("Data:" + toBase64); - }}); - } + section.set(items, new ArrayList<>() {{ + add("Data:" + toBase64); + }}); } section.set(getPath(prizeName, "Chance"), chance); 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 d0dce8f0a..bd3274ac9 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -112,18 +112,10 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, * @return the name of the prize. */ public @NotNull final String getPrizeName() { - if (this.plugin.isLegacy()) { - return this.prizeName.isEmpty() ? "" : this.prizeName; - } - return this.prizeName.isEmpty() ? "" : this.prizeName; } public @NotNull final String getStrippedName() { - if (this.plugin.isLegacy()) { - return ChatColor.stripColor(getPrizeName()); - } - return PlainTextComponentSerializer.plainText().serialize(AdvUtil.parse(getPrizeName())); } @@ -284,21 +276,6 @@ public void broadcast(final Crate crate) { final String prizeName = getPrizeName(); final String strippedName = getStrippedName(); - if (this.plugin.isLegacy()) { - this.plugin.getServer().getOnlinePlayers().forEach(player -> { - if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return; - - this.broadcastMessages.forEach(message -> player.sendMessage(ItemUtil.color(message, new HashMap<>() {{ - put("%player%", player.getName()); - put("%crate%", fancyName); - put("%reward%", prizeName); - put("%reward_stripped%", strippedName); - }}, player))); - }); - - return; - } - this.plugin.getServer().getOnlinePlayers().forEach(player -> { if (!this.broadcastPermission.isEmpty() && player.hasPermission(this.broadcastPermission)) return; diff --git a/src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java b/src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java index be69f0f3e..f1b492c3d 100644 --- a/src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java +++ b/src/main/java/com/badbones69/crazycrates/api/utils/MsgUtils.java @@ -24,17 +24,9 @@ public static void sendMessage(CommandSender commandSender, @NotNull final Strin if (sendPrefix) { final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix)); - if (plugin.isLegacy()) { - player.sendMessage(ItemUtil.color(msg)); - } else { - player.sendRichMessage(msg); - } + player.sendRichMessage(msg); } else { - if (plugin.isLegacy()) { - player.sendMessage(ItemUtil.color(message)); - } else { - player.sendRichMessage(message); - } + player.sendRichMessage(message); } return; @@ -43,17 +35,9 @@ public static void sendMessage(CommandSender commandSender, @NotNull final Strin if (sendPrefix) { final String msg = message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix)); - if (plugin.isLegacy()) { - commandSender.sendMessage(ItemUtil.color(msg)); - } else { - commandSender.sendRichMessage(msg); - } + commandSender.sendRichMessage(msg); } else { - if (plugin.isLegacy()) { - commandSender.sendMessage(ItemUtil.color(message)); - } else { - commandSender.sendRichMessage(message); - } + commandSender.sendRichMessage(message); } } diff --git a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java index 3928120cb..899c10f8d 100644 --- a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java +++ b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java @@ -5,7 +5,6 @@ import ch.jalu.configme.configurationdata.CommentsConfiguration; import ch.jalu.configme.properties.Property; import com.badbones69.crazycrates.api.enums.misc.State; - import java.util.Collections; import java.util.List; import static ch.jalu.configme.properties.PropertyInitializer.newBeanProperty; @@ -62,23 +61,6 @@ public void registerComments(CommentsConfiguration conf) { @Comment("This option will let you test a different way of picking random numbers. If you have any issues, You can set it back to false.") public static final Property use_different_random = newProperty("root.use-different-random", false); - @Comment({ - "This option defines the type of color codes used in CrazyCrates", - "", - "true -> uses minimessage", - "false -> uses legacy color codes", - "", - "Note: inventory titles won't update during Cosmic Crate while this is false.", - "Warning: legacy color codes is highly likely to be removed in the future, so you should find time to migrate as this option won't be here forever.", - "", - "Now I get what you are going to say next, but I can't. Excluding the common reason of people simply want to, or it's easier.", - "I would like you to explain why you use legacy color codes still, is it because of lacking features", - "which make you have to rely on external plugins? I had one such instance with someone using /broadcast", - "from EssentialsX which didn't support MiniMessage, each prize in the crates now let you broadcast to the server.", - "and that section supports MiniMessage, that is one such example of an issue someone had." - }) - public static final Property minimessage_toggle = newProperty("root.use-minimessage", true); - @Comment({ "This option defines what in-game editor format is used in CrazyCrates", "", diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java index 17e5da2f8..d4d818086 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java @@ -11,7 +11,6 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.ryderbelserion.vital.paper.api.enums.Support; import com.ryderbelserion.vital.paper.util.AdvUtil; -import com.ryderbelserion.vital.paper.util.ItemUtil; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -90,11 +89,7 @@ public void onCrateOpen(CrateOpenEvent event) { if (!broadcastMessage.isBlank()) { final String builder = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage; - if (this.plugin.isLegacy()) { - this.plugin.getServer().broadcastMessage(ItemUtil.color(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); - } else { - this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); - } + this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); } } diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/types/CosmicCrateListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/types/CosmicCrateListener.java index af37f9714..28a9c2f3a 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/types/CosmicCrateListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/types/CosmicCrateListener.java @@ -324,11 +324,7 @@ public void onMysteryBoxClick(InventoryClickEvent event) { if (!broadcastMessage.isBlank()) { String builder = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage; - if (this.plugin.isLegacy()) { - this.plugin.getServer().broadcastMessage(ItemUtil.color(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); - } else { - this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); - } + this.plugin.getServer().broadcast(AdvUtil.parse(builder.replaceAll("%crate%", fancyName).replaceAll("%prefix%", MsgUtils.getPrefix()).replaceAll("%player%", player.getName()))); } } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java index afe34d5ed..68a2bcef7 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java @@ -9,7 +9,6 @@ import com.badbones69.crazycrates.api.objects.other.CrateLocation; import com.badbones69.crazycrates.support.holograms.HologramManager; import com.ryderbelserion.vital.paper.util.AdvUtil; -import com.ryderbelserion.vital.paper.util.ItemUtil; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import com.badbones69.crazycrates.tasks.BukkitUserManager; import com.badbones69.crazycrates.tasks.crates.CrateManager; @@ -178,11 +177,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { reward.setVelocity(new Vector(0, .2, 0)); - if (this.plugin.isLegacy()) { - reward.setCustomName(ItemUtil.color(prize.getPrizeName())); - } else { - reward.customName(AdvUtil.parse(prize.getPrizeName())); - } + reward.customName(AdvUtil.parse(prize.getPrizeName())); reward.setCustomNameVisible(true); reward.setCanMobPickup(false); From 85a8cc826eb9b4c0e64ec649bb08740b618fe998 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 12:15:10 -0400 Subject: [PATCH 05/18] update dependencies --- build.gradle.kts | 4 ++-- buildSrc/src/main/kotlin/java-plugin.gradle.kts | 1 + gradle/libs.versions.toml | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 744e00018..f147cbfdb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,8 +33,8 @@ dependencies { implementation(project(":api")) - compileOnly("su.nightexpress.excellentcrates", "ExcellentCrates", "5.3.1") - compileOnly("su.nightexpress.nightcore", "nightcore", "2.6.3") + compileOnly(libs.excellentcrates) + compileOnly(libs.nightcore) compileOnly(libs.decent.holograms) diff --git a/buildSrc/src/main/kotlin/java-plugin.gradle.kts b/buildSrc/src/main/kotlin/java-plugin.gradle.kts index b0a93124e..5cf882e5c 100644 --- a/buildSrc/src/main/kotlin/java-plugin.gradle.kts +++ b/buildSrc/src/main/kotlin/java-plugin.gradle.kts @@ -9,6 +9,7 @@ repositories { maven("https://repo.codemc.io/repository/maven-public") + maven("https://repo.crazycrew.us/libraries") maven("https://repo.crazycrew.us/releases") maven("https://repo.oraxen.com/releases") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c04f5d0a8..bd3b27dfd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -53,6 +53,10 @@ vault = { module = "com.github.MilkBowl:VaultAPI", version.ref = "vault" } itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version.ref = "itemsadder" } oraxen = { module = "io.th0rgal:oraxen", version.ref = "oraxen" } +# Crate Plugins +excellentcrates = { module = "su.nightexpress.excellentcrates:ExcellentCrates", version = "5.3.1" } +nightcore = { module = "su.nightexpress.nightcore:nightcore", version = "2.6.3" } + # Libraries triumph-cmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version.ref = "triumph-cmd" } vital-paper = { module = "com.ryderbelserion.vital:paper", version.ref = "vital" } From c541d2c8182b33343f2f704bf1bd7afc665a04ad Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 12:27:06 -0400 Subject: [PATCH 06/18] update getFiles method --- .../com/badbones69/crazycrates/api/objects/other/Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java b/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java index 8ec9b2884..840089fb6 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java @@ -82,7 +82,7 @@ public void reload() { */ @Override public @NotNull final List getCrateFiles() { - return FileUtil.getFiles(getCrateFolder(), ".yml"); + return FileUtil.getFiles(getCrateFolder(), ".yml", false); } /** From 1b0758bcf65ce115cc9027a20c729a4d4db59243 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:17:40 -0400 Subject: [PATCH 07/18] fix issue with itembuilder --- gradle/libs.versions.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bd3b27dfd..0ed27090d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,7 +31,7 @@ vault = "1.7.1" triumph-cmd = "2.0.0-ALPHA-10" jetbrains = "24.1.0" adventure = "4.17.0" -vital = "0.0.1" +vital-paper = "0.0.2" # Modrinth @@ -59,7 +59,9 @@ nightcore = { module = "su.nightexpress.nightcore:nightcore", version = "2.6.3" # Libraries triumph-cmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version.ref = "triumph-cmd" } -vital-paper = { module = "com.ryderbelserion.vital:paper", version.ref = "vital" } + +vital-paper = { module = "com.ryderbelserion.vital:paper", version.ref = "vital-paper" } + jetbrains = { module = "org.jetbrains:annotations", version.ref = "jetbrains" } [bundles] From 11a71670060d5ada1a661ba01b61b78437019be7 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:18:02 -0400 Subject: [PATCH 08/18] crate animation was delayed by 1 tick --- .../badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java index 233d137d7..f418517dc 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java @@ -104,7 +104,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { player.openInventory(getInventory()); // run the task, which uses the run method above. - runAtFixedRate(this.plugin, 1, 1); + runAtFixedRate(this.plugin, 0, 1); } private void moveItemsAndSetGlass() { From beadf64efd24f645ef8504d70e31455923bfd815 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:22:31 -0400 Subject: [PATCH 09/18] refund keys if the status is failed --- .../listeners/crates/CrateStatusListener.java | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java index 0efb060b5..9af871549 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java @@ -31,42 +31,56 @@ public void onCrateStatus(CrateStatusEvent event) { final Location location = player.getLocation(); switch (status) { - case ended, failed -> { - crate.playSound(player, location, "stop-sound", "entity.player.levelup", Sound.Source.PLAYER); + case ended -> janitor(crate, player, location, event); - switch (crate.getCrateType()) { - case quad_crate -> this.crateManager.endQuadCrate(player); + case cycling -> crate.playSound(player, location, "cycle-sound", "block.note_block.xylophone", Sound.Source.PLAYER); - case quick_crate -> this.crateManager.endQuickCrate(player, location, crate, false); + case opened -> { - default -> this.crateManager.endCrate(player); - } + } - // Always remove thy player from thy opening list! - this.crateManager.removePlayerFromOpeningList(player); + case failed -> { + janitor(crate, player, location, event); - final Inventory inventory = event.getInventory(); + // add the key back, since the crate failed. + this.userManager.addKeys(player.getUniqueId(), crate.getFileName(), KeyType.virtual_key, 1); - // Close inventory, if the crate requires an inventory. - if (inventory != null) { - new FoliaRunnable(player.getScheduler(), null) { - @Override - public void run() { - if (player.getOpenInventory().getTopInventory().equals(inventory)) player.closeInventory(InventoryCloseEvent.Reason.UNLOADED); - } - }.runDelayed(plugin, 40); - } + // inform the player, they have been given a refund. + Messages.key_refund.sendMessage(player, "{crate}", crate.getCrateName()); } - case cycling -> { - crate.playSound(player, location, "cycle-sound", "block.note_block.xylophone", Sound.Source.PLAYER); - } + default -> {} + } + } - case opened -> { + /** + * Sends common tasks, for ending a crate in the cycle. + * + * @param crate {@link Crate} + * @param player {@link Player} + * @param location {@link Location} + * @param event {@link CrateStatusEvent} + */ + private void janitor(final Crate crate, final Player player, final Location location, final CrateStatusEvent event) { + crate.playSound(player, location, "stop-sound", "entity.player.levelup", Sound.Source.PLAYER); - } + switch (crate.getCrateType()) { + case quad_crate -> this.crateManager.endQuadCrate(player); - default -> {} + case quick_crate -> this.crateManager.endQuickCrate(player, location, crate, false); + + default -> this.crateManager.endCrate(player); } + + // Always remove thy player from thy opening list! + this.crateManager.removePlayerFromOpeningList(player); + + // Always close the inventory, after 40 ticks. + new FoliaRunnable(player.getScheduler(), null) { + @Override + public void run() { + player.closeInventory(InventoryCloseEvent.Reason.UNLOADED); + } + }.runDelayed(plugin, 100); // 5 seconds, to take screenshots. } } \ No newline at end of file From 0363319e2226c58ea82fd89ef49ba471ee4e62a9 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:22:48 -0400 Subject: [PATCH 10/18] use getOrDefault, to avoid null pointers --- .../java/com/badbones69/crazycrates/api/objects/Crate.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index 2b978e111..895e81e28 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -547,8 +547,8 @@ public final CrateType getCrateType() { * @param name name of the prize you want. * @return the prize you asked for. */ - public final @Nullable Prize getPrize(@Nullable final String name) { - if (name != null && name.isEmpty()) return null; + public final @Nullable Prize getPrize(@NotNull final String name) { + if (name.isEmpty()) return null; Prize prize = null; @@ -564,7 +564,7 @@ public final CrateType getCrateType() { } public final @Nullable Prize getPrize(@NotNull final ItemStack item) { - return getPrize(item.getPersistentDataContainer().get(Keys.crate_prize.getNamespacedKey(), PersistentDataType.STRING)); + return getPrize(item.getPersistentDataContainer().getOrDefault(Keys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "")); } /** From 725e85da579a618c3b7f8fe5ccbf89eeb06863fd Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:23:29 -0400 Subject: [PATCH 11/18] migrate some prize logic for csgo crate to player prize event --- .../api/events/PlayerPrizeEvent.java | 47 +++++++++++++++---- .../listeners/crates/CrateStatusListener.java | 42 +++++++++++++++++ .../tasks/crates/types/v2/CsgoCrate.java | 28 ++++++++--- 3 files changed, 103 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/api/events/PlayerPrizeEvent.java b/src/main/java/com/badbones69/crazycrates/api/events/PlayerPrizeEvent.java index da929a717..6e51a351d 100644 --- a/src/main/java/com/badbones69/crazycrates/api/events/PlayerPrizeEvent.java +++ b/src/main/java/com/badbones69/crazycrates/api/events/PlayerPrizeEvent.java @@ -1,30 +1,47 @@ package com.badbones69.crazycrates.api.events; +import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.objects.Crate; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class PlayerPrizeEvent extends Event { +public class PlayerPrizeEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); + + private final CrateStatusEvent event; + private final String crateName; private final Player player; private final Crate crate; private final Prize prize; - private final String crateName; + + private boolean isCancelled; @Deprecated(since = "3.7.4", forRemoval = true) - public PlayerPrizeEvent(@NotNull final Player player, @NotNull final Crate crate, @NotNull final String crateName, @NotNull final Prize prize) { + public PlayerPrizeEvent(@NotNull final Player player, @NotNull final Crate crate, @NotNull final String crateName, @Nullable final Prize prize) { + this(player, crate, prize); + } + + public PlayerPrizeEvent(@NotNull final Player player, @NotNull final Crate crate, @Nullable final Prize prize) { + this(player, null, crate, prize); + } + + @ApiStatus.Internal + public PlayerPrizeEvent(@NotNull final Player player, @Nullable final CrateStatusEvent event, @NotNull final Crate crate, @Nullable final Prize prize) { this.player = player; this.crate = crate; + this.crateName = this.crate.getFileName(); this.prize = prize; - this.crateName = crateName; - } - public PlayerPrizeEvent(@NotNull final Player player, @NotNull final Crate crate, @NotNull final Prize prize) { - this(player, crate, crate.getFileName(), prize); + this.isCancelled = false; + + this.event = event; } public static HandlerList getHandlerList() { @@ -47,7 +64,21 @@ public static HandlerList getHandlerList() { return this.crateName; } - public @NotNull final Prize getPrize() { + public @Nullable final Prize getPrize() { return this.prize; } + + public @Nullable final CrateStatusEvent getEvent() { + return this.event; + } + + @Override + public final boolean isCancelled() { + return this.isCancelled; + } + + @Override + public void setCancelled(final boolean cancel) { + this.isCancelled = cancel; + } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java index 9af871549..31f1c02c7 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java @@ -1,9 +1,14 @@ package com.badbones69.crazycrates.listeners.crates; import com.badbones69.crazycrates.CrazyCrates; +import com.badbones69.crazycrates.api.PrizeManager; +import com.badbones69.crazycrates.api.enums.Messages; import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.api.objects.Prize; +import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import net.kyori.adventure.sound.Sound; @@ -15,6 +20,8 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.plugin.java.JavaPlugin; +import us.crazycrew.crazycrates.api.enums.types.KeyType; +import us.crazycrew.crazycrates.api.users.UserManager; public class CrateStatusListener implements Listener { @@ -22,6 +29,41 @@ public class CrateStatusListener implements Listener { private final CrateManager crateManager = this.plugin.getCrateManager(); + private final UserManager userManager = this.plugin.getUserManager(); + + @EventHandler + public void onPlayerPrize(PlayerPrizeEvent event) { + final Player player = event.getPlayer(); + final Prize prize = event.getPrize(); + final Crate crate = event.getCrate(); + + final CrateStatusEvent status = event.getEvent(); + + if (prize == null) { + if (status != null) { + status.setStatus(CrateStatus.failed).callEvent(); + } + + if (MiscUtils.isLogging()) { + this.plugin.getComponentLogger().warn("Prize was not found, thus the crate failed! A refund has been given to {} for the crate {}", player.getName(), crate.getFileName()); + } + + event.setCancelled(true); + + return; + } + + PrizeManager.givePrize(player, prize, crate); + + if (prize.useFireworks()) { + MiscUtils.spawnFirework(player.getLocation().add(0, 1, 0), null); + } + + if (status != null) { + status.setStatus(CrateStatus.ended).callEvent(); + } + } + @EventHandler(priority = EventPriority.MONITOR) public void onCrateStatus(CrateStatusEvent event) { final CrateStatus status = event.getStatus(); diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java index f418517dc..b18e65710 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java @@ -1,11 +1,14 @@ package com.badbones69.crazycrates.tasks.crates.types.v2; import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.enums.misc.Keys; +import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; import com.badbones69.crazycrates.api.objects.Crate; -import com.badbones69.crazycrates.api.PrizeManager; +import com.badbones69.crazycrates.api.objects.Prize; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.api.enums.types.KeyType; @@ -61,8 +64,6 @@ public void run() { this.time++; if (this.time >= 60) { // finished - this.event.setStatus(CrateStatus.ended).callEvent(); - final ItemStack itemStack = new ItemStack(Material.GRAY_STAINED_GLASS); setItem(4, itemStack); @@ -70,7 +71,21 @@ public void run() { final ItemStack item = getInventory().getItem(13); - if (item != null) PrizeManager.givePrize(player, crate, crate.getPrize(item)); + Prize prize = null; + + if (item != null) { + prize = crate.getPrize(item); + } + + final PlayerPrizeEvent playerPrizeEvent = new PlayerPrizeEvent(player, this.event, crate, prize); + + playerPrizeEvent.callEvent(); + + if (playerPrizeEvent.isCancelled()) { + cancel(); + + return; + } cancel(); } @@ -97,7 +112,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { // Set display items. for (int index = 9; index > 8 && index < 18; index++) { - setItem(index, getCrate().pickPrize(getPlayer()).getDisplayItem(getPlayer())); + setItem(index, crate.pickPrize(player).getDisplayItem(player)); } // Open the inventory. @@ -111,10 +126,11 @@ private void moveItemsAndSetGlass() { final List items = new ArrayList<>(); final Player player = getPlayer(); + final Inventory inventory = getInventory(); final Crate crate = getCrate(); for (int i = 9; i > 8 && i < 17; i++) { - items.add(getInventory().getItem(i)); + items.add(inventory.getItem(i)); } setItem(9, crate.pickPrize(player).getDisplayItem(player)); From bfca17c6396ab1ca941f32618409ffbcc01dfadc Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:23:43 -0400 Subject: [PATCH 12/18] wonder crate, is making me wonder about life --- .../tasks/crates/CrateManager.java | 2 +- .../tasks/crates/types/WonderCrate.java | 144 ------------------ .../tasks/crates/types/v2/WonderCrate.java | 133 ++++++++++++++++ 3 files changed, 134 insertions(+), 145 deletions(-) delete mode 100644 src/main/java/com/badbones69/crazycrates/tasks/crates/types/WonderCrate.java create mode 100644 src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index bf581c21e..b2e371aa3 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -23,7 +23,7 @@ import com.badbones69.crazycrates.tasks.crates.types.RouletteCrate; import com.badbones69.crazycrates.tasks.crates.types.WarCrate; import com.badbones69.crazycrates.tasks.crates.types.WheelCrate; -import com.badbones69.crazycrates.tasks.crates.types.WonderCrate; +import com.badbones69.crazycrates.tasks.crates.types.v2.WonderCrate; import com.ryderbelserion.vital.paper.api.files.CustomFile; import com.ryderbelserion.vital.paper.api.files.FileManager; import com.ryderbelserion.vital.common.utils.FileUtil; diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WonderCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WonderCrate.java deleted file mode 100644 index 7f31ecaab..000000000 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WonderCrate.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.badbones69.crazycrates.tasks.crates.types; - -import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; -import com.badbones69.crazycrates.api.objects.Crate; -import com.badbones69.crazycrates.api.objects.Prize; -import com.badbones69.crazycrates.api.PrizeManager; -import com.badbones69.crazycrates.api.builders.ItemBuilder; -import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; -import net.kyori.adventure.sound.Sound; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import us.crazycrew.crazycrates.api.enums.types.KeyType; -import com.badbones69.crazycrates.api.builders.CrateBuilder; -import com.badbones69.crazycrates.api.utils.MiscUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class WonderCrate extends CrateBuilder { - - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - - public WonderCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { - super(crate, player, size); - } - - @Override - public void open(@NotNull final KeyType type, final boolean checkHand) { - // Crate event failed so we return. - if (isCrateEventValid(type, checkHand)) { - return; - } - - final Player player = getPlayer(); - final UUID uuid = player.getUniqueId(); - final Crate crate = getCrate(); - final String fileName = crate.getFileName(); - - final boolean keyCheck = this.userManager.takeKeys(uuid, fileName, type, crate.useRequiredKeys() ? crate.getRequiredKeys() : 1, checkHand); - - if (!keyCheck) { - // Remove from opening list. - this.crateManager.removePlayerFromOpeningList(getPlayer()); - - return; - } - - final List slots = new ArrayList<>(); - - for (int index = 0; index < getSize(); index++) { - final Prize prize = crate.pickPrize(player); - - slots.add(String.valueOf(index)); - - setItem(index, prize.getDisplayItem(player)); - } - - player.openInventory(getInventory()); - - addCrateTask(new FoliaRunnable(player.getScheduler(), null) { - int time = 0; - int full = 0; - - int slot1 = 0; - int slot2 = 44; - - final List other = new ArrayList<>(); - - Prize prize = null; - - @Override - public void run() { - if (this.time >= 2 && this.full <= 65) { - slots.remove(this.slot1 + ""); - slots.remove(this.slot2 + ""); - - other.add(this.slot1); - other.add(this.slot2); - - final ItemStack material = new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(" ").getStack(); - - setItem(this.slot1, material); - setItem(this.slot2, material); - - for (String slot : slots) { - this.prize = crate.pickPrize(player); - - setItem(Integer.parseInt(slot), this.prize.getDisplayItem(player)); - } - - playSound("cycle-sound", Sound.Source.PLAYER, "block.note_block.xylophone"); - - this.slot1++; - this.slot2--; - } - - if (this.full > 67) { - for (int slot : this.other) { - setCustomGlassPane(slot); - } - - playSound("cycle-sound", Sound.Source.PLAYER, "block.note_block.xylophone"); - } - - player.openInventory(getInventory()); - - if (this.full > 100) { - crateManager.endCrate(player); - - getPlayer().closeInventory(InventoryCloseEvent.Reason.UNLOADED); - - PrizeManager.givePrize(player, this.prize, crate); - - playSound("stop-sound", Sound.Source.PLAYER, "entity.player.levelup"); - - if (this.prize.useFireworks()) MiscUtils.spawnFirework(getPlayer().getLocation().add(0, 1, 0), null); - - plugin.getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, this.prize)); - - crateManager.removePlayerFromOpeningList(player); - - return; - } - - this.full++; - this.time++; - - if (this.time > 2) this.time = 0; - } - }.runAtFixedRate(this.plugin, 0, 2)); - } - - @Override - public void run() { - - } -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java new file mode 100644 index 000000000..cdb7807fc --- /dev/null +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java @@ -0,0 +1,133 @@ +package com.badbones69.crazycrates.tasks.crates.types.v2; + +import com.badbones69.crazycrates.api.enums.crates.CrateStatus; +import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; +import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; +import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.api.objects.Prize; +import com.badbones69.crazycrates.api.builders.ItemBuilder; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import us.crazycrew.crazycrates.api.enums.types.KeyType; +import com.badbones69.crazycrates.api.builders.CrateBuilder; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class WonderCrate extends CrateBuilder { + + private final CrateStatusEvent event; + + public WonderCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { + super(crate, player, size); + + this.event = new CrateStatusEvent(crate, player); + } + + private final List slots = new ArrayList<>(); + + private int time = 0; + private int full = 0; + + private int slot1 = 0; + private int slot2 = 44; + + @Override + public void run() { + final Player player = getPlayer(); + final Crate crate = getCrate(); + + final List other = new ArrayList<>(); + + Prize prize = null; + + if (this.time >= 2 && this.full <= 65) { + this.slots.remove(this.slot1); + this.slots.remove(this.slot2); + + other.add(this.slot1); + other.add(this.slot2); + + final ItemStack material = new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(" ").getStack(); + + setItem(this.slot1, material); + setItem(this.slot2, material); + + for (int slot : this.slots) { + prize = crate.pickPrize(player); + + setItem(slot, prize.getDisplayItem(player)); + } + + this.event.setStatus(CrateStatus.cycling).callEvent(); + + this.slot1++; + this.slot2--; + } + + if (this.full > 67) { + for (int slot : other) { + setCustomGlassPane(slot); + } + + this.event.setStatus(CrateStatus.cycling).callEvent(); + } + + player.openInventory(getInventory()); + + if (this.full > 100) { + final PlayerPrizeEvent playerPrizeEvent = new PlayerPrizeEvent(player, this.event, crate, prize); + + playerPrizeEvent.callEvent(); + + if (playerPrizeEvent.isCancelled()) { + cancel(); + + return; + } + + cancel(); + + return; + } + + this.full++; + this.time++; + + if (this.time > 2) this.time = 0; + } + + @Override + public void open(@NotNull final KeyType type, final boolean checkHand) { + // Crate event failed so we return. + if (isCrateEventValid(type, checkHand)) { + return; + } + + final Player player = getPlayer(); + final UUID uuid = player.getUniqueId(); + final Crate crate = getCrate(); + final String fileName = crate.getFileName(); + + final boolean keyCheck = this.userManager.takeKeys(uuid, fileName, type, crate.useRequiredKeys() ? crate.getRequiredKeys() : 1, checkHand); + + if (!keyCheck) { + this.crateManager.removePlayerFromOpeningList(getPlayer()); + + return; + } + + for (int index = 0; index < getSize(); index++) { + this.slots.add(index); + + setItem(index, crate.pickPrize(player).getDisplayItem(player)); + } + + player.openInventory(getInventory()); + + // run the task, which uses the run method above. + runAtFixedRate(this.plugin, 0, 2); + } +} \ No newline at end of file From 7e74b5bf4045fb87125c2dcc0f543c64ac1d6414 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:30:27 -0400 Subject: [PATCH 13/18] Move csgo crate out of v2 directory Signed-off-by: Ryder Belserion --- .../crazycrates/tasks/crates/types/{v2 => }/CsgoCrate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/badbones69/crazycrates/tasks/crates/types/{v2 => }/CsgoCrate.java (99%) diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java similarity index 99% rename from src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java rename to src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java index b18e65710..446af1a11 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/CsgoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java @@ -145,4 +145,4 @@ private void moveItemsAndSetGlass() { private List getBorder() { return Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26); } -} \ No newline at end of file +} From bad1905b400774898882ac6ee8dde95a08283040 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:30:43 -0400 Subject: [PATCH 14/18] Update package Signed-off-by: Ryder Belserion --- .../badbones69/crazycrates/tasks/crates/types/CsgoCrate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java index 446af1a11..5d83e650c 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java @@ -1,4 +1,4 @@ -package com.badbones69.crazycrates.tasks.crates.types.v2; +package com.badbones69.crazycrates.tasks.crates.types; import com.badbones69.crazycrates.api.enums.crates.CrateStatus; import com.badbones69.crazycrates.api.enums.misc.Keys; From 5e4ef9889d5e1f8a9113c05bcb902efcd8360663 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 5 Sep 2024 13:30:59 -0400 Subject: [PATCH 15/18] Update csgo crate import Signed-off-by: Ryder Belserion --- .../com/badbones69/crazycrates/tasks/crates/CrateManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index b2e371aa3..f0a5ab997 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -16,7 +16,7 @@ import com.badbones69.crazycrates.tasks.crates.types.CasinoCrate; import com.badbones69.crazycrates.tasks.crates.types.CosmicCrate; import com.badbones69.crazycrates.tasks.crates.types.CrateOnTheGo; -import com.badbones69.crazycrates.tasks.crates.types.v2.CsgoCrate; +import com.badbones69.crazycrates.tasks.crates.types.CsgoCrate; import com.badbones69.crazycrates.tasks.crates.types.FireCrackerCrate; import com.badbones69.crazycrates.tasks.crates.types.QuadCrate; import com.badbones69.crazycrates.tasks.crates.types.QuickCrate; @@ -1495,4 +1495,4 @@ public final boolean containsSlot(final Player player) { public void removeSlot(final Player player) { this.slots.remove(player.getUniqueId()); } -} \ No newline at end of file +} From db5ae4a4bf3d5901a14c6df5e2e548ed9137131f Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 9 Sep 2024 00:27:42 -0400 Subject: [PATCH 16/18] pass missing variables through --- .../crazycrates/tasks/crates/types/v2/WonderCrate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java index cdb7807fc..4a5a8e59c 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java @@ -58,7 +58,7 @@ public void run() { for (int slot : this.slots) { prize = crate.pickPrize(player); - setItem(slot, prize.getDisplayItem(player)); + setItem(slot, prize.getDisplayItem(player, crate)); } this.event.setStatus(CrateStatus.cycling).callEvent(); @@ -122,7 +122,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { for (int index = 0; index < getSize(); index++) { this.slots.add(index); - setItem(index, crate.pickPrize(player).getDisplayItem(player)); + setItem(index, crate.pickPrize(player).getDisplayItem(player, crate)); } player.openInventory(getInventory()); From 0ca97b14d8ab91fcb6ae6d0cafc273f64cbe69ae Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 9 Sep 2024 13:17:56 -0400 Subject: [PATCH 17/18] use inherited methods --- .../crazycrates/tasks/crates/types/CasinoCrate.java | 6 ------ .../crazycrates/tasks/crates/types/CosmicCrate.java | 3 --- .../crazycrates/tasks/crates/types/CrateOnTheGo.java | 10 ---------- .../tasks/crates/types/FireCrackerCrate.java | 6 ------ .../crazycrates/tasks/crates/types/QuadCrate.java | 6 ------ .../crazycrates/tasks/crates/types/QuickCrate.java | 6 ------ .../crazycrates/tasks/crates/types/RouletteCrate.java | 6 ------ .../crazycrates/tasks/crates/types/WarCrate.java | 6 ------ .../crazycrates/tasks/crates/types/WheelCrate.java | 6 ------ 9 files changed, 55 deletions(-) diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java index 708793019..b32da5ec3 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java @@ -7,8 +7,6 @@ import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.api.PrizeManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; @@ -23,10 +21,6 @@ public class CasinoCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public CasinoCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CosmicCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CosmicCrate.java index 196615fb2..f07b8b67e 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CosmicCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CosmicCrate.java @@ -2,7 +2,6 @@ import com.badbones69.crazycrates.api.PrizeManager; import com.badbones69.crazycrates.api.objects.Tier; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.badbones69.crazycrates.tasks.crates.other.CosmicCrateManager; import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.builders.ItemBuilder; @@ -13,8 +12,6 @@ public class CosmicCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - public CosmicCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size, crate.getCrateName() + " - Choose"); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CrateOnTheGo.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CrateOnTheGo.java index c7a210f39..8fc9bfe55 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CrateOnTheGo.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CrateOnTheGo.java @@ -3,25 +3,15 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.PrizeManager; -import com.badbones69.crazycrates.tasks.BukkitUserManager; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.api.enums.types.KeyType; -import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.api.builders.CrateBuilder; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.badbones69.crazycrates.api.utils.MiscUtils; import java.util.UUID; public class CrateOnTheGo extends CrateBuilder { - private @NotNull final CrazyCrates plugin = CrazyCrates.getPlugin(); - - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public CrateOnTheGo(@NotNull final Crate crate, @NotNull final Player player) { super(crate, player); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/FireCrackerCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/FireCrackerCrate.java index dbc9be8d7..dbe3039ed 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/FireCrackerCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/FireCrackerCrate.java @@ -4,8 +4,6 @@ import com.badbones69.crazycrates.api.objects.other.CrateLocation; import com.badbones69.crazycrates.support.holograms.HologramManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -20,10 +18,6 @@ public class FireCrackerCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public FireCrackerCrate(@NotNull final Crate crate, @NotNull final Player player, final int size, @NotNull final Location location) { super(crate, player, size, location); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java index 9865227c0..5ddae8beb 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java @@ -9,19 +9,13 @@ import org.jetbrains.annotations.NotNull; import org.bukkit.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.KeyType; -import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.api.builders.CrateBuilder; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.badbones69.crazycrates.tasks.crates.other.quadcrates.QuadCrateManager; import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class QuadCrate extends CrateBuilder { - private @NotNull final CrazyCrates plugin = CrazyCrates.getPlugin(); - - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - private final Location location; public QuadCrate(@NotNull final Crate crate, @NotNull final Player player, @NotNull final Location location) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java index 53965f3f3..819a178fb 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java @@ -10,8 +10,6 @@ import com.badbones69.crazycrates.support.holograms.HologramManager; import com.ryderbelserion.vital.paper.util.AdvUtil; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import org.bukkit.Location; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -31,10 +29,6 @@ public class QuickCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public QuickCrate(@NotNull final Crate crate, @NotNull final Player player, @NotNull final Location location) { super(crate, player, location); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/RouletteCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/RouletteCrate.java index 44b7a0783..7e7f12d81 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/RouletteCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/RouletteCrate.java @@ -4,8 +4,6 @@ import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.PrizeManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import net.kyori.adventure.sound.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -18,10 +16,6 @@ public class RouletteCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public RouletteCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WarCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WarCrate.java index 5a37b7132..d6601dcac 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WarCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WarCrate.java @@ -3,8 +3,6 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.builders.ItemBuilder; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -20,10 +18,6 @@ public class WarCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - private final Map colorCodes = new HashMap<>(); public WarCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WheelCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WheelCrate.java index 4c38b3b71..21b84d220 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WheelCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/WheelCrate.java @@ -4,8 +4,6 @@ import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.PrizeManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; -import com.badbones69.crazycrates.tasks.BukkitUserManager; -import com.badbones69.crazycrates.tasks.crates.CrateManager; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -23,10 +21,6 @@ public class WheelCrate extends CrateBuilder { - private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); - - private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); - public WheelCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size); } From 0239673a4f3c36a1bf7e4f932d27d5fe9e1bd0c1 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Mon, 9 Sep 2024 17:22:08 -0400 Subject: [PATCH 18/18] Stash v2 crate builder --- gradle/libs.versions.toml | 2 +- .../api/builders/v2/CrateBuilder.java | 93 ++++++++++++++ .../api/enums/crates/CrateStatus.java | 3 +- .../api/events/crates/CrateStatusEvent.java | 2 +- .../listeners/crates/CrateStatusListener.java | 4 + .../tasks/crates/CrateManager.java | 10 +- .../tasks/crates/types/CsgoCrate.java | 115 ++++++++++-------- .../tasks/crates/types/v2/WonderCrate.java | 2 +- 8 files changed, 168 insertions(+), 63 deletions(-) create mode 100644 paper/src/main/java/com/badbones69/crazycrates/api/builders/v2/CrateBuilder.java diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0ed27090d..ab5b00f18 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,7 +31,7 @@ vault = "1.7.1" triumph-cmd = "2.0.0-ALPHA-10" jetbrains = "24.1.0" adventure = "4.17.0" -vital-paper = "0.0.2" +vital-paper = "0.0.3" # Modrinth diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/builders/v2/CrateBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/api/builders/v2/CrateBuilder.java new file mode 100644 index 000000000..ece71ae71 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/api/builders/v2/CrateBuilder.java @@ -0,0 +1,93 @@ +package com.badbones69.crazycrates.api.builders.v2; + +import com.badbones69.crazycrates.CrazyCrates; +import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; +import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.api.utils.MiscUtils; +import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.Gui; +import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.GuiType; +import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import us.crazycrew.crazycrates.api.enums.types.KeyType; + +@SuppressWarnings("UnusedReturnValue") +public abstract class CrateBuilder extends FoliaRunnable { + + protected CrazyCrates plugin = CrazyCrates.getPlugin(); + protected ComponentLogger logger = this.plugin.getComponentLogger(); + + private final CrateStatusEvent event; + + private final Player player; + private final Crate crate; + + private final Gui gui; + + private String title; + private int seconds; + + public CrateBuilder(final Player player, final Crate crate, final int rows) { + super(player.getScheduler(), null); + + this.gui = Gui.gui().setType(GuiType.CHEST).disableInteractions().setTitle(crate.getCrateName()).setRows(rows).create(); + this.event = new CrateStatusEvent(player, crate); + + this.player = player; + this.crate = crate; + } + + public abstract void open(final KeyType keyType, final boolean inspectInventory); + + public final CrateBuilder setSeconds(final int seconds) { + this.seconds = seconds; + + return this; + } + + public final CrateBuilder setTitle(final String title) { + this.gui.setTitle(this.title = title); + + return this; + } + + // Items + public void setGuiItem(final ItemStack item, final int slot) { + this.gui.setItem(slot, new GuiItem(item)); + } + + public void setRandomGlass(final int slot) { + setGuiItem(getRandomGlass(), slot); + } + + // Getters + public final ItemStack getRandomGlass() { + return MiscUtils.getRandomPaneColor().setDisplayName(" ").getStack(); + } + + public final CrateStatusEvent getEvent() { + return this.event; + } + + public final Player getPlayer() { + return this.player; + } + + public final String getTitle() { + return this.title; + } + + public final Crate getCrate() { + return this.crate; + } + + public final int getSeconds() { + return this.seconds; + } + + public final Gui getGui() { + return this.gui; + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java b/paper/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java index 230e24c41..e0556b779 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/enums/crates/CrateStatus.java @@ -5,7 +5,8 @@ public enum CrateStatus { failed("Failed"), ended("Ended"), cycling("Cycling"), - opened("Opened"); + opened("Opened"), + silent("Silent"); private final String status; diff --git a/paper/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java b/paper/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java index 1f0ab3c70..75c1add34 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java +++ b/paper/src/main/java/com/badbones69/crazycrates/api/events/crates/CrateStatusEvent.java @@ -15,7 +15,7 @@ public class CrateStatusEvent extends Event { private final Player player; private final Crate crate; - public CrateStatusEvent(@NotNull final Crate crate, @NotNull final Player player) { + public CrateStatusEvent(final Player player, final Crate crate) { this.status = CrateStatus.opened; this.player = player; this.crate = crate; diff --git a/paper/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java b/paper/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java index 31f1c02c7..4124ca608 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateStatusListener.java @@ -91,6 +91,10 @@ public void onCrateStatus(CrateStatusEvent event) { Messages.key_refund.sendMessage(player, "{crate}", crate.getCrateName()); } + case silent -> { + + } + default -> {} } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index dd76c1fb1..e85e2efb6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -2,7 +2,7 @@ import ch.jalu.configme.SettingsManager; import com.Zrips.CMI.Modules.ModuleHandling.CMIModule; -import com.badbones69.crazycrates.api.builders.CrateBuilder; +import com.badbones69.crazycrates.api.builders.v2.CrateBuilder; import com.badbones69.crazycrates.api.crates.CrateHologram; import com.badbones69.crazycrates.api.crates.quadcrates.CrateSchematic; import com.badbones69.crazycrates.api.enums.misc.Files; @@ -588,8 +588,8 @@ public void openCrate(@NotNull final Player player, @NotNull final Crate crate, CrateBuilder crateBuilder; switch (crate.getCrateType()) { - case csgo -> crateBuilder = new CsgoCrate(crate, player, 27); - case casino -> crateBuilder = new CasinoCrate(crate, player, 27); + case csgo -> crateBuilder = new CsgoCrate(player, crate); + /*case casino -> crateBuilder = new CasinoCrate(crate, player, 27); case wonder -> crateBuilder = new WonderCrate(crate, player, 45); case wheel -> crateBuilder = new WheelCrate(crate, player, 54); case roulette -> crateBuilder = new RouletteCrate(crate, player, 27); @@ -677,10 +677,10 @@ public void openCrate(@NotNull final Player player, @NotNull final Crate crate, } crateBuilder = new QuickCrate(crate, player, location); - } + }*/ default -> { - crateBuilder = new CsgoCrate(crate, player, 27); + crateBuilder = new CsgoCrate(player, crate); if (MiscUtils.isLogging()) { List.of( diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java index 942ba466f..2ea2e1115 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CsgoCrate.java @@ -1,57 +1,83 @@ package com.badbones69.crazycrates.tasks.crates.types; +import com.badbones69.crazycrates.api.builders.v2.CrateBuilder; import com.badbones69.crazycrates.api.enums.crates.CrateStatus; -import com.badbones69.crazycrates.api.enums.misc.Keys; -import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; import com.badbones69.crazycrates.api.events.crates.CrateStatusEvent; import com.badbones69.crazycrates.api.objects.Crate; -import com.badbones69.crazycrates.api.objects.Prize; -import org.bukkit.Material; +import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.Gui; +import com.ryderbelserion.vital.paper.api.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.api.enums.types.KeyType; -import com.badbones69.crazycrates.api.builders.CrateBuilder; -import com.badbones69.crazycrates.api.utils.MiscUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.UUID; public class CsgoCrate extends CrateBuilder { - private final CrateStatusEvent event; + public CsgoCrate(final Player player, final Crate crate) { + super(player, crate, 3); - public CsgoCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { - super(crate, player, size); - - this.event = new CrateStatusEvent(crate, player); + setSeconds(6000); } - private int time = 1; - private int full = 0; - private int open = 0; + private final CrateStatusEvent event = getEvent(); + private final Player player = getPlayer(); + private final Crate crate = getCrate(); + private final Gui gui = getGui(); + + private final long startTime = System.currentTimeMillis(); // 5.4 seconds + + private int inventoryStatus = 0; + private int delayCounter = 0; @Override public void run() { - final Player player = getPlayer(); - final Crate crate = getCrate(); + final long elapsedTime = System.currentTimeMillis() - this.startTime; - if (this.full <= 50) { // cycling - moveItemsAndSetGlass(); + if (elapsedTime >= getSeconds()) { // elapsed the allowed time. + this.event.setStatus(CrateStatus.ended).callEvent(); + cancel(); + + return; + } + + if (elapsedTime <= 5000) { this.event.setStatus(CrateStatus.cycling).callEvent(); + + moveItemsAndSetGlass(); + } + + this.inventoryStatus++; + + if (this.inventoryStatus >= 5) { + this.player.openInventory(this.gui.getInventory()); + + this.inventoryStatus = 0; } - this.open++; + if (elapsedTime > 5100) { // slowing down + this.delayCounter = this.delayCounter + 10; + + this.event.setStatus(CrateStatus.silent).callEvent(); - if (this.open >= 5) { // opens the inventory - player.openInventory(getInventory()); + new FoliaRunnable(this.player.getScheduler(), null) { + @Override + public void run() { + moveItemsAndSetGlass(); - this.open = 0; + event.setStatus(CrateStatus.cycling).callEvent(); + + cancel(); + } + }.runAtFixedRate(this.plugin, this.delayCounter, 1); } + /* this.full++; if (this.full > 51) { // slowing down @@ -89,57 +115,38 @@ public void run() { cancel(); } - } + }*/ } @Override - public void open(@NotNull final KeyType type, final boolean checkHand) { - final Player player = getPlayer(); - final Crate crate = getCrate(); - - final UUID uuid = player.getUniqueId(); - final String fileName = crate.getFileName(); - - final boolean keyCheck = this.userManager.takeKeys(uuid, fileName, type, crate.useRequiredKeys() ? crate.getRequiredKeys() : 1, checkHand); - - if (!keyCheck) { - this.crateManager.removePlayerFromOpeningList(player); - - return; - } - - getBorder().forEach(this::setCustomGlassPane); + public void open(@NotNull final KeyType type, final boolean inspectInventory) { + getBorder().forEach(this::setRandomGlass); - // Set display items. for (int index = 9; index > 8 && index < 18; index++) { - setItem(index, crate.pickPrize(player).getDisplayItem(player, crate)); + this.gui.setItem(index, new GuiItem(this.crate.pickPrize(this.player).getDisplayItem(this.player, this.crate))); } - // Open the inventory. - player.openInventory(getInventory()); + this.gui.open(this.player); - // run the task, which uses the run method above. runAtFixedRate(this.plugin, 0, 1); } private void moveItemsAndSetGlass() { final List items = new ArrayList<>(); - final Player player = getPlayer(); - final Inventory inventory = getInventory(); - final Crate crate = getCrate(); + final Inventory inventory = this.gui.getInventory(); - for (int i = 9; i > 8 && i < 17; i++) { - items.add(inventory.getItem(i)); + for (int count = 9; count > 8 && count < 17; count++) { + items.add(inventory.getItem(count)); } - setItem(9, crate.pickPrize(player).getDisplayItem(player, crate)); + this.gui.setItem(9, new GuiItem(this.crate.pickPrize(this.player).getDisplayItem(this.player, this.crate))); - for (int i = 0; i < 8; i++) { - setItem(i + 10, items.get(i)); + for (int count = 0; count < 8; count++) { + this.gui.setItem(count, new GuiItem(items.get(count))); } - getBorder().forEach(this::setCustomGlassPane); + getBorder().forEach(this::setRandomGlass); } private List getBorder() { diff --git a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java index 4a5a8e59c..e991033d3 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/tasks/crates/types/v2/WonderCrate.java @@ -23,7 +23,7 @@ public class WonderCrate extends CrateBuilder { public WonderCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size); - this.event = new CrateStatusEvent(crate, player); + this.event = new CrateStatusEvent(player, crate); } private final List slots = new ArrayList<>();