From a22e1d37b92e9b537a1040d125e1f22a4affbec7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:04:46 +0100 Subject: [PATCH 1/7] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandBuildMode.java | 86 +++++++++++++++++++ .../bausystem/commands/CommandTNT.java | 8 ++ .../bausystem/world/BauScoreboard.java | 13 ++- .../de/steamwar/bausystem/world/Region.java | 19 +++- BauSystem_Main/src/plugin.yml | 1 + 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..2563e1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -82,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java new file mode 100644 index 0000000..d65fe6b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -0,0 +1,86 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class CommandBuildMode extends ToggleCommand { + + public CommandBuildMode() { + super(false); + } + + public static ToggleCommand getInstance() { + return getInstance(CommandBuildMode.class); + } + + @Override + String getNoPermMessage() { + return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; + } + + @Override + String getEnableMessage() { + return "§aBuild mode aktiviert"; + } + + @Override + String getDisableMessage() { + return "§cBuild mode deaktiviert"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + if (!CommandTNT.getInstance().isOn()) { + player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); + return false; + } + return super.onCommand(sender, command, label, args); + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..de342b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,6 +45,14 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } + @Override + public void toggle() { + if (CommandBuildMode.getInstance().isOn()) { + CommandBuildMode.getInstance().toggle(); + } + super.toggle(); + } + @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index c15abc1..e1b775f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.world; +import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -61,7 +62,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); + strings.add("§eTNT§8: " + tntString()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -104,4 +105,14 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } + private String tntString() { + if (!CommandTNT.getInstance().isOn()) { + if (CommandBuildMode.getInstance().isOn()) { + return "§eTestblock"; + } + return "§aan"; + } + return "§caus"; + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 5bc4449..b1f4ed4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -80,6 +80,14 @@ public class Region { return prototype.inRegion(this, l); } + public boolean hasBuildRegion() { + return prototype.buildArea != null; + } + + public boolean inBuildRegion(Location l) { + return prototype.buildArea.inRegion(this, l); + } + public void fastreset(){ prototype.fastreset(this); } @@ -101,7 +109,8 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -116,6 +125,8 @@ public class Region { private final boolean rotate; private final Prototype testblock; //nullable + private final Prototype buildArea; //nullable + private final String protectSchematic; //nullable private Prototype(ConfigurationSection config){ @@ -130,9 +141,13 @@ public class Region { ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); testblock = testblockSection != null ? new Prototype(testblockSection) : null; + + ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); + buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + protectSchematic = config.getString("protection", null); - if(!config.getName().equals("testblock")) + if(!config.getName().equals("testblock") && !config.getName().equals("buildArea")) prototypes.put(config.getName(), this); } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..b589f20 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,6 +10,7 @@ commands: debugstick: tnt: fire: + buildmode: trace: tpslimit: testblock: From 0be031f5fed5dab3ed0aaf09d096574fe0c904ef Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:25:34 +0100 Subject: [PATCH 2/7] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 12 ------------ .../de/steamwar/bausystem/commands/CommandTNT.java | 8 -------- .../de/steamwar/bausystem/world/BauScoreboard.java | 2 +- .../src/de/steamwar/bausystem/world/Region.java | 3 +-- 5 files changed, 3 insertions(+), 24 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 2563e1b..6f8ef7c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("tnt").setExecutor(new CommandTNT()); getCommand("buildmode").setExecutor(new CommandBuildMode()); + getCommand("tnt").setExecutor(new CommandTNT()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java index d65fe6b..51a3454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -55,18 +55,6 @@ public class CommandBuildMode extends ToggleCommand { return "§cBuild mode deaktiviert"; } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - if (!CommandTNT.getInstance().isOn()) { - player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); - return false; - } - return super.onCommand(sender, command, label, args); - } - @EventHandler public void onEntityExplode(EntityExplodeEvent event) { boolean blocksDestroyed = event.blockList().removeIf(block -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index de342b1..7298c9b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,14 +45,6 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } - @Override - public void toggle() { - if (CommandBuildMode.getInstance().isOn()) { - CommandBuildMode.getInstance().toggle(); - } - super.toggle(); - } - @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index e1b775f..5a696e8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -108,7 +108,7 @@ public class BauScoreboard implements Listener { private String tntString() { if (!CommandTNT.getInstance().isOn()) { if (CommandBuildMode.getInstance().isOn()) { - return "§eTestblock"; + return "§7nur §eTestblock"; } return "§aan"; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index b1f4ed4..f1949b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -109,8 +109,7 @@ public class Region { } public static class Prototype{ - // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; - private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; + private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; From 28b3733b83f1862314893f998db8e0453467c436 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 18:18:18 +0100 Subject: [PATCH 3/7] Simplify CommandTNT --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 74 ------------ .../bausystem/commands/CommandTNT.java | 112 +++++++++++++++--- .../commands/CommandTNTTabComplete.java | 59 +++++++++ .../bausystem/world/BauScoreboard.java | 13 +- BauSystem_Main/src/plugin.yml | 1 - 6 files changed, 159 insertions(+), 102 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6f8ef7c..96bde54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("tnt").setTabCompleter(new CommandTNTTabComplete()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java deleted file mode 100644 index 51a3454..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.commands; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityExplodeEvent; - -public class CommandBuildMode extends ToggleCommand { - - public CommandBuildMode() { - super(false); - } - - public static ToggleCommand getInstance() { - return getInstance(CommandBuildMode.class); - } - - @Override - String getNoPermMessage() { - return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; - } - - @Override - String getEnableMessage() { - return "§aBuild mode aktiviert"; - } - - @Override - String getDisableMessage() { - return "§cBuild mode deaktiviert"; - } - - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; - } - } - return false; - }); - if (!blocksDestroyed) { - return; - } - Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..7726448 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -19,34 +19,118 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.Welt; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT extends ToggleCommand { +public class CommandTNT implements CommandExecutor { - public CommandTNT(){ - super(true); + private static TNTMode tntMode = TNTMode.OFF; + + public static TNTMode getTntMode() { + return tntMode; } - public static ToggleCommand getInstance(){ - return getInstance(CommandTNT.class); + public enum TNTMode { + ON("§aan"), + ONLY_TB("§7nur §eTestblock"), + OFF("§caus"); + + private String name; + + TNTMode(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } - @Override - String getNoPermMessage() { + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } - @Override - String getEnableMessage(){ + + private String getEnableMessage() { return "§cTNT-Schaden deaktiviert"; } - @Override - String getDisableMessage(){ + + private String getDisableMessage() { return "§aTNT-Schaden aktiviert"; } - @EventHandler - public void onExplode(EntityExplodeEvent e) { - e.blockList().clear(); + private String getTestblockEnableMessage() { + return "§aTNT-Schaden beim Testblock aktiviert"; } + + private String getDamageMessage() { + return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) return false; + Player player = (Player) sender; + + if (Welt.noPermission(player, Permission.world)) { + player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); + return false; + } + + if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + } + + switch (tntMode) { + case ON: + case ONLY_TB: + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + break; + case OFF: + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + break; + } + return false; + } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + if (tntMode == TNTMode.ON) return; + if (tntMode == TNTMode.OFF) { + event.blockList().clear(); + } else { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + sendToActionBar(getDamageMessage()); + } + } + + private void sendToActionBar(String message) { + Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message))); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java new file mode 100644 index 0000000..d79f448 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -0,0 +1,59 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +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 detonaterTabComplete((Player) sender, args); + } + + private List detonaterTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("an"); + + if (args.length >= 2) { + return new ArrayList<>(); + } + return manageList(tabComplete, args, 0); + } + + private List manageList(List strings, String[] args, int index) { + for (int i = strings.size() - 1; i >= 0; i--) { + if (!strings.get(i).startsWith(args[index])) { + strings.remove(i); + } + } + return strings; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5a696e8..8aaf994 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -62,7 +61,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + tntString()); + strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -105,14 +104,4 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } - private String tntString() { - if (!CommandTNT.getInstance().isOn()) { - if (CommandBuildMode.getInstance().isOn()) { - return "§7nur §eTestblock"; - } - return "§aan"; - } - return "§caus"; - } - } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index b589f20..bc85fb9 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,7 +10,6 @@ commands: debugstick: tnt: fire: - buildmode: trace: tpslimit: testblock: From ae6d5ee6713bd591b2ea725e3e4839085e903217 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 13:58:02 +0100 Subject: [PATCH 4/7] Fix PR stuff --- .../bausystem/commands/CommandTNT.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7726448..94f4d4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -31,9 +31,10 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT implements CommandExecutor { +public class CommandTNT implements CommandExecutor, Listener { private static TNTMode tntMode = TNTMode.OFF; @@ -58,6 +59,10 @@ public class CommandTNT implements CommandExecutor { } + public CommandTNT() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } @@ -71,11 +76,11 @@ public class CommandTNT implements CommandExecutor { } private String getTestblockEnableMessage() { - return "§aTNT-Schaden beim Testblock aktiviert"; + return "§aTNT-Schaden am Testblock aktiviert"; } private String getDamageMessage() { - return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } @Override @@ -110,22 +115,25 @@ public class CommandTNT implements CommandExecutor { @EventHandler public void onExplode(EntityExplodeEvent event) { - if (tntMode == TNTMode.ON) return; - if (tntMode == TNTMode.OFF) { - event.blockList().clear(); - } else { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; + switch (tntMode) { + case ON: + break; + case OFF: + event.blockList().clear(); + break; + case ONLY_TB: + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } } + return false; + }); + if (blocksDestroyed) { + sendToActionBar(getDamageMessage()); } - return false; - }); - if (!blocksDestroyed) { - return; - } - sendToActionBar(getDamageMessage()); + break; } } From f04bf70087b00500c61556e1f7f05dd66b91b93a Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 14:50:19 +0100 Subject: [PATCH 5/7] Fix Build issues --- .../steamwar/bausystem/commands/CommandInfo.java | 2 +- .../steamwar/bausystem/commands/CommandTNT.java | 16 +++++++++++++--- .../commands/CommandTNTTabComplete.java | 9 +++++++-- .../steamwar/bausystem/world/ScriptListener.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 0b506d9..82b2563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 94f4d4e..bbebb25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -68,11 +68,11 @@ public class CommandTNT implements CommandExecutor, Listener { } private String getEnableMessage() { - return "§cTNT-Schaden deaktiviert"; + return "§aTNT-Schaden aktiviert"; } private String getDisableMessage() { - return "§aTNT-Schaden aktiviert"; + return "§cTNT-Schaden deaktiviert"; } private String getTestblockEnableMessage() { @@ -93,11 +93,21 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { tntMode = TNTMode.ON; sendToActionBar(getEnableMessage()); return false; } + if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + } + if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + } switch (tntMode) { case ON: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index d79f448..5ce5c30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -34,12 +34,17 @@ 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 detonaterTabComplete((Player) sender, args); + return tntTabComplete((Player) sender, args); } - private List detonaterTabComplete(Player player, String[] args) { + private List tntTabComplete(Player player, 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 (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 762aff6..d0f2fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -284,7 +284,7 @@ public class ScriptListener implements Listener { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; case "tnt": - return CommandTNT.getInstance().isOn() ? 1 : 0; + return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": return CommandFreeze.getInstance().isOn() ? 1 : 0; case "fire": From 7871a88824cd63a2f82328d0a5ed9b61945212da Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 17:02:34 +0100 Subject: [PATCH 6/7] 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){ From f887e633adc1a9371ae35b39468cca7a6f124305 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 20:07:19 +0100 Subject: [PATCH 7/7] Add CommandTNT by Region.buildAreaEnabled() --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandTNT.java | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 82b2563..c6810f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName()); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 3443dee..23ab3b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -93,20 +93,27 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - return false; - } - if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - return false; - } - if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - return false; + if (args.length != 0) { + switch (args[0].toLowerCase()) { + case "an": + case "on": + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + case "aus": + case "off": + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + case "testblock": + case "tb": + if (!Region.buildAreaEnabled()) break; + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + default: + break; + } } switch (tntMode) {