diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 78cdba3..0a54df8 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -1,40 +1,40 @@
# Pull Request
## Description
+###### _- Please provide a brief description of the changes introduced by this pull request._
-Please provide a brief description of the changes introduced by this pull request.
-
+-
+___
## Related Issues
+###### _- List any related issues that this pull request addresses or resolves._
-- List any related issues that this pull request addresses or resolves.
-
+-
+___
## Checklist
-
-Please review and check the following before submitting your pull request:
+### Please review and check the following before submitting your pull request:
- [ ] I have read and followed the [Contributing Guidelines](../CONTRIBUTING.md).
- [ ] My code follows the established [Code Style](../CONTRIBUTING.md#code-style).
- [ ] I have added appropriate comments and documentation.
-- [ ] I have written unit tests for my changes (if applicable).
- [ ] My changes pass the continuous integration tests.
- [ ] I have reviewed and updated the documentation if necessary.
- [ ] I have checked for and resolved any merge conflicts.
-
+- [ ] I have tested my changes locally.
+- [ ] My code does not significantly impact the performance of any existing features in a negative way.
+---
## Security
+### Please ensure that your changes adhere to our [Security Policy](../SECURITY.md) and do not introduce security vulnerabilities.
-Please ensure that your changes adhere to our [Security Policy](../SECURITY.md) and do not introduce security vulnerabilities.
+- [ ] My code does not house any security vulnerabilities, backdoors or any other malicious code.
+___
+## Screenshots (if applicable, delete if not applicable)
+###### _- Include any relevant screenshots or visual representations of your changes._
-## Reviewers
-
-Assign reviewers to your pull request.
-
-## Screenshots (if applicable)
-
-Include any relevant screenshots or visual representations of your changes.
+___
## Additional Notes
+###### _- Provide any additional information or context that reviewers or maintainers may find helpful._
-Provide any additional information or context that reviewers or maintainers may find helpful.
-
-## By submitting this pull request, I confirm that my contribution is made under the terms of the project's [LICENSE](../LICENSE.md).
+___
+## By submitting this pull request, I confirm that my contribution is made under the terms of the project's [LICENSE](../LICENSE.md).
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index e75b143..bac4063 100644
--- a/pom.xml
+++ b/pom.xml
@@ -224,7 +224,7 @@
org.junit.jupiter
junit-jupiter
- 5.10.2
+ 5.10.3
test
@@ -248,7 +248,7 @@
de.tr7zw
item-nbt-api
- 2.12.4
+ 2.13.1
diff --git a/src/main/java/org/gecko/spigotadmintoys/commands/SetRadiusLimitCommand.java b/src/main/java/org/gecko/spigotadmintoys/commands/SetRadiusLimitCommand.java
index 2cf0fd8..7053fe4 100644
--- a/src/main/java/org/gecko/spigotadmintoys/commands/SetRadiusLimitCommand.java
+++ b/src/main/java/org/gecko/spigotadmintoys/commands/SetRadiusLimitCommand.java
@@ -1,5 +1,6 @@
package org.gecko.spigotadmintoys.commands;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -42,14 +43,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
if (operation.equals("tnt")) {
+ int oldLimit = setAndGet.getTntRadiusLimit() - 2;
setAndGet.setTntRadiusLimit(newLimit); // Use the setter method for TNT operations
- player.sendMessage("TNT radius set to " + newLimit);
+ player.sendMessage("TNT radius set from " + ChatColor.RED + oldLimit + ChatColor.RESET + " to " + ChatColor.GREEN + newLimit + newLimit);
} else if (operation.equals(PLAYER)) {
+ int oldLimit = setAndGet.getRadiusLimit() - 2;
setAndGet.setRadiusLimit(newLimit); // Use the setter method for player operations
- player.sendMessage("Player operation limit set to " + newLimit);
+ player.sendMessage("Player operation limit set from " + ChatColor.RED + oldLimit + ChatColor.RESET + " to " + ChatColor.GREEN + newLimit);
} else {
- setAndGet.setCreeperLimit(newLimit);
- player.sendMessage("Creeper radius limit set to " + newLimit);
+ int oldLimit = setAndGet.getCreeperRadiusLimit() - 2;
+ setAndGet.setCreeperLimit(newLimit); // Use the setter method for creeper operations
+ player.sendMessage("Creeper radius limit set from" + ChatColor.RED + oldLimit + ChatColor.RESET + " to " + ChatColor.GREEN + newLimit);
}
} catch (NumberFormatException e) {
player.sendMessage("Please specify a valid integer.");
diff --git a/src/main/java/org/gecko/spigotadmintoys/data/ConfigurationManager.java b/src/main/java/org/gecko/spigotadmintoys/data/ConfigurationManager.java
index 4b8acf7..1463a14 100644
--- a/src/main/java/org/gecko/spigotadmintoys/data/ConfigurationManager.java
+++ b/src/main/java/org/gecko/spigotadmintoys/data/ConfigurationManager.java
@@ -25,8 +25,8 @@ public class ConfigurationManager {
public static final String CREATED = "Config file created!";
private final File configFile;
private final Logger logger = Logger.getLogger(ConfigurationManager.class.getName());
- private FileConfiguration config;
private final SetAndGet setAndGet;
+ private FileConfiguration config;
public ConfigurationManager(SetAndGet setAndGet) {
this.setAndGet = setAndGet;
diff --git a/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java b/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java
index 74dc63b..f6edaa5 100644
--- a/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java
+++ b/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.gui;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -14,6 +15,8 @@
import org.gecko.spigotadmintoys.data.ConfigurationManager;
import org.gecko.spigotadmintoys.logic.SetAndGet;
+import java.util.function.Function;
+
public class ConfigGUI implements Listener {
public static final String ENABLE_BUCKET = "Enable Bucket";
@@ -41,7 +44,6 @@ public class ConfigGUI implements Listener {
private int currentPage = 0;
-
public ConfigGUI(SetAndGet setAndGet) {
configManager = setAndGet.getConfigManager();
config = configManager.getConfig();
@@ -131,9 +133,8 @@ private boolean isClickEventValid(InventoryClickEvent event) {
}
private void handleItemClick(Player player, ItemStack clickedItem) {
- if (clickedItem != null && (clickedItem.getType() == Material.INK_SACK || clickedItem.getType() == Material.PAPER || clickedItem.getType() == Material.CONCRETE ||clickedItem.getType() == Material.ARROW)) {
- NBTItem nbtItem = new NBTItem(clickedItem);
- String identifier = nbtItem.getString("Ident");
+ if (clickedItem != null && (clickedItem.getType() == Material.INK_SACK || clickedItem.getType() == Material.PAPER || clickedItem.getType() == Material.CONCRETE || clickedItem.getType() == Material.ARROW)) {
+ String identifier = NBT.get(clickedItem, (Function) nbt -> nbt.getString("Ident"));
short data = clickedItem.getDurability();
if (handleButtonFeatures(player, identifier, data)) {
diff --git a/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java b/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java
index e67373c..8627587 100644
--- a/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java
+++ b/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.gui.logic;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -8,6 +9,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.function.Consumer;
public class CreateButtonItem {
@@ -28,9 +30,8 @@ public ItemStack createButtonItem(Material material, String name, short data, St
meta.setLore(loreToString);
item.setItemMeta(meta);
- NBTItem nbtItem = new NBTItem(item);
- nbtItem.setString("Ident", ident);
+ NBT.modify(item, (Consumer) nbt -> nbt.setString("Ident", ident));
- return nbtItem.getItem();
+ return item;
}
}
diff --git a/src/main/java/org/gecko/spigotadmintoys/gui/presets/config/Assign.java b/src/main/java/org/gecko/spigotadmintoys/gui/presets/config/Assign.java
index 3fbbb91..1d8cbc5 100644
--- a/src/main/java/org/gecko/spigotadmintoys/gui/presets/config/Assign.java
+++ b/src/main/java/org/gecko/spigotadmintoys/gui/presets/config/Assign.java
@@ -27,14 +27,13 @@ public void assignPage(int page) {
this.playerLimit = setAndGet.getRadiusLimit() - 2;
this.creeperLimit = setAndGet.getCreeperRadiusLimit() - 2;
this.tntLimit = setAndGet.getTntRadiusLimit() - 2;
- switch (page) {
- case 0:
- gui1();
- break;
- case 1:
- gui2();
- break;
+
+ if (page == 0) {
+ gui1();
+ } else if (page == 1) {
+ gui2();
}
+
gui.setItem(8, createButtonItem(Material.PAPER, ChatColor.RESET + "" + ChatColor.RED + "Reset config", (short) 0, null, "Reset"));
}
diff --git a/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java b/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java
index e823aae..bdbd2e0 100644
--- a/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java
+++ b/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.items;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -8,6 +9,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.function.Consumer;
public class TriggerItems {
@@ -21,9 +23,8 @@ public ItemStack createCustomItem(Material material, String name, short data, St
meta.setLore(loreToList);
item.setItemMeta(meta);
- NBTItem nbtItem = new NBTItem(item);
- nbtItem.setString("Ident", ident);
+ NBT.modify(item, (Consumer) nbt -> nbt.setString("Ident", ident));
- return nbtItem.getItem();
+ return item;
}
}
diff --git a/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java b/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java
index cb00208..3e23a38 100644
--- a/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java
+++ b/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.items.weapons;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
@@ -12,6 +13,8 @@
import org.gecko.spigotadmintoys.enchantments.enchants.weapons.bows.BowListener;
import org.gecko.spigotadmintoys.items.TriggerItems;
+import java.util.function.Function;
+
public class Shortbow implements Listener {
public static final String SHORTBOWCONST = "Shortbow";
@@ -31,8 +34,7 @@ public void onPlayerBowClick(PlayerInteractEvent event) {
return;
}
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
if (!identifier.equals(SHORTBOWCONST)) {
return;
diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java
index 947305f..18c80b4 100644
--- a/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java
+++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.listeners;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -15,10 +16,12 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.spigotadmintoys.Main;
+import org.gecko.spigotadmintoys.logic.IterateBlocks;
import org.gecko.spigotadmintoys.logic.Scale;
import org.gecko.spigotadmintoys.logic.SetAndGet;
import java.util.*;
+import java.util.function.Function;
public class BarrierListener implements Listener {
@@ -60,8 +63,7 @@ public void barrierBreakEventHandler(BlockBreakEvent event) {
BucketListener bucketListener = setAndGet.getBucketListener();
BedrockListener bedrockListener = setAndGet.getBedrockListener();
WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener();
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
radiusLimit = setAndGet.getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
showRemoval = setAndGet.getShowRemoval();
@@ -98,6 +100,7 @@ private void processBlockRemoval() {
Set nextSet = new HashSet<>();
boolean limitReachedThisIteration = false; // Variable to track whether the limit was reached this iteration
String bR = "Block removal: ";
+ IterateBlocks iterateBlocks = setAndGet.getIterateBlocks();
for (Block block : blocksToProcess) {
if (processedBlocks.contains(block)) {
continue;
@@ -138,7 +141,7 @@ private void processBlockRemoval() {
// Iterate through neighboring blocks and add them to the next set
for (int i = -1; i <= 1; i++) {
if (i == 0) continue; // Skip the current block
- setAndGet.getIterateBlocks().iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
+ iterateBlocks.iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
}
processedBlocks.add(block);
}
@@ -183,19 +186,11 @@ public void displaySummary() {
String removed = "Removed ";
String dA = " dirt blocks and ";
String bB = " barrier blocks.";
- if (barrierRemovedCount == 0 && grassRemovedCount == 0 && dirtRemovedCount > 0) {
- player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + " dirt blocks.");
- } else if (barrierRemovedCount == 0 && dirtRemovedCount == 0 && grassRemovedCount > 0) {
- player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks.");
- } else if (barrierRemovedCount == 0 && grassRemovedCount > 0 && dirtRemovedCount > 0) {
- player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks and " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + " dirt blocks.");
- } else if (barrierRemovedCount > 0 && grassRemovedCount > 0 && dirtRemovedCount > 0) {
+
+ if (barrierRemovedCount > 0 || grassRemovedCount > 0 || dirtRemovedCount > 0) {
player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks, " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + dA + ChatColor.RED + barrierRemovedCount + ChatColor.GREEN + bB);
- } else if (barrierRemovedCount > 0 && grassRemovedCount > 0 && dirtRemovedCount == 0) {
- player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks and " + ChatColor.RED + barrierRemovedCount + ChatColor.GREEN + bB);
- } else if (barrierRemovedCount > 0 && grassRemovedCount == 0 && dirtRemovedCount > 0) {
- player.sendMessage(ChatColor.GREEN + removed + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + dA + ChatColor.RED + barrierRemovedCount + ChatColor.GREEN + bB);
}
+
// Display the block removal summary in the console
Bukkit.getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + player.getName() + ChatColor.GREEN + " removed " + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks, " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + dA + ChatColor.RED + barrierRemovedCount + ChatColor.GREEN + bB);
if (!showRemoval) {
@@ -218,7 +213,7 @@ private void removeMarkedBlocks() {
}
cleanup();
} else {
- scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "barrier");
+ scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "barrier", this::cleanRemove);
// If there are more blocks to remove, schedule the next batch
if (!markedBlocks.isEmpty()) {
diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java
index b326425..e911044 100644
--- a/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java
+++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.listeners;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -21,7 +22,10 @@
import org.gecko.spigotadmintoys.logic.Scale;
import org.gecko.spigotadmintoys.logic.SetAndGet;
-import java.util.*;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Function;
public class BedrockListener implements Listener {
@@ -65,7 +69,7 @@ private void addIfValid(Block block, Set nextSet) {
TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.add(0.5, 0.5, 0.5), EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks(20);
if (tntListener.getTntPlayer() != null) {
- tntPrimed.setMetadata(SOURCE, new FixedMetadataValue(JavaPlugin.getPlugin(Main.class), tntListener.getTntPlayer().getName()));
+ tntPrimed.setMetadata(SOURCE, new FixedMetadataValue(JavaPlugin.getPlugin(Main.class), tntListener.getTntPlayer().getName()));
}
nextSet.add(block);
}
@@ -127,17 +131,11 @@ private void bedrockExplosionSource() {
Bukkit.getConsoleSender().sendMessage("Real player not OP");
return;
}
- } else {
- Player metaPlayer = Bukkit.getPlayer(tntListener.getTnt().getMetadata(SOURCE).getFirst().asString());
- if (metaPlayer == null) {
- Bukkit.getConsoleSender().sendMessage("Meta player not found");
- return;
- }
- if (!metaPlayer.isOp()) {
- Bukkit.getConsoleSender().sendMessage("Meta player not OP");
- return;
- }
+ } else if (Bukkit.getPlayer(tntListener.getTnt().getMetadata(SOURCE).getFirst().asString()) instanceof Player metaPlayer && !metaPlayer.isOp()) {
+ Bukkit.getConsoleSender().sendMessage("Meta player not OP");
+ return;
}
+
allRemovalActive = false;
explosionTrigger = true;
limitReached = false;
@@ -172,8 +170,7 @@ private void bedrockPlayerSource(BlockBreakEvent event) {
return;
}
Player player = event.getPlayer();
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK && identifier.equalsIgnoreCase("Custom Bedrock") && (!IMMUTABLE_MATERIALS.contains(event.getBlock().getType()))) {
allRemovalActive = false;
@@ -316,7 +313,7 @@ private void removeMarkedBlocks() {
clearAll();
return;
} else {
- scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bedrock");
+ scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bedrock", null);
}
setAndGet.getBlockRemovalScheduler().scheduleBlockRemoval(markedBlocks, removedBlocks, currentRemovingPlayer, this::removeMarkedBlocks, this::clearAll, repetitions, this::lowerRepetitionsAndToggleRepeated);
diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java
index be80430..fb6fa7c 100644
--- a/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java
+++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.listeners;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -15,10 +16,12 @@
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.spigotadmintoys.Main;
+import org.gecko.spigotadmintoys.logic.IterateBlocks;
import org.gecko.spigotadmintoys.logic.Scale;
import org.gecko.spigotadmintoys.logic.SetAndGet;
import java.util.*;
+import java.util.function.Function;
public class BucketListener implements Listener {
@@ -62,8 +65,7 @@ public void onBucketFill(PlayerBucketFillEvent event) {
BarrierListener barrierListener = setAndGet.getBarrierListener();
BedrockListener bedrockListener = setAndGet.getBedrockListener();
WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener();
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
radiusLimit = setAndGet.getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
showRemoval = setAndGet.getShowRemoval();
@@ -103,6 +105,7 @@ private void processWaterRemoval() {
Set nextSet = new HashSet<>();
boolean limitReachedThisIteration = false; // Variable to track whether the limit was reached this iteration
String wR = "Wauh removal: ";
+ IterateBlocks iterateBlocks = setAndGet.getIterateBlocks();
for (Block block : blocksToProcess) {
if (processedBlocks.contains(block)) {
continue;
@@ -142,7 +145,7 @@ private void processWaterRemoval() {
} else {
markedBlocks.add(block);
}
- setAndGet.getIterateBlocks().iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
+ iterateBlocks.iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
processedBlocks.add(block);
}
@@ -210,7 +213,7 @@ private void removeReplacedBlocks() {
processedBlocks.clear();
return;
} else {
- scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bucket");
+ scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bucket", this::cleanRemove);
}
// If there are more blocks to remove, schedule the next batch
diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java b/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java
index 42d8d30..48cac0b 100644
--- a/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java
+++ b/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.listeners;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -15,17 +16,23 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.spigotadmintoys.Main;
+import org.gecko.spigotadmintoys.logic.IterateBlocks;
import org.gecko.spigotadmintoys.logic.Scale;
import org.gecko.spigotadmintoys.logic.SetAndGet;
-import java.util.*;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Function;
public class SphereMaker implements Listener {
- private Set blocksToProcess = new HashSet<>();
+ private static final Set IMMUTABLE_MATERIALS = EnumSet.of(Material.BEDROCK, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.AIR);
private final Set processedBlocks = new HashSet<>();
private final Set markedBlocks = new HashSet<>();
private final Set removedBlocks = new HashSet<>();
+ private final SetAndGet setAndGet;
+ private Set blocksToProcess = new HashSet<>();
private Location clickedLocation;
private Player currentRemovingPlayer;
private int radiusLimit;
@@ -35,8 +42,6 @@ public class SphereMaker implements Listener {
private boolean showRemoval;
private boolean sphereingActive;
private boolean stopSphereing;
- private final SetAndGet setAndGet;
- private static final Set IMMUTABLE_MATERIALS = EnumSet.of(Material.BEDROCK, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.TNT, Material.AIR);
private int repetitions;
private boolean repeated;
@@ -61,8 +66,7 @@ public void onBlockBreak(BlockBreakEvent event) {
BedrockListener bedrockListener = setAndGet.getBedrockListener();
BucketListener bucketListener = setAndGet.getBucketListener();
WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener();
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
radiusLimit = setAndGet.getRadiusLimit();
realradiusLimit = setAndGet.getRadiusLimit() - 2;
if (realradiusLimit > 1 && !barrierListener.isBlockRemovalActive() && !bedrockListener.isAllRemovalActive() && !bucketListener.isWauhRemovalActive() && !waterBucketListener.isTsunamiActive() && !IMMUTABLE_MATERIALS.contains(event.getBlock().getType()) && identifier.equals("SphereMaker")) {
@@ -94,6 +98,7 @@ private void processSphereing() {
Set nextSet = new HashSet<>();
String sphereing = "Sphereing: ";
+ IterateBlocks iterateBlocks = setAndGet.getIterateBlocks();
for (Block block : blocksToProcess) {
if (processedBlocks.contains(block) || (int) clickedLocation.distance(block.getLocation()) + 1 > radiusLimit - 3) {
continue;
@@ -119,7 +124,7 @@ private void processSphereing() {
} else {
markedBlocks.add(block);
}
- setAndGet.getIterateBlocks().iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, true);
+ iterateBlocks.iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, true);
processedBlocks.add(block);
}
@@ -162,7 +167,7 @@ private void removeMarkedBlocks() {
clear();
return;
} else {
- scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "sphere");
+ scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "sphere", null);
}
setAndGet.getBlockRemovalScheduler().scheduleBlockRemoval(markedBlocks, removedBlocks, currentRemovingPlayer, this::removeMarkedBlocks, this::clear, repetitions, this::lowerRepetitionsAndToggleRepeated);
}
diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java
index 7a4ac98..862aac7 100644
--- a/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java
+++ b/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java
@@ -1,6 +1,7 @@
package org.gecko.spigotadmintoys.listeners;
-import de.tr7zw.changeme.nbtapi.NBTItem;
+import de.tr7zw.changeme.nbtapi.NBT;
+import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@@ -15,10 +16,12 @@
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.spigotadmintoys.Main;
+import org.gecko.spigotadmintoys.logic.IterateBlocks;
import org.gecko.spigotadmintoys.logic.Scale;
import org.gecko.spigotadmintoys.logic.SetAndGet;
import java.util.*;
+import java.util.function.Function;
public class WaterBucketListener implements Listener {
@@ -59,8 +62,7 @@ public void tsunamiClick(PlayerBucketEmptyEvent event) {
BucketListener bucketListener = setAndGet.getBucketListener();
BarrierListener barrierListener = setAndGet.getBarrierListener();
BedrockListener bedrockListener = setAndGet.getBedrockListener();
- NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
- String identifier = nbtItem.getString("Ident");
+ String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident"));
radiusLimit = setAndGet.getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
showRemoval = setAndGet.getShowRemoval();
@@ -96,6 +98,7 @@ private void processTsunami() {
Set nextSet = new HashSet<>();
boolean limitReachedThisIteration = false; // Variable to track whether the limit was reached this iteration
String tsunami = "Tsunami: ";
+ IterateBlocks iterateBlocks = setAndGet.getIterateBlocks();
for (Block block : blocksToProcess) {
if (processedBlocks.contains(block)) {
continue;
@@ -130,7 +133,7 @@ private void processTsunami() {
// Iterate through neighboring blocks and add them to the next set
for (int i = -1; i <= 1; i++) {
if (i == 0) continue; // Skip the current block
- setAndGet.getIterateBlocks().iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
+ iterateBlocks.iterateBlocks(block, nextSet, IMMUTABLE_MATERIALS, false);
}
processedBlocks.add(block);
}
@@ -214,7 +217,7 @@ private void removeMarkedBlocks() {
removedBlocks.clear();
return;
} else {
- scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "wauh");
+ scale.scaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "wauh", this::cleanRemove);
}
// If there are more blocks to remove, schedule the next batch
diff --git a/src/main/java/org/gecko/spigotadmintoys/logic/CleanRemoveBedrock.java b/src/main/java/org/gecko/spigotadmintoys/logic/CleanRemoveBedrock.java
index de33811..d024db2 100644
--- a/src/main/java/org/gecko/spigotadmintoys/logic/CleanRemoveBedrock.java
+++ b/src/main/java/org/gecko/spigotadmintoys/logic/CleanRemoveBedrock.java
@@ -7,13 +7,11 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
public class CleanRemoveBedrock {
+ private static final Set fallingBlocks = EnumSet.of(Material.SAND, Material.GRAVEL);
private final SetAndGet setAndGet;
CleanRemoveBedrock(SetAndGet setAndGet) {
@@ -44,7 +42,7 @@ public void cleanRemoveBedrockFunction(int scaledBlocksPerIteration, Iterator markedBlocks, String source) {
-
- BucketListener bucketListener = setAndGet.getBucketListener();
- BarrierListener barrierListener = setAndGet.getBarrierListener();
- WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener();
-
+ public void scaleReverseLogic(int totalRemovedCount, int radiusLimit, Set markedBlocks, String source, BiConsumer> cleanRemoveMethod) {
// Set BLOCKS_PER_ITERATION dynamically based on the total count
int sqrtTotalBlocks = (int) (Math.sqrt(totalRemovedCount) * (Math.sqrt(radiusLimit) * 1.25));
int scaledBlocksPerIteration = Math.max(1, sqrtTotalBlocks);
@@ -29,14 +24,9 @@ public void scaleReverseLogic(int totalRemovedCount, int radiusLimit, Set
if (source.equalsIgnoreCase("bedrock") || source.equalsIgnoreCase("sphere")) {
setAndGet.getCleanRemoveBedrock().cleanRemoveBedrockFunction(scaledBlocksPerIteration, iterator, markedBlocks, source);
- } else if (source.equalsIgnoreCase("bucket")) {
- bucketListener.cleanRemove(scaledBlocksPerIteration, iterator);
- } else if (source.equalsIgnoreCase("barrier")) {
- barrierListener.cleanRemove(scaledBlocksPerIteration, iterator);
- } else if (source.equalsIgnoreCase("wauh")) {
- waterBucketListener.cleanRemove(scaledBlocksPerIteration, iterator);
+ return;
}
-
+ cleanRemoveMethod.accept(scaledBlocksPerIteration, iterator);
}
}
diff --git a/src/main/java/org/gecko/spigotadmintoys/logic/SetAndGet.java b/src/main/java/org/gecko/spigotadmintoys/logic/SetAndGet.java
index 28c369f..ea7fb47 100644
--- a/src/main/java/org/gecko/spigotadmintoys/logic/SetAndGet.java
+++ b/src/main/java/org/gecko/spigotadmintoys/logic/SetAndGet.java
@@ -25,12 +25,12 @@ public class SetAndGet {
private final CreateButtonItem createButtonItem;
private final Assign assign;
private final ConfigGUI configGUI;
+ private final CleanRemoveBedrock cleanRemoveBedrock;
+ private final BlockRemovalScheduler blockRemovalScheduler;
FileConfiguration config;
private int playerRadiusLimit;
private int tntRadiusLimit;
private int creeperRadiusLimit;
- private final CleanRemoveBedrock cleanRemoveBedrock;
- private final BlockRemovalScheduler blockRemovalScheduler;
public SetAndGet() {
this.configManager = new ConfigurationManager(this);