From ea345fb46cbeabad7ce488cec259bf89c2cec2a7 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 14:32:52 +0100 Subject: [PATCH 01/22] Add Region section Support for /tnt /fire /freeze --- .../bausystem/commands/CommandFire.java | 29 +++-- .../bausystem/commands/CommandFreeze.java | 103 ++++++++++++----- .../bausystem/commands/CommandInfo.java | 15 ++- .../bausystem/commands/CommandProtect.java | 40 +++---- .../bausystem/commands/CommandReset.java | 42 ++++--- .../bausystem/commands/CommandTNT.java | 106 ++++++++--------- .../bausystem/commands/CommandTestblock.java | 40 +++---- .../commands/RegionToggleCommand.java | 83 +++++++++++++ .../bausystem/commands/ToggleCommand.java | 87 -------------- .../bausystem/world/BauScoreboard.java | 10 +- .../de/steamwar/bausystem/world/Region.java | 109 +++++++++++++++++- .../bausystem/world/ScriptListener.java | 16 ++- 12 files changed, 417 insertions(+), 263 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 4403ec7..bd640fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -19,18 +19,15 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockSpreadEvent; -public class CommandFire extends ToggleCommand { +public class CommandFire extends RegionToggleCommand { - public CommandFire(){ - super(true); - } - - public static ToggleCommand getInstance(){ - return getInstance(CommandFire.class); + public CommandFire() { + super(); } @Override @@ -45,15 +42,29 @@ public class CommandFire extends ToggleCommand { String getDisableMessage(){ return "§aFeuerschaden aktiviert"; } + @Override + String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + + @Override + boolean toggle(Region region) { + region.setFire(!region.isFire()); + return region.isFire(); + } @EventHandler public void onFireDamage(BlockBurnEvent e) { - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFire()) e.setCancelled(true); + }); } @EventHandler public void onFireSpread(BlockSpreadEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFire()) e.setCancelled(true); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 6443e32..9a9c80f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -1,36 +1,41 @@ -/* - 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 . -*/ +/* + * + * 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.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; -public class CommandFreeze extends ToggleCommand { +public class CommandFreeze extends RegionToggleCommand { public CommandFreeze(){ - super(false); - } - - public static ToggleCommand getInstance(){ - return getInstance(CommandFreeze.class); + super(); } @Override @@ -45,39 +50,75 @@ public class CommandFreeze extends ToggleCommand { String getDisableMessage(){ return "§aWelt aufgetaut"; } + @Override + String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + + @Override + boolean toggle(Region region) { + region.setFreeze(!region.isFreeze()); + return region.isFreeze(); + } + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) { + Region.getRegion(e.getLocation(), region -> { + if (!region.isFreeze()) { + return; + } + if (e.getEntityType() == EntityType.FALLING_BLOCK) { + e.setCancelled(true); + } + }); + } @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onPistonExtend(BlockPistonExtendEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onPistonRetract(BlockPistonRetractEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onBlockGrow(BlockGrowEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onRedstoneEvent(BlockRedstoneEvent e){ - e.setNewCurrent(e.getOldCurrent()); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); + }); } @EventHandler public void onBlockDispense(BlockDispenseEvent e){ - e.setCancelled(true); + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } @EventHandler public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - e.setCancelled(true); + Region.getRegion(e.getDestination().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c6810f7..ae8960f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -20,12 +20,14 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.List; @@ -33,10 +35,17 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + return false; + } + Player player = (Player) sender; + sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - 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")); + Region.getRegion(player.getLocation(), region -> { + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + }, () -> { + sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); + }); List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index f12afb7..6adcd6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -45,28 +45,26 @@ public class CommandProtect implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasProtection()){ - try { - Schematic schem = null; - if(args.length > 0){ - schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - } - region.protect(schem); - player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null || !region.hasProtection()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); + return false; + } + try { + Schematic schem = null; + if(args.length > 0){ + schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + } + region.protect(schem); + player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 353fd22..a75be05 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -45,29 +45,27 @@ public class CommandReset implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation())){ - try { - if(args.length > 0){ - Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - region.reset(schem); - }else{ - region.fastreset(); - } - player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return false; + } + try { + if(args.length > 0){ + Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + region.reset(schem); + }else{ + region.fastreset(); + } + player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 91eb203..c5ccad2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,12 +36,6 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class CommandTNT implements CommandExecutor, Listener { - private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; - - public static TNTMode getTntMode() { - return tntMode; - } - public enum TNTMode { ON("§aan"), ONLY_TB("§7nur §eTestblock"), @@ -83,6 +77,10 @@ public class CommandTNT implements CommandExecutor, Listener { return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } + private String getNoRegionMessage() { + return "§cDu befindest dich derzeit in keiner Region"; + } + @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; @@ -93,74 +91,72 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } + TNTMode requestedMode = null; + String requestedMessage = null; if (args.length != 0) { switch (args[0].toLowerCase()) { case "an": case "on": - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - return false; + requestedMode = TNTMode.ON; + requestedMessage = getEnableMessage(); + break; case "aus": case "off": - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - return false; + requestedMode = TNTMode.OFF; + requestedMessage = getDisableMessage(); + break; case "testblock": case "tb": if (!Region.buildAreaEnabled()) break; - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - return false; + requestedMode = TNTMode.ONLY_TB; + requestedMessage = getTestblockEnableMessage(); + break; default: break; } } - switch (tntMode) { - case ON: - case ONLY_TB: - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - break; - case OFF: - if (Region.buildAreaEnabled()) { - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - } else { - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - } - break; - } + TNTMode finalRequestedMode = requestedMode; + String finalRequestedMessage = requestedMessage; + Region.getRegion(player.getLocation(), region -> { + if (finalRequestedMode != null) { + region.setTntMode(finalRequestedMode); + RegionToggleCommand.actionBar(region, finalRequestedMessage); + return; + } + switch (region.getTntMode()) { + case ON: + case ONLY_TB: + region.setTntMode(TNTMode.OFF); + RegionToggleCommand.actionBar(region, getDisableMessage()); + break; + case OFF: + if (Region.buildAreaEnabled()) { + region.setTntMode(TNTMode.ONLY_TB); + RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); + } else { + region.setTntMode(TNTMode.ON); + RegionToggleCommand.actionBar(region, getEnableMessage()); + } + break; + } + }, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage())); return false; } @EventHandler public void onExplode(EntityExplodeEvent event) { - 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()); - } - break; - } - } - - private void sendToActionBar(String message) { - Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message))); + event.blockList().removeIf(block -> { + Region region = Region.getRegion(block.getLocation()); + if (region == null) return false; + if (region.getTntMode() == TNTMode.OFF) return true; + if (region.getTntMode() == TNTMode.ON) return false; + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + RegionToggleCommand.actionBar(region, getDamageMessage()); + return true; + } + return false; + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 6859231..e44d889 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -45,28 +45,26 @@ public class CommandTestblock implements CommandExecutor { return false; } - for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasTestblock()){ - try { - Schematic schem = null; - if(args.length > 0){ - schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - } - region.resetTestblock(schem); - player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); - }catch(Exception e){ - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); - Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); - } - return false; - } + Region region = Region.getRegion(player); + if (region == null || !region.hasTestblock()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return false; + } + try { + Schematic schem = null; + if(args.length > 0){ + schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); + if(schem == null){ + player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return false; + } + } + region.resetTestblock(schem); + player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); + }catch(Exception e){ + player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); + Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); } - - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java new file mode 100644 index 0000000..7aaff41 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -0,0 +1,83 @@ +/* + * + * 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.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 net.minecraft.server.v1_15_R1.BlockCactus; +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.Listener; + +public abstract class RegionToggleCommand implements CommandExecutor, Listener { + + RegionToggleCommand() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, 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; + } + + Region.getRegion(player.getLocation(), region -> { + if (toggle(region)) { + actionBar(region, getEnableMessage()); + } else { + actionBar(region, getDisableMessage()); + } + }, () -> actionBar(player, getNoRegionMessage())); + return false; + } + + public static void actionBar(Region region, String s) { + Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } + + public static void actionBar(Player player, String s) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); + } + + abstract String getNoRegionMessage(); + abstract String getNoPermMessage(); + abstract String getEnableMessage(); + abstract String getDisableMessage(); + + /** + * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} + */ + abstract boolean toggle(Region region); + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java deleted file mode 100644 index 0551a80..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/ToggleCommand.java +++ /dev/null @@ -1,87 +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.Permission; -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.HandlerList; -import org.bukkit.event.Listener; - -import java.util.HashMap; -import java.util.Map; - -public abstract class ToggleCommand implements CommandExecutor, Listener { - - private static Map, Boolean> enabled = new HashMap<>(); - private static Map, ToggleCommand> instance = new HashMap<>(); - - ToggleCommand(boolean on){ - enabled.put(getClass(), false); - if(on) - toggle(); - instance.put(getClass(), this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, 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; - } - - toggle(); - return false; - } - - static ToggleCommand getInstance(Class clazz){ - return instance.get(clazz); - } - - abstract String getNoPermMessage(); - abstract String getEnableMessage(); - abstract String getDisableMessage(); - - public boolean isOn(){ - return enabled.get(getClass()); - } - - public void toggle(){ - enabled.compute(getClass(), (clazz, value) -> !value); - if(enabled.get(getClass())){ - Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getEnableMessage()))); - }else{ - HandlerList.unregisterAll(this); - Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getDisableMessage()))); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 8aaf994..3faa945 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.commands.CommandFreeze; -import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.core.TPSWatcher; @@ -61,8 +59,12 @@ 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.getTntMode().getName()); - strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); + Region region = Region.getRegion(p); + if (region != null) { + strings.add("§eTNT§8: " + region.getTntMode().getName()); + strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); + } strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 82e9f96..3c170f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.bausystem.commands.CommandTNT.TNTMode; import de.steamwar.core.Core; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; @@ -28,10 +29,12 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.function.Consumer; import java.util.logging.Level; public class Region { @@ -39,10 +42,6 @@ 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(); try { @@ -64,23 +63,125 @@ public class Region { } } + public static boolean buildAreaEnabled() { + return buildArea; + } + + public static Region getRegion(Player player) { + return getRegion(player.getLocation()); + } + + public static Region getRegion(Location location) { + for (Region region : regions) { + if (region.inRegion(location)) return region; + } + return null; + } + + public static void getRegion(Location location, Consumer regionConsumer) { + getRegion(location, regionConsumer, () -> {}); + } + + public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { + boolean b = true; + for (Region region : regions) { + if (region.inRegion(location)) { + regionConsumer.accept(region); + b = false; + } + } + if (b) { + noRegion.run(); + } + } + public static List getRegions(){ return regions; } + private static Region getRegionByName(String name) { + for (Region region : regions) { + if (region.name.equals(name)) return region; + } + return null; + } + + private final String name; private final int minX; private final int minY; private final int minZ; private final Prototype prototype; + private final String optionsLinkedWith; // nullable + private Region linkedRegion = null; // nullable + + private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; + private boolean freeze = false; + private boolean fire = false; private Region(ConfigurationSection config){ + name = config.getName(); minX = config.getInt("minX"); minY = config.getInt("minY"); minZ = config.getInt("minZ"); prototype = Prototype.prototypes.get(config.getString("prototype")); + optionsLinkedWith = config.getString("optionsLinkedWith", null); regions.add(this); } + private void link() { + if (optionsLinkedWith != null && linkedRegion == null) { + linkedRegion = getRegionByName(optionsLinkedWith); + } + } + + public TNTMode getTntMode() { + return tntMode; + } + + public void setTntMode(TNTMode tntMode) { + this.tntMode = tntMode; + link(); + if (linkedRegion != null) { + linkedRegion.setTntModeOther(tntMode); + } + } + + private void setTntModeOther(TNTMode tntMode) { + this.tntMode = tntMode; + } + + public boolean isFreeze() { + return freeze; + } + + public void setFreeze(boolean freeze) { + this.freeze = freeze; + link(); + if (linkedRegion != null) { + linkedRegion.setFreezeOther(freeze); + } + } + + public void setFreezeOther(boolean freeze) { + this.freeze = freeze; + } + + public boolean isFire() { + return fire; + } + + public void setFire(boolean fire) { + this.fire = fire; + link(); + if (linkedRegion != null) { + linkedRegion.setFireOther(fire); + } + } + + public void setFireOther(boolean fire) { + this.fire = fire; + } + public boolean inRegion(Location l){ return prototype.inRegion(this, l); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index d0f2fc8..e50d7c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.CommandFire; -import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandScript; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.tracer.record.RecordStateMachine; @@ -153,6 +151,8 @@ public class ScriptListener implements Listener { index = ifJumpIndex; } continue; + default: + break; } PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command); @@ -235,6 +235,8 @@ public class ScriptListener implements Listener { case "--": add(scriptExecutor, args[0], -1); return; + default: + break; } setValue(scriptExecutor, args[0], args[1]); } @@ -280,17 +282,19 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { + Region region = Region.getRegion(scriptExecutor.player); switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; case "tnt": - return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; + return region == null || region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": - return CommandFreeze.getInstance().isOn() ? 1 : 0; + return region == null || !region.isFreeze() ? 0 : 1; case "fire": - return CommandFire.getInstance().isOn() ? 1 : 0; + return region == null || !region.isFire() ? 0 : 1; + default: + return scriptExecutor.variables.getOrDefault(key, 0); } - return scriptExecutor.variables.getOrDefault(key, 0); } private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { From 041741bc756d43551056019096d870d02fe20cb4 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 16:39:21 +0100 Subject: [PATCH 02/22] Fix CommandTNT Fix RegionToggleCommand --- .../bausystem/commands/CommandTNT.java | 51 ++++++++++--------- .../commands/RegionToggleCommand.java | 17 ++++--- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index c5ccad2..4230f93 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -116,31 +116,32 @@ public class CommandTNT implements CommandExecutor, Listener { } } - TNTMode finalRequestedMode = requestedMode; - String finalRequestedMessage = requestedMessage; - Region.getRegion(player.getLocation(), region -> { - if (finalRequestedMode != null) { - region.setTntMode(finalRequestedMode); - RegionToggleCommand.actionBar(region, finalRequestedMessage); - return; - } - switch (region.getTntMode()) { - case ON: - case ONLY_TB: - region.setTntMode(TNTMode.OFF); - RegionToggleCommand.actionBar(region, getDisableMessage()); - break; - case OFF: - if (Region.buildAreaEnabled()) { - region.setTntMode(TNTMode.ONLY_TB); - RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); - } else { - region.setTntMode(TNTMode.ON); - RegionToggleCommand.actionBar(region, getEnableMessage()); - } - break; - } - }, () -> RegionToggleCommand.actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player.getLocation()); + if (region == null) { + RegionToggleCommand.actionBar(player, getNoRegionMessage()); + return false; + } + if (requestedMode != null) { + region.setTntMode(requestedMode); + RegionToggleCommand.actionBar(region, requestedMessage); + return false; + } + switch (region.getTntMode()) { + case ON: + case ONLY_TB: + region.setTntMode(TNTMode.OFF); + RegionToggleCommand.actionBar(region, getDisableMessage()); + break; + case OFF: + if (Region.buildAreaEnabled()) { + region.setTntMode(TNTMode.ONLY_TB); + RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); + } else { + region.setTntMode(TNTMode.ON); + RegionToggleCommand.actionBar(region, getEnableMessage()); + } + break; + } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 7aaff41..6b01ea4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -52,13 +52,16 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region.getRegion(player.getLocation(), region -> { - if (toggle(region)) { - actionBar(region, getEnableMessage()); - } else { - actionBar(region, getDisableMessage()); - } - }, () -> actionBar(player, getNoRegionMessage())); + Region region = Region.getRegion(player); + if (region == null) { + actionBar(player, getNoRegionMessage()); + return false; + } + if (toggle(region)) { + actionBar(region, getEnableMessage()); + } else { + actionBar(region, getDisableMessage()); + } return false; } From 4268647057c212498e25df63f1d67c8b21ea9f82 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 16:41:42 +0100 Subject: [PATCH 03/22] Fix CommandInfo --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index ae8960f..3c31049 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -41,11 +41,12 @@ public class CommandInfo implements CommandExecutor { Player player = (Player) sender; sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - Region.getRegion(player.getLocation(), region -> { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); - }, () -> { + Region region = Region.getRegion(player); + if (region == null) { sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); - }); + } else { + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + } List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); From 90d006346515ee281fb2044220447af8b7ca5783 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:10:45 +0100 Subject: [PATCH 04/22] Add other region to toggleable --- .../bausystem/commands/CommandFire.java | 14 +++++-- .../bausystem/commands/CommandFreeze.java | 35 +++++++++++++---- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandTNT.java | 39 ++++++++++++++----- .../commands/RegionToggleCommand.java | 9 +++-- .../bausystem/world/BauScoreboard.java | 4 ++ .../de/steamwar/bausystem/world/Region.java | 11 ++++-- 7 files changed, 84 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index bd640fb..009b2d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -42,10 +42,6 @@ public class CommandFire extends RegionToggleCommand { String getDisableMessage(){ return "§aFeuerschaden aktiviert"; } - @Override - String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } @Override boolean toggle(Region region) { @@ -53,10 +49,18 @@ public class CommandFire extends RegionToggleCommand { return region.isFire(); } + @Override + boolean toggleGlobal() { + Region.NoRegion.fire = !Region.NoRegion.fire; + return Region.NoRegion.fire; + } + @EventHandler public void onFireDamage(BlockBurnEvent e) { Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.fire) e.setCancelled(true); }); } @@ -64,6 +68,8 @@ public class CommandFire extends RegionToggleCommand { public void onFireSpread(BlockSpreadEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFire()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.fire) e.setCancelled(true); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 9a9c80f..cb6b5b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -21,11 +21,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -50,10 +46,6 @@ public class CommandFreeze extends RegionToggleCommand { String getDisableMessage(){ return "§aWelt aufgetaut"; } - @Override - String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } @Override boolean toggle(Region region) { @@ -61,6 +53,12 @@ public class CommandFreeze extends RegionToggleCommand { return region.isFreeze(); } + @Override + boolean toggleGlobal() { + Region.NoRegion.freeze = !Region.NoRegion.freeze; + return Region.NoRegion.freeze; + } + @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { Region.getRegion(e.getLocation(), region -> { @@ -70,6 +68,13 @@ public class CommandFreeze extends RegionToggleCommand { if (e.getEntityType() == EntityType.FALLING_BLOCK) { e.setCancelled(true); } + }, () -> { + if (!Region.NoRegion.freeze) { + return; + } + if (e.getEntityType() == EntityType.FALLING_BLOCK) { + e.setCancelled(true); + } }); } @@ -77,6 +82,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -84,6 +91,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonExtend(BlockPistonExtendEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -91,6 +100,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onPistonRetract(BlockPistonRetractEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -98,6 +109,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockGrow(BlockGrowEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -105,6 +118,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onRedstoneEvent(BlockRedstoneEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); + }, () -> { + if (Region.NoRegion.freeze) e.setNewCurrent(e.getOldCurrent()); }); } @@ -112,6 +127,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onBlockDispense(BlockDispenseEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } @@ -119,6 +136,8 @@ public class CommandFreeze extends RegionToggleCommand { public void onInventoryMoveEvent(InventoryMoveItemEvent e){ Region.getRegion(e.getDestination().getLocation(), region -> { if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 3c31049..fa3ea86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -43,7 +43,7 @@ public class CommandInfo implements CommandExecutor { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(player); if (region == null) { - sender.sendMessage(BauSystem.PREFIX + "§7Du bist in keiner Region."); + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); } else { sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 4230f93..9e44eb8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -23,8 +23,6 @@ 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; @@ -77,10 +75,6 @@ public class CommandTNT implements CommandExecutor, Listener { return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } - private String getNoRegionMessage() { - return "§cDu befindest dich derzeit in keiner Region"; - } - @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { if (!(sender instanceof Player)) return false; @@ -118,13 +112,37 @@ public class CommandTNT implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { - RegionToggleCommand.actionBar(player, getNoRegionMessage()); + tntGlobalToggle(player, requestedMode, requestedMessage); return false; } + tntToggle(region, requestedMode, requestedMessage); + return false; + } + + private void tntGlobalToggle(Player player, TNTMode requestedMode, String requestedMessage) { + if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { + Region.NoRegion.tnt = requestedMode; + RegionToggleCommand.actionBar(player, requestedMessage); + return; + } + switch (Region.NoRegion.tnt) { + case ON: + case ONLY_TB: + Region.NoRegion.tnt = TNTMode.OFF; + RegionToggleCommand.actionBar(player, getDisableMessage()); + break; + case OFF: + Region.NoRegion.tnt = TNTMode.ON; + RegionToggleCommand.actionBar(player, getEnableMessage()); + break; + } + } + + private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null) { region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); - return false; + return; } switch (region.getTntMode()) { case ON: @@ -142,14 +160,15 @@ public class CommandTNT implements CommandExecutor, Listener { } break; } - return false; } @EventHandler public void onExplode(EntityExplodeEvent event) { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); - if (region == null) return false; + if (region == null) { + return Region.NoRegion.tnt == TNTMode.OFF; + } if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 6b01ea4..5661ec5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -27,7 +27,6 @@ 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 net.minecraft.server.v1_15_R1.BlockCactus; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -54,7 +53,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Region region = Region.getRegion(player); if (region == null) { - actionBar(player, getNoRegionMessage()); + if (toggleGlobal()) { + actionBar(player, getEnableMessage()); + } else { + actionBar(player, getDisableMessage()); + } return false; } if (toggle(region)) { @@ -73,7 +76,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); } - abstract String getNoRegionMessage(); abstract String getNoPermMessage(); abstract String getEnableMessage(); abstract String getDisableMessage(); @@ -82,5 +84,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} */ abstract boolean toggle(Region region); + abstract boolean toggleGlobal(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3faa945..3a9ae2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -64,6 +64,10 @@ public class BauScoreboard implements Listener { strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); + } else { + strings.add("§eTNT§8: " + Region.NoRegion.tnt.getName()); + strings.add("§eFreeze§8: " + (Region.NoRegion.freeze ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (Region.NoRegion.fire ? "§aaus" : "§can")); } strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 3c170f7..6388c0b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -42,6 +42,13 @@ public class Region { private static final List regions = new ArrayList<>(); private static boolean buildArea = false; + public static class NoRegion { + private NoRegion() {} + public static TNTMode tnt = TNTMode.OFF; + public static boolean fire = false; + public static boolean freeze = false; + } + static{ YamlConfiguration config = new YamlConfiguration(); try { @@ -78,10 +85,6 @@ public class Region { return null; } - public static void getRegion(Location location, Consumer regionConsumer) { - getRegion(location, regionConsumer, () -> {}); - } - public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { boolean b = true; for (Region region : regions) { From ddcbec834e9fdd03f20ef85ff52cd43664b09e65 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:37:21 +0100 Subject: [PATCH 05/22] Fix last stuff --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandProtect.java | 2 +- .../bausystem/commands/CommandReset.java | 2 +- .../bausystem/commands/CommandTestblock.java | 2 +- .../commands/RegionToggleCommand.java | 2 +- .../bausystem/world/BauScoreboard.java | 2 +- .../de/steamwar/bausystem/world/Region.java | 64 ++++++------------- .../bausystem/world/ScriptListener.java | 2 +- 8 files changed, 25 insertions(+), 53 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index fa3ea86..fd8fc56 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -41,7 +41,7 @@ public class CommandInfo implements CommandExecutor { Player player = (Player) sender; sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 6adcd6b..b6a34d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -45,7 +45,7 @@ public class CommandProtect implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasProtection()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index a75be05..934a383 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -45,7 +45,7 @@ public class CommandReset implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index e44d889..87ffbf3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -45,7 +45,7 @@ public class CommandTestblock implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasTestblock()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 5661ec5..49e36b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -51,7 +51,7 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { if (toggleGlobal()) { actionBar(player, getEnableMessage()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3a9ae2a..316cf00 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -59,7 +59,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"); - Region region = Region.getRegion(p); + Region region = Region.getRegion(p.getLocation()); if (region != null) { strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 6388c0b..590e033 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -29,7 +29,6 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; @@ -74,10 +73,6 @@ public class Region { return buildArea; } - public static Region getRegion(Player player) { - return getRegion(player.getLocation()); - } - public static Region getRegion(Location location) { for (Region region : regions) { if (region.inRegion(location)) return region; @@ -93,20 +88,7 @@ public class Region { b = false; } } - if (b) { - noRegion.run(); - } - } - - public static List getRegions(){ - return regions; - } - - private static Region getRegionByName(String name) { - for (Region region : regions) { - if (region.name.equals(name)) return region; - } - return null; + if (b) noRegion.run(); } private final String name; @@ -131,9 +113,20 @@ public class Region { regions.add(this); } - private void link() { - if (optionsLinkedWith != null && linkedRegion == null) { - linkedRegion = getRegionByName(optionsLinkedWith); + private void setLinkedRegion(Consumer regionConsumer) { + if (optionsLinkedWith == null) { + return; + } + if (linkedRegion != null) { + regionConsumer.accept(linkedRegion); + return; + } + for (Region region : regions) { + if (region.name.equals(name)) { + linkedRegion = region; + regionConsumer.accept(linkedRegion); + return; + } } } @@ -143,14 +136,7 @@ public class Region { public void setTntMode(TNTMode tntMode) { this.tntMode = tntMode; - link(); - if (linkedRegion != null) { - linkedRegion.setTntModeOther(tntMode); - } - } - - private void setTntModeOther(TNTMode tntMode) { - this.tntMode = tntMode; + setLinkedRegion(region -> region.tntMode = tntMode); } public boolean isFreeze() { @@ -159,14 +145,7 @@ public class Region { public void setFreeze(boolean freeze) { this.freeze = freeze; - link(); - if (linkedRegion != null) { - linkedRegion.setFreezeOther(freeze); - } - } - - public void setFreezeOther(boolean freeze) { - this.freeze = freeze; + setLinkedRegion(region -> region.freeze = freeze); } public boolean isFire() { @@ -175,14 +154,7 @@ public class Region { public void setFire(boolean fire) { this.fire = fire; - link(); - if (linkedRegion != null) { - linkedRegion.setFireOther(fire); - } - } - - public void setFireOther(boolean fire) { - this.fire = fire; + setLinkedRegion(region -> region.fire = fire); } public boolean inRegion(Location l){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 0bc9897..60c3121 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -282,7 +282,7 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { - Region region = Region.getRegion(scriptExecutor.player); + Region region = Region.getRegion(scriptExecutor.player.getLocation()); switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; From 2d068abe3224678b58bd0a726d5168559b3630b1 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 11:20:42 +0100 Subject: [PATCH 06/22] Remove Redstone ore activation while freezed --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index cb6b5b9..507c454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.world.Region; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; @@ -78,6 +79,15 @@ public class CommandFreeze extends RegionToggleCommand { }); } + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent e) { + Region.getRegion(e.getBlock().getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); + }); + } + @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { From 200926d41d948005d17d3aea8a04ea75c2d6c677 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 09:50:41 +0100 Subject: [PATCH 07/22] Fix merge conflicts --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index b3f05c6..507c454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -88,16 +88,6 @@ public class CommandFreeze extends RegionToggleCommand { }); } - @EventHandler - public void onEntitySpawn(EntitySpawnEvent e) { - e.setCancelled(true); - } - - @EventHandler - public void onEntityChangeBlock(EntityChangeBlockEvent e) { - e.setCancelled(true); - } - @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ Region.getRegion(e.getBlock().getLocation(), region -> { From 7be5700359979ff5283f0f806f32982fdee9573c Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 09:51:14 +0100 Subject: [PATCH 08/22] Fix merge conflicts --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 507c454..53d6395 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -16,7 +16,6 @@ * * 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; From 88b9ae0ec4b74ad4e563983ddb954343b2260b9b Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 11:12:27 +0100 Subject: [PATCH 09/22] Fix tnt spawning on redstone sources --- .../de/steamwar/bausystem/commands/CommandFreeze.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index c158459..8ab7445 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,7 +19,9 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -53,6 +55,11 @@ public class CommandFreeze extends ToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); + } } @EventHandler From 709e6f11dc78a2838a34cda46d6325400df7b614 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 11:13:33 +0100 Subject: [PATCH 10/22] Fix tnt spawning on redstone sources --- .../bausystem/commands/CommandFreeze.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 53d6395..4c1103e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -20,7 +20,10 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -65,15 +68,21 @@ public class CommandFreeze extends RegionToggleCommand { if (!region.isFreeze()) { return; } - if (e.getEntityType() == EntityType.FALLING_BLOCK) { - e.setCancelled(true); + e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); } }, () -> { if (!Region.NoRegion.freeze) { return; } - if (e.getEntityType() == EntityType.FALLING_BLOCK) { - e.setCancelled(true); + e.setCancelled(true); + if (e.getEntityType() == EntityType.PRIMED_TNT) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getLocation().getBlock().setType(Material.TNT, false); + }, 1); } }); } From 7b4c0681d0715d4c92a21cc5bc96d2c5d9108764 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 14:30:59 +0100 Subject: [PATCH 11/22] Fix copyright --- .../bausystem/commands/CommandFreeze.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 4c1103e..67b7e19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -1,26 +1,26 @@ /* - * - * 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 . - */ + 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.commands.RegionToggleCommand; import de.steamwar.bausystem.world.Region; import org.bukkit.Bukkit; import org.bukkit.Material; From 16ad0ad5e62fdba7906aba2af4bb7afaa5759942 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 14:31:24 +0100 Subject: [PATCH 12/22] Optimize Imports --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 67b7e19..769ecd5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.RegionToggleCommand; import de.steamwar.bausystem.world.Region; import org.bukkit.Bukkit; import org.bukkit.Material; From 168819e5c819da2f24e34626313ef810fd20b34f Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 15:38:12 +0100 Subject: [PATCH 13/22] Fix pr stuff --- .../de/steamwar/bausystem/commands/CommandFire.java | 4 ---- .../steamwar/bausystem/commands/CommandFreeze.java | 4 ---- .../de/steamwar/bausystem/commands/CommandTNT.java | 12 ++++++------ .../bausystem/commands/RegionToggleCommand.java | 10 +++++----- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 009b2d7..9c341d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -26,10 +26,6 @@ import org.bukkit.event.block.BlockSpreadEvent; public class CommandFire extends RegionToggleCommand { - public CommandFire() { - super(); - } - @Override String getNoPermMessage() { return "§cDu darfst hier nicht Feuerschaden (de-)aktivieren"; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 769ecd5..d456416 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -32,10 +32,6 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; public class CommandFreeze extends RegionToggleCommand { - public CommandFreeze(){ - super(); - } - @Override String getNoPermMessage() { return "§cDu darfst diese Welt nicht einfrieren"; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 9e44eb8..2199bc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,7 +36,7 @@ public class CommandTNT implements CommandExecutor, Listener { public enum TNTMode { ON("§aan"), - ONLY_TB("§7nur §eTestblock"), + ONLY_TB("§7Kein §eBaurahmen"), OFF("§caus"); private String name; @@ -112,28 +112,28 @@ public class CommandTNT implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { - tntGlobalToggle(player, requestedMode, requestedMessage); + tntGlobalToggle(requestedMode, requestedMessage); return false; } tntToggle(region, requestedMode, requestedMessage); return false; } - private void tntGlobalToggle(Player player, TNTMode requestedMode, String requestedMessage) { + private void tntGlobalToggle(TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { Region.NoRegion.tnt = requestedMode; - RegionToggleCommand.actionBar(player, requestedMessage); + RegionToggleCommand.actionBar(requestedMessage); return; } switch (Region.NoRegion.tnt) { case ON: case ONLY_TB: Region.NoRegion.tnt = TNTMode.OFF; - RegionToggleCommand.actionBar(player, getDisableMessage()); + RegionToggleCommand.actionBar(getDisableMessage()); break; case OFF: Region.NoRegion.tnt = TNTMode.ON; - RegionToggleCommand.actionBar(player, getEnableMessage()); + RegionToggleCommand.actionBar(getEnableMessage()); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 49e36b8..6eba349 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -36,7 +36,7 @@ import org.bukkit.event.Listener; public abstract class RegionToggleCommand implements CommandExecutor, Listener { - RegionToggleCommand() { + public RegionToggleCommand() { Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); } @@ -54,9 +54,9 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Region region = Region.getRegion(player.getLocation()); if (region == null) { if (toggleGlobal()) { - actionBar(player, getEnableMessage()); + actionBar(getEnableMessage()); } else { - actionBar(player, getDisableMessage()); + actionBar(getDisableMessage()); } return false; } @@ -72,8 +72,8 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } - public static void actionBar(Player player, String s) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)); + public static void actionBar(String s) { + Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); } abstract String getNoPermMessage(); From 4648186c1a864de2dd8663c1de48e4a1507d5cb6 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 15:39:06 +0100 Subject: [PATCH 14/22] Fix pr stuff --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 2199bc2..bc9e866 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -68,7 +68,7 @@ public class CommandTNT implements CommandExecutor, Listener { } private String getTestblockEnableMessage() { - return "§aTNT-Schaden am Testblock aktiviert"; + return "§aTNT-Schaden außerhalb Baurahmen aktiviert"; } private String getDamageMessage() { From d406ed7e66f6ac82c88fd786780429969a89c3c0 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 18:06:30 +0100 Subject: [PATCH 15/22] Fix CommandTNT for Region without Testblock --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 +++++- BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index bc9e866..e86ba40 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -140,6 +140,10 @@ public class CommandTNT implements CommandExecutor, Listener { private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null) { + if (!region.hasTestblock() && requestedMode == TNTMode.ONLY_TB) { + requestedMode = TNTMode.ON; + requestedMessage = getEnableMessage(); + } region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); return; @@ -151,7 +155,7 @@ public class CommandTNT implements CommandExecutor, Listener { RegionToggleCommand.actionBar(region, getDisableMessage()); break; case OFF: - if (Region.buildAreaEnabled()) { + if (Region.buildAreaEnabled() && region.hasTestblock()) { region.setTntMode(TNTMode.ONLY_TB); RegionToggleCommand.actionBar(region, getTestblockEnableMessage()); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 590e033..781a0b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -110,6 +110,7 @@ public class Region { minZ = config.getInt("minZ"); prototype = Prototype.prototypes.get(config.getString("prototype")); optionsLinkedWith = config.getString("optionsLinkedWith", null); + if (!hasTestblock()) tntMode = TNTMode.OFF; regions.add(this); } From 475f93426c10b77f12be2a761369198fc38d0596 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 18:09:16 +0100 Subject: [PATCH 16/22] Simplify CommandTNT for Region without Testblock --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index e86ba40..c976f9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -139,11 +139,7 @@ public class CommandTNT implements CommandExecutor, Listener { } private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { - if (requestedMode != null) { - if (!region.hasTestblock() && requestedMode == TNTMode.ONLY_TB) { - requestedMode = TNTMode.ON; - requestedMessage = getEnableMessage(); - } + if (requestedMode != null && region.hasTestblock()) { region.setTntMode(requestedMode); RegionToggleCommand.actionBar(region, requestedMessage); return; From 375885bbde4e2bf607d4514ce23fcf8d171af675 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 19:37:52 +0100 Subject: [PATCH 17/22] Fix Sound of TNT ignite with freeze enabled --- .../bausystem/commands/CommandFreeze.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index d456416..08097c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -60,24 +60,30 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { Region.getRegion(e.getLocation(), region -> { + if (region.isFreeze()) e.setCancelled(true); + }, () -> { + if (Region.NoRegion.freeze) e.setCancelled(true); + }); + } + + @EventHandler(ignoreCancelled = true) + public void onBlockCanBuild(BlockCanBuildEvent e) { + if (!e.isBuildable()) return; + Region.getRegion(e.getBlock().getLocation(), region -> { if (!region.isFreeze()) { return; } - e.setCancelled(true); - if (e.getEntityType() == EntityType.PRIMED_TNT) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1); + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); } }, () -> { if (!Region.NoRegion.freeze) { return; } - e.setCancelled(true); - if (e.getEntityType() == EntityType.PRIMED_TNT) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - e.getLocation().getBlock().setType(Material.TNT, false); - }, 1); + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); } }); } From 5c73e5874d8cdf961bcdd9902e19a21d13e07827 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 19:41:00 +0100 Subject: [PATCH 18/22] Fix Sound of TNT ignite with freeze enabled --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 08097c3..9c2ddac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -66,7 +66,7 @@ public class CommandFreeze extends RegionToggleCommand { }); } - @EventHandler(ignoreCancelled = true) + @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { if (!e.isBuildable()) return; Region.getRegion(e.getBlock().getLocation(), region -> { From 7cb2f224a2a5b25a5217da134c9d7115bc8344a7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:07:40 +0100 Subject: [PATCH 19/22] Fix freeze allow building of tnt --- .../src/de/steamwar/bausystem/commands/CommandFreeze.java | 3 --- .../src/de/steamwar/bausystem/world/RegionListener.java | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 9c2ddac..4873c01 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,11 +19,8 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityChangeBlockEvent; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 0719a4f..3019aad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -29,7 +29,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -59,13 +59,13 @@ public class RegionListener implements Listener { } @EventHandler(priority = EventPriority.LOWEST) - public void onBlockPlace(BlockPlaceEvent e) { + public void onBlockCanBuild(BlockCanBuildEvent e) { Player p = e.getPlayer(); try{ if (Welt.noPermission(p, Permission.build)){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); - e.setCancelled(true); + e.setBuildable(false); } }catch(NullPointerException ex){ //ignored, caused by worldedit brushes From 78c0e72178bfba86eef2ecfc1adb071bc8272c8c Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:21:31 +0100 Subject: [PATCH 20/22] Add plugin.yml --- BauSystem_Main/src/plugin.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..4d17a57 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,10 +1,12 @@ name: BauSystem -author: Lixfel +author: [Lixfel, YoyoNow, Chaoscaot] version: "1.0" depend: [WorldEdit, SpigotCore] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" +webside: www.steamwar.de +description: "So unseriös wie wir sind: BauSystem nur besser." commands: debugstick: From 5f0477e920e7a738d20cca633fb23c4b9ece7c86 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:25:23 +0100 Subject: [PATCH 21/22] Fix plugin.yml --- BauSystem_Main/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 74b9ef6..0c1df7e 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -5,7 +5,7 @@ depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" -webside: www.steamwar.de +website: "https://steamwar.de" description: "So unseriös wie wir sind: BauSystem nur besser." commands: From 607b1f155725836739f0c222823e65844709bea8 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 20:27:16 +0100 Subject: [PATCH 22/22] Fix plugin.yml --- BauSystem_Main/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 0c1df7e..5a10a50 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,5 +1,5 @@ name: BauSystem -author: [Lixfel, YoyoNow, Chaoscaot] +authors: [Lixfel, YoyoNow, Chaoscaot] version: "1.0" depend: [WorldEdit, SpigotCore, ProtocolLib] load: POSTWORLD