From 7871a88824cd63a2f82328d0a5ed9b61945212da Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 17:02:34 +0100 Subject: [PATCH] Add CommandTNT by Region.buildAreaEnabled() --- .../de/steamwar/bausystem/commands/CommandTNT.java | 11 ++++++++--- .../bausystem/commands/CommandTNTTabComplete.java | 11 +++++++---- .../src/de/steamwar/bausystem/world/Region.java | 14 +++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index bbebb25..3443dee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -103,7 +103,7 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { tntMode = TNTMode.ONLY_TB; sendToActionBar(getTestblockEnableMessage()); return false; @@ -116,8 +116,13 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); break; case OFF: - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); + if (Region.buildAreaEnabled()) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + } else { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + } break; } return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index 5ce5c30..dbc18b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -34,17 +35,19 @@ public class CommandTNTTabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return tntTabComplete((Player) sender, args); + return tntTabComplete(args); } - private List tntTabComplete(Player player, String[] args) { + private List tntTabComplete(String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("an"); tabComplete.add("on"); tabComplete.add("aus"); tabComplete.add("off"); - tabComplete.add("testblock"); - tabComplete.add("tb"); + if (Region.buildAreaEnabled()) { + tabComplete.add("testblock"); + tabComplete.add("tb"); + } if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index f1949b1..6f7ec11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -37,6 +37,11 @@ import java.util.logging.Level; public class Region { private static final List regions = new ArrayList<>(); + private static boolean buildArea = false; + + public static boolean buildAreaEnabled() { + return buildArea; + } static{ YamlConfiguration config = new YamlConfiguration(); @@ -143,6 +148,9 @@ public class Region { ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + if (buildArea != null) { + Region.buildArea = true; + } protectSchematic = config.getString("protection", null); @@ -151,9 +159,9 @@ public class Region { } public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && - inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && - inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); + return inRange(l.getX(), region.minX + offsetX, sizeX) && + inRange(l.getY(), region.minY + offsetY, sizeY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public void fastreset(Region region){