From 6c81e725ad38d5ea986c793584dbf0142480b0bc Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 13:59:38 +0100 Subject: [PATCH 1/6] Added custom items They took my AI away from me :( --- .../gecko/wauh/commands/GiveCustomItems.java | 57 +++++++++++++++++++ .../java/org/gecko/wauh/gui/ConfigGUI.java | 17 +++--- .../org/gecko/wauh/items/TriggerItems.java | 28 +++++++++ .../gecko/wauh/listeners/BarrierListener.java | 5 +- 4 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/gecko/wauh/commands/GiveCustomItems.java create mode 100644 src/main/java/org/gecko/wauh/items/TriggerItems.java diff --git a/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java new file mode 100644 index 0000000..297fdf1 --- /dev/null +++ b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java @@ -0,0 +1,57 @@ +package org.gecko.wauh.commands; + +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.gecko.wauh.items.TriggerItems; + +import java.util.List; + +public class GiveCustomItems implements CommandExecutor, TabCompleter { + + private TriggerItems items; + private ItemStack createdItem; + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + createdItem = null; + items = new TriggerItems(); + if (sender instanceof Player) { + if (args.length == 1) { + String operation = args[0].toLowerCase(); + + if (operation.equals("bucket") || operation.equals("barrier") || operation.equals("bedrock") || operation.equals("tsunami")) { + if (operation.equals("bucket")) { + createdItem = items.createCustomItem(Material.BUCKET, "Water Drainer", (short) 0, "Removes all fluids", "Custom Bucket"); + ((Player) sender).getInventory().addItem(createdItem); + } else if (operation.equals("barrier")) { + createdItem = items.createCustomItem(Material.BARRIER, "Surface Remover", (short) 0, "Removes grass and dirt blocks", "Custom Barrier"); + ((Player) sender).getInventory().addItem(createdItem); + } else if (operation.equals("bedrock")) { + createdItem = items.createCustomItem(Material.BEDROCK, "Water Drainer", (short) 0, "Removes almost all blocks", "Custom Bedrock"); + ((Player) sender).getInventory().addItem(createdItem); + } else { + createdItem = items.createCustomItem(Material.WATER_BUCKET, "Water Drainer", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami"); + ((Player) sender).getInventory().addItem(createdItem); + } + } else return true; + } else { + sender.sendMessage("Usage: /givecustomitems [bucket/barrier/bedrock/tsunami]"); + return true; + } + } else { + sender.sendMessage("Only players can execute this command"); + return true; + } + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return null; + } +} diff --git a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java index bf0dbc3..3b75f18 100644 --- a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java +++ b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java @@ -111,11 +111,12 @@ private void fillBorders(ItemStack borderItem) { } - private ItemStack createButtonItem(Material material, String name, short data, List lore, String ident) { + private ItemStack createButtonItem(Material material, String name, short data, String lore, String ident) { + List loreToString = Collections.singletonList(lore); ItemStack item = new ItemStack(material, 1, data); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(name); - meta.setLore(lore); + meta.setLore(loreToString); item.setItemMeta(meta); NBTItem nbtItem = new NBTItem(item); @@ -129,17 +130,17 @@ public void openGUI(Player player) { int creeperLimit = plugin.getCreeperRadiusLimit() - 2; int tntLimit = plugin.getTntRadiusLimit() - 2; gui.setItem(9 + 1, createButtonItem(Material.BUCKET, ChatColor.RESET + "Liquid removal", (short) 0, null, null)); - gui.setItem(9 * 2 + 1, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null)); + gui.setItem(9 * 2 + 1, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null)); gui.setItem(9 + 2, createButtonItem(Material.BARRIER, ChatColor.RESET + "Surface removal", (short) 0, null, null)); - gui.setItem(9 * 2 + 2, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null)); + gui.setItem(9 * 2 + 2, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null)); gui.setItem(9 + 3, createButtonItem(Material.BEDROCK, ChatColor.RESET + "All block removal", (short) 0, null, null)); - gui.setItem(9 * 2 + 3, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null)); + gui.setItem(9 * 2 + 3, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null)); gui.setItem(9 + 4, createButtonItem(Material.WATER_BUCKET, ChatColor.RESET + "Tsunami", (short) 0, null, null)); - gui.setItem(9 * 2 + 4, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null)); + gui.setItem(9 * 2 + 4, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null)); gui.setItem(9 + 5, createButtonItem(Material.SKULL_ITEM, ChatColor.RESET + "Custom creeper explosions", (short) 4, null, null)); - gui.setItem(9 * 2 + 5, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(creeperLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the creeper radius limit."), null)); + gui.setItem(9 * 2 + 5, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(creeperLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the creeper radius limit.", null)); gui.setItem(9 + 6, createButtonItem(Material.TNT, ChatColor.RESET + "Custom TNT explosions", (short) 0, null, null)); - gui.setItem(9 * 2 + 6, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(tntLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the TNT radius limit."), null)); + gui.setItem(9 * 2 + 6, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(tntLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the TNT radius limit.", null)); player.openInventory(gui); } diff --git a/src/main/java/org/gecko/wauh/items/TriggerItems.java b/src/main/java/org/gecko/wauh/items/TriggerItems.java new file mode 100644 index 0000000..0389c5d --- /dev/null +++ b/src/main/java/org/gecko/wauh/items/TriggerItems.java @@ -0,0 +1,28 @@ +package org.gecko.wauh.items; + +import de.tr7zw.changeme.nbtapi.NBTItem; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Collections; +import java.util.List; + +public class TriggerItems { + + public ItemStack createCustomItem(Material material, String name, short data, String lore, String ident) { + ItemStack item = new ItemStack(material, 1, data); + lore = ChatColor.RESET + "" + ChatColor.DARK_PURPLE + lore; + List loreToList = Collections.singletonList(lore); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(name); + meta.setLore(loreToList); + item.setItemMeta(meta); + + NBTItem nbtItem = new NBTItem(item); + nbtItem.setString("Ident", ident); + + return nbtItem.getItem(); + } +} diff --git a/src/main/java/org/gecko/wauh/listeners/BarrierListener.java b/src/main/java/org/gecko/wauh/listeners/BarrierListener.java index 841db05..146c884 100644 --- a/src/main/java/org/gecko/wauh/listeners/BarrierListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BarrierListener.java @@ -1,5 +1,6 @@ package org.gecko.wauh.listeners; +import de.tr7zw.changeme.nbtapi.NBTItem; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -59,6 +60,8 @@ public void barrierBreakEventHandler(BlockBreakEvent event) { BucketListener bucketListener = Main.getPlugin(Main.class).getBucketListener(); BedrockListener bedrockListener = Main.getPlugin(Main.class).getBedrockListener(); WaterBucketListener waterBucketListener = Main.getPlugin(Main.class).getWaterBucketListener(); + NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); + String identifier = nbtItem.getString("Ident"); radiusLimit = Main.getPlugin(Main.class).getRadiusLimit(); realRadiusLimit = radiusLimit - 2; if (realRadiusLimit > 1) { @@ -66,7 +69,7 @@ public void barrierBreakEventHandler(BlockBreakEvent event) { Player player = event.getPlayer(); if (IMMUTABLE_MATERIALS.contains(event.getBlock().getType())) { // Check if the bucket is filling with water - if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER) { + if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER && identifier.equalsIgnoreCase("Barrier Item")) { blockRemovalActive = true; limitReached = false; clickedLocation = event.getBlock().getLocation(); From 7ae6ae3860fb050203529442e29c04212666b465 Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 14:13:06 +0100 Subject: [PATCH 2/6] Added command completions --- src/main/java/org/gecko/wauh/Main.java | 7 +- .../gecko/wauh/commands/GiveCustomItems.java | 66 ++++++++++++------- .../wauh/commands/SetRadiusLimitCommand.java | 1 - src/main/resources/plugin.yml | 5 ++ 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/gecko/wauh/Main.java b/src/main/java/org/gecko/wauh/Main.java index 7e39ba2..39d54f5 100644 --- a/src/main/java/org/gecko/wauh/Main.java +++ b/src/main/java/org/gecko/wauh/Main.java @@ -4,10 +4,7 @@ import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import org.gecko.wauh.commands.SetRadiusLimitCommand; -import org.gecko.wauh.commands.StopWauh; -import org.gecko.wauh.commands.ToggleRemovalView; -import org.gecko.wauh.commands.test; +import org.gecko.wauh.commands.*; import org.gecko.wauh.data.ConfigurationManager; import org.gecko.wauh.gui.ConfigGUI; import org.gecko.wauh.listeners.*; @@ -59,6 +56,8 @@ public void onEnable() { this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this)); this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this)); this.getCommand("test").setExecutor(new test(configGUI)); + this.getCommand("givecustomitems").setExecutor(new GiveCustomItems()); + this.getCommand("givecustomitems").setTabCompleter(new SetRadiusLimitCommand(this)); } @Override diff --git a/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java index 297fdf1..26870da 100644 --- a/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java +++ b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java @@ -5,53 +5,75 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.gecko.wauh.items.TriggerItems; +import java.util.ArrayList; import java.util.List; public class GiveCustomItems implements CommandExecutor, TabCompleter { - private TriggerItems items; - private ItemStack createdItem; - @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - createdItem = null; - items = new TriggerItems(); + TriggerItems items = new TriggerItems(); if (sender instanceof Player) { if (args.length == 1) { String operation = args[0].toLowerCase(); - if (operation.equals("bucket") || operation.equals("barrier") || operation.equals("bedrock") || operation.equals("tsunami")) { - if (operation.equals("bucket")) { - createdItem = items.createCustomItem(Material.BUCKET, "Water Drainer", (short) 0, "Removes all fluids", "Custom Bucket"); - ((Player) sender).getInventory().addItem(createdItem); - } else if (operation.equals("barrier")) { - createdItem = items.createCustomItem(Material.BARRIER, "Surface Remover", (short) 0, "Removes grass and dirt blocks", "Custom Barrier"); - ((Player) sender).getInventory().addItem(createdItem); - } else if (operation.equals("bedrock")) { - createdItem = items.createCustomItem(Material.BEDROCK, "Water Drainer", (short) 0, "Removes almost all blocks", "Custom Bedrock"); - ((Player) sender).getInventory().addItem(createdItem); - } else { - createdItem = items.createCustomItem(Material.WATER_BUCKET, "Water Drainer", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami"); - ((Player) sender).getInventory().addItem(createdItem); + if (operation.equals("bucket") || operation.equals("barrier") || operation.equals("bedrock") || operation.equals("tsunami") || operation.equals("all")) { + ItemStack customBucket = items.createCustomItem(Material.BUCKET, "Water Drainer", (short) 0, "Removes all fluids", "Custom Bucket"); + ItemStack customBarrier = items.createCustomItem(Material.BARRIER, "Surface Remover", (short) 0, "Removes grass and dirt blocks", "Custom Barrier"); + ItemStack customBedrock = items.createCustomItem(Material.BEDROCK, "Water Drainer", (short) 0, "Removes almost all blocks", "Custom Bedrock"); + ItemStack customTsunami = items.createCustomItem(Material.WATER_BUCKET, "Water Drainer", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami"); + switch (operation) { + case "bucket": + ((Player) sender).getInventory().addItem(customBucket); + break; + case "barrier": + ((Player) sender).getInventory().addItem(customBarrier); + break; + case "bedrock": + ((Player) sender).getInventory().addItem(customBedrock); + break; + case "tsunami": + ((Player) sender).getInventory().addItem(customTsunami); + break; + default: + ((Player) sender).getInventory().addItem(customBucket, customBarrier, customBedrock, customTsunami); + break; } } else return true; } else { - sender.sendMessage("Usage: /givecustomitems [bucket/barrier/bedrock/tsunami]"); + sender.sendMessage("Usage: /givecustomitems [bucket/barrier/bedrock/tsunami/all]"); return true; } } else { sender.sendMessage("Only players can execute this command"); return true; } + return true; } @Override - public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { - return null; + public List onTabComplete(CommandSender commandSender, Command command, String alias, String[] args) { + List completions = new ArrayList<>(); + + if (args.length == 1) { + String input = args[0].toLowerCase(); + + if ("bucket".startsWith(input)) { + completions.add("bucket"); + } else if ("barrier".startsWith(input)) { + completions.add("barrier"); + } else if ("bedrock".startsWith(input)) { + completions.add("bedrock"); + } else if ("tsunami".startsWith(input)) { + completions.add("tsunami"); + } else if ("all".startsWith(input)) { + completions.add("all"); + } + } + return completions; } } diff --git a/src/main/java/org/gecko/wauh/commands/SetRadiusLimitCommand.java b/src/main/java/org/gecko/wauh/commands/SetRadiusLimitCommand.java index 18aeb02..d3af722 100644 --- a/src/main/java/org/gecko/wauh/commands/SetRadiusLimitCommand.java +++ b/src/main/java/org/gecko/wauh/commands/SetRadiusLimitCommand.java @@ -82,7 +82,6 @@ public List onTabComplete(CommandSender sender, Command cmd, String alia completions.add("creeper"); } } - return completions; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 107eadf..cce6a7c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -22,4 +22,9 @@ commands: description: test gui usage: /test permission: op + permission-message: §cYou need to have operator permissions to run this command! + givecustomitems: + description: give yourself a custom item + usage: /givecustomitems [bucket/barrier/bedrock/tsunami/all] + permission: op permission-message: §cYou need to have operator permissions to run this command! \ No newline at end of file From cefd74510f4bb06067aff8c39d4c393c0ec0c162 Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 14:17:32 +0100 Subject: [PATCH 3/6] Added Item condition --- src/main/java/org/gecko/wauh/listeners/BarrierListener.java | 2 +- src/main/java/org/gecko/wauh/listeners/BedrockListener.java | 5 ++++- src/main/java/org/gecko/wauh/listeners/BucketListener.java | 5 ++++- .../java/org/gecko/wauh/listeners/WaterBucketListener.java | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gecko/wauh/listeners/BarrierListener.java b/src/main/java/org/gecko/wauh/listeners/BarrierListener.java index 146c884..9377718 100644 --- a/src/main/java/org/gecko/wauh/listeners/BarrierListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BarrierListener.java @@ -69,7 +69,7 @@ public void barrierBreakEventHandler(BlockBreakEvent event) { Player player = event.getPlayer(); if (IMMUTABLE_MATERIALS.contains(event.getBlock().getType())) { // Check if the bucket is filling with water - if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER && identifier.equalsIgnoreCase("Barrier Item")) { + if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER && identifier.equalsIgnoreCase("Custom Barrier")) { blockRemovalActive = true; limitReached = false; clickedLocation = event.getBlock().getLocation(); diff --git a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java index 836b7dd..0e6168c 100644 --- a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java @@ -1,5 +1,6 @@ package org.gecko.wauh.listeners; +import de.tr7zw.changeme.nbtapi.NBTItem; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -79,6 +80,8 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { BarrierListener barrierListener = mainPlugin.getBarrierListener(); WaterBucketListener waterBucketListener = mainPlugin.getWaterBucketListener(); CreeperListener creeperListener = mainPlugin.getCreeperListener(); + NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); + String identifier = nbtItem.getString("Ident"); if (source.equalsIgnoreCase("player")) { radiusLimit = mainPlugin.getRadiusLimit(); } else if (source.equalsIgnoreCase("TNT")) { @@ -117,7 +120,7 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { } else { Player player = event.getPlayer(); // Check if the bucket is filling with water - if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK) { + if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK && identifier.equalsIgnoreCase("Custom Bedrock")) { if (!IMMUTABLE_MATERIALS.contains(event.getBlock().getType())) { allRemovalActive = true; limitReached = false; diff --git a/src/main/java/org/gecko/wauh/listeners/BucketListener.java b/src/main/java/org/gecko/wauh/listeners/BucketListener.java index 3713f5c..83bddf4 100644 --- a/src/main/java/org/gecko/wauh/listeners/BucketListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BucketListener.java @@ -1,5 +1,6 @@ package org.gecko.wauh.listeners; +import de.tr7zw.changeme.nbtapi.NBTItem; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -59,13 +60,15 @@ public void onBucketFill(PlayerBucketFillEvent event) { BarrierListener barrierListener = Main.getPlugin(Main.class).getBarrierListener(); BedrockListener bedrockListener = Main.getPlugin(Main.class).getBedrockListener(); WaterBucketListener waterBucketListener = Main.getPlugin(Main.class).getWaterBucketListener(); + NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); + String identifier = nbtItem.getString("Ident"); radiusLimit = Main.getPlugin(Main.class).getRadiusLimit(); realRadiusLimit = radiusLimit - 2; if (realRadiusLimit > 1) { if (!wauhRemovalActive && !barrierListener.blockRemovalActive && !bedrockListener.allRemovalActive && !waterBucketListener.tsunamiActive) { // Check if the bucket is filling with water if (IMMUTABLE_MATERIALS.contains(event.getBlockClicked().getType())) { - if (event.getBucket() == Material.BUCKET) { + if (event.getBucket() == Material.BUCKET && identifier.equalsIgnoreCase("Custom Bucket")) { wauhRemovalActive = true; Player player = event.getPlayer(); diff --git a/src/main/java/org/gecko/wauh/listeners/WaterBucketListener.java b/src/main/java/org/gecko/wauh/listeners/WaterBucketListener.java index b63a148..a31fb28 100644 --- a/src/main/java/org/gecko/wauh/listeners/WaterBucketListener.java +++ b/src/main/java/org/gecko/wauh/listeners/WaterBucketListener.java @@ -1,5 +1,6 @@ package org.gecko.wauh.listeners; +import de.tr7zw.changeme.nbtapi.NBTItem; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -59,13 +60,15 @@ public void TsunamiClick(PlayerBucketEmptyEvent event) { BucketListener bucketListener = Main.getPlugin(Main.class).getBucketListener(); BarrierListener barrierListener = Main.getPlugin(Main.class).getBarrierListener(); BedrockListener bedrockListener = Main.getPlugin(Main.class).getBedrockListener(); + NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); + String identifier = nbtItem.getString("Ident"); radiusLimit = Main.getPlugin(Main.class).getRadiusLimit(); realRadiusLimit = radiusLimit - 2; if (realRadiusLimit > 1) { if (!bucketListener.wauhRemovalActive && !barrierListener.blockRemovalActive && !bedrockListener.allRemovalActive && !tsunamiActive) { Player player = event.getPlayer(); // Check if the bucket is filling with water - if (player.getInventory().getItemInMainHand().getType() == Material.WATER_BUCKET) { + if (player.getInventory().getItemInMainHand().getType() == Material.WATER_BUCKET && identifier.equalsIgnoreCase("Custom Tsunami")) { if (player.isSneaking()) { tsunamiActive = true; limitReached = false; From eae2d5de58a41b273df351417a28345378edd5fa Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 14:24:55 +0100 Subject: [PATCH 4/6] Code cleanup --- pom.xml | 2 +- .../java/org/gecko/wauh/commands/test.java | 2 +- .../gecko/wauh/data/ConfigurationManager.java | 25 +-- .../java/org/gecko/wauh/gui/ConfigGUI.java | 38 ++--- .../gecko/wauh/informations/RemovalInfo.java | 11 -- .../gecko/wauh/listeners/BedrockListener.java | 1 - .../gecko/wauh/listeners/CreeperListener.java | 3 - .../org/gecko/wauh/logic/ScaleReverse.java | 3 - src/test/java/org/gecko/wauh/MainTest.java | 0 .../commands/SetRadiusLimitCommandTest.java | 86 ---------- .../gecko/wauh/listeners/TNTListenerTest.java | 0 .../gecko/wauh/logic/ScaleReverseTest.java | 156 ------------------ 12 files changed, 34 insertions(+), 293 deletions(-) delete mode 100644 src/main/java/org/gecko/wauh/informations/RemovalInfo.java delete mode 100644 src/test/java/org/gecko/wauh/MainTest.java delete mode 100644 src/test/java/org/gecko/wauh/commands/SetRadiusLimitCommandTest.java delete mode 100644 src/test/java/org/gecko/wauh/listeners/TNTListenerTest.java delete mode 100644 src/test/java/org/gecko/wauh/logic/ScaleReverseTest.java diff --git a/pom.xml b/pom.xml index 52be98e..bafcc82 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.gecko Wauh - 5.4.0 + 5.5.0 jar wauh diff --git a/src/main/java/org/gecko/wauh/commands/test.java b/src/main/java/org/gecko/wauh/commands/test.java index 7155353..d7d9a6a 100644 --- a/src/main/java/org/gecko/wauh/commands/test.java +++ b/src/main/java/org/gecko/wauh/commands/test.java @@ -8,7 +8,7 @@ import org.gecko.wauh.gui.ConfigGUI; public class test implements CommandExecutor { - ConfigGUI configGUI; + final ConfigGUI configGUI; public test(ConfigGUI configGUI) { this.configGUI = configGUI; diff --git a/src/main/java/org/gecko/wauh/data/ConfigurationManager.java b/src/main/java/org/gecko/wauh/data/ConfigurationManager.java index ea7018e..84ad58f 100644 --- a/src/main/java/org/gecko/wauh/data/ConfigurationManager.java +++ b/src/main/java/org/gecko/wauh/data/ConfigurationManager.java @@ -39,16 +39,7 @@ public ConfigurationManager(Main plugin) { logger.log(Level.SEVERE, "Config file could not be created"); } else { Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!"); - FileWriter writer = new FileWriter(configFile); - writer.write("playerRadiusLimit: 20\n"); - writer.write("tntRadiusLimit: 5\n"); - writer.write("creeperRadiusLimit: 5\n"); - writer.write("Bucket enabled: 1\n"); - writer.write("Barrier enabled: 1\n"); - writer.write("Bedrock enabled: 1\n"); - writer.write("Tsunami enabled: 1\n"); - writer.write("Creeper enabled: 0\n"); - writer.write("TNT enabled: 1\n"); + FileWriter writer = getFileWriter(); writer.close(); } } @@ -59,6 +50,20 @@ public ConfigurationManager(Main plugin) { } } + private FileWriter getFileWriter() throws IOException { + FileWriter writer = new FileWriter(configFile); + writer.write("playerRadiusLimit: 20\n"); + writer.write("tntRadiusLimit: 5\n"); + writer.write("creeperRadiusLimit: 5\n"); + writer.write("Bucket enabled: 1\n"); + writer.write("Barrier enabled: 1\n"); + writer.write("Bedrock enabled: 1\n"); + writer.write("Tsunami enabled: 1\n"); + writer.write("Creeper enabled: 0\n"); + writer.write("TNT enabled: 1\n"); + return writer; + } + public FileConfiguration getConfig() { return config; } diff --git a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java index 3b75f18..2ba4c0b 100644 --- a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java +++ b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java @@ -28,7 +28,7 @@ public class ConfigGUI implements Listener { private final Inventory gui; private final int size = 45; - ConfigurationManager configManager; + final ConfigurationManager configManager; FileConfiguration config; private final File configFile; private final Logger logger = Logger.getLogger(Main.class.getName()); @@ -264,16 +264,7 @@ private void resetConfig(Main plugin, Player player) { logger.log(Level.SEVERE, "Config file could not be created"); } else { Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!"); - FileWriter writer = new FileWriter(configFile); - writer.write("playerRadiusLimit: 20\n"); - writer.write("tntRadiusLimit: 5\n"); - writer.write("creeperRadiusLimit: 5\n"); - writer.write("Bucket enabled: 1\n"); - writer.write("Barrier enabled: 1\n"); - writer.write("Bedrock enabled: 1\n"); - writer.write("Tsunami enabled: 1\n"); - writer.write("Creeper enabled: 0\n"); - writer.write("TNT enabled: 1\n"); + FileWriter writer = getFileWriter(); writer.close(); } } else { @@ -289,16 +280,7 @@ private void resetConfig(Main plugin, Player player) { player.sendMessage(ChatColor.RED + "Config file could not be reset"); } else { Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!"); - FileWriter writer = new FileWriter(configFile); - writer.write("playerRadiusLimit: 20\n"); - writer.write("tntRadiusLimit: 5\n"); - writer.write("creeperRadiusLimit: 5\n"); - writer.write("Bucket enabled: 1\n"); - writer.write("Barrier enabled: 1\n"); - writer.write("Bedrock enabled: 1\n"); - writer.write("Tsunami enabled: 1\n"); - writer.write("Creeper enabled: 0\n"); - writer.write("TNT enabled: 1\n"); + FileWriter writer = getFileWriter(); writer.close(); player.sendMessage(ChatColor.GREEN + "Config reset!"); } @@ -311,4 +293,18 @@ private void resetConfig(Main plugin, Player player) { } } + private FileWriter getFileWriter() throws IOException { + FileWriter writer = new FileWriter(configFile); + writer.write("playerRadiusLimit: 20\n"); + writer.write("tntRadiusLimit: 5\n"); + writer.write("creeperRadiusLimit: 5\n"); + writer.write("Bucket enabled: 1\n"); + writer.write("Barrier enabled: 1\n"); + writer.write("Bedrock enabled: 1\n"); + writer.write("Tsunami enabled: 1\n"); + writer.write("Creeper enabled: 0\n"); + writer.write("TNT enabled: 1\n"); + return writer; + } + } \ No newline at end of file diff --git a/src/main/java/org/gecko/wauh/informations/RemovalInfo.java b/src/main/java/org/gecko/wauh/informations/RemovalInfo.java deleted file mode 100644 index 017a382..0000000 --- a/src/main/java/org/gecko/wauh/informations/RemovalInfo.java +++ /dev/null @@ -1,11 +0,0 @@ -/*package org.gecko.wauh.informations; - -import org.bukkit.entity.Player; - -public class RemovalInfo { - public void showProgress(Player player, int currentProgress, int totalProgress) { - int progressPercentage = (int) ((double) currentProgress / totalProgress * 100); - String actionBarMessage = "Progress" - } -} -*/ \ No newline at end of file diff --git a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java index 0e6168c..5f1f028 100644 --- a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java @@ -24,7 +24,6 @@ public class BedrockListener implements Listener { private static final Set IMMUTABLE_MATERIALS = EnumSet.of(Material.AIR, Material.BEDROCK, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.TNT); - private static final Set ORES = EnumSet.of(Material.COAL_ORE, Material.DIAMOND_ORE, Material.EMERALD_ORE, Material.GOLD_ORE, Material.IRON_ORE, Material.LAPIS_ORE, Material.QUARTZ_ORE, Material.REDSTONE_ORE); private final Set markedBlocks = new HashSet<>(); private final Set processedBlocks = new HashSet<>(); private final Set removedBlocks = new HashSet<>(); diff --git a/src/main/java/org/gecko/wauh/listeners/CreeperListener.java b/src/main/java/org/gecko/wauh/listeners/CreeperListener.java index 4432235..764c96e 100644 --- a/src/main/java/org/gecko/wauh/listeners/CreeperListener.java +++ b/src/main/java/org/gecko/wauh/listeners/CreeperListener.java @@ -4,7 +4,6 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -14,7 +13,6 @@ public class CreeperListener implements Listener { public Location creeperLocation; - public Player creeperPlayer = null; @EventHandler public void onCreeperExplode(EntityExplodeEvent event) { @@ -28,7 +26,6 @@ public void onCreeperExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); // Check if the exploding entity is TNT if (entity instanceof Creeper) { - int creeperLimit = Main.getPlugin(Main.class).getCreeperRadiusLimit() - 2; event.setCancelled(true); // Cancel the normal explosion diff --git a/src/main/java/org/gecko/wauh/logic/ScaleReverse.java b/src/main/java/org/gecko/wauh/logic/ScaleReverse.java index 23fb98f..b2b0d6a 100644 --- a/src/main/java/org/gecko/wauh/logic/ScaleReverse.java +++ b/src/main/java/org/gecko/wauh/logic/ScaleReverse.java @@ -25,9 +25,6 @@ public void ScaleReverseLogic(int totalRemovedCount, int radiusLimit, Set int scaledBlocksPerIteration = Math.max(1, sqrtTotalBlocks); // Update BLOCKS_PER_ITERATION based on the scaled value -// List reversedBlocks = new ArrayList<>(markedBlocks); -// Collections.reverse(reversedBlocks); // Reverse the order of blocks - Iterator iterator = markedBlocks.iterator(); if (source.equalsIgnoreCase("bedrock")) { diff --git a/src/test/java/org/gecko/wauh/MainTest.java b/src/test/java/org/gecko/wauh/MainTest.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/org/gecko/wauh/commands/SetRadiusLimitCommandTest.java b/src/test/java/org/gecko/wauh/commands/SetRadiusLimitCommandTest.java deleted file mode 100644 index e0a5126..0000000 --- a/src/test/java/org/gecko/wauh/commands/SetRadiusLimitCommandTest.java +++ /dev/null @@ -1,86 +0,0 @@ -//package org.gecko.wauh.commands; -// -//import org.bukkit.command.Command; -//import org.bukkit.command.CommandSender; -//import org.bukkit.entity.Player; -//import org.gecko.wauh.Main; -//import org.junit.jupiter.api.Test; -//import org.mockito.Mockito; -// -//import static org.mockito.BDDMockito.given; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -//public class SetRadiusLimitCommandTest { -// -// @Test -// public void testOnCommand() { -// // Arrange -// Main mockMain = Mockito.mock(Main.class); -// Player mockSender = Mockito.mock(Player.class); -// Command mockCommand = Mockito.mock(Command.class); -// String[] args = new String[]{"tnt", "10"}; -// -// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain); -// -// // Act -// command.onCommand(mockSender, mockCommand,"", args); -// -// // Assert -// verify(mockMain).setTntRadiusLimit(10); -// verify(mockSender).sendMessage("TNT radius set to 10"); -// } -// -// @Test -// public void testOnCommandWithNonPlayerSender() { -// // Arrange -// Main mockMain = Mockito.mock(Main.class); -// CommandSender mockSender = Mockito.mock(CommandSender.class); -// Command mockCommand = Mockito.mock(Command.class); -// String[] args = new String[]{"tnt", "10"}; -// -// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain); -// -// // Act -// command.onCommand(mockSender, mockCommand,"", args); -// -// // Assert -// verify(mockSender).sendMessage("Only players can use this command."); -// } -// -// @Test -// public void testOnCommandWithNonNumericLimit() { -// // Arrange -// Main mockMain = Mockito.mock(Main.class); -// CommandSender mockSender = Mockito.mock(Player.class); -// Command mockCommand = Mockito.mock(Command.class); -// String[] args = new String[]{"tnt", "a"}; -// -// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain); -// -// // Act -// command.onCommand(mockSender, mockCommand,"", args); -// -// // Assert -// verify((Player) mockSender).sendMessage("Please specify a valid integer."); -// } -// -// @Test -// public void testOnCommandWithNegativeLimit() { -// // Arrange -// Main mockMain = Mockito.mock(Main.class); -// CommandSender mockSender = Mockito.mock(Player.class); -// Command mockCommand = Mockito.mock(Command.class); -// String[] args = new String[]{"tnt", "-1"}; -// -// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain); -// -// // Act -// command.onCommand(mockSender, mockCommand,"", args); -// -// // Assert -// verify((Player) mockSender).sendMessage("The limit must be a positive value."); -// } -// -// // Similarly other scenarios can be tested -//} \ No newline at end of file diff --git a/src/test/java/org/gecko/wauh/listeners/TNTListenerTest.java b/src/test/java/org/gecko/wauh/listeners/TNTListenerTest.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/org/gecko/wauh/logic/ScaleReverseTest.java b/src/test/java/org/gecko/wauh/logic/ScaleReverseTest.java deleted file mode 100644 index facf125..0000000 --- a/src/test/java/org/gecko/wauh/logic/ScaleReverseTest.java +++ /dev/null @@ -1,156 +0,0 @@ -//package org.gecko.wauh.logic; -// -//import org.bukkit.block.Block; -//import org.bukkit.plugin.java.JavaPlugin; -//import org.gecko.wauh.Main; -//import org.gecko.wauh.listeners.BarrierListener; -//import org.gecko.wauh.listeners.BedrockListener; -//import org.gecko.wauh.listeners.BucketListener; -//import org.gecko.wauh.listeners.WaterBucketListener; -//import org.junit.jupiter.api.Test; -//import org.mockito.MockedStatic; -//import org.mockito.Mockito; -// -//import java.util.HashSet; -//import java.util.Set; -// -//import static org.mockito.Mockito.*; -// -//class ScaleReverseTest { -// -// // create dummy block -// Block blockMock = Mockito.mock(Block.class); -// Set markedBlocks = new HashSet<>(); -// -// @Test -// void testScaleReverseLogic_BucketSource() { -// try (MockedStatic mocked = Mockito.mockStatic(JavaPlugin.class)) { -// // Arrange -// Main mainMock = Mockito.mock(Main.class); -// mocked.when(() -> JavaPlugin.getPlugin(Main.class)).thenReturn(mainMock); -// -// BucketListener bucketListenerMock = Mockito.mock(BucketListener.class); -// when(mainMock.getBucketListener()).thenReturn(bucketListenerMock); -// -// BarrierListener barrierListenerMock = Mockito.mock(BarrierListener.class); -// when(mainMock.getBarrierListener()).thenReturn(barrierListenerMock); -// -// BedrockListener bedrockListenerMock = Mockito.mock(BedrockListener.class); -// when(mainMock.getBedrockListener()).thenReturn(bedrockListenerMock); -// -// WaterBucketListener waterBucketListenerMock = Mockito.mock(WaterBucketListener.class); -// when(mainMock.getWaterBucketListener()).thenReturn(waterBucketListenerMock); -// -// ScaleReverse scaleReverse = new ScaleReverse(); -// int totalRemovedCount = 20; -// int radiusLimit = 3; -// markedBlocks.add(blockMock); -// -// // Act -// scaleReverse.ScaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bucket"); -// -// // Assertions -// // Verify that CleanRemove() method of BucketListener is called once -// verify(bucketListenerMock, times(1)).CleanRemove(anyInt(), any()); -// } -// } -// -// @Test -// void testScaleReverseLogic_BarrierSource() { -// try (MockedStatic mocked = Mockito.mockStatic(JavaPlugin.class)) { -// // Arrange -// Main mainMock = Mockito.mock(Main.class); -// mocked.when(() -> JavaPlugin.getPlugin(Main.class)).thenReturn(mainMock); -// -// BucketListener bucketListenerMock = Mockito.mock(BucketListener.class); -// when(mainMock.getBucketListener()).thenReturn(bucketListenerMock); -// -// BarrierListener barrierListenerMock = Mockito.mock(BarrierListener.class); -// when(mainMock.getBarrierListener()).thenReturn(barrierListenerMock); -// -// BedrockListener bedrockListenerMock = Mockito.mock(BedrockListener.class); -// when(mainMock.getBedrockListener()).thenReturn(bedrockListenerMock); -// -// WaterBucketListener waterBucketListenerMock = Mockito.mock(WaterBucketListener.class); -// when(mainMock.getWaterBucketListener()).thenReturn(waterBucketListenerMock); -// -// ScaleReverse scaleReverse = new ScaleReverse(); -// int totalRemovedCount = 30; -// int radiusLimit = 4; -// markedBlocks.add(blockMock); -// -// // Act -// scaleReverse.ScaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "barrier"); -// -// // Assertions -// // Verify that CleanRemove() method of BarrierListener is called once -// verify(barrierListenerMock, times(1)).CleanRemove(anyInt(), any()); -// } -// } -// -// @Test -// void testScaleReverseLogic_BedrockSource() { -// try (MockedStatic mocked = Mockito.mockStatic(JavaPlugin.class)) { -// // Arrange -// Main mainMock = Mockito.mock(Main.class); -// mocked.when(() -> JavaPlugin.getPlugin(Main.class)).thenReturn(mainMock); -// -// BucketListener bucketListenerMock = Mockito.mock(BucketListener.class); -// when(mainMock.getBucketListener()).thenReturn(bucketListenerMock); -// -// BarrierListener barrierListenerMock = Mockito.mock(BarrierListener.class); -// when(mainMock.getBarrierListener()).thenReturn(barrierListenerMock); -// -// BedrockListener bedrockListenerMock = Mockito.mock(BedrockListener.class); -// when(mainMock.getBedrockListener()).thenReturn(bedrockListenerMock); -// -// WaterBucketListener waterBucketListenerMock = Mockito.mock(WaterBucketListener.class); -// when(mainMock.getWaterBucketListener()).thenReturn(waterBucketListenerMock); -// -// ScaleReverse scaleReverse = new ScaleReverse(); -// int totalRemovedCount = 10; -// int radiusLimit = 2; -// markedBlocks.add(blockMock); -// -// // Act -// scaleReverse.ScaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "bedrock"); -// -// // Assertions -// // Verify that CleanRemove() method of BedrockListener is called once -// verify(bedrockListenerMock, times(1)).CleanRemove(anyInt(), any()); -// } -// } -// -// @Test -// void testScaleReverseLogic_WauhSource() { -// try (MockedStatic mocked = Mockito.mockStatic(JavaPlugin.class)) { -// // Arrange -// Main mainMock = Mockito.mock(Main.class); -// mocked.when(() -> JavaPlugin.getPlugin(Main.class)).thenReturn(mainMock); -// -// BucketListener bucketListenerMock = Mockito.mock(BucketListener.class); -// when(mainMock.getBucketListener()).thenReturn(bucketListenerMock); -// -// BarrierListener barrierListenerMock = Mockito.mock(BarrierListener.class); -// when(mainMock.getBarrierListener()).thenReturn(barrierListenerMock); -// -// BedrockListener bedrockListenerMock = Mockito.mock(BedrockListener.class); -// when(mainMock.getBedrockListener()).thenReturn(bedrockListenerMock); -// -// WaterBucketListener waterBucketListenerMock = Mockito.mock(WaterBucketListener.class); -// when(mainMock.getWaterBucketListener()).thenReturn(waterBucketListenerMock); -// -// ScaleReverse scaleReverse = new ScaleReverse(); -// int totalRemovedCount = 40; -// int radiusLimit = 5; -// markedBlocks.add(blockMock); -// -// // Act -// scaleReverse.ScaleReverseLogic(totalRemovedCount, radiusLimit, markedBlocks, "wauh"); -// -// // Assertions -// // Verify that CleanRemove() method of WauhBucketListener is called once -// verify(waterBucketListenerMock, times(1)).CleanRemove(anyInt(), any()); -// } -// } -//} \ No newline at end of file From f3e8cc1ebc67c212f5ac1c469bc6b2e646b77203 Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 15:06:41 +0100 Subject: [PATCH 5/6] Fixed BedrockListener.java, Changed tnt fuse duration --- .../gecko/wauh/commands/GiveCustomItems.java | 4 +- .../java/org/gecko/wauh/gui/ConfigGUI.java | 13 +++-- .../gecko/wauh/listeners/BedrockListener.java | 49 +++++++++++++++---- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java index 26870da..efd6569 100644 --- a/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java +++ b/src/main/java/org/gecko/wauh/commands/GiveCustomItems.java @@ -24,8 +24,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String if (operation.equals("bucket") || operation.equals("barrier") || operation.equals("bedrock") || operation.equals("tsunami") || operation.equals("all")) { ItemStack customBucket = items.createCustomItem(Material.BUCKET, "Water Drainer", (short) 0, "Removes all fluids", "Custom Bucket"); ItemStack customBarrier = items.createCustomItem(Material.BARRIER, "Surface Remover", (short) 0, "Removes grass and dirt blocks", "Custom Barrier"); - ItemStack customBedrock = items.createCustomItem(Material.BEDROCK, "Water Drainer", (short) 0, "Removes almost all blocks", "Custom Bedrock"); - ItemStack customTsunami = items.createCustomItem(Material.WATER_BUCKET, "Water Drainer", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami"); + ItemStack customBedrock = items.createCustomItem(Material.BEDROCK, "Block Obliterator", (short) 0, "Removes almost all blocks", "Custom Bedrock"); + ItemStack customTsunami = items.createCustomItem(Material.WATER_BUCKET, "Tsunami Bucket", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami"); switch (operation) { case "bucket": ((Player) sender).getInventory().addItem(customBucket); diff --git a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java index 2ba4c0b..fdb4d73 100644 --- a/src/main/java/org/gecko/wauh/gui/ConfigGUI.java +++ b/src/main/java/org/gecko/wauh/gui/ConfigGUI.java @@ -112,7 +112,12 @@ private void fillBorders(ItemStack borderItem) { private ItemStack createButtonItem(Material material, String name, short data, String lore, String ident) { - List loreToString = Collections.singletonList(lore); + List loreToString; + if (lore != null) { + loreToString = Collections.singletonList(lore); + } else { + loreToString = null; + } ItemStack item = new ItemStack(material, 1, data); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(name); @@ -247,7 +252,7 @@ public void onInventoryClick(InventoryClickEvent event) { if (clickedItem.getType() == Material.PAPER) { if (identifier.equalsIgnoreCase("Reset")) { - resetConfig(plugin, player); + resetConfig(player); } } @@ -255,7 +260,7 @@ public void onInventoryClick(InventoryClickEvent event) { } } - private void resetConfig(Main plugin, Player player) { + private void resetConfig(Player player) { try { // Create the data.yml file if it doesn't exist if (!configFile.exists()) { @@ -289,7 +294,7 @@ private void resetConfig(Main plugin, Player player) { this.config = YamlConfiguration.loadConfiguration(configFile); } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, "Could not reset config file", ex); + logger.log(Level.SEVERE, "Could not reset config file", ex); } } diff --git a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java index 5f1f028..7132959 100644 --- a/src/main/java/org/gecko/wauh/listeners/BedrockListener.java +++ b/src/main/java/org/gecko/wauh/listeners/BedrockListener.java @@ -20,10 +20,12 @@ import org.gecko.wauh.logic.ScaleReverse; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; public class BedrockListener implements Listener { - private static final Set IMMUTABLE_MATERIALS = EnumSet.of(Material.AIR, Material.BEDROCK, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.TNT); + private static final Set IMMUTABLE_MATERIALS = EnumSet.of(Material.BEDROCK, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.TNT); private final Set markedBlocks = new HashSet<>(); private final Set processedBlocks = new HashSet<>(); private final Set removedBlocks = new HashSet<>(); @@ -42,15 +44,28 @@ public class BedrockListener implements Listener { private int repetitions = 3; private boolean repeated = false; private boolean explosionTrigger = false; + private String realSource; + private final java.util.logging.Logger logger = Logger.getLogger(Main.class.getName()); private void addIfValid(Block block, Set nextSet) { - if (!IMMUTABLE_MATERIALS.contains(block.getType())) { + if (realSource.equalsIgnoreCase("TNT") || realSource.equalsIgnoreCase("creeper")) { + if (!IMMUTABLE_MATERIALS.contains(block.getType())) { + nextSet.add(block); + } else if (block.getType() == Material.TNT) { + Location location = block.getLocation(); + block.setType(Material.AIR); + TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.add(0.5, 0.5, 0.5), EntityType.PRIMED_TNT); + tntPrimed.setFuseTicks(20); + nextSet.add(block); + } + } + if (!IMMUTABLE_MATERIALS.contains(block.getType()) || block.getType() == Material.AIR) { nextSet.add(block); } else if (block.getType() == Material.TNT) { Location location = block.getLocation(); block.setType(Material.AIR); TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.add(0.5, 0.5, 0.5), EntityType.PRIMED_TNT); - tntPrimed.setFuseTicks(40); + tntPrimed.setFuseTicks(20); nextSet.add(block); } } @@ -61,12 +76,22 @@ public void bedrockBreakEventHandler(BlockBreakEvent event) { } public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { + realSource = source; TNTListener tntListener = mainPlugin.getTntListener(); if (tntListener == null) { return; } - if (!event.getPlayer().isOp() || tntListener.tntPlayer.isOp()) { - return; + if (event == null && source.equalsIgnoreCase("TNT")) { + if (tntListener.tntPlayer != null) { + if (!tntListener.tntPlayer.isOp()) { + return; + } + } + } + if (event != null) { + if (!event.getPlayer().isOp()) { + return; + } } ConfigurationManager configManager; FileConfiguration config; @@ -79,8 +104,6 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { BarrierListener barrierListener = mainPlugin.getBarrierListener(); WaterBucketListener waterBucketListener = mainPlugin.getWaterBucketListener(); CreeperListener creeperListener = mainPlugin.getCreeperListener(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); if (source.equalsIgnoreCase("player")) { radiusLimit = mainPlugin.getRadiusLimit(); } else if (source.equalsIgnoreCase("TNT")) { @@ -91,7 +114,7 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { realRadiusLimit = radiusLimit - 2; if (realRadiusLimit > 1) { if (!bucketListener.wauhRemovalActive && !barrierListener.blockRemovalActive && !allRemovalActive && !waterBucketListener.tsunamiActive || explosionTrigger) { - if (source.equalsIgnoreCase("TNT") || source.equalsIgnoreCase("creeper")) { + if (event == null && source.equalsIgnoreCase("TNT") || source.equalsIgnoreCase("creeper")) { allRemovalActive = true; explosionTrigger = true; limitReached = false; @@ -116,8 +139,10 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { blocksToProcess.add(clickedLocation.getBlock()); processAllRemoval(); - } else { + } else if (event != null) { Player player = event.getPlayer(); + NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); + String identifier = nbtItem.getString("Ident"); // Check if the bucket is filling with water if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK && identifier.equalsIgnoreCase("Custom Bedrock")) { if (!IMMUTABLE_MATERIALS.contains(event.getBlock().getType())) { @@ -139,6 +164,8 @@ public void bedrockValueAssignHandler(BlockBreakEvent event, String source) { } } } + } else { + logger.log(Level.WARNING, "Too many explosions"); } } } @@ -248,6 +275,7 @@ public void displaySummary() { tntListener.tntLocation = null; tntListener.tntPlayer = null; creeperListener.creeperLocation = null; + realSource = null; stopAllRemoval = false; blocksToProcess.clear(); markedBlocks.clear(); @@ -262,6 +290,7 @@ public void displaySummary() { tntListener.tntLocation = null; tntListener.tntPlayer = null; creeperListener.creeperLocation = null; + realSource = null; stopAllRemoval = false; blocksToProcess.clear(); markedBlocks.clear(); @@ -297,6 +326,7 @@ private void removeMarkedBlocks() { tntListener.tntLocation = null; tntListener.tntPlayer = null; creeperListener.creeperLocation = null; + realSource = null; stopAllRemoval = false; blocksToProcess.clear(); markedBlocks.clear(); @@ -329,6 +359,7 @@ private void removeMarkedBlocks() { tntListener.tntLocation = null; tntListener.tntPlayer = null; creeperListener.creeperLocation = null; + realSource = null; stopAllRemoval = false; blocksToProcess.clear(); markedBlocks.clear(); From 582c19177c21ffe251f2f1feb9a25075da1b73d9 Mon Sep 17 00:00:00 2001 From: Gecko! Date: Wed, 13 Dec 2023 15:14:20 +0100 Subject: [PATCH 6/6] Fix name formatting --- src/main/java/org/gecko/wauh/items/TriggerItems.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/gecko/wauh/items/TriggerItems.java b/src/main/java/org/gecko/wauh/items/TriggerItems.java index 0389c5d..6275355 100644 --- a/src/main/java/org/gecko/wauh/items/TriggerItems.java +++ b/src/main/java/org/gecko/wauh/items/TriggerItems.java @@ -13,6 +13,7 @@ public class TriggerItems { public ItemStack createCustomItem(Material material, String name, short data, String lore, String ident) { ItemStack item = new ItemStack(material, 1, data); + name = ChatColor.RESET + name; lore = ChatColor.RESET + "" + ChatColor.DARK_PURPLE + lore; List loreToList = Collections.singletonList(lore); ItemMeta meta = item.getItemMeta();