From 7a5b1f2eca1fa47465b99712a0d472088fba3221 Mon Sep 17 00:00:00 2001 From: Marcel <8513034+MrEAlderson@users.noreply.github.com> Date: Sat, 16 Mar 2024 20:59:13 +0100 Subject: [PATCH] Fixed degarding buy groups not going for level 0 --- .../advancedswords/DegradingBuyGroups.java | 26 +++++++++---------- .../advancedswords/ToolSwordHelper.java | 4 --- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/DegradingBuyGroups.java b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/DegradingBuyGroups.java index 6dab463..91a9b17 100644 --- a/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/DegradingBuyGroups.java +++ b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/DegradingBuyGroups.java @@ -22,31 +22,31 @@ public void onRespawn(PlayerIngameRespawnEvent event) { final Player player = event.getPlayer(); final Arena arena = event.getArena(); - for (BuyGroup buyGroup : GameAPI.get().getBuyGroups()) { - final String buyGroupName = buyGroup.getName(); + for (String name : SwordsToolsConfig.degrading_buygroups) { + final BuyGroup buyGroup = GameAPI.get().getBuyGroup(name); - // TODO case sensitive - if (!SwordsToolsConfig.degrading_buygroups.contains(buyGroupName)) + if (buyGroup == null) continue; - int level = ToolSwordHelper.getBuyGroupTracker(player).getBuyGroupLevel(player, buyGroupName); + final BuyGroupTracker tracker = ToolSwordHelper.getBuyGroupTracker(arena); + int newLevel = tracker.getBuyGroupLevel(player, name); - if (level > 1) { - level -= 1; - ToolSwordHelper.getBuyGroupTracker(player).setBuyGroupLevel(player, buyGroupName, level); - } + if (buyGroup.getLevels().contains(newLevel - 1)) + newLevel--; - arena.setBuyGroupLevel(player, buyGroup, level); + tracker.setBuyGroupLevel(player, name, newLevel); + arena.setBuyGroupLevel(player, buyGroup, newLevel); + + // Give items + final Collection shopItems = buyGroup.getItems(newLevel); - // Give item - final Collection shopItems = buyGroup.getItems(level); if (shopItems == null) continue; final Team team = arena.getPlayerTeam(player); + for (ShopItem item : shopItems) ToolSwordHelper.givePlayerShopItem(arena, team, player, item); - } } } \ No newline at end of file diff --git a/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/ToolSwordHelper.java b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/ToolSwordHelper.java index 581f020..367c49e 100644 --- a/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/ToolSwordHelper.java +++ b/src/main/java/me/metallicgoat/tweaksaddon/tweaks/advancedswords/ToolSwordHelper.java @@ -82,10 +82,6 @@ private void removeArena(Arena arena) { buyGroupTrackerMap.remove(arena); } - public static BuyGroupTracker getBuyGroupTracker(Player player) { - return getBuyGroupTracker(GameAPI.get().getArenaByPlayer(player)); - } - public static BuyGroupTracker getBuyGroupTracker(Arena arena) { if(arena == null || !buyGroupTrackerMap.containsKey(arena)) return new BuyGroupTracker();