From d9612b0cfe24acc323bd0878483363dbfb6859ca Mon Sep 17 00:00:00 2001 From: ceze88 Date: Wed, 20 Mar 2024 12:36:33 +0100 Subject: [PATCH 1/5] NPE fix --- .../listeners/BlockListeners.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java index dd9c33a..451d59b 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java @@ -261,7 +261,10 @@ public class BlockListeners implements Listener { CreatureSpawner cs = (CreatureSpawner) block.getState(); - EntityType blockType = cs.getSpawnedType(); + EntityType spawnedEntityType = cs.getSpawnedType(); + + //Empty spawners return null?? It is annotated as @NotNull + if (spawnedEntityType == null) return; Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInHand(); @@ -280,7 +283,7 @@ public class BlockListeners implements Listener { remove = true; } - SpawnerBreakEvent breakEvent = new SpawnerBreakEvent(player, block, blockType, amt); + SpawnerBreakEvent breakEvent = new SpawnerBreakEvent(player, block, spawnedEntityType, amt); Bukkit.getPluginManager().callEvent(breakEvent); if (breakEvent.isCancelled()) return; @@ -297,7 +300,7 @@ public class BlockListeners implements Listener { } if (player.hasPermission("ultimatestacker.spawner.nosilkdrop") || item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && player.hasPermission("ultimatestacker.spawner.silktouch")) { - ItemStack spawner = Methods.getSpawnerItem(blockType, amt); + ItemStack spawner = Methods.getSpawnerItem(spawnedEntityType, amt); if (player.getInventory().firstEmpty() == -1 || !Settings.SPAWNERS_TO_INVENTORY.getBoolean()) block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), spawner); else From d88c61fc94ba55c5266fb376310c3dbd04461662 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sat, 23 Mar 2024 19:17:01 +0100 Subject: [PATCH 2/5] Fix concurrent modification exception --- .../com.craftaro.ultimatestacker/tasks/StackingTask.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/StackingTask.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/StackingTask.java index 04270f2..3c42abe 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/StackingTask.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/StackingTask.java @@ -89,12 +89,15 @@ public class StackingTask extends BukkitRunnable { //Filter non-stackable entities to improve performance on main thread entities.removeIf(this::isEntityNotStackable); - for (LivingEntity entity : entities) { + List remove = new ArrayList<>(); + for (LivingEntity entity : entities) { //Q: What can cause current modification exception here? // Check our WorldGuard flag. Boolean flag = WorldGuardHook.isEnabled() ? WorldGuardHook.getBooleanFlag(entity.getLocation(), "mob-stacking") : null; //Does this work async? - if (flag != null && !flag) - entities.removeIf(entity1 -> entity1.getUniqueId().equals(entity.getUniqueId())); + if (flag != null && !flag) { + remove.add(entity); + } } + entities.removeAll(remove); Bukkit.getScheduler().runTask(plugin, () -> { // Loop through the entities. From 1c79ce54854e7e2c46a04e82fd3c7ed1343e87cd Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sat, 23 Mar 2024 19:17:14 +0100 Subject: [PATCH 3/5] update package for core class --- .../java/com.craftaro.ultimatestacker/tasks/BreedingTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/BreedingTask.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/BreedingTask.java index e30d6b8..861a46f 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/BreedingTask.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/tasks/BreedingTask.java @@ -1,6 +1,6 @@ package com.craftaro.ultimatestacker.tasks; -import com.craftaro.core.task.TaskScheduler; +import com.craftaro.core.thread.TaskScheduler; import com.craftaro.ultimatestacker.UltimateStacker; import org.bukkit.entity.LivingEntity; From 29e675053911505ae69b559da1db91beabce5f66 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sat, 23 Mar 2024 19:17:44 +0100 Subject: [PATCH 4/5] Add stack all feature for spawners --- .../listeners/BlockListeners.java | 37 ++++++++++++++++++- .../settings/Settings.java | 3 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java index 451d59b..7c78174 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/listeners/BlockListeners.java @@ -181,7 +181,41 @@ public class BlockListeners implements Listener { if (itemType == blockType) { SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block); if (stack == null) return; - if (player.isSneaking()) return; + if (player.isSneaking()) { + //Add all to stack from hand + if (Settings.SNEAK_TO_ADD_ALL.getBoolean()) { + + //Redo this logic, if we have 10 items in hand and each item is 5 stack size, we need to take into consideration that what happens if we can only add 2 stack total in a stack? We have to remove one extra item and add one spawner with 3 stack back + int amountToAdd = Math.min(maxStackSize - stack.getAmount(), itemAmount * inHand.getAmount()); //Multiply by inHand.getAmount() to get the total amount of items in hand + int remaining = itemAmount * inHand.getAmount() - amountToAdd; //Calculate the remaining amount of items in hand + stack.setAmount(stack.getAmount() + amountToAdd); + plugin.updateHologram(stack); + plugin.getDataManager().save(stack); + if (remaining % itemAmount == 0) { //We don't have to worry about leftovers + if (player.getGameMode() != GameMode.CREATIVE) { + hand.takeItem(player, amountToAdd / itemAmount); + } + } else { + int fullStacks = amountToAdd / itemAmount; + int overflow = remaining % itemAmount; + //remove fullstacks-1 and add back overflow as a new item stack + if (player.getGameMode() != GameMode.CREATIVE) { + if (overflow > 0) { + hand.takeItem(player, fullStacks+1); + ItemStack overflowItem = Methods.getSpawnerItem(blockType, overflow); + if (player.getInventory().firstEmpty() == -1) { + block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), overflowItem); + } else { + player.getInventory().addItem(overflowItem); + } + } else { + hand.takeItem(player, fullStacks); + } + } + } + } + return; + } if (player.hasPermission("ultimatestacker.spawner.nostack") && !player.isOp()) { event.setCancelled(false); return; @@ -270,6 +304,7 @@ public class BlockListeners implements Listener { ItemStack item = player.getInventory().getItemInHand(); SpawnerStack stack = UltimateStackerApi.getSpawnerStackManager().getSpawner(block); + if (stack == null) return; event.setCancelled(true); diff --git a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/settings/Settings.java b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/settings/Settings.java index 58cf8b5..eccf5f8 100644 --- a/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/settings/Settings.java +++ b/UltimateStacker-Plugin/src/main/java/com.craftaro.ultimatestacker/settings/Settings.java @@ -239,6 +239,9 @@ public class Settings implements com.craftaro.ultimatestacker.api.Settings { public static final ConfigSetting SNEAK_FOR_STACK = new ConfigSetting(config, "Spawners.Sneak To Receive A Stacked Spawner", true, "Toggle ability to receive a stacked spawner when breaking a spawner while sneaking."); + public static final ConfigSetting SNEAK_TO_ADD_ALL = new ConfigSetting(config, "Spawners.Sneak To Add All", true, + "Should the player be able to add all spawners to the stack if they are sneaking?"); + public static final ConfigSetting SPAWNERS_DONT_EXPLODE = new ConfigSetting(config, "Spawners.Prevent Spawners From Exploding", false, "Should spawners not break when blown up?"); From e92d86a4c4235396da42830cc795db28acafe1d8 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Sat, 23 Mar 2024 13:29:07 -0500 Subject: [PATCH 5/5] version 3.1.5 --- UltimateStacker-API/pom.xml | 2 +- UltimateStacker-Plugin/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UltimateStacker-API/pom.xml b/UltimateStacker-API/pom.xml index c24721b..f4e6e5b 100644 --- a/UltimateStacker-API/pom.xml +++ b/UltimateStacker-API/pom.xml @@ -7,7 +7,7 @@ com.craftaro UltimateStacker-Parent - 3.1.4 + 3.1.5 UltimateStacker-API 1.0.0-SNAPSHOT diff --git a/UltimateStacker-Plugin/pom.xml b/UltimateStacker-Plugin/pom.xml index effe227..9e7997f 100644 --- a/UltimateStacker-Plugin/pom.xml +++ b/UltimateStacker-Plugin/pom.xml @@ -7,7 +7,7 @@ com.craftaro UltimateStacker-Parent - 3.1.4 + 3.1.5 UltimateStacker-Plugin diff --git a/pom.xml b/pom.xml index bfdc25b..92b56b4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.craftaro UltimateStacker-Parent pom - 3.1.4 + 3.1.5 UltimateStacker-API