From 73197bf6ddd4b519c35c130951e667c7d1de1767 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Wed, 9 Apr 2025 01:26:17 -0700 Subject: [PATCH 01/52] editorconfig - prevent wildcard imports --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 0882495e..5a0107fd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true ij_continuation_indent_size = 4 [*.yml] indent_size = 2 +[*.java] +ij_java_class_count_to_use_import_on_demand = 999999 +ij_java_names_count_to_use_import_on_demand = 999999 From 4c2b552154b604f3115c8bab78c119b495efc7e3 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 12:29:26 -0700 Subject: [PATCH 02/52] Update MC 1.21.4 to 1.21.5 --- build.gradle.kts | 4 ++-- .../java/com/shanebeestudios/hg/api/parsers/ItemParser.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7669c288..3cd98ec0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,9 +5,9 @@ plugins { // Version of HungerGames val projectVersion = "5.0.0-beta1" // Where this builds on the server -val serverLocation = "1-21-4" +val serverLocation = "1-21-5" // Minecraft version to build against -val minecraftVersion = "1.21.4" +val minecraftVersion = "1.21.5" java.sourceCompatibility = JavaVersion.VERSION_21 diff --git a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java index 79cc240e..248d0838 100644 --- a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java +++ b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java @@ -174,7 +174,7 @@ public class ItemParser { // DYED_COLOR if (config.contains("dyed_color")) { int color = config.getInt("dyed_color"); - itemStack.setData(DataComponentTypes.DYED_COLOR, DyedItemColor.dyedItemColor(Color.fromRGB(color), false)); + itemStack.setData(DataComponentTypes.DYED_COLOR, DyedItemColor.dyedItemColor(Color.fromRGB(color))); } // NBT From 21dd32f23b203c3e54b161b2aefa950e89aed1ae Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 12:29:52 -0700 Subject: [PATCH 03/52] ItemParser - remove old code --- .../hg/api/parsers/ItemParser.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java index 248d0838..261081d6 100644 --- a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java +++ b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java @@ -22,12 +22,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; public class ItemParser { - @SuppressWarnings({"UnstableApiUsage", "unchecked"}) + @SuppressWarnings({"UnstableApiUsage"}) public static @Nullable ItemStack parseItem(@Nullable ConfigurationSection config) { if (config == null) return null; @@ -133,25 +131,6 @@ public class ItemParser { } } - // POTION_EFFECT -// if (config.contains("potion_effects")) { -// List> potionEffectsList = (List>) config.getList("potion_effects"); -// assert potionEffectsList != null; -// PotionContents.Builder builder = PotionContents.potionContents(); -// AtomicInteger color = new AtomicInteger(-1); -// potionEffectsList.forEach(entry -> { -// PotionEffect potionEffect = parsePotionEffect(entry); -// if (potionEffect != null) { -// builder.addCustomEffect(potionEffect); -// if (entry.containsKey("custom_color")) { -// color.set((int) entry.get("custom_color")); -// } -// } -// }); -// if (color.get() != -1) builder.customColor(Color.fromRGB(color.get())); -// itemStack.setData(DataComponentTypes.POTION_CONTENTS, builder.build()); -// } - // POTION_EFFECT if (config.isConfigurationSection("potion_effects")) { ConfigurationSection potionEffectsSection = config.getConfigurationSection("potion_effects"); From 6f546212c4628f03bc5081662b885d5658fb6798 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 12:45:51 -0700 Subject: [PATCH 04/52] build.gradle.kts - update CommandAPI --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3cd98ec0..37645749 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,7 +41,7 @@ dependencies { compileOnly("io.papermc.paper:paper-api:${minecraftVersion}-R0.1-SNAPSHOT") // Command Api - implementation("dev.jorel:commandapi-bukkit-shade:9.7.0") + implementation("dev.jorel:commandapi-bukkit-shade:10.0.0") // bStats implementation("org.bstats:bstats-bukkit:3.1.0") From 9e00c47a322906fb516412ae58480153a1be0d51 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 12:46:06 -0700 Subject: [PATCH 05/52] ItemParser - add support for hidden components --- .../hg/api/parsers/ItemParser.java | 21 +++++++++++++++++++ .../hg/api/registry/Registries.java | 2 ++ src/main/resources/kits.yml | 20 ++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java index 261081d6..f1aa14be 100644 --- a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java +++ b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java @@ -3,10 +3,12 @@ import com.shanebeestudios.hg.api.registry.Registries; import com.shanebeestudios.hg.api.util.NBTApi; import com.shanebeestudios.hg.api.util.Util; +import io.papermc.paper.datacomponent.DataComponentType; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.DyedItemColor; import io.papermc.paper.datacomponent.item.ItemEnchantments; import io.papermc.paper.datacomponent.item.PotionContents; +import io.papermc.paper.datacomponent.item.TooltipDisplay; import net.kyori.adventure.text.Component; import org.bukkit.Color; import org.bukkit.NamespacedKey; @@ -156,6 +158,25 @@ public class ItemParser { itemStack.setData(DataComponentTypes.DYED_COLOR, DyedItemColor.dyedItemColor(Color.fromRGB(color))); } + // HIDDEN COMPONENTS + if (config.isList("hidden_components")) { + TooltipDisplay.Builder builder = TooltipDisplay.tooltipDisplay(); + for (String compKey : config.getStringList("hidden_components")) { + NamespacedKey namespacedKey = NamespacedKey.fromString(compKey); + if (namespacedKey == null) { + Util.warning("Invalid component key: " + compKey); + continue; + } + DataComponentType type = Registries.DATA_COMPONENT_TYPE_REGISTRY.get(namespacedKey); + if (type == null) { + Util.warning("Invalid component key: " + compKey); + continue; + } + builder.addHiddenComponents(type); + } + itemStack.setData(DataComponentTypes.TOOLTIP_DISPLAY, builder.build()); + } + // NBT if (config.contains("nbt")) { String nbtString = config.getString("nbt"); diff --git a/src/main/java/com/shanebeestudios/hg/api/registry/Registries.java b/src/main/java/com/shanebeestudios/hg/api/registry/Registries.java index b685bd23..384cee4f 100644 --- a/src/main/java/com/shanebeestudios/hg/api/registry/Registries.java +++ b/src/main/java/com/shanebeestudios/hg/api/registry/Registries.java @@ -1,5 +1,6 @@ package com.shanebeestudios.hg.api.registry; +import io.papermc.paper.datacomponent.DataComponentType; import io.papermc.paper.registry.RegistryAccess; import io.papermc.paper.registry.RegistryKey; import org.bukkit.Registry; @@ -21,6 +22,7 @@ public class Registries { public static final Registry ATTRIBUTE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.ATTRIBUTE); public static final Registry BLOCK_TYPE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.BLOCK); public static final Registry DAMAGE_TYPE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.DAMAGE_TYPE); + public static final Registry DATA_COMPONENT_TYPE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.DATA_COMPONENT_TYPE); public static final Registry ENCHANTMENT_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT); public static final Registry ENTITY_TYPE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENTITY_TYPE); public static final Registry ITEM_TYPE_REGISTRY = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM); diff --git a/src/main/resources/kits.yml b/src/main/resources/kits.yml index 92c9865a..56b36921 100644 --- a/src/main/resources/kits.yml +++ b/src/main/resources/kits.yml @@ -36,18 +36,26 @@ kits: id: 'minecraft:leather_helmet' count: 1 dyed_color: 11546150 + hidden_components: + - 'minecraft:dyed_color' chestplate: id: 'minecraft:leather_chestplate' count: 1 dyed_color: 11546150 + hidden_components: + - 'minecraft:dyed_color' leggings: id: 'minecraft:leather_leggings' count: 1 dyed_color: 11546150 + hidden_components: + - 'minecraft:dyed_color' boots: id: 'minecraft:leather_boots' count: 1 dyed_color: 11546150 + hidden_components: + - 'minecraft:dyed_color' items: '1': id: 'minecraft:bow' @@ -98,10 +106,14 @@ kits: id: 'minecraft:leather_chestplate' count: 1 dyed_color: 6192150 + hidden_components: + - 'minecraft:dyed_color' leggings: id: 'minecraft:leather_leggings' count: 1 dyed_color: 6192150 + hidden_components: + - 'minecraft:dyed_color' boots: id: 'minecraft:leather_boots' count: 1 @@ -155,6 +167,8 @@ kits: id: 'minecraft:leather_helmet' count: 1 dyed_color: 1908001 + hidden_components: + - 'minecraft:dyed_color' chestplate: id: 'minecraft:leather_chestplate' count: 1 @@ -165,16 +179,22 @@ kits: enchantments: 'minecraft:fire_protection': 1 dyed_color: 1908001 + hidden_components: + - 'minecraft:dyed_color' leggings: id: 'minecraft:leather_leggings' count: 1 dyed_color: 1908001 + hidden_components: + - 'minecraft:dyed_color' boots: id: 'minecraft:leather_boots' count: 1 enchantments: 'minecraft:feather_falling': 1 dyed_color: 1908001 + hidden_components: + - 'minecraft:dyed_color' items: '1': id: 'minecraft:potion' From cc88e3217b8b781e829c62a189efa497714ef6be Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 13:46:42 -0700 Subject: [PATCH 06/52] ItemParser - add some 1.21.4 support (minimal) --- .../shanebeestudios/hg/api/gui/KitGUI.java | 31 +++++++++++++------ .../hg/api/parsers/ItemParser.java | 9 ++++-- .../com/shanebeestudios/hg/api/util/Util.java | 6 +++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/gui/KitGUI.java b/src/main/java/com/shanebeestudios/hg/api/gui/KitGUI.java index 3e096dd3..cc4b0e44 100644 --- a/src/main/java/com/shanebeestudios/hg/api/gui/KitGUI.java +++ b/src/main/java/com/shanebeestudios/hg/api/gui/KitGUI.java @@ -1,11 +1,12 @@ package com.shanebeestudios.hg.api.gui; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.data.KitEntry; -import com.shanebeestudios.hg.plugin.configs.Language; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.ItemLore; +import io.papermc.paper.datacomponent.item.TooltipDisplay; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -38,11 +39,16 @@ public KitGUI(KitsGUI kitsGUI, Player player, KitEntry kitEntry) { Util.getMini(this.lang.kits_kit_gui_title.replace("", kitEntry.getName()))); // SETUP INVENTORY - // white line - ItemStack line = ItemType.WHITE_WOOL.createItemStack(); - // TODO hide tooltip (1.21.5 way) + // divider + ItemStack divider = ItemType.BLACK_STAINED_GLASS_PANE.createItemStack(); + if (Util.RUNNING_1_21_5) { + divider.setData(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay() + .hideTooltip(true)); + } else { + divider.setData(DataComponentTypes.CUSTOM_NAME, Component.text(" ")); + } for (int i = 9; i < 18; i++) { - this.inventory.setItem(i, line); + this.inventory.setItem(i, divider); } // exit button @@ -71,7 +77,7 @@ public KitGUI(KitsGUI kitsGUI, Player player, KitEntry kitEntry) { } this.inventory.setItem(1, chestplate); - // Helmet + // Leggings ItemStack leggings = kitEntry.getLeggings(); if (leggings == null) { leggings = ItemType.BARRIER.createItemStack(); @@ -79,7 +85,7 @@ public KitGUI(KitsGUI kitsGUI, Player player, KitEntry kitEntry) { } this.inventory.setItem(2, leggings); - // Helmet + // Boots ItemStack boots = kitEntry.getBoots(); if (boots == null) { boots = ItemType.BARRIER.createItemStack(); @@ -90,8 +96,13 @@ public KitGUI(KitsGUI kitsGUI, Player player, KitEntry kitEntry) { // Potions ItemStack potion = ItemType.POTION.createItemStack(); potion.setData(DataComponentTypes.CUSTOM_NAME, Util.getMini(this.lang.kits_kit_gui_potion_effects)); - // TODO 1.21.5 hide potion contents - potion.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); + if (Util.RUNNING_1_21_5) { + potion.setData(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay() + .hideTooltip(true)); + } else { + //noinspection deprecation + potion.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); + } List potionEffects = kitEntry.getPotionEffects(); List lore = new ArrayList<>(); diff --git a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java index f1aa14be..de088cb7 100644 --- a/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java +++ b/src/main/java/com/shanebeestudios/hg/api/parsers/ItemParser.java @@ -14,6 +14,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemType; import org.bukkit.potion.PotionEffect; @@ -151,15 +152,17 @@ public class ItemParser { itemStack.setData(DataComponentTypes.POTION_CONTENTS, builder.build()); } - // DYED_COLOR if (config.contains("dyed_color")) { int color = config.getInt("dyed_color"); - itemStack.setData(DataComponentTypes.DYED_COLOR, DyedItemColor.dyedItemColor(Color.fromRGB(color))); + itemStack.setData(DataComponentTypes.DYED_COLOR, DyedItemColor.dyedItemColor().color(Color.fromRGB(color))); + if (!Util.RUNNING_1_21_5) { + itemStack.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP); + } } // HIDDEN COMPONENTS - if (config.isList("hidden_components")) { + if (Util.RUNNING_1_21_5 && config.isList("hidden_components")) { TooltipDisplay.Builder builder = TooltipDisplay.tooltipDisplay(); for (String compKey : config.getStringList("hidden_components")) { NamespacedKey namespacedKey = NamespacedKey.fromString(compKey); diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Util.java b/src/main/java/com/shanebeestudios/hg/api/util/Util.java index 9cb88877..d54c39c5 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Util.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Util.java @@ -27,7 +27,11 @@ @SuppressWarnings("WeakerAccess") public class Util { - public static final BlockFace[] BLOCK_FACES = new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; + // PUBLIC + // Quick link to help for removing legacy stuff later + public static final boolean RUNNING_1_21_5 = isRunningMinecraft(1, 21, 5); + + // PRIVATE private static final Pattern HEX_PATTERN = Pattern.compile("<#([A-Fa-f0-9]){6}>"); private static final CommandSender CONSOLE = Bukkit.getConsoleSender(); private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); From a771ae9735835cffcdbfd2db991626b59a954b3c Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 13:51:29 -0700 Subject: [PATCH 07/52] Validate.java - remove unused class --- .../shanebeestudios/hg/api/util/Validate.java | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/main/java/com/shanebeestudios/hg/api/util/Validate.java diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Validate.java b/src/main/java/com/shanebeestudios/hg/api/util/Validate.java deleted file mode 100644 index e997fc0f..00000000 --- a/src/main/java/com/shanebeestudios/hg/api/util/Validate.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.shanebeestudios.hg.api.util; - -public abstract class Validate { - - /** - * Validate if a value is between a min and max value - * - * @param value Value to validate - * @param min Min value amount - * @param max Max value amount - */ - public static void isBetween(int value, int min, int max) { - //value >= min && value <= max, "Value must be between " + min + " and " + max); - // TODO this seems like a wasted class/method - } - -} From ad21afc0b53c75dc0b45bc3237b49f0f8637ebfc Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 13:51:49 -0700 Subject: [PATCH 08/52] GamePlayerData - remove todo --- .../java/com/shanebeestudios/hg/api/game/GamePlayerData.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index 5ee1f0f5..8c80d3a8 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -63,8 +63,6 @@ protected GamePlayerData(Game game) { this.gameManager = this.plugin.getGameManager(); } - // TODO Data methods - /** * Get a list of all players in the game * From 336e3d856f32f1110633816f0b5328287fcdbab8 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 13:53:34 -0700 Subject: [PATCH 09/52] GameManager - remove useless variables --- .../com/shanebeestudios/hg/plugin/managers/GameManager.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java index 00b5f17b..59f0e0c3 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java @@ -128,9 +128,7 @@ public void stopAllGames() { public Game createGame(String name, Block corner1, Block corner2, List spawns, Location sign, int timer, int minPlayers, int maxPlayers, int cost) { GameRegion gameRegion = GameRegion.createNew(corner1, corner2); - int roam = 1; // tODO what are you? - boolean isReady = true; // TODO yeah? - Game game = new Game(name, gameRegion, spawns, sign, timer, minPlayers, maxPlayers, roam, isReady, cost); + Game game = new Game(name, gameRegion, spawns, sign, timer, minPlayers, maxPlayers, Config.SETTINGS_FREE_ROAM_TIME, true, cost); this.games.put(name, game); this.plugin.getArenaConfig().saveGameToConfig(game); return game; From 722d60e676fbf9f320fc82d52de42e621a7d3259 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 15:01:40 -0700 Subject: [PATCH 10/52] Game - teleport players into arena when the game is ready to go --- .../com/shanebeestudios/hg/api/game/Game.java | 11 +++-- .../hg/api/game/GamePlayerData.java | 42 +++++++++++-------- .../hg/plugin/configs/Config.java | 4 +- .../hg/plugin/configs/Language.java | 2 + src/main/resources/language.yml | 1 + 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index 53d75015..155b689f 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -244,6 +244,7 @@ public void startPreGameCountdown() { Bukkit.getPluginManager().callEvent(event); this.gameArenaData.setStatus(Status.COUNTDOWN); + this.gamePlayerData.putAllPlayersIntoArena(); this.startingTask = new StartingTask(this); } @@ -366,26 +367,28 @@ public boolean joinGame(Player player, boolean savePreviousLocation) { } case READY -> { if (!canJoin(player)) return false; - this.gamePlayerData.addPlayerData(player); + this.gamePlayerData.addPlayerData(player, savePreviousLocation); startWaitingPeriod(); broadcastJoin(player); + Util.sendPrefixedMessage(player, this.lang.game_joined_waiting_to_teleport.replace("", arenaName)); } case WAITING -> { if (!canJoin(player)) return false; - this.gamePlayerData.addPlayerData(player); + this.gamePlayerData.addPlayerData(player, savePreviousLocation); if (this.gamePlayerData.getPlayers().size() >= this.gameArenaData.getMinPlayers()) { startPreGameCountdown(); } else { broadcastJoin(player); + Util.sendPrefixedMessage(player, this.lang.game_joined_waiting_to_teleport.replace("", arenaName)); } } case COUNTDOWN -> { if (!canJoin(player)) return false; - this.gamePlayerData.addPlayerData(player); + this.gamePlayerData.addPlayerData(player, savePreviousLocation); + this.gamePlayerData.putPlayerIntoArena(player); } } - this.gamePlayerData.putPlayerIntoArena(player, savePreviousLocation); return true; } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index 8c80d3a8..4794017d 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -47,8 +47,8 @@ public class GamePlayerData extends Data { private final GameManager gameManager; // Player Lists - final List players = new ArrayList<>(); - final List spectators = new ArrayList<>(); + final Map players = new HashMap<>(); + final Map spectators = new HashMap<>(); // This list contains all players who have joined the arena // Will be used to broadcast messages even if a player is no longer in the game final List allPlayers = new ArrayList<>(); @@ -69,7 +69,7 @@ protected GamePlayerData(Game game) { * @return UUID list of all players in game */ public List getPlayers() { - return this.players; + return new ArrayList<>(this.players.keySet()); } void clearPlayers() { @@ -83,7 +83,7 @@ void clearPlayers() { * @return List of spectators */ public List getSpectators() { - return new ArrayList<>(this.spectators); + return new ArrayList<>(this.spectators.keySet()); } void clearSpectators() { @@ -118,7 +118,7 @@ private void startMessage(Player player) { */ public void respawnAll() { this.randomizedSpawns.clear(); - for (Player player : this.players) { + for (Player player : this.players.keySet()) { player.teleport(pickRandomSpawn()); } } @@ -174,8 +174,8 @@ public void unFreeze(Player player) { */ public void messageAllActivePlayers(String message) { List allPlayers = new ArrayList<>(); - allPlayers.addAll(this.players); - allPlayers.addAll(this.spectators); + allPlayers.addAll(this.players.keySet()); + allPlayers.addAll(this.spectators.keySet()); for (Player player : allPlayers) { Util.sendMessage(player, message); } @@ -190,7 +190,7 @@ public void messageAllActivePlayers(String message) { */ public void messageAllPlayers(String message) { List allPlayers = new ArrayList<>(this.allPlayers); - allPlayers.addAll(this.spectators); + allPlayers.addAll(this.spectators.keySet()); for (Player player : allPlayers) { Util.sendPrefixedMessage(player, message); } @@ -206,13 +206,21 @@ private Location pickRandomSpawn() { return spawn; } - void addPlayerData(Player player) { - this.players.add(player); + void addPlayerData(Player player, boolean savePreviousLocation) { + this.players.put(player, savePreviousLocation); this.allPlayers.add(player); this.game.getGameBlockData().updateLobbyBlock(); } - void putPlayerIntoArena(Player player, boolean savePreviousLocation) { + /** + * Teleport all waiting players into the arena + */ + public void putAllPlayersIntoArena() { + this.players.keySet().forEach(this::putPlayerIntoArena); + } + + void putPlayerIntoArena(Player player) { + boolean savePreviousLocation = this.players.get(player); Location loc = pickRandomSpawn(); if (loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) { while (loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) { @@ -224,12 +232,12 @@ void putPlayerIntoArena(Player player, boolean savePreviousLocation) { player.leaveVehicle(); } - Location previousLocation = player.getLocation(); + Location previousLocation = player.getLocation().clone(); // Teleport async into the arena so it loads a little more smoothly player.teleportAsync(loc).thenAccept(a -> { PlayerData playerData = new PlayerData(player, this.game); - if (savePreviousLocation && Config.savePreviousLocation) { + if (savePreviousLocation && Config.SETTINGS_SAVE_PREVIOUS_LOCATION) { playerData.setPreviousLocation(previousLocation); } this.playerManager.addPlayerData(playerData); @@ -319,19 +327,19 @@ public void spectate(Player spectator) { if (this.playerManager.hasPlayerData(uuid)) { this.playerManager.transferPlayerDataToSpectator(uuid); } else { - this.playerManager.addSpectatorData(new PlayerData(spectator, game)); + this.playerManager.addSpectatorData(new PlayerData(spectator, this.game)); } - this.spectators.add(spectator); + this.spectators.put(spectator, true); // TODO should we handle location saving? spectator.setGameMode(GameMode.SURVIVAL); spectator.setCollidable(false); if (Config.SPECTATE_FLY) spectator.setAllowFlight(true); if (Config.SPECTATE_HIDE) { - for (Player player : this.players) { + for (Player player : this.players.keySet()) { player.hidePlayer(this.plugin, spectator); } - for (Player player : this.spectators) { + for (Player player : this.spectators.keySet()) { player.hidePlayer(this.plugin, spectator); } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java index 4f47eb1a..8e7b4f46 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java @@ -30,7 +30,7 @@ public class Config { public static int TRACKING_STICK_USES; public static int PLAYERS_FOR_TRACKING_STICK; public static int SETTINGS_TELEPORT_AT_END_TIME; - public static boolean savePreviousLocation; + public static boolean SETTINGS_SAVE_PREVIOUS_LOCATION; public static int SETTINGS_FREE_ROAM_TIME; public static Location GLOBAL_EXIT_LOCATION; @@ -134,7 +134,7 @@ private void loadConfig() { bossbar = config.getBoolean("settings.bossbar-countdown"); TRACKING_STICK_USES = config.getInt("settings.trackingstick-uses"); PLAYERS_FOR_TRACKING_STICK = config.getInt("settings.players-for-trackingstick"); - savePreviousLocation = config.getBoolean("settings.save-previous-location"); + SETTINGS_SAVE_PREVIOUS_LOCATION = config.getBoolean("settings.save-previous-location"); SETTINGS_TELEPORT_AT_END_TIME = config.getInt("settings.teleport-at-end-time"); SETTINGS_FREE_ROAM_TIME = config.getInt("settings.free-room-time"); String locString = config.getString("settings.global-exit-location"); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java index 3fba7709..b9f09dee 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java @@ -130,6 +130,7 @@ public class Language { // GAME public String game_waiting_join; public String game_waiting_players_to_start; + public String game_joined_waiting_to_teleport; public String game_join; public String game_countdown_started; public String game_countdown_timer; @@ -415,6 +416,7 @@ private void loadLang() { // GAME this.game_waiting_join = this.lang.getString("game.waiting-join"); this.game_waiting_players_to_start = this.lang.getString("game.waiting-players-to-start"); + this.game_joined_waiting_to_teleport = this.lang.getString("game.joined-waiting-to-teleport"); this.game_join = this.lang.getString("game.join"); this.game_countdown_started = this.lang.getString("game.countdown-started"); this.game_countdown_timer = this.lang.getString("game.countdown-timer"); diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 1b339539..91d8b1b6 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -181,6 +181,7 @@ game: waiting-join: " joined arena ''" # will be replaced with amount of players left to start a game waiting-players-to-start: ' players to start!' + joined-waiting-to-teleport: "You have joined arena ''! You will teleport when the game is ready to go." running: "The game '' is already running and cannot be joined!" join: "Use: /hg join to join!" From 6073c3c77dddfc08d39d6b4650368d7a12ab59d4 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 15:07:26 -0700 Subject: [PATCH 11/52] Game - fix error when stopping game if players have joined but arent in arena yet --- src/main/java/com/shanebeestudios/hg/api/game/Game.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index 155b689f..ccc20783 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -417,7 +417,10 @@ public void stop(Boolean death) { for (Player player : this.gamePlayerData.getPlayers()) { UUID uuid = player.getUniqueId(); PlayerData playerData = this.playerManager.getPlayerData(uuid); - assert playerData != null; + + // We might be in the waiting stage + if (playerData == null) continue; + Location previousLocation = playerData.getPreviousLocation(); this.gamePlayerData.heal(player); From 5635fae71e905ce9a9880e33629899aeddfe7c54 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 15:16:30 -0700 Subject: [PATCH 12/52] KillManager - fix spectators keeping items after death --- .../java/com/shanebeestudios/hg/plugin/managers/KillManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java index 99c1fa76..f3bb7fd0 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java @@ -188,6 +188,7 @@ public boolean isShotByPlayer(Entity projectile) { public void processDeath(Player player, Game game, Entity attacker, DamageSource damageSource) { List drops = dropInventoryOfPlayer(player); player.setHealth(20); + player.getInventory().clear(); Bukkit.getScheduler().runTaskLater(this.plugin, () -> { GamePlayerData gamePlayerData = game.getGamePlayerData(); String deathString; From 38fcfadc50e9fd4bfefadcb2434a7a9485a4d515 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 16:46:25 -0700 Subject: [PATCH 13/52] language.yml - fix typo --- src/main/resources/language.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 91d8b1b6..89cf10a1 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -48,7 +48,7 @@ command: create-error-session-exists: 'Looks like you are already in a creation session!' create-divisible-1: 'Time-in-seconds must be divisible by 30!' create-divisible-2: 'Ex: 90 is divisible by 30' - create-minmax: 'min-players cannot be more then max-players!' + create-minmax: 'min-players cannot be more than max-players!' create-session-stick-name: 'HungerGames Selection Stick' create-session-start: 'You are now ready to create your area, click the first corner of your area with the stick.' create-session-next-corner: 'First corner selected! Now select your second corner.' From c42f8426bf68d8ce99d0a000d58bc0ab4283ad36 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 16:58:46 -0700 Subject: [PATCH 14/52] CustomArg - better handling of invalid game arg --- .../hg/api/command/CustomArg.java | 36 +++++++++---------- .../com/shanebeestudios/hg/api/util/Util.java | 5 +++ .../hg/plugin/commands/DebugCommand.java | 3 +- .../plugin/commands/DeleteArenaCommand.java | 3 +- .../hg/plugin/commands/EditCommand.java | 28 +++++++-------- .../commands/RefillChestNowCommand.java | 3 +- .../hg/plugin/commands/SetExitCommand.java | 2 +- .../hg/plugin/commands/SpectateCommand.java | 3 +- .../hg/plugin/configs/Language.java | 2 ++ .../hg/plugin/managers/GameManager.java | 2 +- src/main/resources/language.yml | 1 + 11 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/command/CustomArg.java b/src/main/java/com/shanebeestudios/hg/api/command/CustomArg.java index cb4af4bc..d477d68e 100644 --- a/src/main/java/com/shanebeestudios/hg/api/command/CustomArg.java +++ b/src/main/java/com/shanebeestudios/hg/api/command/CustomArg.java @@ -1,14 +1,14 @@ package com.shanebeestudios.hg.api.command; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.plugin.managers.GameManager; -import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.CustomArgument; import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.executors.ExecutionInfo; import org.jetbrains.annotations.ApiStatus; import java.util.Locale; @@ -16,6 +16,7 @@ public abstract class CustomArg { + private static Language LANG; private static GameManager GAME_MANAGER; /** @@ -25,32 +26,27 @@ public abstract class CustomArg { * @param gameManager GameManager instance */ @ApiStatus.Internal - public static void init(GameManager gameManager) { + public static void init(HungerGames plugin, GameManager gameManager) { + LANG = plugin.getLang(); GAME_MANAGER = gameManager; } - /** - * @hidden - */ - public static Game getGame(ExecutionInfo info) throws WrapperCommandSyntaxException { - Game game = info.args().getByClass("game", Game.class); - if (game == null) { - String raw = info.args().getRaw("game"); - throw CommandAPI.failWithString("invalid game '" + raw + "'"); - } - return game; - } - /** * Custom command argument for {@link Game Games} */ public static final CustomArg GAME = new CustomArg() { @Override public Argument get(String name) { - return new CustomArgument<>(new StringArgument(name), info -> - GAME_MANAGER.getGame(info.input().toLowerCase(Locale.ROOT))) - .includeSuggestions(ArgumentSuggestions.stringCollectionAsync(info -> - CompletableFuture.supplyAsync(GAME_MANAGER::getGameNames))); + return new CustomArgument<>(new StringArgument(name), info -> { + String gameName = info.input().toLowerCase(Locale.ROOT); + Game game = GAME_MANAGER.getGame(gameName); + if (game == null) { + String msg = LANG.command_base_invalid_game.replace("", gameName); + Util.throwCustomArgException(msg); + } + return game; + }).includeSuggestions(ArgumentSuggestions.stringCollectionAsync(info -> + CompletableFuture.supplyAsync(GAME_MANAGER::getGameNames))); } }; diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Util.java b/src/main/java/com/shanebeestudios/hg/api/util/Util.java index d54c39c5..c90920cf 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Util.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Util.java @@ -3,6 +3,7 @@ import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.plugin.configs.Language; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.md_5.bungee.api.ChatColor; @@ -172,6 +173,10 @@ public static Component getMini(String format, Object... objects) { return MINI_MESSAGE.deserialize(String.format(format, objects)); } + public static void throwCustomArgException(String message) throws CustomArgumentException { + throw CustomArgumentException.fromAdventureComponent(getMini(getPrefix() + " " + message)); + } + /** * Convert a MiniMessage/Component to text * diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java index 6afdff52..a76749cf 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java @@ -19,7 +19,8 @@ protected Argument register() { .withPermission(Permissions.COMMAND_DEBUG.permission()) .then(CustomArg.GAME.get("game") .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); + assert game != null; this.gameManager.checkGame(game, info.sender()); })); } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java index 851e8abb..b475b1ae 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java @@ -25,7 +25,8 @@ protected Argument register() { .then(CustomArg.GAME.get("game") .executes(info -> { CommandSender sender = info.sender(); - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); + assert game != null; GamePlayerData gamePlayerData = game.getGamePlayerData(); GameArenaData gameArenaData = game.getGameArenaData(); String name = gameArenaData.getName(); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java index 89882dbf..5f75bc35 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java @@ -46,7 +46,7 @@ private Argument border() { .then(LiteralArgument.literal("final_size") .then(new IntegerArgument("final_size", 5) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int finalSize = info.args().getByClass("final_size", Integer.class); GameBorderData gameBorderData = game.getGameBorderData(); gameBorderData.setFinalBorderSize(finalSize); @@ -56,7 +56,7 @@ private Argument border() { .then(LiteralArgument.literal("countdown_start") .then(new IntegerArgument("countdown_start", 5) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int countdownStart = info.args().getByClass("countdown_start", Integer.class); GameBorderData gameBorderData = game.getGameBorderData(); gameBorderData.setBorderCountdownStart(countdownStart); @@ -66,7 +66,7 @@ private Argument border() { .then(LiteralArgument.literal("countdown_end") .then(new IntegerArgument("countdown_end", 5) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int countdownEnd = info.args().getByClass("countdown_end", Integer.class); GameBorderData gameBorderData = game.getGameBorderData(); gameBorderData.setBorderCountdownEnd(countdownEnd); @@ -77,7 +77,7 @@ private Argument border() { .then(LiteralArgument.literal("center_location") .then(new Location2DArgument("center_location", LocationType.BLOCK_POSITION) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); Location2D centerLocation = info.args().getByClass("center_location", Location2D.class); GameBorderData gameBorderData = game.getGameBorderData(); gameBorderData.setCenterLocation(convert(centerLocation)); @@ -91,7 +91,7 @@ private Argument chestRefillTime() { return LiteralArgument.literal("chest-refill-time") .then(new IntegerArgument("time", 30) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); CommandSender sender = info.sender(); String name = game.getGameArenaData().getName(); int time = info.args().getByClass("time", Integer.class); @@ -113,7 +113,7 @@ private Argument chestRefillRepeat() { return LiteralArgument.literal("chest-refill-repeat") .then(new IntegerArgument("time", 30) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); CommandSender sender = info.sender(); String name = game.getGameArenaData().getName(); int time = info.args().getByClass("time", Integer.class); @@ -135,7 +135,7 @@ private Argument info() { .then(LiteralArgument.literal("free_roam_time") .then(new IntegerArgument("seconds", -1) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int freeRoamTime = info.args().getByClass("seconds", Integer.class); game.getGameArenaData().setFreeRoamTime(freeRoamTime); Util.sendPrefixedMessage(info.sender(), "Free roam time set to %s", freeRoamTime); @@ -144,7 +144,7 @@ private Argument info() { .then(LiteralArgument.literal("cost") .then(new IntegerArgument("dollars", 0) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int cost = info.args().getByClass("dollars", Integer.class); game.getGameArenaData().setCost(cost); Util.sendPrefixedMessage(info.sender(), "Cost set to %s", cost); @@ -153,7 +153,7 @@ private Argument info() { .then(LiteralArgument.literal("timer") .then(new IntegerArgument("seconds", 30) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int timerSeconds = info.args().getByClass("seconds", Integer.class); game.getGameArenaData().setTimer(timerSeconds); Util.sendPrefixedMessage(info.sender(), "Timer set to %s", timerSeconds); @@ -162,7 +162,7 @@ private Argument info() { .then(LiteralArgument.literal("min_players") .then(new IntegerArgument("min", 2) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int minPlayers = info.args().getByClass("min", Integer.class); if (minPlayers > game.getGameArenaData().getMaxPlayers()) { throw CommandAPI.failWithString("Min players cannot be greater than max players"); @@ -174,7 +174,7 @@ private Argument info() { .then(LiteralArgument.literal("max_players") .then(new IntegerArgument("max", 2) .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); int maxPlayers = info.args().getByClass("max", Integer.class); if (maxPlayers < game.getGameArenaData().getMinPlayers()) { throw CommandAPI.failWithString("Max players cannot be less than min players"); @@ -189,7 +189,7 @@ private Argument locations() { return LiteralArgument.literal("locations") .then(LiteralArgument.literal("lobby_wall") .executesPlayer(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); Player player = info.sender(); Block targetBlock = player.getTargetBlockExact(10); if (targetBlock != null && Tag.WALL_SIGNS.isTagged(targetBlock.getType()) && game.getGameBlockData().setLobbyBlock(targetBlock.getLocation())) { @@ -202,7 +202,7 @@ private Argument locations() { })) .then(LiteralArgument.literal("clear_spawns") .executes(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); game.getGameArenaData().clearSpawns(); Util.sendPrefixedMessage(info.sender(), "Spawns have been cleared. Arena '%s' has a max of %s players, so make sure to add spawns for them.", game.getGameArenaData().getName(), game.getGameArenaData().getMaxPlayers()); @@ -211,7 +211,7 @@ private Argument locations() { .then(LiteralArgument.literal("add_spawn") .then(new LocationArgument("location", LocationType.BLOCK_POSITION) .executesPlayer(info -> { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); GameArenaData gameArenaData = game.getGameArenaData(); Location location = info.args().getByClass("location", Location.class); assert location != null; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java index 38f51c84..1e3f4f0e 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java @@ -23,7 +23,8 @@ protected Argument register() { .then(CustomArg.GAME.get("game") .executes(info -> { CommandSender sender = info.sender(); - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); + assert game != null; if (game.getGameArenaData().getStatus() != Status.RUNNING) { Util.sendMessage(sender, this.lang.listener_not_running); return; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java index 0e934b80..6985f107 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java @@ -35,7 +35,7 @@ protected Argument register() { .then(CustomArg.GAME.get("game") .executesPlayer(info -> { Player player = info.sender(); - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); setExit(game, player); Util.sendPrefixedMessage(player, this.lang.command_exit_set_arena.replace("", game.getGameArenaData().getName())); })); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java index 80491d56..ac2e77ed 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java @@ -27,7 +27,8 @@ protected Argument register() { if (this.playerManager.hasPlayerData(player) || this.playerManager.hasSpectatorData(player)) { Util.sendMessage(player, this.lang.command_join_already_in_game); } else { - Game game = CustomArg.getGame(info); + Game game = info.args().getByClass("game", Game.class); + assert game != null; GameArenaData arenaData = game.getGameArenaData(); Status status = arenaData.getStatus(); if (status == Status.RUNNING || status == Status.FREE_ROAM) { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java index b9f09dee..fa2a48ed 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Language.java @@ -41,6 +41,7 @@ public class Language { // COMMANDS // - Base + public String command_base_invalid_game; public String command_base_not_in_valid_game; public String command_base_no_region; public String command_base_status; @@ -315,6 +316,7 @@ private void loadLang() { // COMMANDS // - Base + this.command_base_invalid_game = this.lang.getString("command.base-invalid-game"); this.command_base_not_in_valid_game = this.lang.getString("command.base-not-in-valid-game"); this.command_base_no_region = this.lang.getString("command.base-no-region"); this.command_base_status = this.lang.getString("command.base-status"); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java index 59f0e0c3..37ebe104 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java @@ -45,7 +45,7 @@ public class GameManager { public GameManager(HungerGames plugin) { this.plugin = plugin; this.lang = plugin.getLang(); - CustomArg.init(this); + CustomArg.init(plugin, this); this.globalExitLocation = Config.GLOBAL_EXIT_LOCATION; } diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 89cf10a1..c82dff09 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -37,6 +37,7 @@ arena-debug: # COMMANDS command: # Base + base-invalid-game: "Invalid game ''" base-not-in-valid-game: 'You are not in a valid game!' base-no-region: 'You are not in a valid HungerGames region!' base-status: "Status for arena '' = " From 99b3f45e5e1001d880cfe53a1b4e388491cffdf9 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 17:33:10 -0700 Subject: [PATCH 15/52] Game - cleanup winners/rewards --- .../com/shanebeestudios/hg/api/game/Game.java | 87 ++++++++++--------- .../com/shanebeestudios/hg/api/util/Util.java | 32 ------- .../shanebeestudios/hg/api/util/Vault.java | 6 +- .../hg/plugin/commands/LeaveCommand.java | 2 +- .../hg/plugin/configs/Config.java | 30 +++---- 5 files changed, 65 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index ccc20783..17c46501 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -28,9 +28,8 @@ import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.UUID; +import java.util.StringJoiner; /** * General game object @@ -402,21 +401,19 @@ public void stop() { /** * Stop the game * - * @param death Whether the game stopped after the result of a death (false = no winnings payed out) + * @param death Whether the game stopped after the result of a death (false = no winnings paid out) */ - public void stop(Boolean death) { + public void stop(boolean death) { if (Config.WORLD_BORDER_ENABLED) { this.gameBorderData.resetBorder(); } this.gameEntityData.removeEntities(); this.gameScoreboard.resetSidebars(); - // TODO win list should be players - List win = new ArrayList<>(); + List winners = new ArrayList<>(); cancelTasks(); for (Player player : this.gamePlayerData.getPlayers()) { - UUID uuid = player.getUniqueId(); - PlayerData playerData = this.playerManager.getPlayerData(uuid); + PlayerData playerData = this.playerManager.getPlayerData(player); // We might be in the waiting stage if (playerData == null) continue; @@ -425,9 +422,9 @@ public void stop(Boolean death) { this.gamePlayerData.heal(player); playerData.restore(player); - win.add(uuid); + winners.add(player); this.gamePlayerData.exit(player, previousLocation); - this.playerManager.removePlayerData(uuid); + this.playerManager.removePlayerData(player); } for (Player spectator : this.gamePlayerData.getSpectators()) { @@ -435,48 +432,58 @@ public void stop(Boolean death) { } if (gameArenaData.getStatus() == Status.RUNNING) { - bar.clearBar(); + this.bar.clearBar(); } - if (!win.isEmpty() && death) { - double db = (double) Config.cash / win.size(); - for (UUID u : win) { - if (Config.giveReward) { - Player p = Bukkit.getPlayer(u); - assert p != null; - if (!Config.rewardCommands.isEmpty()) { - for (String cmd : Config.rewardCommands) { - if (!cmd.equalsIgnoreCase("none")) - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("", p.getName())); + // Handle rewards and stats + if (!winners.isEmpty() && death) { + double winningReward = (double) Config.REWARD_CASH / winners.size(); + for (Player winner : winners) { + if (Config.REWARD_GIVE_REWARD) { + // Run reward commands + if (!Config.REWARD_COMMANDS.isEmpty()) { + for (String cmd : Config.REWARD_COMMANDS) { + if (cmd.equalsIgnoreCase("none")) continue; + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("", winner.getName())); } } - if (!Config.rewardMessages.isEmpty()) { - for (String msg : Config.rewardMessages) { - if (!msg.equalsIgnoreCase("none")) - Util.sendMessage(p, msg.replace("", p.getName())); + // Send reward messages + if (!Config.REWARD_MESSAGES.isEmpty()) { + for (String msg : Config.REWARD_MESSAGES) { + if (msg.equalsIgnoreCase("none")) continue; + Util.sendMessage(winner, msg.replace("", winner.getName())); } } - if (Config.cash != 0) { - Vault.economy.depositPlayer(Bukkit.getServer().getOfflinePlayer(u), db); - Util.sendMessage(p, lang.winning_amount.replace("", String.valueOf(db))); + // Deposit reward winnings + if (winningReward > 0) { + Vault.ECONOMY.depositPlayer(winner, winningReward); + Util.sendMessage(winner, this.lang.winning_amount.replace("", String.valueOf(winningReward))); } } - this.plugin.getLeaderboard().addStat(u, Leaderboard.Stats.WINS); - this.plugin.getLeaderboard().addStat(u, Leaderboard.Stats.GAMES); + this.plugin.getLeaderboard().addStat(winner, Leaderboard.Stats.WINS); + this.plugin.getLeaderboard().addStat(winner, Leaderboard.Stats.GAMES); } } this.gameBlockData.clearChests(); - String winner = Util.translateStop(Util.convertUUIDListToStringList(win)); // Broadcast wins if (death) { - String broadcast = this.lang.game_player_won.replace("", this.gameArenaData.name).replace("", winner); - if (Config.broadcastWinMessages) { + // String together winners names + StringJoiner joiner = new StringJoiner(", "); + winners.forEach(player -> joiner.add(player.getName())); + String joinedWinners = joiner.toString(); + + String broadcast = this.lang.game_player_won + .replace("", this.gameArenaData.getName()) + .replace("", joinedWinners); + if (Config.SETTINGS_BROADCAST_WIN_MESSAGES) { Util.broadcast(broadcast); } else { this.gamePlayerData.messageAllPlayers(broadcast); } } + + // Run rollback if (this.gameBlockData.requiresRollback()) { if (this.plugin.isEnabled()) { new RollbackTask(this); @@ -487,18 +494,16 @@ public void stop(Boolean death) { } else { this.gameArenaData.setStatus(Status.READY); } - this.gameCommandData.runCommands(CommandType.STOP, null); - // Call GameEndEvent - Collection winners = new ArrayList<>(); - for (UUID uuid : win) { - winners.add(Bukkit.getPlayer(uuid)); - } + // Run stop commands + this.gameCommandData.runCommands(CommandType.STOP, null); // Game has ended, we can clear all players now this.gamePlayerData.clearPlayers(); this.gamePlayerData.clearSpectators(); this.gameScoreboard.clearGameTeams(); + + // Call GameEndEvent new GameEndEvent(this, winners, death).callEvent(); } @@ -566,8 +571,8 @@ boolean canJoin(Player player) { boolean vaultCheck(Player player) { if (Config.economy) { int cost = this.getGameArenaData().getCost(); - if (Vault.economy.getBalance(player) >= cost) { - Vault.economy.withdrawPlayer(player, cost); + if (Vault.ECONOMY.getBalance(player) >= cost) { + Vault.ECONOMY.withdrawPlayer(player, cost); return true; } else { Util.sendPrefixedMessage(player, this.lang.command_join_no_money.replace("", String.valueOf(cost))); diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Util.java b/src/main/java/com/shanebeestudios/hg/api/util/Util.java index c90920cf..db6d54dd 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Util.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Util.java @@ -226,38 +226,6 @@ public static void clearInv(Player player) { player.updateInventory(); } - /** - * Convert a list of UUIDs to a string of player names - * - * @param uuid UUID list to convert - * @return List of player names - */ - public static List convertUUIDListToStringList(List uuid) { - List winners = new ArrayList<>(); - for (UUID id : uuid) { - winners.add(Objects.requireNonNull(Bukkit.getPlayer(id)).getName()); - } - return winners; - } - - public static String translateStop(List win) { - StringBuilder builder = null; - int count = 0; - for (String s : win) { - count++; - if (count == 1) builder = new StringBuilder(s); - else if (count == win.size()) { - builder.append(", and ").append(s); - } else { - builder.append(", ").append(s); - } - } - if (builder != null) - return builder.toString(); - else - return "No one"; - } - @SuppressWarnings("DataFlowIssue") public static @NotNull NamespacedKey getPluginKey(String key) { return NamespacedKey.fromString("hungergames:" + key); diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Vault.java b/src/main/java/com/shanebeestudios/hg/api/util/Vault.java index 7b548288..555abfc7 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Vault.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Vault.java @@ -10,14 +10,14 @@ */ public class Vault { - public static Economy economy = null; + public static Economy ECONOMY = null; public static boolean setupEconomy() { RegisteredServiceProvider economyProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { - economy = economyProvider.getProvider(); + ECONOMY = economyProvider.getProvider(); } - return (economy != null); + return (ECONOMY != null); } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java index d9d06ea1..d20ae0cf 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java @@ -33,7 +33,7 @@ protected Argument register() { Status status = gameArenaData.getStatus(); int cost = gameArenaData.getCost(); if ((status == Status.WAITING || status == Status.COUNTDOWN) && cost > 0) { - Vault.economy.depositPlayer(player, cost); + Vault.ECONOMY.depositPlayer(player, cost); Util.sendMessage(player, this.lang.command_leave_refund.replace("", String.valueOf(cost))); } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java index 8e7b4f46..5897e0fb 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java @@ -24,7 +24,7 @@ public class Config { //Basic settings public static boolean BROADCAST_JOIN_MESSAGES; - public static boolean broadcastWinMessages; + public static boolean SETTINGS_BROADCAST_WIN_MESSAGES; public static boolean economy = true; public static boolean bossbar; public static int TRACKING_STICK_USES; @@ -50,10 +50,10 @@ public class Config { public static int MOBS_SPAWN_CAP_PER_PLAYER; //Reward info - public static boolean giveReward; - public static int cash; - public static List rewardCommands; - public static List rewardMessages; + public static boolean REWARD_GIVE_REWARD; + public static int REWARD_CASH; + public static List REWARD_COMMANDS; + public static List REWARD_MESSAGES; //Rollback public static boolean ROLLBACK_ALLOW_BREAK_BLOCKS; @@ -130,7 +130,7 @@ private void loadConfig() { // Settings SETTINGS_DEBUG = config.getBoolean("settings.debug"); BROADCAST_JOIN_MESSAGES = config.getBoolean("settings.broadcast-join-messages"); - broadcastWinMessages = config.getBoolean("settings.broadcast-win-messages"); + SETTINGS_BROADCAST_WIN_MESSAGES = config.getBoolean("settings.broadcast-win-messages"); bossbar = config.getBoolean("settings.bossbar-countdown"); TRACKING_STICK_USES = config.getInt("settings.trackingstick-uses"); PLAYERS_FOR_TRACKING_STICK = config.getInt("settings.players-for-trackingstick"); @@ -157,12 +157,12 @@ private void loadConfig() { MOBS_SPAWN_INTERVAL = config.getInt("mob-spawning.interval") * 20; MOBS_SPAWN_CAP_PER_PLAYER = config.getInt("mob-spawning.cap-per-player"); - giveReward = config.getBoolean("reward.enabled"); - cash = config.getInt("reward.cash"); - rewardCommands = config.getStringList("reward.commands"); - rewardMessages = config.getStringList("reward.messages"); - giveReward = config.getBoolean("reward.enabled"); - cash = config.getInt("reward.cash"); + REWARD_GIVE_REWARD = config.getBoolean("reward.enabled"); + REWARD_CASH = config.getInt("reward.cash"); + REWARD_COMMANDS = config.getStringList("reward.commands"); + REWARD_MESSAGES = config.getStringList("reward.messages"); + REWARD_GIVE_REWARD = config.getBoolean("reward.enabled"); + REWARD_CASH = config.getInt("reward.cash"); // Rollback ROLLBACK_ALLOW_BREAK_BLOCKS = config.getBoolean("rollback.allow-block-break"); @@ -204,17 +204,17 @@ private void loadConfig() { try { Vault.setupEconomy(); - if (Vault.economy == null) { + if (Vault.ECONOMY == null) { Util.log("Unable to setup vault!"); Util.log(" - Economy provider is missing."); Util.log(" - Cash rewards will not be given out.."); - giveReward = false; + REWARD_GIVE_REWARD = false; economy = false; } } catch (NoClassDefFoundError e) { Util.log("Unable to setup vault!"); Util.log(" - Cash rewards will not be given out.."); - giveReward = false; + REWARD_GIVE_REWARD = false; economy = false; } } From 40328863a5ebf1a30770e058568148005d77865a Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 18:19:00 -0700 Subject: [PATCH 16/52] Game - fix ability to double join a gam --- .../hg/api/data/PlayerData.java | 94 ++++++++++--------- .../com/shanebeestudios/hg/api/game/Game.java | 18 ++-- .../hg/api/game/GamePlayerData.java | 6 +- .../hg/plugin/managers/PlayerManager.java | 15 +-- 4 files changed, 69 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java b/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java index ed736009..9c655127 100755 --- a/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java @@ -24,24 +24,27 @@ public class PlayerData implements Cloneable { private static final Scoreboard DUMMY = Bukkit.getScoreboardManager().getNewScoreboard(); - //Pregame data - private final ItemStack[] inv; - private final ItemStack[] equip; - private final int expL; - private final float expP; - private final double health; - private final int food; - private final float saturation; - private final GameMode mode; + private final Game game; + private final Player player; private final UUID uuid; - private final Scoreboard scoreboard; + + //Pregame data + private ItemStack[] inv; + private ItemStack[] equip; + private int expL; + private float expP; + private double health; + private int food; + private float saturation; + private GameMode mode; + private Scoreboard scoreboard; private Location previousLocation = null; private boolean online; + private boolean hasGameStarted; //InGame data private GameTeam gameTeam; private GameTeam pendingGameTeam; - private final Game game; /** * New player pre-game data file @@ -51,20 +54,25 @@ public class PlayerData implements Cloneable { */ public PlayerData(Player player, Game game) { this.game = game; + this.player = player; this.uuid = player.getUniqueId(); - inv = player.getInventory().getStorageContents(); - equip = player.getInventory().getArmorContents(); - expL = player.getLevel(); - expP = player.getExp(); - mode = player.getGameMode(); - food = player.getFoodLevel(); - saturation = player.getSaturation(); - health = player.getHealth(); - Util.clearInv(player); - player.setLevel(0); - player.setExp(0); - scoreboard = player.getScoreboard(); - online = true; + this.online = true; + } + + public void backup() { + this.hasGameStarted = true; + this.inv = this.player.getInventory().getStorageContents(); + this.equip = this.player.getInventory().getArmorContents(); + this.expL = this.player.getLevel(); + this.expP = this.player.getExp(); + this.mode = this.player.getGameMode(); + this.food = this.player.getFoodLevel(); + this.saturation = this.player.getSaturation(); + this.health = this.player.getHealth(); + Util.clearInv(this.player); + this.player.setLevel(0); + this.player.setExp(0); + this.scoreboard = this.player.getScoreboard(); } /** @@ -73,16 +81,15 @@ public PlayerData(Player player, Game game) { * @param player Player to restore data to */ public void restore(Player player) { - if (player == null) return; + if (player == null || !this.hasGameStarted) return; Util.clearInv(player); - player.setWalkSpeed(0.2f); - player.setLevel(expL); - player.setExp(expP); - player.setFoodLevel(food); - player.setSaturation(saturation); - player.getInventory().setStorageContents(inv); - player.getInventory().setArmorContents(equip); - player.setGameMode(mode); + player.setLevel(this.expL); + player.setExp(this.expP); + player.setFoodLevel(this.food); + player.setSaturation(this.saturation); + player.getInventory().setStorageContents(this.inv); + player.getInventory().setArmorContents(this.equip); + player.setGameMode(this.mode); player.updateInventory(); player.setInvulnerable(false); restoreHealth(player); @@ -95,11 +102,11 @@ public void restore(Player player) { // Restores later if player has an item in their inventory which changes their max health value @SuppressWarnings("ConstantConditions") private void restoreHealth(Player player) { - double att = player.getAttribute(Attribute.MAX_HEALTH).getValue(); - if (health > att) { - Bukkit.getScheduler().runTaskLater(HungerGames.getPlugin(), () -> player.setHealth(health), 10); + double maxHealth = player.getAttribute(Attribute.MAX_HEALTH).getValue(); + if (this.health > maxHealth) { + Bukkit.getScheduler().runTaskLater(HungerGames.getPlugin(), () -> player.setHealth(this.health), 10); } else { - player.setHealth(health); + player.setHealth(this.health); } } @@ -203,17 +210,12 @@ public boolean isOnline() { return online; } - public void setOnline(boolean online) { - this.online = online; + public boolean hasGameStared() { + return this.hasGameStarted; } - /** - * Get the {@link Player Bukkit Player} belonging to this player data - * - * @return Player belonging to this player data - */ - public Player getBukkitPlayer() { - return Bukkit.getPlayer(this.uuid); + public void setOnline(boolean online) { + this.online = online; } @Override diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index 17c46501..df60f6a1 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -414,16 +414,16 @@ public void stop(boolean death) { cancelTasks(); for (Player player : this.gamePlayerData.getPlayers()) { PlayerData playerData = this.playerManager.getPlayerData(player); + assert playerData != null; - // We might be in the waiting stage - if (playerData == null) continue; - - Location previousLocation = playerData.getPreviousLocation(); + if (playerData.hasGameStared()) { + Location previousLocation = playerData.getPreviousLocation(); - this.gamePlayerData.heal(player); - playerData.restore(player); - winners.add(player); - this.gamePlayerData.exit(player, previousLocation); + this.gamePlayerData.heal(player); + playerData.restore(player); + winners.add(player); + this.gamePlayerData.exit(player, previousLocation); + } this.playerManager.removePlayerData(player); } @@ -431,7 +431,7 @@ public void stop(boolean death) { this.gamePlayerData.leaveSpectate(spectator); } - if (gameArenaData.getStatus() == Status.RUNNING) { + if (this.gameArenaData.getStatus() == Status.RUNNING) { this.bar.clearBar(); } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index 4794017d..8c7d3aa4 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -210,6 +210,7 @@ void addPlayerData(Player player, boolean savePreviousLocation) { this.players.put(player, savePreviousLocation); this.allPlayers.add(player); this.game.getGameBlockData().updateLobbyBlock(); + this.playerManager.createPlayerData(player, this.game); } /** @@ -236,11 +237,12 @@ void putPlayerIntoArena(Player player) { // Teleport async into the arena so it loads a little more smoothly player.teleportAsync(loc).thenAccept(a -> { - PlayerData playerData = new PlayerData(player, this.game); + PlayerData playerData = this.playerManager.getPlayerData(player); + assert playerData != null; + playerData.backup(); if (savePreviousLocation && Config.SETTINGS_SAVE_PREVIOUS_LOCATION) { playerData.setPreviousLocation(previousLocation); } - this.playerManager.addPlayerData(playerData); this.game.getGameScoreboard().setupBoard(player); heal(player); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java index 2885353c..7e6c788d 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.managers; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.PlayerStatus; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.status.PlayerStatus; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -154,13 +154,14 @@ public boolean hasData(UUID uuid) { } /** - * Add a PlayerData to the stored PlayerData map - *

This should mainly be used internally only

+ * Create {@link PlayerData} for a player * - * @param playerData PlayerData to add + * @param player Player to create data for + * @param game Game player is entering */ - public void addPlayerData(PlayerData playerData) { - playerMap.put(playerData.getUuid(), playerData); + public void createPlayerData(Player player, Game game) { + PlayerData playerData = new PlayerData(player, game); + this.playerMap.put(player.getUniqueId(), playerData); } /** From cf5f74ea49d2ecfdc4cb341ca934c63bfc8b9adc Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 18:32:45 -0700 Subject: [PATCH 17/52] PlayerManager - small cleanup --- .../hg/api/game/GamePlayerData.java | 16 +-- .../plugin/listeners/GameCommandListener.java | 5 +- .../plugin/listeners/GameEntityListener.java | 2 +- .../hg/plugin/managers/GameManager.java | 22 ++- .../hg/plugin/managers/PlayerManager.java | 131 +++++------------- .../tasks/NearestPlayerCompassTask.java | 2 +- 6 files changed, 51 insertions(+), 127 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index 8c7d3aa4..c290ae4f 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -31,7 +31,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; /** * Data class for holding a {@link Game Game's} players @@ -273,7 +272,6 @@ public void addKill(Player player) { */ public void leaveGame(Player player, boolean death) { new PlayerLeaveGameEvent(this.game, player, death).callEvent(); - UUID uuid = player.getUniqueId(); this.players.remove(player); if (!death) this.allPlayers.remove(player); // Only remove the player if they voluntarily left the game unFreeze(player); @@ -289,7 +287,7 @@ public void leaveGame(Player player, boolean death) { } } heal(player); - PlayerData playerData = this.playerManager.getPlayerData(uuid); + PlayerData playerData = this.playerManager.getPlayerData(player); assert playerData != null; Location previousLocation = playerData.getPreviousLocation(); @@ -324,12 +322,11 @@ void exit(Player player, @Nullable Location exitLocation) { * @param spectator The player to spectate */ public void spectate(Player spectator) { - UUID uuid = spectator.getUniqueId(); spectator.teleport(this.game.getGameArenaData().getSpawns().getFirst()); - if (this.playerManager.hasPlayerData(uuid)) { - this.playerManager.transferPlayerDataToSpectator(uuid); + if (this.playerManager.hasPlayerData(spectator)) { + this.playerManager.transferPlayerDataToSpectator(spectator); } else { - this.playerManager.addSpectatorData(new PlayerData(spectator, this.game)); + this.playerManager.createSpectatorData(spectator, this.game); } this.spectators.put(spectator, true); // TODO should we handle location saving? spectator.setGameMode(GameMode.SURVIVAL); @@ -356,8 +353,7 @@ public void spectate(Player spectator) { * @param spectator The player to remove */ public void leaveSpectate(Player spectator) { - UUID uuid = spectator.getUniqueId(); - PlayerData playerData = this.playerManager.getSpectatorData(uuid); + PlayerData playerData = this.playerManager.getSpectatorData(spectator); if (playerData == null) return; Location previousLocation = playerData.getPreviousLocation(); @@ -373,7 +369,7 @@ public void leaveSpectate(Player spectator) { if (Config.SPECTATE_HIDE) revealPlayer(spectator); exit(spectator, previousLocation); - this.playerManager.removeSpectatorData(uuid); + this.playerManager.removeSpectatorData(spectator); } void revealPlayer(Player hidden) { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java index ec6c85d2..61342702 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java @@ -25,10 +25,9 @@ private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); if (Permissions.BYPASS_COMMAND_RESTRICTION.has(player)) return; - UUID uuid = player.getUniqueId(); String[] st = event.getMessage().split(" "); // Prevent game players running non hunger games commands - if (this.playerManager.hasData(uuid) && !st[0].equalsIgnoreCase("/login")) { + if (this.playerManager.isInGame(player) && !st[0].equalsIgnoreCase("/login")) { if (st[0].equalsIgnoreCase("/hg") || st[0].equalsIgnoreCase("/hungergames")) { return; } @@ -40,7 +39,7 @@ private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { else if (("/tp".equalsIgnoreCase(st[0]) || "/teleport".equalsIgnoreCase(st[0])) && st.length >= 2) { Player p = Bukkit.getServer().getPlayer(st[1]); if (p != null) { - if (this.playerManager.hasPlayerData(uuid)) { + if (this.playerManager.hasPlayerData(p)) { Util.sendMessage(player, this.lang.listener_command_handler_playing); event.setMessage("/"); event.setCancelled(true); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java index bf2fc4cb..5b6a5675 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java @@ -75,7 +75,7 @@ private void onEntityShoot(EntityShootBowEvent event) { event.getProjectile().setMetadata("death-message", new FixedMetadataValue(plugin, entity.getMetadata("death-message").get(0).asString())); } - if (entity instanceof Player && playerManager.hasPlayerData(entity.getUniqueId())) { + if (entity instanceof Player player && playerManager.hasPlayerData(player)) { event.getProjectile().setMetadata("shooter", new FixedMetadataValue(plugin, entity.getName())); } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java index 37ebe104..ebb2e604 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java @@ -2,15 +2,15 @@ import com.google.common.collect.ImmutableList; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Language; +import com.shanebeestudios.hg.api.data.ItemData.ChestType; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; -import com.shanebeestudios.hg.api.data.ItemData.ChestType; import com.shanebeestudios.hg.api.game.GameRegion; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Random; -import java.util.UUID; import java.util.stream.Collectors; /** @@ -110,15 +109,14 @@ public void stopAllGames() { players.addAll(game.getGamePlayerData().getSpectators()); } for (Player player : players) { - UUID uuid = player.getUniqueId(); player.closeInventory(); - if (playerManager.hasPlayerData(uuid)) { - playerManager.getPlayerData(uuid).getGame().getGamePlayerData().leaveGame(player, false); - playerManager.removePlayerData(uuid); + if (playerManager.hasPlayerData(player)) { + playerManager.getPlayerData(player).getGame().getGamePlayerData().leaveGame(player, false); + playerManager.removePlayerData(player); } - if (playerManager.hasSpectatorData(uuid)) { - playerManager.getSpectatorData(uuid).getGame().getGamePlayerData().leaveSpectate(player); - playerManager.removePlayerData(uuid); + if (playerManager.hasSpectatorData(player)) { + playerManager.getSpectatorData(player).getGame().getGamePlayerData().leaveSpectate(player); + playerManager.removePlayerData(player); } } this.games.clear(); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java index 7e6c788d..c2ba4bef 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/PlayerManager.java @@ -33,17 +33,7 @@ public PlayerManager() { * @return True if player is playing in a game and has data */ public boolean hasPlayerData(Player player) { - return hasPlayerData(player.getUniqueId()); - } - - /** - * Check if a player is playing a game and has PlayerData - * - * @param uuid UUID of player to check - * @return True if player is playing in a game and has data - */ - public boolean hasPlayerData(UUID uuid) { - return playerMap.containsKey(uuid); + return this.playerMap.containsKey(player.getUniqueId()); } /** @@ -53,17 +43,7 @@ public boolean hasPlayerData(UUID uuid) { * @return True if player is spectating a game and has data */ public boolean hasSpectatorData(Player player) { - return hasSpectatorData(player.getUniqueId()); - } - - /** - * Check if a player is spectating a game and has PlayerData - * - * @param uuid UUID of player to check - * @return True if player is spectating a game and has data - */ - public boolean hasSpectatorData(UUID uuid) { - return spectatorMap.containsKey(uuid); + return this.spectatorMap.containsKey(player.getUniqueId()); } /** @@ -74,19 +54,9 @@ public boolean hasSpectatorData(UUID uuid) { */ @Nullable public PlayerData getPlayerData(Player player) { - return getPlayerData(player.getUniqueId()); - } - - /** - * Get an instance of a player's data if player is playing in a game - * - * @param uuid UUID of player to get data for - * @return PlayerData from player, null if player is not in a game - */ - @Nullable - public PlayerData getPlayerData(UUID uuid) { - if (hasPlayerData(uuid)) { - return playerMap.get(uuid); + UUID uuid = player.getUniqueId(); + if (this.playerMap.containsKey(uuid)) { + return this.playerMap.get(uuid); } return null; } @@ -99,19 +69,10 @@ public PlayerData getPlayerData(UUID uuid) { */ @Nullable public PlayerData getSpectatorData(Player player) { - return getSpectatorData(player.getUniqueId()); - } - - /** - * Get an instance of a player's data if player is spectating a game - * - * @param uuid UUID of player to get data for - * @return PlayerData from player, null if player is not spectating a game - */ - @Nullable - public PlayerData getSpectatorData(UUID uuid) { - if (hasSpectatorData(uuid)) + UUID uuid = player.getUniqueId(); + if (this.spectatorMap.containsKey(uuid)) { return spectatorMap.get(uuid); + } return null; } @@ -125,34 +86,13 @@ public PlayerData getSpectatorData(UUID uuid) { */ @Nullable public PlayerData getData(Player player) { - return getData(player.getUniqueId()); - } - - /** - * Get an instance of a player's data if player is in a game - *

This will first check if a player is playing in a game, then check if they are spectating a game. - *
If you would like specific data use {@link #getPlayerData(UUID)} or {@link #getSpectatorData(UUID)}

- * - * @param uuid UUID of player to get data for - * @return PlayerData from player, null if player is not in a game - */ - @Nullable - public PlayerData getData(UUID uuid) { - if (hasPlayerData(uuid)) - return getPlayerData(uuid); - else if (hasSpectatorData(uuid)) - return getSpectatorData(uuid); + if (hasPlayerData(player)) + return getPlayerData(player); + else if (hasSpectatorData(player)) + return getSpectatorData(player); return null; } - public boolean hasData(Player player) { - return hasData(player.getUniqueId()); - } - - public boolean hasData(UUID uuid) { - return hasPlayerData(uuid) || hasSpectatorData(uuid); - } - /** * Create {@link PlayerData} for a player * @@ -165,13 +105,14 @@ public void createPlayerData(Player player, Game game) { } /** - * Add a PlayerData to the stored SpectatorData map - *

This should mainly be used internally only

+ * Create {@link PlayerData} for a spectator * - * @param playerData PlayerData to add + * @param spectator Player to create data for + * @param game Game player is entering */ - public void addSpectatorData(PlayerData playerData) { - this.spectatorMap.put(playerData.getUuid(), playerData); + public void createSpectatorData(Player spectator, Game game) { + PlayerData playerData = new PlayerData(spectator, game); + this.spectatorMap.put(spectator.getUniqueId(), playerData); } /** @@ -210,20 +151,20 @@ public void removeSpectatorData(UUID uuid) { this.spectatorMap.remove(uuid); } - public boolean transferPlayerDataToSpectator(Player player) { - return transferPlayerDataToSpectator(player.getUniqueId()); - } - - public boolean transferPlayerDataToSpectator(UUID uuid) { + /** + * Transfer {@link PlayerData} from Player to Spectator + * + * @param player Player to transfer + */ + public void transferPlayerDataToSpectator(Player player) { + UUID uuid = player.getUniqueId(); if (this.playerMap.containsKey(uuid)) { PlayerData clone = this.playerMap.get(uuid).clone(); if (clone != null) { this.spectatorMap.put(uuid, clone); this.playerMap.remove(uuid); - return true; } } - return false; } /** @@ -232,22 +173,12 @@ public boolean transferPlayerDataToSpectator(UUID uuid) { * @param player Player to get game * @return Game of player, null if player is not in a game */ + @SuppressWarnings("DataFlowIssue") public @Nullable Game getGame(Player player) { - return getGame(player.getUniqueId()); - } - - /** - * Get the current game of a player - * - * @param uuid UUID of player to get game - * @return Game of player, null if player is not in a game - */ - @SuppressWarnings("ConstantConditions") - public @Nullable Game getGame(UUID uuid) { - if (hasPlayerData(uuid)) - return getPlayerData(uuid).getGame(); - else if (hasSpectatorData(uuid)) - return getSpectatorData(uuid).getGame(); + if (hasPlayerData(player)) + return getPlayerData(player).getGame(); + else if (hasSpectatorData(player)) + return getSpectatorData(player).getGame(); else return null; } @@ -259,7 +190,7 @@ else if (hasSpectatorData(uuid)) * @return True if in game, otherwise false */ public boolean isInGame(Player player) { - return getGame(player) != null; + return getPlayerStatus(player) != PlayerStatus.NOT_IN_GAME; } /** diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java index 6518b0aa..2870c363 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java @@ -29,7 +29,7 @@ public NearestPlayerCompassTask(Game game) { public void run() { for (Player player : this.game.getGamePlayerData().getPlayers()) { if (player.getInventory().getItemInMainHand().getType() == Material.COMPASS) { - PlayerData playerData = this.playerManager.getPlayerData(player.getUniqueId()); + PlayerData playerData = this.playerManager.getPlayerData(player); if (playerData == null) continue; Player nearest = getNearestPlayer(player); From 621e153e43de9e1218c098272e4d45939442af0d Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 19:40:37 -0700 Subject: [PATCH 18/52] HungerGames - change up metrics for config --- .../shanebeestudios/hg/plugin/HungerGames.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java index 8e4a6b63..5cc0f6d1 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java @@ -31,12 +31,16 @@ import dev.jorel.commandapi.exceptions.UnsupportedVersionException; import io.lumine.mythic.api.MythicProvider; import org.bstats.bukkit.Metrics; +import org.bstats.charts.DrilldownPie; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import java.util.HashMap; +import java.util.Map; + /** * Main class for HungerGames */ @@ -174,10 +178,14 @@ public void onDisable() { private void setupMetrics() { this.metrics = new Metrics(this, 25144); // Config - this.metrics.addCustomChart(new SimplePie("config-worldborder-enabled", () -> - "" + Config.WORLD_BORDER_ENABLED)); - this.metrics.addCustomChart(new SimplePie("config-chestdrop-enabled", () -> - "" + Config.CHESTS_CHEST_DROP_ENABLED)); + this.metrics.addCustomChart(new DrilldownPie("config", () -> { + Map> map = new HashMap<>(); + map.put("worldborder-enabled", Map.of("" + Config.WORLD_BORDER_ENABLED, 1)); + map.put("chestdrop-enabled", Map.of("" + Config.CHESTS_CHEST_DROP_ENABLED, 1)); + map.put("reward-enabled", Map.of("" + Config.REWARD_GIVE_REWARD, 1)); + map.put("spectate-enabled", Map.of("" + Config.SPECTATE_ENABLED, 1)); + return map; + })); // Arenas this.metrics.addCustomChart(new SimplePie("arenas-count", () -> From b9639a0b94226463b7b6f17dbdbb53599b4d4859 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sat, 12 Apr 2025 20:04:18 -0700 Subject: [PATCH 19/52] Config - more cleanup --- .../com/shanebeestudios/hg/api/game/Game.java | 14 ++--- .../hg/api/game/GamePlayerData.java | 6 +- .../hg/api/util/ItemUtils.java | 2 +- .../hg/plugin/HungerGames.java | 2 +- .../hg/plugin/commands/LeaveCommand.java | 2 +- .../hg/plugin/configs/Config.java | 58 +++++++++---------- .../hg/plugin/managers/GameManager.java | 2 +- .../hg/plugin/managers/KillManager.java | 2 +- .../hg/plugin/tasks/GameTimerTask.java | 4 +- .../hg/plugin/tasks/StartingTask.java | 2 +- src/main/resources/config.yml | 4 +- 11 files changed, 46 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index df60f6a1..56ee4f1b 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -267,7 +267,7 @@ public void startRunningGame() { if (Config.MOBS_SPAWN_ENABLED) this.mobSpawnerTask = new MobSpawnerTask(this); if (Config.CHESTS_CHEST_DROP_ENABLED) this.chestDropTask = new ChestDropTask(this); this.gameBlockData.updateLobbyBlock(); - if (Config.bossbar) { + if (Config.SETTINGS_BOSSBAR_COUNTDOWN) { this.bar.createBossBar(gameArenaData.timer); } if (Config.WORLD_BORDER_ENABLED) { @@ -301,7 +301,7 @@ public void cancelTasks() { * @param player Player who joined */ private void broadcastJoin(Player player) { - if (!Config.BROADCAST_JOIN_MESSAGES) return; + if (!Config.SETTINGS_BROADCAST_JOIN_MESSAGES) return; String name = this.getGameArenaData().getName(); Util.broadcast(this.lang.game_waiting_join .replace("", name) @@ -439,7 +439,7 @@ public void stop(boolean death) { if (!winners.isEmpty() && death) { double winningReward = (double) Config.REWARD_CASH / winners.size(); for (Player winner : winners) { - if (Config.REWARD_GIVE_REWARD) { + if (Config.REWARD_ENABLED) { // Run reward commands if (!Config.REWARD_COMMANDS.isEmpty()) { for (String cmd : Config.REWARD_COMMANDS) { @@ -565,12 +565,8 @@ boolean canJoin(Player player) { Util.sendPrefixedMessage(player, this.lang.game_full.replace("", name)); return false; } - return vaultCheck(player); - } - - boolean vaultCheck(Player player) { - if (Config.economy) { - int cost = this.getGameArenaData().getCost(); + int cost = this.getGameArenaData().getCost(); + if (Config.HAS_ECONOMY && cost > 0) { if (Vault.ECONOMY.getBalance(player) >= cost) { Vault.ECONOMY.withdrawPlayer(player, cost); return true; diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index c290ae4f..9c889fe4 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -276,7 +276,7 @@ public void leaveGame(Player player, boolean death) { if (!death) this.allPlayers.remove(player); // Only remove the player if they voluntarily left the game unFreeze(player); if (death) { - if (Config.SPECTATE_ENABLED && Config.spectateOnDeath && !game.isGameOver()) { + if (Config.SPECTATE_ENABLED && Config.SPECTATE_DEATH_TO_SPECTATE && !game.isGameOver()) { spectate(player); player.playSound(player.getLocation(), Config.SOUNDS_DEATH, 5, 1); player.showTitle(createTitle()); @@ -334,7 +334,7 @@ public void spectate(Player spectator) { if (Config.SPECTATE_FLY) spectator.setAllowFlight(true); - if (Config.SPECTATE_HIDE) { + if (Config.SPECTATE_HIDE_HIDE_SPECTATORS) { for (Player player : this.players.keySet()) { player.hidePlayer(this.plugin, spectator); } @@ -366,7 +366,7 @@ public void leaveSpectate(Player spectator) { if (mode == GameMode.SURVIVAL || mode == GameMode.ADVENTURE) spectator.setAllowFlight(false); } - if (Config.SPECTATE_HIDE) + if (Config.SPECTATE_HIDE_HIDE_SPECTATORS) revealPlayer(spectator); exit(spectator, previousLocation); this.playerManager.removeSpectatorData(spectator); diff --git a/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java b/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java index 04592627..3bae994e 100644 --- a/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java @@ -40,7 +40,7 @@ public static ItemStack getTrackingStick() { itemStack.setData(DataComponentTypes.ITEM_NAME, Util.getMini(LANG.tracking_stick_name)); itemStack.setData(DataComponentTypes.MAX_STACK_SIZE, 1); - itemStack.setData(DataComponentTypes.MAX_DAMAGE, Config.TRACKING_STICK_USES); + itemStack.setData(DataComponentTypes.MAX_DAMAGE, Config.SETTINGS_TRACKING_STICK_USES); itemStack.setData(DataComponentTypes.DAMAGE, 0); List lore = new ArrayList<>(); LANG.tracking_stick_lore.forEach(line -> lore.add(Util.getMini(line))); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java index 5cc0f6d1..20a4f16a 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java @@ -182,7 +182,7 @@ private void setupMetrics() { Map> map = new HashMap<>(); map.put("worldborder-enabled", Map.of("" + Config.WORLD_BORDER_ENABLED, 1)); map.put("chestdrop-enabled", Map.of("" + Config.CHESTS_CHEST_DROP_ENABLED, 1)); - map.put("reward-enabled", Map.of("" + Config.REWARD_GIVE_REWARD, 1)); + map.put("reward-enabled", Map.of("" + Config.REWARD_ENABLED, 1)); map.put("spectate-enabled", Map.of("" + Config.SPECTATE_ENABLED, 1)); return map; })); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java index d20ae0cf..6ceeb140 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java @@ -28,7 +28,7 @@ protected Argument register() { Game game; if (this.playerManager.hasPlayerData(player)) { game = this.playerManager.getPlayerData(player).getGame(); - if (Config.economy) { + if (Config.HAS_ECONOMY) { GameArenaData gameArenaData = game.getGameArenaData(); Status status = gameArenaData.getStatus(); int cost = gameArenaData.getCost(); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java index 5897e0fb..35eddfc8 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java @@ -23,16 +23,16 @@ public class Config { public static boolean SETTINGS_DEBUG; //Basic settings - public static boolean BROADCAST_JOIN_MESSAGES; + public static boolean SETTINGS_BROADCAST_JOIN_MESSAGES; public static boolean SETTINGS_BROADCAST_WIN_MESSAGES; - public static boolean economy = true; - public static boolean bossbar; - public static int TRACKING_STICK_USES; - public static int PLAYERS_FOR_TRACKING_STICK; + public static boolean HAS_ECONOMY = true; + public static boolean SETTINGS_BOSSBAR_COUNTDOWN; + public static int SETTINGS_TRACKING_STICK_USES; + public static int SETTINGS_PLAYERS_FOR_TRACKING_STICK; public static int SETTINGS_TELEPORT_AT_END_TIME; public static boolean SETTINGS_SAVE_PREVIOUS_LOCATION; public static int SETTINGS_FREE_ROAM_TIME; - public static Location GLOBAL_EXIT_LOCATION; + public static Location SETTINGS_GLOBAL_EXIT_LOCATION; // Scoreboard public static boolean SCOREBOARD_HIDE_NAMETAGS; @@ -49,8 +49,8 @@ public class Config { public static int MOBS_SPAWN_INTERVAL; public static int MOBS_SPAWN_CAP_PER_PLAYER; - //Reward info - public static boolean REWARD_GIVE_REWARD; + // Reward info + public static boolean REWARD_ENABLED; public static int REWARD_CASH; public static List REWARD_COMMANDS; public static List REWARD_MESSAGES; @@ -93,8 +93,8 @@ public class Config { //Spectate public static boolean SPECTATE_ENABLED; - public static boolean spectateOnDeath; - public static boolean SPECTATE_HIDE; + public static boolean SPECTATE_DEATH_TO_SPECTATE; + public static boolean SPECTATE_HIDE_HIDE_SPECTATORS; public static boolean SPECTATE_FLY; public static boolean SPECTATE_CHAT; @@ -112,15 +112,15 @@ public Config(HungerGames plugin) { } private void loadConfigFile() { - if (configFile == null) { - configFile = new File(plugin.getDataFolder(), "config.yml"); + if (this.configFile == null) { + this.configFile = new File(this.plugin.getDataFolder(), "config.yml"); } - if (!configFile.exists()) { - plugin.saveResource("config.yml", false); + if (!this.configFile.exists()) { + this.plugin.saveResource("config.yml", false); Util.log("New config.yml created"); } - config = YamlConfiguration.loadConfiguration(configFile); - matchConfig(config, configFile); + this.config = YamlConfiguration.loadConfiguration(this.configFile); + matchConfig(this.config, this.configFile); loadConfig(); Util.log("config.yml successfully loaded"); } @@ -129,17 +129,17 @@ private void loadConfigFile() { private void loadConfig() { // Settings SETTINGS_DEBUG = config.getBoolean("settings.debug"); - BROADCAST_JOIN_MESSAGES = config.getBoolean("settings.broadcast-join-messages"); + SETTINGS_BROADCAST_JOIN_MESSAGES = config.getBoolean("settings.broadcast-join-messages"); SETTINGS_BROADCAST_WIN_MESSAGES = config.getBoolean("settings.broadcast-win-messages"); - bossbar = config.getBoolean("settings.bossbar-countdown"); - TRACKING_STICK_USES = config.getInt("settings.trackingstick-uses"); - PLAYERS_FOR_TRACKING_STICK = config.getInt("settings.players-for-trackingstick"); + SETTINGS_BOSSBAR_COUNTDOWN = config.getBoolean("settings.bossbar-countdown"); + SETTINGS_TRACKING_STICK_USES = config.getInt("settings.tracking-stick-uses"); + SETTINGS_PLAYERS_FOR_TRACKING_STICK = config.getInt("settings.players-for-tracking-stick"); SETTINGS_SAVE_PREVIOUS_LOCATION = config.getBoolean("settings.save-previous-location"); SETTINGS_TELEPORT_AT_END_TIME = config.getInt("settings.teleport-at-end-time"); SETTINGS_FREE_ROAM_TIME = config.getInt("settings.free-room-time"); String locString = config.getString("settings.global-exit-location"); if (locString != null && locString.contains(":")) { - GLOBAL_EXIT_LOCATION = LocationParser.getLocFromString(locString); + SETTINGS_GLOBAL_EXIT_LOCATION = LocationParser.getLocFromString(locString); } // Scoreboard @@ -157,12 +157,10 @@ private void loadConfig() { MOBS_SPAWN_INTERVAL = config.getInt("mob-spawning.interval") * 20; MOBS_SPAWN_CAP_PER_PLAYER = config.getInt("mob-spawning.cap-per-player"); - REWARD_GIVE_REWARD = config.getBoolean("reward.enabled"); + REWARD_ENABLED = config.getBoolean("reward.enabled"); REWARD_CASH = config.getInt("reward.cash"); REWARD_COMMANDS = config.getStringList("reward.commands"); REWARD_MESSAGES = config.getStringList("reward.messages"); - REWARD_GIVE_REWARD = config.getBoolean("reward.enabled"); - REWARD_CASH = config.getInt("reward.cash"); // Rollback ROLLBACK_ALLOW_BREAK_BLOCKS = config.getBoolean("rollback.allow-block-break"); @@ -194,8 +192,8 @@ private void loadConfig() { WORLD_BORDER_FINAL_SIZE = config.getInt("world-border.final-border-size"); SPECTATE_ENABLED = config.getBoolean("spectate.enabled"); - spectateOnDeath = config.getBoolean("spectate.death-to-spectate"); - SPECTATE_HIDE = config.getBoolean("spectate.hide-spectators"); + SPECTATE_DEATH_TO_SPECTATE = config.getBoolean("spectate.death-to-spectate"); + SPECTATE_HIDE_HIDE_SPECTATORS = config.getBoolean("spectate.hide-spectators"); SPECTATE_FLY = config.getBoolean("spectate.fly"); SPECTATE_CHAT = config.getBoolean("spectate.chat"); @@ -208,14 +206,14 @@ private void loadConfig() { Util.log("Unable to setup vault!"); Util.log(" - Economy provider is missing."); Util.log(" - Cash rewards will not be given out.."); - REWARD_GIVE_REWARD = false; - economy = false; + REWARD_ENABLED = false; + HAS_ECONOMY = false; } } catch (NoClassDefFoundError e) { Util.log("Unable to setup vault!"); Util.log(" - Cash rewards will not be given out.."); - REWARD_GIVE_REWARD = false; - economy = false; + REWARD_ENABLED = false; + HAS_ECONOMY = false; } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java index ebb2e604..dac31106 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/GameManager.java @@ -45,7 +45,7 @@ public GameManager(HungerGames plugin) { this.plugin = plugin; this.lang = plugin.getLang(); CustomArg.init(plugin, this); - this.globalExitLocation = Config.GLOBAL_EXIT_LOCATION; + this.globalExitLocation = Config.SETTINGS_GLOBAL_EXIT_LOCATION; } /** diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java index f3bb7fd0..6fe82f5b 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java @@ -271,7 +271,7 @@ private List dropInventoryOfPlayer(Player player) { } private void checkStick(Game game) { - if (Config.PLAYERS_FOR_TRACKING_STICK == game.getGamePlayerData().getPlayers().size()) { + if (Config.SETTINGS_PLAYERS_FOR_TRACKING_STICK == game.getGamePlayerData().getPlayers().size()) { for (Player player : game.getGamePlayerData().getPlayers()) { Util.sendMessage(player, this.lang.tracking_stick_bar); Util.sendMessage(player, this.lang.tracking_stick_new1); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java index 2b71c56a..de4cd1ab 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java @@ -47,7 +47,7 @@ public GameTimerTask(Game game, int time) { public void run() { if (this.gameArenaData.getStatus() != Status.RUNNING) stop(); // Safety exit - if (Config.bossbar) this.game.getGameBarData().bossBarUpdate(this.remainingTime); + if (Config.SETTINGS_BOSSBAR_COUNTDOWN) this.game.getGameBarData().bossBarUpdate(this.remainingTime); // Refill chests if (this.gameArenaData.getChestRefillTime() > 0 && this.remainingTime == this.gameArenaData.getChestRefillTime()) { @@ -62,7 +62,7 @@ public void run() { } else if (this.remainingTime <= 0) { stop(); this.game.stop(false); - } else if (!Config.bossbar && this.remainingTime % 30 == 0) { + } else if (!Config.SETTINGS_BOSSBAR_COUNTDOWN && this.remainingTime % 30 == 0) { int minutes = this.remainingTime / 60; int seconds = this.remainingTime % 60; if (minutes != 0) { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java index 4ebfc7c6..2cdf3ce6 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java @@ -21,7 +21,7 @@ public StartingTask(Game game) { String broadcast = this.lang.game_countdown_started .replace("", name) .replace("", "" + this.timer); - if (Config.BROADCAST_JOIN_MESSAGES) { + if (Config.SETTINGS_BROADCAST_JOIN_MESSAGES) { Util.broadcast(broadcast); Util.broadcast(this.lang.game_join.replace("", name)); } else { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index db654fc6..ef3020ed 100755 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -27,9 +27,9 @@ settings: # Whether or not to show a countdown bossbar in game bossbar-countdown: true # The amount of uses a tracking stick will have - trackingstick-uses: 8 + tracking-stick-uses: 8 # Minimum amount of players required in a game for a tracking stick to work - players-for-trackingstick: 5 + players-for-tracking-stick: 5 # Maximum/Minimum amount of items that will spawn in chests max-chestcontent: 5 min-chestcontent: 1 From 01786aafc0103d7488f27cda2cb592115862ad20 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 11:15:45 -0700 Subject: [PATCH 20/52] Leaderboard - overhaul --- .../hg/api/data/Leaderboard.java | 305 +++++++----------- .../com/shanebeestudios/hg/api/game/Game.java | 1 + .../hg/plugin/HungerGames.java | 2 +- .../hg/plugin/managers/Placeholders.java | 44 ++- src/main/resources/leaderboard.yml | 5 +- 5 files changed, 142 insertions(+), 215 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/data/Leaderboard.java b/src/main/java/com/shanebeestudios/hg/api/data/Leaderboard.java index 57b7ce20..199529bb 100644 --- a/src/main/java/com/shanebeestudios/hg/api/data/Leaderboard.java +++ b/src/main/java/com/shanebeestudios/hg/api/data/Leaderboard.java @@ -1,15 +1,23 @@ package com.shanebeestudios.hg.api.data; -import com.shanebeestudios.hg.plugin.configs.Language; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import com.shanebeestudios.hg.plugin.HungerGames; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; /** * HungerGames leader boards @@ -18,265 +26,168 @@ @SuppressWarnings({"WeakerAccess", "unused"}) public class Leaderboard { + private static class Data implements Comparable { + private final String playerName; + private int score; + + public Data(UUID uuid) { + this.playerName = Bukkit.getOfflinePlayer(uuid).getName(); + } + + @Override + public int compareTo(@NotNull Data data) { + return data.score - this.score; + } + } + private final HungerGames plugin; - private final Language lang; private FileConfiguration leaderboardConfig; private File config_file; - private final Map wins; - private final Map kills; - private final Map deaths; - private final Map gamesPlayed; - - private final List sorted_players_wins; - private final List sorted_scores_wins; - private final List sorted_players_kills; - private final List sorted_scores_kills; - private final List sorted_players_deaths; - private final List sorted_scores_deaths; - private final List sorted_players_gamesPlayed; - private final List sorted_scores_gamesPlayed; + private final Map> stats = new HashMap<>(); public Leaderboard(HungerGames plugin) { this.plugin = plugin; - this.lang = plugin.getLang(); - wins = new TreeMap<>(); - kills = new TreeMap<>(); - deaths = new TreeMap<>(); - gamesPlayed = new TreeMap<>(); - sorted_players_wins = new ArrayList<>(); - sorted_scores_wins = new ArrayList<>(); - sorted_players_kills = new ArrayList<>(); - sorted_scores_kills = new ArrayList<>(); - sorted_players_deaths = new ArrayList<>(); - sorted_scores_deaths = new ArrayList<>(); - sorted_players_gamesPlayed = new ArrayList<>(); - sorted_scores_gamesPlayed = new ArrayList<>(); - loadLeaderboard(); - } - - /** Add a win to the leaderboard - * @param uuid UUID of player to add - * @deprecated Use {@link #addStat(UUID, Stats)} instead - */ - @Deprecated - public void addWin(UUID uuid) { - if (wins.containsKey(uuid.toString())) { - wins.replace(uuid.toString(), wins.get(uuid.toString()) + 1); - } else { - wins.put(uuid.toString(), 1); + for (Stats value : Stats.values()) { + this.stats.put(value, new LinkedHashMap<>()); } - saveLeaderboard(); - } - - /** Add a win to the leaderboard - * @param player Player to add - * @deprecated Use {@link #addStat(Player, Stats)} instead - */ - @Deprecated - public void addWin(Player player) { - addWin(player.getUniqueId()); - } - - /** Get the wins for a player from the leaderboard - * @param uuid UUID of player to get wins for - * @return Number of wins for the player - * @deprecated Use {@link #getStat(UUID, Stats)} instead - */ - @Deprecated - public int getWins(UUID uuid) { - return wins.get(uuid.toString()); - } - - /** Get the wins for a player from the leaderboard - * @param player Player to get wins for - * @return Number of wins for the player - * @deprecated Use {@link #getStat(Player, Stats)} instead - */ - @Deprecated - public int getWins(Player player) { - return getWins(player.getUniqueId()); - } - - /** Add a stat to the leaderboard (Will default to 1) - * @param uuid Uuid of player to add - * @param stat Stat to add - */ - public void addStat(UUID uuid, Stats stat) { - addStat(uuid, stat, 1); + loadLeaderboard(); } - /** Add a stat to the leaderboard - * @param uuid Uuid of player to add - * @param stat Stat to add + /** + * Add a stat to the leaderboard + * + * @param uuid Uuid of player to add + * @param stat Stat to add * @param amount Amount to add */ public void addStat(UUID uuid, Stats stat, int amount) { - Map map; - switch (stat) { - case KILLS: - map = this.kills; - break; - case DEATHS: - map = this.deaths; - break; - case GAMES: - map = this.gamesPlayed; - break; - default: - map = this.wins; - } - if (map.containsKey(uuid.toString())) { - map.replace(uuid.toString(), map.get(uuid.toString()) + amount); - } else { - map.put(uuid.toString(), amount); - } - saveLeaderboard(); + Map map = this.stats.get(stat); + Data data = map.getOrDefault(uuid.toString(), new Data(uuid)); + data.score += amount; + map.put(uuid.toString(), data); + sort(stat); } - /** Add a stat to the leaderboard (Will default to 1) + /** + * Add a stat to the leaderboard (Will default to 1) + * * @param player Player to add - * @param stat Stat to add + * @param stat Stat to add */ public void addStat(Player player, Stats stat) { addStat(player, stat, 1); } - /** Add a stat to the leaderboard + /** + * Add a stat to the leaderboard + * * @param player Player to add - * @param stat Stat to add + * @param stat Stat to add * @param amount Amount to add */ public void addStat(Player player, Stats stat, int amount) { addStat(player.getUniqueId(), stat, amount); } - /** Get a stat from the leaderboard + /** + * Get a stat from the leaderboard + * * @param player Player to get - * @param stat Stat to get + * @param stat Stat to get * @return Amount of the relative stat */ public int getStat(Player player, Stats stat) { return getStat(player.getUniqueId(), stat); } - /** Get a stat from the leaderboard + /** + * Get a stat from the leaderboard + * * @param uuid Uuid of player to get * @param stat Stat to get * @return Amount of the relative stat */ public int getStat(UUID uuid, Stats stat) { - Map map; - switch (stat) { - case KILLS: - map = this.kills; - break; - case DEATHS: - map = this.deaths; - break; - case GAMES: - map = this.gamesPlayed; - break; - default: - map = this.wins; + Map map = this.stats.get(stat); + if (map.containsKey(uuid.toString())) { + return map.get(uuid.toString()).score; } - return map.getOrDefault(uuid.toString(), 0); + return 0; } - /** Gets a list of players from a stat + /** + * Gets a list of players from a stat *

Will match up with scores from {@link #getStatsScores(Stats)}

+ * * @param stat Stat to get players from * @return Sorted list of players from a stat */ public List getStatsPlayers(Stats stat) { - switch (stat) { - case KILLS: - return sorted_players_kills; - case DEATHS: - return sorted_players_deaths; - case GAMES: - return sorted_players_gamesPlayed; - default: - return sorted_players_wins; + Map map = this.stats.get(stat); + List playerNames = new ArrayList<>(); + for (Map.Entry entry : map.entrySet()) { + playerNames.add(entry.getValue().playerName); } + return playerNames; } - /** Gets a list of scores from a stat + /** + * Gets a list of scores from a stat *

Will match up with players from {@link #getStatsPlayers(Stats)}

+ * * @param stat Stat to get scores from * @return Sorted list of scores from a stat */ - public List getStatsScores(Stats stat) { - switch (stat) { - case KILLS: - return sorted_scores_kills; - case DEATHS: - return sorted_scores_deaths; - case GAMES: - return sorted_scores_gamesPlayed; - default: - return sorted_scores_wins; + public List getStatsScores(Stats stat) { + Map map = this.stats.get(stat); + List playerScores = new ArrayList<>(); + for (Map.Entry entry : map.entrySet()) { + playerScores.add(entry.getValue().score); } + return playerScores; } - private void saveLeaderboard() { - leaderboardConfig.set("Total-Wins", wins); - leaderboardConfig.set("Total-Deaths", deaths); - leaderboardConfig.set("Total-Kills", kills); - leaderboardConfig.set("Games-Played", gamesPlayed); + public void saveLeaderboard() { + for (Stats stat : Stats.values()) { + ConfigurationSection statSection = this.leaderboardConfig.createSection(stat.getName()); + this.stats.get(stat).forEach((key, value) -> + statSection.set(key, value.score)); + } try { - leaderboardConfig.save(config_file); + this.leaderboardConfig.save(this.config_file); } catch (IOException e) { - e.printStackTrace(); + Util.warning("Could not save leaderboard file: %s", e.getMessage()); } - sortScores(wins, sorted_scores_wins, sorted_players_wins); - sortScores(kills, sorted_scores_kills, sorted_players_kills); - sortScores(deaths, sorted_scores_deaths, sorted_players_deaths); - sortScores(gamesPlayed, sorted_scores_gamesPlayed, sorted_players_gamesPlayed); } private void loadLeaderboard() { - config_file = new File(plugin.getDataFolder(), "leaderboard.yml"); - if (!config_file.exists()) { - plugin.saveResource("leaderboard.yml", true); + this.config_file = new File(this.plugin.getDataFolder(), "leaderboard.yml"); + if (!this.config_file.exists()) { + this.plugin.saveResource("leaderboard.yml", true); } - leaderboardConfig = YamlConfiguration.loadConfiguration(config_file); - getLeaderboard("Total-Wins", wins, sorted_scores_wins, sorted_players_wins); - getLeaderboard("Total-Kills", kills, sorted_scores_kills, sorted_players_kills); - getLeaderboard("Total-Deaths", deaths, sorted_scores_deaths, sorted_players_deaths); - getLeaderboard("Games-Played", gamesPlayed, sorted_scores_gamesPlayed, sorted_players_gamesPlayed); - } - - private void getLeaderboard(String path, Map map, List scores, List players) { - if (leaderboardConfig.getConfigurationSection(path) != null) { - //noinspection ConstantConditions - for (String key : leaderboardConfig.getConfigurationSection(path).getKeys(false)) { - map.put(key, leaderboardConfig.getInt(path + "." + key)); + this.leaderboardConfig = YamlConfiguration.loadConfiguration(this.config_file); + for (Stats stat : Stats.values()) { + ConfigurationSection statSection = this.leaderboardConfig.getConfigurationSection(stat.getName()); + if (statSection == null) continue; + + Map map = new HashMap<>(); + for (String key : statSection.getKeys(false)) { + UUID uuid = UUID.fromString(key); + Data data = new Data(uuid); + data.score = statSection.getInt(key); + map.put(key, data); } - sortScores(map, scores, players); + this.stats.put(stat, map); + sort(stat); } } - private void sortScores(Map map, List scores, List players) { - scores.clear(); - players.clear(); - for (Map.Entry sortingMap : entriesSortedByValues(map)) { - String player = Bukkit.getOfflinePlayer(UUID.fromString(sortingMap.getKey())).getName(); - int score = sortingMap.getValue(); - scores.add(String.valueOf(score)); - players.add(player != null ? player : lang.leaderboard_missing_player); - } - } - - private static > SortedSet> entriesSortedByValues(Map map) { - SortedSet> sortedEntries = new TreeSet<>( - (Map.Entry e2, Map.Entry e1) -> { - int res = e1.getValue().compareTo(e2.getValue()); - if (res == 0) return 1; - else return res; - } - ); - sortedEntries.addAll(map.entrySet()); - return sortedEntries; + private void sort(Stats stat) { + LinkedHashMap collect = this.stats.get(stat).entrySet().stream() + .sorted(Map.Entry.comparingByValue()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, + (e1, e2) -> e1, LinkedHashMap::new)); + this.stats.put(stat, collect); } /** @@ -288,7 +199,7 @@ public enum Stats { */ WINS("wins"), /** - * Amount of players a player has killed in a game + * Amount of players a player has killed in all games */ KILLS("kills"), /** @@ -297,7 +208,8 @@ public enum Stats { DEATHS("deaths"), /** * Amount of games a player has played - *

Only counted for a game a player has either won or died in. Leaving a game does not count

+ *

Only counted for a game a player has either won or died in. + * Leaving a game does not count

*/ GAMES("games"); @@ -310,7 +222,6 @@ public enum Stats { public String getName() { return this.stat; } - } } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index 56ee4f1b..b35c29e6 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -502,6 +502,7 @@ public void stop(boolean death) { this.gamePlayerData.clearPlayers(); this.gamePlayerData.clearSpectators(); this.gameScoreboard.clearGameTeams(); + this.plugin.getLeaderboard().saveLeaderboard(); // Call GameEndEvent new GameEndEvent(this, winners, death).callEvent(); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java index 20a4f16a..fc486d2d 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/HungerGames.java @@ -160,6 +160,7 @@ private void unloadPlugin(boolean reload) { this.arenaConfig = null; this.killManager = null; this.gameManager = null; + this.leaderboard.saveLeaderboard(); this.leaderboard = null; HandlerList.unregisterAll(this); if (reload) { @@ -190,7 +191,6 @@ private void setupMetrics() { // Arenas this.metrics.addCustomChart(new SimplePie("arenas-count", () -> "" + this.gameManager.getGames().size())); - } private void loadListeners() { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/Placeholders.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/Placeholders.java index a974bdaf..6815d649 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/Placeholders.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/Placeholders.java @@ -1,8 +1,9 @@ package com.shanebeestudios.hg.plugin.managers; +import com.shanebeestudios.hg.api.data.Leaderboard; +import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; -import com.shanebeestudios.hg.api.data.Leaderboard; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -16,11 +17,13 @@ public class Placeholders extends PlaceholderExpansion { private final HungerGames plugin; + private final GameManager gameManager; private final Leaderboard leaderboard; private final Language lang; public Placeholders(HungerGames plugin) { this.plugin = plugin; + this.gameManager = plugin.getGameManager(); this.leaderboard = plugin.getLeaderboard(); this.lang = plugin.getLang(); } @@ -57,7 +60,6 @@ public String getVersion() { @Nullable @Override public String onRequest(OfflinePlayer offlinePlayer, @NotNull String identifier) { - GameManager gameManager = this.plugin.getGameManager(); String[] id = identifier.split("_"); switch (id[0]) { case "lb": @@ -71,41 +73,51 @@ public String onRequest(OfflinePlayer offlinePlayer, @NotNull String identifier) else if (id[2].equalsIgnoreCase("s")) return getStatScores(identifier); else if (id[2].equalsIgnoreCase("c")) - return getStatPlayers(identifier) + " : " + getStatScores(identifier); + return getStatPlayers(identifier) + this.lang.leaderboard_combined_separator + getStatScores(identifier); else if (id[2].equalsIgnoreCase("player")) return getStatsPlayer(identifier, offlinePlayer); } case "status": - return gameManager.getGame(id[1]).getGameArenaData().getStatus().getStringName(); - case "player_status": + if (getGame(id[1]) == null) return "invalid game"; + return getGame(id[1]).getGameArenaData().getStatus().getStringName(); + case "playerstatus": if (offlinePlayer instanceof Player player) return this.plugin.getPlayerManager().getPlayerStatus(player).getStringName(); + return "offline"; case "cost": - return String.valueOf(gameManager.getGame(id[1]).getGameArenaData().getCost()); + if (getGame(id[1]) == null) return "invalid game"; + return String.valueOf(getGame(id[1]).getGameArenaData().getCost()); case "playerscurrent": - return String.valueOf(gameManager.getGame(id[1]).getGamePlayerData().getPlayers().size()); + if (getGame(id[1]) == null) return "invalid game"; + return String.valueOf(getGame(id[1]).getGamePlayerData().getPlayers().size()); case "playersmax": - return String.valueOf(gameManager.getGame(id[1]).getGameArenaData().getMaxPlayers()); + if (getGame(id[1]) == null) return "invalid game"; + return String.valueOf(getGame(id[1]).getGameArenaData().getMaxPlayers()); case "playersmin": - return String.valueOf(gameManager.getGame(id[1]).getGameArenaData().getMinPlayers()); + if (getGame(id[1]) == null) return "invalid game"; + return String.valueOf(getGame(id[1]).getGameArenaData().getMinPlayers()); } return null; } + private Game getGame(String name) { + return this.gameManager.getGame(name); + } + private String getStatsPlayer(String identifier, OfflinePlayer player) { String[] ind = identifier.split("_"); Leaderboard.Stats stat = Leaderboard.Stats.valueOf(ind[1].toUpperCase()); - return String.valueOf(leaderboard.getStat(player.getUniqueId(), stat)); + return String.valueOf(this.leaderboard.getStat(player.getUniqueId(), stat)); } private String getStatPlayers(String identifier) { String[] ind = identifier.split("_"); Leaderboard.Stats stat = Leaderboard.Stats.valueOf(ind[1].toUpperCase()); int leader = (Integer.parseInt(ind[3])); - if (leaderboard.getStatsPlayers(stat).size() >= leader) { - return leaderboard.getStatsPlayers(stat).get(leader - 1); + if (this.leaderboard.getStatsPlayers(stat).size() >= leader + 1) { + return this.leaderboard.getStatsPlayers(stat).get(leader); } else { - return lang.leaderboard_blank_space; + return this.lang.leaderboard_blank_space; } } @@ -113,10 +125,10 @@ private String getStatScores(String identifier) { String[] ind = identifier.split("_"); Leaderboard.Stats stat = Leaderboard.Stats.valueOf(ind[1].toUpperCase()); int leader = (Integer.parseInt(ind[3])); - if (leaderboard.getStatsScores(stat).size() >= leader) { - return leaderboard.getStatsScores(stat).get(leader - 1); + if (this.leaderboard.getStatsScores(stat).size() >= leader + 1) { + return "" + this.leaderboard.getStatsScores(stat).get(leader); } else { - return lang.leaderboard_blank_space; + return this.lang.leaderboard_blank_space; } } diff --git a/src/main/resources/leaderboard.yml b/src/main/resources/leaderboard.yml index c1a5c0cf..ebb491d2 100644 --- a/src/main/resources/leaderboard.yml +++ b/src/main/resources/leaderboard.yml @@ -1,4 +1,7 @@ # ARENA GAMES LEADERBOARD # This file saves stats from arenas -Total-Wins: \ No newline at end of file +wins: {} +kills: {} +deaths: {} +games: {} From d995299720b3334a195a0cd35ec37798d54aac14 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 11:19:10 -0700 Subject: [PATCH 21/52] Cleanup to fix guidelines --- .../shanebeestudios/hg/api/data/KitEntry.java | 2 +- .../hg/api/data/PlayerData.java | 34 +++---- .../hg/api/data/PlayerSession.java | 2 +- .../hg/api/events/ChestOpenEvent.java | 2 +- .../hg/api/events/GameStartEvent.java | 52 +++++----- .../hg/api/events/PlayerDeathGameEvent.java | 2 +- .../hg/api/events/PlayerJoinGameEvent.java | 96 ++++++++++--------- .../hg/api/events/PlayerLeaveGameEvent.java | 92 +++++++++--------- .../hg/api/game/GameBarData.java | 1 - .../hg/api/game/GameBlockData.java | 8 +- .../hg/api/game/GameLobbyWall.java | 6 +- .../shanebeestudios/hg/api/game/GameTeam.java | 4 +- .../shanebeestudios/hg/api/gui/KitsGUI.java | 6 +- .../hg/api/gui/SpectatorGUI.java | 2 +- .../hg/api/status/PlayerStatus.java | 2 +- .../shanebeestudios/hg/api/status/Status.java | 41 ++++---- .../shanebeestudios/hg/api/util/HgLogger.java | 4 +- .../hg/api/util/ItemUtils.java | 2 +- .../shanebeestudios/hg/api/util/NBTApi.java | 1 - .../com/shanebeestudios/hg/api/util/Util.java | 4 - .../shanebeestudios/hg/api/util/Vault.java | 3 +- .../hg/plugin/commands/CreateCommand.java | 4 +- .../hg/plugin/commands/DebugCommand.java | 2 +- .../plugin/commands/DeleteArenaCommand.java | 4 +- .../hg/plugin/commands/EditCommand.java | 6 +- .../hg/plugin/commands/ForceStartCommand.java | 6 +- .../hg/plugin/commands/JoinCommand.java | 4 +- .../hg/plugin/commands/KitCommand.java | 6 +- .../hg/plugin/commands/KitsCommand.java | 2 +- .../hg/plugin/commands/LeaveCommand.java | 6 +- .../hg/plugin/commands/ListCommand.java | 4 +- .../hg/plugin/commands/ListGamesCommand.java | 4 +- .../plugin/commands/PermissionsCommand.java | 2 +- .../commands/RefillChestNowCommand.java | 6 +- .../hg/plugin/commands/ReloadCommand.java | 2 +- .../hg/plugin/commands/SetExitCommand.java | 2 +- .../hg/plugin/commands/SpectateCommand.java | 6 +- .../hg/plugin/commands/StatusCommand.java | 4 +- .../hg/plugin/commands/StopAllCommand.java | 2 +- .../hg/plugin/commands/StopCommand.java | 2 +- .../hg/plugin/commands/SubCommand.java | 2 +- .../hg/plugin/commands/TeamCommand.java | 6 +- .../hg/plugin/commands/ToggleCommand.java | 6 +- .../hg/plugin/configs/ArenaConfig.java | 6 +- .../hg/plugin/configs/Config.java | 6 +- .../plugin/listeners/GameBlockListener.java | 10 +- .../plugin/listeners/GameChestListener.java | 10 +- .../plugin/listeners/GameCommandListener.java | 2 - .../plugin/listeners/GameCompassListener.java | 2 - .../listeners/GameDamageListenerBase.java | 4 +- .../plugin/listeners/GameEntityListener.java | 2 +- .../hg/plugin/listeners/GameListenerBase.java | 2 +- .../plugin/listeners/GameLobbyListener.java | 4 +- .../plugin/listeners/GamePlayerListener.java | 8 +- .../listeners/GameTrackingStickListener.java | 6 +- .../plugin/listeners/SessionWandListener.java | 6 +- .../hg/plugin/managers/ItemManager.java | 2 +- .../hg/plugin/managers/KillManager.java | 12 +-- .../hg/plugin/tasks/ChestDropChestTask.java | 2 +- .../hg/plugin/tasks/ChestDropTask.java | 6 +- .../plugin/tasks/ChestRefillRepeatTask.java | 4 +- .../hg/plugin/tasks/FreeRoamTask.java | 4 +- .../hg/plugin/tasks/GameTimerTask.java | 8 +- .../tasks/NearestPlayerCompassTask.java | 6 +- .../hg/plugin/tasks/RollbackTask.java | 78 +++++++-------- .../hg/plugin/tasks/StartingTask.java | 10 +- .../hg/plugin/tasks/WorldBorderTask.java | 4 +- 67 files changed, 331 insertions(+), 327 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/data/KitEntry.java b/src/main/java/com/shanebeestudios/hg/api/data/KitEntry.java index e084c23f..886b187c 100755 --- a/src/main/java/com/shanebeestudios/hg/api/data/KitEntry.java +++ b/src/main/java/com/shanebeestudios/hg/api/data/KitEntry.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.api.data; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.permission.Permissions; import com.shanebeestudios.hg.plugin.permission.Permissions.Permission; import org.bukkit.entity.Player; diff --git a/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java b/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java index 9c655127..fe7ac45d 100755 --- a/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/data/PlayerData.java @@ -1,5 +1,9 @@ package com.shanebeestudios.hg.api.data; +import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.game.GameTeam; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -8,10 +12,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scoreboard.Scoreboard; import org.jetbrains.annotations.Nullable; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.game.Game; -import com.shanebeestudios.hg.api.game.GameTeam; -import com.shanebeestudios.hg.api.util.Util; import java.util.Arrays; import java.util.UUID; @@ -221,19 +221,19 @@ public void setOnline(boolean online) { @Override public String toString() { return "PlayerData{" + - "inv=" + Arrays.toString(inv) + - ", equip=" + Arrays.toString(equip) + - ", expLevel=" + expL + - ", expPoints=" + expP + - ", health=" + health + - ", food=" + food + - ", saturation=" + saturation + - ", mode=" + mode + - ", uuid=" + uuid + - ", team=" + gameTeam + - ", pending=" + pendingGameTeam + - ", game=" + game + - '}'; + "inv=" + Arrays.toString(inv) + + ", equip=" + Arrays.toString(equip) + + ", expLevel=" + expL + + ", expPoints=" + expP + + ", health=" + health + + ", food=" + food + + ", saturation=" + saturation + + ", mode=" + mode + + ", uuid=" + uuid + + ", team=" + gameTeam + + ", pending=" + pendingGameTeam + + ", game=" + game + + '}'; } @Override diff --git a/src/main/java/com/shanebeestudios/hg/api/data/PlayerSession.java b/src/main/java/com/shanebeestudios/hg/api/data/PlayerSession.java index d0f81a53..d48a3cf4 100755 --- a/src/main/java/com/shanebeestudios/hg/api/data/PlayerSession.java +++ b/src/main/java/com/shanebeestudios/hg/api/data/PlayerSession.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.api.data; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import org.bukkit.Location; diff --git a/src/main/java/com/shanebeestudios/hg/api/events/ChestOpenEvent.java b/src/main/java/com/shanebeestudios/hg/api/events/ChestOpenEvent.java index 5c98ceff..ce7a7427 100755 --- a/src/main/java/com/shanebeestudios/hg/api/events/ChestOpenEvent.java +++ b/src/main/java/com/shanebeestudios/hg/api/events/ChestOpenEvent.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.api.events; -import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.data.ItemData.ChestType; +import com.shanebeestudios.hg.api.game.Game; import org.bukkit.block.Block; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; diff --git a/src/main/java/com/shanebeestudios/hg/api/events/GameStartEvent.java b/src/main/java/com/shanebeestudios/hg/api/events/GameStartEvent.java index d8774fb6..ed703f34 100644 --- a/src/main/java/com/shanebeestudios/hg/api/events/GameStartEvent.java +++ b/src/main/java/com/shanebeestudios/hg/api/events/GameStartEvent.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.api.events; +import com.shanebeestudios.hg.api.game.Game; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import com.shanebeestudios.hg.api.game.Game; /** * Called when a game starts the pregame stage of a game @@ -10,29 +10,31 @@ @SuppressWarnings("unused") public class GameStartEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Game game; - - public GameStartEvent(Game game) { - this.game = game; - } - - /** Get the game involved in this event - * @return The game - */ - public Game getGame() { - return this.game; - } - - @SuppressWarnings("NullableProblems") - @Override - public HandlerList getHandlers() { - return handlers; - } - - @SuppressWarnings("unused") - public static HandlerList getHandlerList() { - return handlers; - } + private static final HandlerList handlers = new HandlerList(); + private Game game; + + public GameStartEvent(Game game) { + this.game = game; + } + + /** + * Get the game involved in this event + * + * @return The game + */ + public Game getGame() { + return this.game; + } + + @SuppressWarnings("NullableProblems") + @Override + public HandlerList getHandlers() { + return handlers; + } + + @SuppressWarnings("unused") + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/com/shanebeestudios/hg/api/events/PlayerDeathGameEvent.java b/src/main/java/com/shanebeestudios/hg/api/events/PlayerDeathGameEvent.java index c6528131..09923f3a 100644 --- a/src/main/java/com/shanebeestudios/hg/api/events/PlayerDeathGameEvent.java +++ b/src/main/java/com/shanebeestudios/hg/api/events/PlayerDeathGameEvent.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.api.events; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; import org.bukkit.damage.DamageSource; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; diff --git a/src/main/java/com/shanebeestudios/hg/api/events/PlayerJoinGameEvent.java b/src/main/java/com/shanebeestudios/hg/api/events/PlayerJoinGameEvent.java index a317fb65..dbd08e80 100644 --- a/src/main/java/com/shanebeestudios/hg/api/events/PlayerJoinGameEvent.java +++ b/src/main/java/com/shanebeestudios/hg/api/events/PlayerJoinGameEvent.java @@ -1,60 +1,64 @@ package com.shanebeestudios.hg.api.events; +import com.shanebeestudios.hg.api.game.Game; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import com.shanebeestudios.hg.api.game.Game; /** * Called when a player joins a game */ public class PlayerJoinGameEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - private Game game; - private Player player; - private boolean isCancelled; - - public PlayerJoinGameEvent(Game game, Player player) { - this.game = game; - this.player = player; - this.isCancelled = false; - } - - /** Get the player that joined a game - * @return The player that joined the game - */ - public Player getPlayer() { - return this.player; - } - - /** Get the game the player joined - * @return The game the player joined - */ - public Game getGame() { - return this.game; - } - - @SuppressWarnings("NullableProblems") - @Override - public HandlerList getHandlers() { - return handlers; - } - - @SuppressWarnings("unused") - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public boolean isCancelled() { - return this.isCancelled; - } - - @Override - public void setCancelled(boolean isCancelled) { - this.isCancelled = isCancelled; - } + private static final HandlerList handlers = new HandlerList(); + private Game game; + private Player player; + private boolean isCancelled; + + public PlayerJoinGameEvent(Game game, Player player) { + this.game = game; + this.player = player; + this.isCancelled = false; + } + + /** + * Get the player that joined a game + * + * @return The player that joined the game + */ + public Player getPlayer() { + return this.player; + } + + /** + * Get the game the player joined + * + * @return The game the player joined + */ + public Game getGame() { + return this.game; + } + + @SuppressWarnings("NullableProblems") + @Override + public HandlerList getHandlers() { + return handlers; + } + + @SuppressWarnings("unused") + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.isCancelled; + } + + @Override + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; + } } diff --git a/src/main/java/com/shanebeestudios/hg/api/events/PlayerLeaveGameEvent.java b/src/main/java/com/shanebeestudios/hg/api/events/PlayerLeaveGameEvent.java index 1c46263f..d5a539b5 100644 --- a/src/main/java/com/shanebeestudios/hg/api/events/PlayerLeaveGameEvent.java +++ b/src/main/java/com/shanebeestudios/hg/api/events/PlayerLeaveGameEvent.java @@ -1,56 +1,62 @@ package com.shanebeestudios.hg.api.events; +import com.shanebeestudios.hg.api.game.Game; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import com.shanebeestudios.hg.api.game.Game; /** * Called when a player leaves a game */ public class PlayerLeaveGameEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Game game; - private Player player; - private boolean death; - - public PlayerLeaveGameEvent(Game game, Player player, boolean death) { - this.game = game; - this.player = player; - this.death = death; - } - - /** Get the game the player left - * @return The game the player left - */ - public Game getGame() { - return this.game; - } - - /** Get the player that left the game - * @return The player that left the game - */ - public Player getPlayer() { - return this.player; - } - - /** Check if the player died when they left the game - * @return If the player died when they left the game - */ - @SuppressWarnings("unused") - public boolean getDied() { - return death; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - @SuppressWarnings("unused") - public static HandlerList getHandlerList() { - return handlers; - } + private static final HandlerList handlers = new HandlerList(); + private Game game; + private Player player; + private boolean death; + + public PlayerLeaveGameEvent(Game game, Player player, boolean death) { + this.game = game; + this.player = player; + this.death = death; + } + + /** + * Get the game the player left + * + * @return The game the player left + */ + public Game getGame() { + return this.game; + } + + /** + * Get the player that left the game + * + * @return The player that left the game + */ + public Player getPlayer() { + return this.player; + } + + /** + * Check if the player died when they left the game + * + * @return If the player died when they left the game + */ + @SuppressWarnings("unused") + public boolean getDied() { + return death; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @SuppressWarnings("unused") + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java index a9a7aef6..f291a84e 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java @@ -1,6 +1,5 @@ package com.shanebeestudios.hg.api.game; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Util; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.bossbar.BossBar; diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java index 48427361..4f6057f0 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.api.game; -import com.shanebeestudios.hg.api.util.BlockUtils; import com.shanebeestudios.hg.api.data.ItemData; import com.shanebeestudios.hg.api.data.ItemFrameData; +import com.shanebeestudios.hg.api.util.BlockUtils; import com.shanebeestudios.hg.plugin.configs.Config; import org.bukkit.Location; import org.bukkit.Material; @@ -186,9 +186,9 @@ public void setupRandomizedBonusChests() { if (Config.CHESTS_BONUS_RANDOMIZE_ENABLED) { this.randomBonusChests.forEach(bonusChest -> { - if (this.random.nextInt(100) < Config.CHESTS_BONUS_RANDOMIZE_CHANCE) { - bonusChest.setBlockData(blockData); - } + if (this.random.nextInt(100) < Config.CHESTS_BONUS_RANDOMIZE_CHANCE) { + bonusChest.setBlockData(blockData); + } }); } } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java b/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java index 726b6afb..32606955 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.api.game; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Constants; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -25,7 +25,9 @@ protected GameLobbyWall(Game game) { super(game); } - /** Get location of far left sign of lobby wall + /** + * Get location of far left sign of lobby wall + * * @return Location of sign */ public Location getSignLocation() { diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameTeam.java b/src/main/java/com/shanebeestudios/hg/api/game/GameTeam.java index 098f8097..525089b2 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameTeam.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameTeam.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.api.game; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.data.PlayerData; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.plugin.managers.PlayerManager; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; diff --git a/src/main/java/com/shanebeestudios/hg/api/gui/KitsGUI.java b/src/main/java/com/shanebeestudios/hg/api/gui/KitsGUI.java index efc5a678..7fb6e3c3 100644 --- a/src/main/java/com/shanebeestudios/hg/api/gui/KitsGUI.java +++ b/src/main/java/com/shanebeestudios/hg/api/gui/KitsGUI.java @@ -1,12 +1,12 @@ package com.shanebeestudios.hg.api.gui; -import com.shanebeestudios.hg.api.registry.Registries; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.data.KitData; import com.shanebeestudios.hg.api.data.KitEntry; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.registry.Registries; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.registry.TypedKey; import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; diff --git a/src/main/java/com/shanebeestudios/hg/api/gui/SpectatorGUI.java b/src/main/java/com/shanebeestudios/hg/api/gui/SpectatorGUI.java index 3d1b26e7..98bbd00f 100644 --- a/src/main/java/com/shanebeestudios/hg/api/gui/SpectatorGUI.java +++ b/src/main/java/com/shanebeestudios/hg/api/gui/SpectatorGUI.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.api.gui; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/com/shanebeestudios/hg/api/status/PlayerStatus.java b/src/main/java/com/shanebeestudios/hg/api/status/PlayerStatus.java index b1699f6a..b7835e7c 100644 --- a/src/main/java/com/shanebeestudios/hg/api/status/PlayerStatus.java +++ b/src/main/java/com/shanebeestudios/hg/api/status/PlayerStatus.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.api.status; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; import net.kyori.adventure.text.Component; diff --git a/src/main/java/com/shanebeestudios/hg/api/status/Status.java b/src/main/java/com/shanebeestudios/hg/api/status/Status.java index 2b260bc1..fd8ddf0f 100755 --- a/src/main/java/com/shanebeestudios/hg/api/status/Status.java +++ b/src/main/java/com/shanebeestudios/hg/api/status/Status.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.api.status; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; -import com.shanebeestudios.hg.api.util.Util; import net.kyori.adventure.text.Component; /** @@ -26,29 +26,28 @@ public enum Status { * Game is starting to run in the free roam state */ FREE_ROAM, - /** - * Game is running - */ - RUNNING, - /** - * Game has stopped - */ - STOPPED, + /** + * Game is running + */ + RUNNING, + /** + * Game has stopped + */ + STOPPED, /** * Game is currently rolling back blocks */ ROLLBACK, - /** - * Game is broken - */ - BROKEN, - /** - * Game is not ready - */ - NOT_READY - ; + /** + * Game is broken + */ + BROKEN, + /** + * Game is not ready + */ + NOT_READY; - final Language lang = HungerGames.getPlugin().getLang(); + final Language lang = HungerGames.getPlugin().getLang(); public boolean isActive() { return switch (this) { @@ -57,7 +56,7 @@ public boolean isActive() { }; } - public Component getName() { + public Component getName() { return switch (this) { case RUNNING -> Util.getMini(this.lang.game_status_running); case STOPPED -> Util.getMini(this.lang.game_status_stopped); @@ -69,7 +68,7 @@ public Component getName() { case FREE_ROAM -> Util.getMini(this.lang.game_status_beginning); case COUNTDOWN -> Util.getMini(this.lang.game_status_countdown); }; - } + } public String getStringName() { return Util.unMini(this.getName()); diff --git a/src/main/java/com/shanebeestudios/hg/api/util/HgLogger.java b/src/main/java/com/shanebeestudios/hg/api/util/HgLogger.java index c271bf13..dfbb5f0f 100644 --- a/src/main/java/com/shanebeestudios/hg/api/util/HgLogger.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/HgLogger.java @@ -11,7 +11,9 @@ protected HgLogger(String name, String resourceBundleName) { super(name, resourceBundleName); } - /** Get an instance of HgLogger + /** + * Get an instance of HgLogger + * * @return new instance of HgLogger */ public static HgLogger getLogger() { diff --git a/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java b/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java index 3bae994e..68ff7b02 100644 --- a/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/ItemUtils.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.api.util; import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.ItemLore; import io.papermc.paper.persistence.PersistentDataContainerView; diff --git a/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java b/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java index d451a49c..988acce3 100644 --- a/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java @@ -1,7 +1,6 @@ package com.shanebeestudios.hg.api.util; import de.tr7zw.changeme.nbtapi.NBT; -import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTContainer; import de.tr7zw.changeme.nbtapi.NbtApiException; import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Util.java b/src/main/java/com/shanebeestudios/hg/api/util/Util.java index db6d54dd..20e3b613 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Util.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Util.java @@ -15,10 +15,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/main/java/com/shanebeestudios/hg/api/util/Vault.java b/src/main/java/com/shanebeestudios/hg/api/util/Vault.java index 555abfc7..d2f009d2 100755 --- a/src/main/java/com/shanebeestudios/hg/api/util/Vault.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/Vault.java @@ -1,10 +1,9 @@ package com.shanebeestudios.hg.api.util; +import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; -import net.milkbowl.vault.economy.Economy; - /** * General Vault class */ diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/CreateCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/CreateCommand.java index 9beeb490..412e1465 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/CreateCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/CreateCommand.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.data.PlayerSession; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.managers.SessionManager; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java index a76749cf..cfacefe2 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/DebugCommand.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java index b475b1ae..0d40760d 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/DeleteArenaCommand.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GamePlayerData; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java index 5f75bc35..cfd779f3 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBorderData; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.arguments.Argument; @@ -215,7 +215,7 @@ private Argument locations() { GameArenaData gameArenaData = game.getGameArenaData(); Location location = info.args().getByClass("location", Location.class); assert location != null; - location.add(0.5,0,0.5); + location.add(0.5, 0, 0.5); location.setPitch(0); location.setYaw(info.sender().getLocation().getYaw()); gameArenaData.addSpawn(location); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ForceStartCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ForceStartCommand.java index 00ca00ae..c448fb4f 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ForceStartCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ForceStartCommand.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/JoinCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/JoinCommand.java index 12a8b5f8..0355ff41 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/JoinCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/JoinCommand.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.EntitySelectorArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/KitCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/KitCommand.java index fbbb3ce0..f4e0d09a 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/KitCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/KitCommand.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.data.KitData; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/KitsCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/KitsCommand.java index 22012f62..be9d290a 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/KitsCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/KitsCommand.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.commands; +import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.gui.KitsGUI; import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java index 6ceeb140..69ed6adc 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/LeaveCommand.java @@ -1,12 +1,12 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.util.Vault; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; -import com.shanebeestudios.hg.api.game.Game; -import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java index ad2cd5f2..597a1d46 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListGamesCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListGamesCommand.java index 82b5220c..4de5e69b 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListGamesCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListGamesCommand.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/PermissionsCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/PermissionsCommand.java index d94f0b91..7b50940c 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/PermissionsCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/PermissionsCommand.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java index 1e3f4f0e..a928ef35 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/RefillChestNowCommand.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ReloadCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ReloadCommand.java index e0ef4d08..7bfc03fb 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ReloadCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ReloadCommand.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java index 6985f107..e2fc7d05 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/SetExitCommand.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.commands; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java index ac2e77ed..624fc133 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/SpectateCommand.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/StatusCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/StatusCommand.java index eb28b814..8f3b462a 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/StatusCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/StatusCommand.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/StopAllCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/StopAllCommand.java index e872555e..457db7fe 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/StopAllCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/StopAllCommand.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/StopCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/StopCommand.java index df59cd30..40e6e346 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/StopCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/StopCommand.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.command.CustomArg; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/SubCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/SubCommand.java index 70afa251..e7dbcb9a 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/SubCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/SubCommand.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.commands; +import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; -import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.plugin.managers.GameManager; import com.shanebeestudios.hg.plugin.managers.PlayerManager; import dev.jorel.commandapi.arguments.Argument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/TeamCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/TeamCommand.java index 62bed6b8..70fe2aab 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/TeamCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/TeamCommand.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameTeam; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.EntitySelectorArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ToggleCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ToggleCommand.java index e4c6adcd..82a91028 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ToggleCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ToggleCommand.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.commands; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.command.CustomArg; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.permission.Permissions; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/ArenaConfig.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/ArenaConfig.java index 59222db3..446a848c 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/ArenaConfig.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/ArenaConfig.java @@ -1,12 +1,12 @@ package com.shanebeestudios.hg.plugin.configs; -import com.shanebeestudios.hg.api.parsers.LocationParser; -import com.shanebeestudios.hg.api.util.Pair; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBorderData; import com.shanebeestudios.hg.api.game.GameRegion; +import com.shanebeestudios.hg.api.parsers.LocationParser; +import com.shanebeestudios.hg.api.util.Pair; +import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.managers.GameManager; import org.bukkit.Difficulty; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java index 35eddfc8..b4b3690e 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java @@ -1,13 +1,13 @@ package com.shanebeestudios.hg.plugin.configs; import com.shanebeestudios.hg.api.parsers.LocationParser; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.api.util.Vault; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Location; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.api.util.Vault; import java.io.File; import java.io.IOException; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameBlockListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameBlockListener.java index c20aea91..7908c7f9 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameBlockListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameBlockListener.java @@ -1,13 +1,13 @@ package com.shanebeestudios.hg.plugin.listeners; import com.shanebeestudios.hg.api.data.ItemData; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.api.util.BlockUtils; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBlockData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.BlockUtils; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.plugin.permission.Permissions; import org.bukkit.Material; @@ -153,7 +153,7 @@ private void blockBreak(BlockBreakEvent event) { switch (status) { case FREE_ROAM: case RUNNING: - game.getGameBlockData().removeChest( block.getLocation()); + game.getGameBlockData().removeChest(block.getLocation()); default: return; } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameChestListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameChestListener.java index d5629653..b97faf1c 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameChestListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameChestListener.java @@ -1,14 +1,14 @@ package com.shanebeestudios.hg.plugin.listeners; import com.shanebeestudios.hg.api.data.ItemData; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.events.ChestOpenEvent; -import com.shanebeestudios.hg.api.util.BlockUtils; -import com.shanebeestudios.hg.api.util.Constants; +import com.shanebeestudios.hg.api.data.ItemData.ChestType; import com.shanebeestudios.hg.api.data.PlayerData; +import com.shanebeestudios.hg.api.events.ChestOpenEvent; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameBlockData; -import com.shanebeestudios.hg.api.data.ItemData.ChestType; +import com.shanebeestudios.hg.api.util.BlockUtils; +import com.shanebeestudios.hg.api.util.Constants; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java index 61342702..95e1252c 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCommandListener.java @@ -9,8 +9,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import java.util.UUID; - /** * Internal event listener */ diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCompassListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCompassListener.java index 3f745df7..876611c8 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCompassListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameCompassListener.java @@ -5,7 +5,6 @@ import com.shanebeestudios.hg.api.util.Constants; import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Material; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -14,7 +13,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameDamageListenerBase.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameDamageListenerBase.java index d74aa7ec..a958735e 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameDamageListenerBase.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameDamageListenerBase.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java index 5b6a5675..b4c2e8f4 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameEntityListener.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameListenerBase.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameListenerBase.java index dd8dff70..ac340d48 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameListenerBase.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameListenerBase.java @@ -1,8 +1,8 @@ package com.shanebeestudios.hg.plugin.listeners; +import com.shanebeestudios.hg.api.data.Leaderboard; import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Language; -import com.shanebeestudios.hg.api.data.Leaderboard; import com.shanebeestudios.hg.plugin.managers.GameManager; import com.shanebeestudios.hg.plugin.managers.KillManager; import com.shanebeestudios.hg.plugin.managers.PlayerManager; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameLobbyListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameLobbyListener.java index db7014c6..4e58efc4 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameLobbyListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameLobbyListener.java @@ -1,9 +1,9 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.util.Constants; import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GamePlayerListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GamePlayerListener.java index 216988c9..445d35ff 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GamePlayerListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GamePlayerListener.java @@ -1,12 +1,12 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Config; import io.papermc.paper.event.player.AsyncChatEvent; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameTrackingStickListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameTrackingStickListener.java index 3b0976bc..2397c55a 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameTrackingStickListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/GameTrackingStickListener.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.ItemUtils; -import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.ItemUtils; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/listeners/SessionWandListener.java b/src/main/java/com/shanebeestudios/hg/plugin/listeners/SessionWandListener.java index 831e4572..64530bc3 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/listeners/SessionWandListener.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/listeners/SessionWandListener.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.listeners; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.data.PlayerSession; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.plugin.managers.GameManager; import com.shanebeestudios.hg.plugin.managers.SessionManager; import org.bukkit.Location; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/ItemManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/ItemManager.java index da2e8a11..66cfbe1b 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/ItemManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/ItemManager.java @@ -2,12 +2,12 @@ import com.shanebeestudios.hg.api.data.ItemData; import com.shanebeestudios.hg.api.data.ItemData.ChestType; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.parsers.ItemParser; import com.shanebeestudios.hg.api.util.Constants; import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java index 6fe82f5b..778d546e 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/managers/KillManager.java @@ -1,16 +1,16 @@ package com.shanebeestudios.hg.plugin.managers; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.registry.Registries; -import com.shanebeestudios.hg.api.util.ItemUtils; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Config; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.data.Leaderboard; import com.shanebeestudios.hg.api.events.PlayerDeathGameEvent; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameCommandData; import com.shanebeestudios.hg.api.game.GamePlayerData; +import com.shanebeestudios.hg.api.registry.Registries; +import com.shanebeestudios.hg.api.util.ItemUtils; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import io.papermc.paper.datacomponent.DataComponentTypes; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropChestTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropChestTask.java index 9a5496fe..8d6dc264 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropChestTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropChestTask.java @@ -1,7 +1,7 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.api.util.Constants; +import com.shanebeestudios.hg.plugin.HungerGames; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.BlockFace; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropTask.java index 10a93ad4..f364ac08 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestDropTask.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameRegion; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestRefillRepeatTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestRefillRepeatTask.java index 96c0b16d..3da31896 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestRefillRepeatTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/ChestRefillRepeatTask.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBlockData; import com.shanebeestudios.hg.api.game.GamePlayerData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.plugin.configs.Language; import org.bukkit.Bukkit; public class ChestRefillRepeatTask implements Runnable { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/FreeRoamTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/FreeRoamTask.java index fc041e2c..63ccf862 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/FreeRoamTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/FreeRoamTask.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.plugin.configs.Language; -import com.shanebeestudios.hg.api.game.Game; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java index de4cd1ab..efe7cf72 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/GameTimerTask.java @@ -1,13 +1,13 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.status.Status; -import com.shanebeestudios.hg.plugin.configs.Config; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBlockData; import com.shanebeestudios.hg.api.game.GamePlayerData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import org.bukkit.Bukkit; public class GameTimerTask implements Runnable { diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java index 2870c363..32373135 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/NearestPlayerCompassTask.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.api.util.Util; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.data.PlayerData; import com.shanebeestudios.hg.api.game.Game; +import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.plugin.managers.PlayerManager; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/RollbackTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/RollbackTask.java index 15b52b4d..a01f22ad 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/RollbackTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/RollbackTask.java @@ -1,58 +1,58 @@ package com.shanebeestudios.hg.plugin.tasks; -import java.util.Iterator; - -import org.bukkit.Bukkit; -import org.bukkit.block.BlockState; -import com.shanebeestudios.hg.plugin.HungerGames; -import com.shanebeestudios.hg.plugin.configs.Config; import com.shanebeestudios.hg.api.data.ItemFrameData; import com.shanebeestudios.hg.api.game.Game; -import com.shanebeestudios.hg.api.status.Status; import com.shanebeestudios.hg.api.game.GameBlockData; +import com.shanebeestudios.hg.api.status.Status; +import com.shanebeestudios.hg.plugin.HungerGames; +import com.shanebeestudios.hg.plugin.configs.Config; +import org.bukkit.Bukkit; +import org.bukkit.block.BlockState; + +import java.util.Iterator; /** * Rollback task for resetting blocks after a game finishes */ public class RollbackTask implements Runnable { - private final Iterator blockRollbackSession; - private final Iterator itemFrameDataIterator; - private final Game game; - private final GameBlockData gameBlockData; - private final int blocks_per_tick; - private int taskId; + private final Iterator blockRollbackSession; + private final Iterator itemFrameDataIterator; + private final Game game; + private final GameBlockData gameBlockData; + private final int blocks_per_tick; + private int taskId; - public RollbackTask(Game game) { - this.game = game; - this.gameBlockData = game.getGameBlockData(); - this.blocks_per_tick = Config.ROLLBACK_BLOCKS_PER_SECOND / 20; - game.getGameArenaData().setStatus(Status.ROLLBACK); - this.blockRollbackSession = this.gameBlockData.getBlocks().iterator(); - this.itemFrameDataIterator = this.gameBlockData.getItemFrameData().iterator(); - this.taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(HungerGames.getPlugin(), this, 20); - } + public RollbackTask(Game game) { + this.game = game; + this.gameBlockData = game.getGameBlockData(); + this.blocks_per_tick = Config.ROLLBACK_BLOCKS_PER_SECOND / 20; + game.getGameArenaData().setStatus(Status.ROLLBACK); + this.blockRollbackSession = this.gameBlockData.getBlocks().iterator(); + this.itemFrameDataIterator = this.gameBlockData.getItemFrameData().iterator(); + this.taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(HungerGames.getPlugin(), this, 20); + } - public void run() { - int rolledBack = 0; - // Rollback blocks - while (rolledBack < this.blocks_per_tick && this.blockRollbackSession.hasNext()) { - BlockState state = this.blockRollbackSession.next(); - if (state != null && state.getType() != state.getBlock().getType()) { + public void run() { + int rolledBack = 0; + // Rollback blocks + while (rolledBack < this.blocks_per_tick && this.blockRollbackSession.hasNext()) { + BlockState state = this.blockRollbackSession.next(); + if (state != null && state.getType() != state.getBlock().getType()) { state.update(true, false); rolledBack++; } - } - if (this.blockRollbackSession.hasNext()) { - this.taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(HungerGames.getPlugin(), this, 1); - return; - } + } + if (this.blockRollbackSession.hasNext()) { + this.taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(HungerGames.getPlugin(), this, 1); + return; + } - // Rollback item frames - while (this.itemFrameDataIterator.hasNext()) { - ItemFrameData data = this.itemFrameDataIterator.next(); - if (data != null) { - data.resetItem(); + // Rollback item frames + while (this.itemFrameDataIterator.hasNext()) { + ItemFrameData data = this.itemFrameDataIterator.next(); + if (data != null) { + data.resetItem(); } } @@ -60,6 +60,6 @@ public void run() { this.gameBlockData.resetItemFrames(); this.game.getGameArenaData().setStatus(Status.READY); Bukkit.getScheduler().cancelTask(this.taskId); - } + } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java index 2cdf3ce6..1b412e99 100755 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/StartingTask.java @@ -1,10 +1,10 @@ package com.shanebeestudios.hg.plugin.tasks; -import org.bukkit.Bukkit; -import com.shanebeestudios.hg.plugin.configs.Config; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.util.Util; +import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; +import org.bukkit.Bukkit; public class StartingTask implements Runnable { @@ -19,8 +19,8 @@ public StartingTask(Game game) { this.lang = game.getPlugin().getLang(); String name = game.getGameArenaData().getName(); String broadcast = this.lang.game_countdown_started - .replace("", name) - .replace("", "" + this.timer); + .replace("", name) + .replace("", "" + this.timer); if (Config.SETTINGS_BROADCAST_JOIN_MESSAGES) { Util.broadcast(broadcast); Util.broadcast(this.lang.game_join.replace("", name)); diff --git a/src/main/java/com/shanebeestudios/hg/plugin/tasks/WorldBorderTask.java b/src/main/java/com/shanebeestudios/hg/plugin/tasks/WorldBorderTask.java index d50e9634..507bb10c 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/tasks/WorldBorderTask.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/tasks/WorldBorderTask.java @@ -1,11 +1,11 @@ package com.shanebeestudios.hg.plugin.tasks; -import com.shanebeestudios.hg.plugin.configs.Config; -import com.shanebeestudios.hg.plugin.configs.Language; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.game.GameArenaData; import com.shanebeestudios.hg.api.game.GameBorderData; import com.shanebeestudios.hg.api.game.GamePlayerData; +import com.shanebeestudios.hg.plugin.configs.Config; +import com.shanebeestudios.hg.plugin.configs.Language; import org.bukkit.Bukkit; import org.bukkit.WorldBorder; import org.bukkit.damage.DamageSource; From 7b25c257dd4ff439ab8437cde83037662a9bb881 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 11:24:08 -0700 Subject: [PATCH 22/52] NBTApi - fix javadoc --- src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java b/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java index 988acce3..bd8dd674 100644 --- a/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java +++ b/src/main/java/com/shanebeestudios/hg/api/util/NBTApi.java @@ -129,10 +129,10 @@ public static void applyNBTToEntity(Entity entity, String nbtString) { * Get a pretty NBT string *

This is the same as what vanilla Minecraft outputs when using the '/data' command

* - * @param compound Compound to convert to pretty - * @param split When null NBT will print on one long line, if not null NBT compound will be - * split into lines with JSON style, and this string will start each line off - * (usually spaces) + * @param nbtString NBT string to convert to pretty + * @param split When null NBT will print on one long line, if not null NBT compound will be + * split into lines with JSON style, and this string will start each line off + * (usually spaces) * @return Pretty string of NBTCompound */ @SuppressWarnings("deprecation") From bd578a57dd996fb5bc459f84c7d9d6081d36f7b9 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 11:27:06 -0700 Subject: [PATCH 23/52] build.gradle.kts - update paper docs --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 37645749..024fe8a3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -91,7 +91,7 @@ tasks { exclude("com/shanebeestudios/hg/plugin/commands") exclude("com/shanebeestudios/hg/plugin/listeners") (options as StandardJavadocDocletOptions).links( - "https://jd.papermc.io/paper/1.21.1/", + "https://jd.papermc.io/paper/1.21.5/", "https://jd.advntr.dev/api/4.17.0/", "https://tr7zw.github.io/Item-NBT-API/v2-api/" ) From c5177e7e37a527d4ef44b55e697b23b8c9e41106 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 11:33:50 -0700 Subject: [PATCH 24/52] Change some access --- .../com/shanebeestudios/hg/api/game/Game.java | 24 +++++++++---------- .../hg/api/game/GameArenaData.java | 20 ++++++++-------- .../hg/api/game/GameBarData.java | 2 +- .../hg/api/game/GameCommandData.java | 4 ++-- .../hg/api/game/GameLobbyWall.java | 4 ++-- .../hg/api/game/GamePlayerData.java | 12 ++++++---- .../hg/api/game/GameScoreboard.java | 2 +- 7 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index b35c29e6..6426ea6e 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -53,15 +53,15 @@ public class Game { private NearestPlayerCompassTask nearestPlayerCompassTask; // Data Objects - final GameArenaData gameArenaData; + private final GameArenaData gameArenaData; private final GameEntityData gameEntityData; - final GameScoreboard gameScoreboard; - final GameBarData bar; - final GamePlayerData gamePlayerData; - final GameBlockData gameBlockData; - final GameItemData gameItemData; - final GameCommandData gameCommandData; - final GameBorderData gameBorderData; + private final GameScoreboard gameScoreboard; + private final GameBarData bar; + private final GamePlayerData gamePlayerData; + private final GameBlockData gameBlockData; + private final GameItemData gameItemData; + private final GameCommandData gameCommandData; + private final GameBorderData gameBorderData; /** * Create a new game @@ -91,7 +91,7 @@ public Game(String name, GameRegion gameRegion, List spawns, Location this.gameItemData = new GameItemData(this); this.gameCommandData = new GameCommandData(this); this.gameBorderData = new GameBorderData(this); - this.gameArenaData.spawns.addAll(spawns); + this.gameArenaData.getSpawns().addAll(spawns); // If lobby signs are not properly setup, game is not ready if (!this.gameBlockData.setLobbyBlock(lobbySign)) { @@ -268,7 +268,7 @@ public void startRunningGame() { if (Config.CHESTS_CHEST_DROP_ENABLED) this.chestDropTask = new ChestDropTask(this); this.gameBlockData.updateLobbyBlock(); if (Config.SETTINGS_BOSSBAR_COUNTDOWN) { - this.bar.createBossBar(gameArenaData.timer); + this.bar.createBossBar(this.gameArenaData.getTimer()); } if (Config.WORLD_BORDER_ENABLED) { this.gameBorderData.initialize(); @@ -514,7 +514,7 @@ void updateAfterDeath(Player player, boolean death) { if (isGameOver()) { if (!death) { for (Player player1 : this.gamePlayerData.getPlayers()) { - if (this.gamePlayerData.kills.get(player1) >= 1) { + if (this.gamePlayerData.getKills().get(player1) >= 1) { death = true; } } @@ -548,7 +548,7 @@ boolean isGameOver() { assert playerData != null; GameTeam gameTeam = playerData.getTeam(); - if (gameTeam != null && (gameTeam.getPlayers().size() >= gamePlayerData.players.size())) { + if (gameTeam != null && (gameTeam.getPlayers().size() >= this.gamePlayerData.getPlayers().size())) { for (Player player1 : this.gamePlayerData.getPlayers()) { if (!gameTeam.getPlayers().contains(player1)) { return false; diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameArenaData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameArenaData.java index 88689139..98a39008 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameArenaData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameArenaData.java @@ -13,18 +13,18 @@ */ public class GameArenaData extends Data { - final String name; - final GameRegion gameRegion; - int timer; - int minPlayers; - int maxPlayers; + private final String name; + private final GameRegion gameRegion; + private int timer; + private int minPlayers; + private int maxPlayers; private int freeRoamTime; - int cost; - final List spawns; - Location exit; + private int cost; + private final List spawns; + private Location exit; private Status status = Status.NOT_READY; - int chestRefillTime = 0; - int chestRefillRepeat = 0; + private int chestRefillTime = 0; + private int chestRefillRepeat = 0; GameArenaData(Game game, String name, GameRegion gameRegion, int timer, int minPlayers, int maxPlayers, int freeRoamTime, int cost) { super(game); diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java index f291a84e..b5ba5e8e 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameBarData.java @@ -46,7 +46,7 @@ public void createBossBar(int time) { */ public void bossBarUpdate(int remaining) { if (this.bar == null) return; - float remain = ((float) remaining) / ((float) getGame().gameArenaData.timer); + float remain = ((float) remaining) / ((float) getGame().getGameArenaData().getTimer()); int min = (remaining / 60); int sec = (remaining % 60); String title = formatTitle(min, sec); diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameCommandData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameCommandData.java index f53cdf4a..0b7e7413 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameCommandData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameCommandData.java @@ -62,8 +62,8 @@ public void runCommands(CommandType commandType, @Nullable Player player) { if (!type.equals(commandType.getName())) continue; if (command.equalsIgnoreCase("none")) continue; command = command.split(":")[1] - .replace("", this.game.gameArenaData.gameRegion.getWorld().getName()) - .replace("", this.game.gameArenaData.getName()); + .replace("", this.game.getGameArenaData().getGameRegion().getWorld().getName()) + .replace("", this.game.getGameArenaData().getName()); if (player != null) { command = command.replace("", player.getName()); } diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java b/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java index 32606955..fa0aec92 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameLobbyWall.java @@ -57,8 +57,8 @@ protected boolean setLobbyBlock(Location location) { sign1.getSide(Side.FRONT).line(0, Util.getMini(this.lang.lobby_sign_1_1)); sign1.getSide(Side.FRONT).line(1, Util.getMini("" + gameArenaData.getName())); sign1.getSide(Side.FRONT).line(2, Util.getMini(this.lang.lobby_sign_1_3)); - if (gameArenaData.cost > 0) - sign1.getSide(Side.FRONT).line(3, Util.getMini(HungerGames.getPlugin().getLang().lobby_sign_cost.replace("", String.valueOf(gameArenaData.cost)))); + if (gameArenaData.getCost() > 0) + sign1.getSide(Side.FRONT).line(3, Util.getMini(HungerGames.getPlugin().getLang().lobby_sign_cost.replace("", String.valueOf(gameArenaData.getCost())))); sign2.getSide(Side.FRONT).line(0, Util.getMini(this.lang.lobby_sign_2_1)); sign2.getSide(Side.FRONT).line(1, gameArenaData.getStatus().getName()); sign3.getSide(Side.FRONT).line(0, Util.getMini(this.lang.lobby_sign_3_1)); diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java index 9c889fe4..7d3e3fab 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GamePlayerData.java @@ -46,14 +46,14 @@ public class GamePlayerData extends Data { private final GameManager gameManager; // Player Lists - final Map players = new HashMap<>(); - final Map spectators = new HashMap<>(); + private final Map players = new HashMap<>(); + private final Map spectators = new HashMap<>(); // This list contains all players who have joined the arena // Will be used to broadcast messages even if a player is no longer in the game - final List allPlayers = new ArrayList<>(); + private final List allPlayers = new ArrayList<>(); // Data lists - final Map kills = new HashMap<>(); + private final Map kills = new HashMap<>(); private final List randomizedSpawns = new ArrayList<>(); protected GamePlayerData(Game game) { @@ -76,6 +76,10 @@ void clearPlayers() { this.allPlayers.clear(); } + public Map getKills() { + return this.kills; + } + /** * Get a list of all players currently spectating the game * diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameScoreboard.java b/src/main/java/com/shanebeestudios/hg/api/game/GameScoreboard.java index 41361e6c..86fe5004 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameScoreboard.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameScoreboard.java @@ -24,7 +24,7 @@ public class GameScoreboard extends Data { private final GameSidebar gameSidebar; private final Scoreboard scoreboard; private final Team baseBukkitTeam; - final Map gameTeams = new HashMap<>(); + private final Map gameTeams = new HashMap<>(); protected GameScoreboard(Game game) { super(game); From f55484ae3ff67fcefa9a97e7ea6d6dc11e53d96e Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 12:15:05 -0700 Subject: [PATCH 25/52] Game - change block log --- src/main/java/com/shanebeestudios/hg/api/game/Game.java | 6 ++++-- .../java/com/shanebeestudios/hg/api/game/GameBlockData.java | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/api/game/Game.java b/src/main/java/com/shanebeestudios/hg/api/game/Game.java index 6426ea6e..38733fa4 100755 --- a/src/main/java/com/shanebeestudios/hg/api/game/Game.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/Game.java @@ -228,10 +228,12 @@ public int getRemainingTime() { public void startWaitingPeriod() { this.gameArenaData.setStatus(Status.WAITING); long start = System.currentTimeMillis(); - this.gameBlockData.logBlocksForRollback(); + int count = this.gameBlockData.logBlocksForRollback(); this.gameBlockData.setupRandomizedBonusChests(); long fin = System.currentTimeMillis() - start; - Util.log("Logged blocks in %s ms", fin); + if (Config.SETTINGS_DEBUG) { + Util.log("Logged %,d blocks in %sms for arena %s", count, fin, getGameArenaData().getName()); + } } /** diff --git a/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java b/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java index 4f6057f0..ca700237 100644 --- a/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java +++ b/src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java @@ -167,15 +167,18 @@ public boolean canBeFilled(Location location) { /** * Log all blocks in an arena for rollback */ - public void logBlocksForRollback() { + public int logBlocksForRollback() { + int count = 0; for (Location location : this.getGame().getGameArenaData().getGameRegion().getBlocks(null)) { Block block = location.getBlock(); this.blocks.add(block.getState()); + count++; if (Config.CHESTS_BONUS_RANDOMIZE_ENABLED && BlockUtils.isBonusBlockReplacement(block)) { this.randomBonusChests.add(block); block.setType(Material.AIR); } } + return count; } @SuppressWarnings("UnstableApiUsage") From 63faa4dffca97a60c8f87d6f054920273c79a403 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 12:44:34 -0700 Subject: [PATCH 26/52] ListCommand - add option to see players in any game --- .../hg/plugin/commands/ListCommand.java | 26 +++++++++++++++++-- .../hg/plugin/permission/Permissions.java | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java index 597a1d46..d4307108 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/ListCommand.java @@ -1,5 +1,6 @@ package com.shanebeestudios.hg.plugin.commands; +import com.shanebeestudios.hg.api.command.CustomArg; import com.shanebeestudios.hg.api.game.Game; import com.shanebeestudios.hg.api.util.Util; import com.shanebeestudios.hg.plugin.HungerGames; @@ -8,6 +9,7 @@ import dev.jorel.commandapi.arguments.LiteralArgument; import org.bukkit.entity.Player; +import java.util.List; import java.util.StringJoiner; public class ListCommand extends SubCommand { @@ -28,12 +30,32 @@ protected Argument register() { return; } + List players = game.getGamePlayerData().getPlayers(); StringJoiner joiner = new StringJoiner(this.lang.command_list_players_delimiter); - game.getGamePlayerData().getPlayers().forEach(p -> joiner.add(p.getName())); + if (players.isEmpty()) { + joiner.add("none"); + } else { + players.forEach(p -> joiner.add(p.getName())); + } Util.sendPrefixedMessage(player, this.lang.command_list_players .replace("", game.getGameArenaData().getName()) .replace("", joiner.toString())); - }); + }).then(CustomArg.GAME.get("game") + .withPermission(Permissions.COMMAND_LIST_GAME.permission()) + .executes(info -> { + Game game = info.args().getByClass("game", Game.class); + assert game != null; + List players = game.getGamePlayerData().getPlayers(); + StringJoiner joiner = new StringJoiner(this.lang.command_list_players_delimiter); + if (players.isEmpty()) { + joiner.add("none"); + } else { + players.forEach(p -> joiner.add(p.getName())); + } + Util.sendPrefixedMessage(info.sender(), this.lang.command_list_players + .replace("", game.getGameArenaData().getName()) + .replace("", joiner.toString())); + })); } } diff --git a/src/main/java/com/shanebeestudios/hg/plugin/permission/Permissions.java b/src/main/java/com/shanebeestudios/hg/plugin/permission/Permissions.java index 523727fa..08408c46 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/permission/Permissions.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/permission/Permissions.java @@ -30,6 +30,7 @@ public boolean has(CommandSender sender) { public static final Permission COMMAND_KIT = getCommand("kit", "Get a kit in a game", PermissionDefault.TRUE); public static final Permission COMMAND_LEAVE = getCommand("leave", "Leave a game", PermissionDefault.TRUE); public static final Permission COMMAND_LIST = getCommand("list", "List all players in your game", PermissionDefault.TRUE); + public static final Permission COMMAND_LIST_GAME = getCommand("list_game", "List all players in a game", PermissionDefault.TRUE); public static final Permission COMMAND_NBT = getCommand("nbt", "Get the NBT of an item from the configs", PermissionDefault.OP); public static final Permission COMMAND_PERMISSIONS = getCommand("permissions", "List of permissions", PermissionDefault.OP); public static final Permission COMMAND_REFILL_CHESTS = getCommand("refill_chests", "Refill chests in a game", PermissionDefault.OP); From c775e5a49cf14703c4397b490180f41e46abfd5e Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Sun, 13 Apr 2025 12:48:46 -0700 Subject: [PATCH 27/52] EditCommand - combine chest refill subs --- .../hg/plugin/commands/EditCommand.java | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java index cfd779f3..63b00086 100644 --- a/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java +++ b/src/main/java/com/shanebeestudios/hg/plugin/commands/EditCommand.java @@ -32,9 +32,8 @@ protected Argument register() { return LiteralArgument.literal("edit") .withPermission(Permissions.COMMAND_EDIT.permission()) .then(CustomArg.GAME.get("game") - .then(chestRefillRepeat()) - .then(chestRefillTime()) .then(border()) + .then(chestRefill()) .then(info()) .then(locations()) ); @@ -87,46 +86,43 @@ private Argument border() { } @SuppressWarnings("DataFlowIssue") - private Argument chestRefillTime() { - return LiteralArgument.literal("chest-refill-time") - .then(new IntegerArgument("time", 30) - .executes(info -> { - Game game = info.args().getByClass("game", Game.class); - CommandSender sender = info.sender(); - String name = game.getGameArenaData().getName(); - int time = info.args().getByClass("time", Integer.class); - if (time % 30 != 0) { - Util.sendPrefixedMessage(sender, "