From a22e1d37b92e9b537a1040d125e1f22a4affbec7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:04:46 +0100 Subject: [PATCH] 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: