From b335b43eaf9be90753aa90ff100ddd024b9f7422 Mon Sep 17 00:00:00 2001 From: Misat11 <20199703+Misat11@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:08:38 +0100 Subject: [PATCH 1/3] feat: print stack traces when using sba.utils.Logger --- .../main/java/io/github/pronze/sba/utils/Logger.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/Logger.java b/plugin/src/main/java/io/github/pronze/sba/utils/Logger.java index ffd8964e..9935cf77 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/Logger.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/Logger.java @@ -40,6 +40,7 @@ public static void info(@NonNull String message, Object... params) { return; } instance.logger.info(getMessage(message, params)); + printStackTraces(params); } public static void trace(@NonNull String message, Object... params) { if (instance.testMode) { @@ -48,6 +49,7 @@ public static void trace(@NonNull String message, Object... params) { } if (instance.level.getLevel() >= Level.TRACE.getLevel()) { instance.logger.info(getMessage(message, params)); + printStackTraces(params); } } @@ -58,6 +60,7 @@ public static void warn(@NonNull String message, Object... params) { } if (instance.level.getLevel() >= Level.WARNING.getLevel()) { instance.logger.warning(getMessage(message, params)); + printStackTraces(params); } } @@ -68,6 +71,7 @@ public static void error(@NonNull String message, Object... params) { } if (instance.level.getLevel() >= Level.ERROR.getLevel()) { instance.logger.severe(getMessage(message, params)); + printStackTraces(params); } } @@ -84,6 +88,14 @@ private static String getMessage(String message, Object... params) { return message; } + private static void printStackTraces(Object... params) { + for (var param : params) { + if (param instanceof Throwable) { + ((Throwable) param).printStackTrace(); + } + } + } + public static void setMode(Level level) { if(instance != null) instance.level = level; From f5ab15aa7b962216df5de0c21cf8bdb94c9dc085 Mon Sep 17 00:00:00 2001 From: Misat11 <20199703+Misat11@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:06:22 +0100 Subject: [PATCH 2/3] fix: shop and special items related fixes --- gradle.properties | 2 +- .../inventories/AbstractStoreInventory.java | 2 +- .../sba/inventories/SBAStoreInventoryV2.java | 7 -- .../pronze/sba/specials/PopupTower.java | 74 ++++++++++--------- .../specials/listener/BridgeEggListener.java | 15 +++- .../specials/listener/PopupTowerListener.java | 19 ++++- .../specials/runners/BridgeEggRunnable.java | 13 +++- 7 files changed, 85 insertions(+), 47 deletions(-) diff --git a/gradle.properties b/gradle.properties index f3f8c5de..6ac055bd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ SBA_VERSION=1.5.12 PAPER_LEGACY_VERSION=1.16.5 -BEDWARS_VERSION=0.2.30-SNAPSHOT +BEDWARS_VERSION=0.2.30 CLOUD_COMMANDS_VERSION=1.6.2 COMMODORE_VERSION=2.2 KYORI_ADVENTURE_VERSION=4.11.0 diff --git a/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java b/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java index c346b2ac..3ae165dc 100644 --- a/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java +++ b/plugin/src/main/java/io/github/pronze/sba/inventories/AbstractStoreInventory.java @@ -258,7 +258,7 @@ public void handlePrePurchase(OnTradeEvent event) { double maxStackSize; int finalStackSize; - for (ItemStack itemStack : player.getInventory().getStorageContents()) { + for (ItemStack itemStack : player.getInventory().getContents()) { if (itemStack != null && itemStack.isSimilar(type.getStack())) { inInventory = inInventory + itemStack.getAmount(); } diff --git a/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java b/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java index a8382041..742e66ca 100644 --- a/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java +++ b/plugin/src/main/java/io/github/pronze/sba/inventories/SBAStoreInventoryV2.java @@ -23,7 +23,6 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.Main; -import org.screamingsandals.bedwars.api.events.BedwarsApplyPropertyToItem; import org.screamingsandals.bedwars.api.events.BedwarsOpenShopEvent; import org.screamingsandals.bedwars.api.game.ItemSpawner; import org.screamingsandals.bedwars.api.game.ItemSpawnerType; @@ -198,9 +197,6 @@ public Map.Entry handlePurchase(Player player, AtomicReference switch (propertyName) { case "trap": if (!property.getPropertyData().hasChild("identifier") && property.getPropertyData().hasChild("data")) { // Fix support for SBW Trap special item - var applyEvent = new BedwarsApplyPropertyToItem(game, player, newItem.get(), propertyData); - SBA.getPluginInstance().getServer().getPluginManager().callEvent(applyEvent); - newItem.set(applyEvent.getStack()); return Map.entry(true, true); } @@ -689,9 +685,6 @@ public Map.Entry handlePurchase(Player player, AtomicReference break; } // } - var applyEvent = new BedwarsApplyPropertyToItem(game, player, newItem.get(), propertyData); - SBA.getPluginInstance().getServer().getPluginManager().callEvent(applyEvent); - newItem.set(applyEvent.getStack()); } else { diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java b/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java index c2e4c488..3964d669 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/PopupTower.java @@ -15,6 +15,7 @@ import org.screamingsandals.bedwars.api.RunningTeam; import org.screamingsandals.bedwars.api.game.Game; import org.screamingsandals.bedwars.api.game.GameStatus; +import org.screamingsandals.bedwars.utils.Sounds; import org.screamingsandals.lib.tasker.DefaultThreads; import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; @@ -40,6 +41,7 @@ public class PopupTower { private final Game game; private final Material material; + private final byte legacyData; private final Location centerPoint; private final BlockFace placementFace; private final List enterancelocation = new ArrayList<>(); @@ -66,41 +68,41 @@ public void createTower() { Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> { // second platform final Block secondPlatform = centerPoint.getBlock().getRelative(BlockFace.UP, 5); - placeBlock(secondPlatform.getLocation(), material); - pillarSides.forEach(blockFace -> placeBlock(secondPlatform.getRelative(blockFace).getLocation(), material)); + placeBlock(secondPlatform.getLocation(), material, legacyData); + pillarSides.forEach(blockFace -> placeBlock(secondPlatform.getRelative(blockFace).getLocation(), material, legacyData)); - placeBlock(secondPlatform.getRelative(BlockFace.NORTH_WEST).getLocation(), material); - placeBlock(secondPlatform.getRelative(BlockFace.NORTH_EAST).getLocation(), material); - placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_WEST).getLocation(), material); - placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_EAST).getLocation(), material); + placeBlock(secondPlatform.getRelative(BlockFace.NORTH_WEST).getLocation(), material, legacyData); + placeBlock(secondPlatform.getRelative(BlockFace.NORTH_EAST).getLocation(), material, legacyData); + placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_WEST).getLocation(), material, legacyData); + placeBlock(secondPlatform.getRelative(BlockFace.SOUTH_EAST).getLocation(), material, legacyData); final var northWestCornerBlock = secondPlatform.getRelative(BlockFace.NORTH_WEST, 2).getRelative(BlockFace.UP); - placeBlock(northWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material); - placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material); - placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material); - placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material); - placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material); + placeBlock(northWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData); + placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material, legacyData); + placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material, legacyData); + placeBlock(northWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material, legacyData); + placeBlock(northWestCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material, legacyData); final var northEastCornerBlock = secondPlatform.getRelative(BlockFace.NORTH_EAST, 2).getRelative(BlockFace.UP); - placeBlock(northEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material); - placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material); - placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material); - placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material); - placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material); + placeBlock(northEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData); + placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material, legacyData); + placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getLocation(), material, legacyData); + placeBlock(northEastCornerBlock.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).getLocation(), material, legacyData); + placeBlock(northEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material, legacyData); final var southWestCornerBlock = secondPlatform.getRelative(BlockFace.SOUTH_WEST, 2).getRelative(BlockFace.UP); - placeBlock(southWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material); - placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material); - placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material); - placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material); - placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material); + placeBlock(southWestCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData); + placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getLocation(), material, legacyData); + placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material, legacyData); + placeBlock(southWestCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material, legacyData); + placeBlock(southWestCornerBlock.getRelative(BlockFace.WEST).getRelative(BlockFace.UP).getLocation(), material, legacyData); final var southEastCornerBlock = secondPlatform.getRelative(BlockFace.SOUTH_EAST, 2).getRelative(BlockFace.UP); - placeBlock(southEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material); - placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material); - placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material); - placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material); - placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material); + placeBlock(southEastCornerBlock.getRelative(BlockFace.DOWN).getLocation(), material, legacyData); + placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), material, legacyData); + placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getLocation(), material, legacyData); + placeBlock(southEastCornerBlock.getRelative(BlockFace.EAST).getRelative(BlockFace.UP).getLocation(), material, legacyData); + placeBlock(southEastCornerBlock.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).getLocation(), material, legacyData); // connection blocks placeRowAnimated(3, northWestCornerBlock.getRelative(BlockFace.NORTH).getLocation(), BlockFace.EAST, 1); @@ -108,8 +110,8 @@ public void createTower() { placeRowAnimated(4, southWestCornerBlock.getRelative(BlockFace.SOUTH_WEST).getLocation(), BlockFace.NORTH, 1); placeRowAnimated(4, southEastCornerBlock.getRelative(BlockFace.EAST).getLocation(), BlockFace.NORTH, 1); - placeBlock(secondPlatform.getRelative(placementFace, 3).getRelative(BlockFace.UP, 2).getLocation(), material); - placeBlock(secondPlatform.getRelative(placementFace.getOppositeFace(), 3).getRelative(BlockFace.UP, 2).getLocation(), material); + placeBlock(secondPlatform.getRelative(placementFace, 3).getRelative(BlockFace.UP, 2).getLocation(), material, legacyData); + placeBlock(secondPlatform.getRelative(placementFace.getOppositeFace(), 3).getRelative(BlockFace.UP, 2).getLocation(), material, legacyData); final Location firstLadderBlock = centerPoint.getBlock().getRelative(placementFace).getLocation(); placeLadderRow(5, firstLadderBlock, BlockFace.UP, placementFace.getOppositeFace()); @@ -126,7 +128,7 @@ public void placeRowAnimated(int length, Location loc, BlockFace face, int delay for (int i = 0; i < length; i++) { lastLoc = lastLoc.getBlock().getRelative(face).getLocation(); Location finalLastLoc = lastLoc; - Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> placeBlock(finalLastLoc, material), (delay += 1), TaskerTime.TICKS); + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> placeBlock(finalLastLoc, material, legacyData), (delay += 1), TaskerTime.TICKS); } } @@ -171,12 +173,12 @@ public void placeLadderRow(int length, Location loc, BlockFace face, BlockFace l } else { Reflect.getMethod(ladder, "setData", byte.class).invoke(faceToByte.get(ladderFace)); } - Objects.requireNonNull(loc.getWorld()).playSound(loc, Sound.BLOCK_STONE_PLACE, 1, 1); + Sounds.playSound(loc, "BLOCK_STONE_PLACE", Sounds.BLOCK_STONE_BREAK, 1, 1); } } - public void placeBlock(Location loc, Material mat) { - if (!isLocationSafe(loc)) { + public void placeBlock(Location loc, Material mat, byte legacyData) { + if (!isLocationSafe(loc) || !game.isLocationInArena(loc)) { return; } if (game.getStatus() != GameStatus.RUNNING) { @@ -184,8 +186,14 @@ public void placeBlock(Location loc, Material mat) { } game.getRegion().removeBlockBuiltDuringGame(loc); loc.getBlock().setType(mat); + + if (Main.isLegacy() && legacyData != 0) { + var block = loc.getBlock(); + Reflect.getMethod(block, "setData", byte.class).invoke(legacyData); + } + game.getRegion().addBuiltDuringGame(loc); - loc.getWorld().playSound(loc, Sound.BLOCK_STONE_PLACE, 1, 1); + Sounds.playSound(loc, "BLOCK_STONE_PLACE", Sounds.BLOCK_STONE_BREAK, 1, 1); } public boolean isLocationSafe(Location location) { diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/listener/BridgeEggListener.java b/plugin/src/main/java/io/github/pronze/sba/specials/listener/BridgeEggListener.java index 8e77adaf..e2e4f640 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/listener/BridgeEggListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/listener/BridgeEggListener.java @@ -3,6 +3,7 @@ import io.github.pronze.sba.SBA; import io.github.pronze.sba.specials.runners.BridgeEggRunnable; import io.github.pronze.sba.utils.SBAUtil; +import org.bukkit.Material; import org.bukkit.entity.Egg; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -58,7 +59,19 @@ public void onEggUse(PlayerInteractEvent event) { String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, BRIDGE_EGG_PREFIX); if (unhidden != null) { event.setCancelled(true); - stack.setAmount(stack.getAmount() - 1); + if (stack.getAmount() > 1) { + stack.setAmount(stack.getAmount() - 1); + } else { + try { + if (player.getInventory().getItemInOffHand().equals(stack)) { + player.getInventory().setItemInOffHand(new ItemStack(Material.AIR)); + } else { + player.getInventory().remove(stack); + } + } catch (Throwable e) { + player.getInventory().remove(stack); + } + } player.updateInventory(); final var egg = player.launchProjectile(Egg.class); final var playerTeam = game.getTeamOfPlayer(player); diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/listener/PopupTowerListener.java b/plugin/src/main/java/io/github/pronze/sba/specials/listener/PopupTowerListener.java index 26874cd6..bf255633 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/listener/PopupTowerListener.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/listener/PopupTowerListener.java @@ -5,6 +5,7 @@ import io.github.pronze.sba.specials.PopupTower; import io.github.pronze.sba.specials.SpawnerProtection; import io.github.pronze.sba.utils.SBAUtil; +import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -54,13 +55,27 @@ public void onPopupTowerUse(PlayerInteractEvent event) { String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, POPUP_TOWER_PREFIX); if (unhidden != null) { event.setCancelled(true); - stack.setAmount(stack.getAmount() - 1); + if (stack.getAmount() > 1) { + stack.setAmount(stack.getAmount() - 1); + } else { + try { + if (player.getInventory().getItemInOffHand().equals(stack)) { + player.getInventory().setItemInOffHand(new ItemStack(Material.AIR)); + } else { + player.getInventory().remove(stack); + } + } catch (Throwable e) { + player.getInventory().remove(stack); + } + } player.updateInventory(); final var team = game.getTeamOfPlayer(player); final var playerFace = SBAUtil.yawToFace(player.getLocation().getYaw(), false); + final var wool = TeamColor.fromApiColor(team.getColor()).getWool(); PopupTower tower = new PopupTower( game, - TeamColor.fromApiColor(team.getColor()).getWool().getType(), + wool.getType(), + Main.isLegacy() ? wool.getData().getData() : 0, player.getLocation().getBlock().getRelative(playerFace).getRelative(BlockFace.DOWN) .getLocation(), playerFace); diff --git a/plugin/src/main/java/io/github/pronze/sba/specials/runners/BridgeEggRunnable.java b/plugin/src/main/java/io/github/pronze/sba/specials/runners/BridgeEggRunnable.java index 18957fa1..e4bfefca 100644 --- a/plugin/src/main/java/io/github/pronze/sba/specials/runners/BridgeEggRunnable.java +++ b/plugin/src/main/java/io/github/pronze/sba/specials/runners/BridgeEggRunnable.java @@ -17,6 +17,7 @@ import org.screamingsandals.bedwars.api.game.GameStatus; import org.screamingsandals.bedwars.game.TeamColor; import org.screamingsandals.bedwars.utils.Sounds; +import org.screamingsandals.lib.utils.reflect.Reflect; public class BridgeEggRunnable extends BukkitRunnable { @Getter @@ -26,13 +27,16 @@ public class BridgeEggRunnable extends BukkitRunnable { private final Game game; private final RunningTeam team; private final Material wool; + private final byte legacyData; public BridgeEggRunnable(Egg egg, RunningTeam team, Player thrower, Game game) { this.egg = egg; this.team = team; this.thrower = thrower; this.game = game; - this.wool = TeamColor.fromApiColor(team.getColor()).getWool().getType(); + var wool = TeamColor.fromApiColor(team.getColor()).getWool(); + this.wool = wool.getType(); + this.legacyData = Main.isLegacy() ? wool.getData().getData() : 0; task = runTaskTimer(SBA.getPluginInstance(), 0L, 1L); } @@ -59,8 +63,13 @@ public void run() { } public void setBlock(Block block) { - if (block.getType() == Material.AIR) { + if (block.getType() == Material.AIR && game.isLocationInArena(block.getLocation())) { block.setType(wool); + + if (Main.isLegacy() && legacyData != 0) { + Reflect.getMethod(block, "setData", byte.class).invoke(legacyData); + } + game.getRegion().addBuiltDuringGame(block.getLocation()); Sounds.playSound(block.getLocation(), "ENTITY_CHICKEN_EGG", Sounds.ENTITY_CHICKEN_EGG, 1, 1); } From e0d4cb236fee229b439788ac3a929085e95462ef Mon Sep 17 00:00:00 2001 From: Jonathan Boisclair Date: Fri, 17 Nov 2023 07:46:00 -0500 Subject: [PATCH 3/3] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6ac055bd..cd4f4960 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -SBA_VERSION=1.5.12 +SBA_VERSION=1.5.12.1 PAPER_LEGACY_VERSION=1.16.5 BEDWARS_VERSION=0.2.30 CLOUD_COMMANDS_VERSION=1.6.2