From 2f123d9a97d71d6793b8ae1db93eb177ce280514 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 11 Dec 2020 14:33:00 +0100 Subject: [PATCH 01/26] Refactoring sections.yml, Adding Region.paste to player history --- .../steamwar/bausystem/world/Region_12.java | 11 +- .../steamwar/bausystem/world/Region_15.java | 11 +- .../src/de/steamwar/bausystem/BauSystem.java | 27 +-- .../bausystem/commands/CommandProtect.java | 27 ++- .../bausystem/commands/CommandReset.java | 10 +- .../bausystem/commands/CommandTestblock.java | 37 ++-- .../bausystem/world/ArenaSection.java | 65 ------ .../de/steamwar/bausystem/world/Region.java | 206 +++++++++++++----- .../bausystem/world/RegionListener.java | 31 +-- 9 files changed, 226 insertions(+), 199 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java index 5170fb2..0330428 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.operation.Operations; @@ -30,16 +31,17 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Objects; -public class Region_12 { +class Region_12 { private Region_12(){} - static void paste(File file, int x, int y, int z, boolean rotate){ + static void paste(Player player, File file, int x, int y, int z, boolean rotate){ World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Clipboard clipboard; try { @@ -48,10 +50,10 @@ public class Region_12 { throw new SecurityException("Bausystem schematic not found", e); } - paste(clipboard, x, y, z, rotate); + paste(player, clipboard, x, y, z, rotate); } - static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ + static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); @@ -70,5 +72,6 @@ public class Region_12 { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); e.flushQueue(); + ((WorldEditPlugin) Bukkit.getServer().getPluginManager() .getPlugin("WorldEdit")).getSession(player).remember(e); } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java index e2998ec..6839f0e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.function.operation.Operations; @@ -37,16 +38,17 @@ import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; +import org.bukkit.entity.Player; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Objects; -public class Region_15 { +class Region_15 { private Region_15(){} - static void paste(File file, int x, int y, int z, boolean rotate){ + static void paste(Player player, File file, int x, int y, int z, boolean rotate){ Clipboard clipboard; try { clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file)).read(); @@ -54,10 +56,10 @@ public class Region_15 { throw new SecurityException("Bausystem schematic not found", e); } - paste(clipboard, x, y, z, rotate); + paste(player, clipboard, x, y, z, rotate); } - static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ + static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); @@ -74,6 +76,7 @@ public class Region_15 { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e).to(v).build()); e.flushSession(); + ((WorldEditPlugin) Objects.requireNonNull(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"))).getSession(player).remember(e); } static void fastpaste(File file, int x, int y, int z, boolean rotate){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 45641d7..d62aab6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -32,7 +32,6 @@ import org.bukkit.Bukkit; import org.bukkit.GameRule; import org.bukkit.Material; import org.bukkit.attribute.Attribute; -import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -46,19 +45,14 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import java.io.File; -import java.io.IOException; import java.util.Arrays; -import java.util.List; import java.util.UUID; import java.util.logging.Level; public class BauSystem extends JavaPlugin implements Listener { private static BauSystem plugin; private static UUID owner; - private static List sections; public static final String PREFIX = "§eBauSystem§8» §7"; - public static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; private BukkitTask autoShutdown; @@ -66,23 +60,10 @@ public class BauSystem extends JavaPlugin implements Listener { public void onEnable() { plugin = this; - String worldName = Bukkit.getWorlds().get(0).getName(); try { - owner = UUID.fromString(worldName); - sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + getOwner().toString() + "/sections.yml")); + owner = UUID.fromString(Bukkit.getWorlds().get(0).getName()); } catch (IllegalArgumentException e) { - try { - owner = null; - sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + worldName + "/sections.yml")); - } catch (IOException | InvalidConfigurationException ex) { - getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e); - Bukkit.shutdown(); - return; - } - } catch (InvalidConfigurationException | IOException e) { - getLogger().log(Level.SEVERE, "Failed to load sections.yml", e); - Bukkit.shutdown(); - return; + owner = null; } try { @@ -160,10 +141,6 @@ public class BauSystem extends JavaPlugin implements Listener { return owner; } - public static List getSections() { - return sections; - } - public static int getOwnerID() { return SteamwarUser.get(getOwner()).getId(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index b24b8e8..8e0bb6b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -21,13 +21,17 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.world.ArenaSection; +import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; +import de.steamwar.sql.Schematic; +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 java.util.logging.Level; + public class CommandProtect implements CommandExecutor { @Override @@ -41,10 +45,23 @@ public class CommandProtect implements CommandExecutor { return false; } - for(ArenaSection section : BauSystem.getSections()){ - if(section.inRegion(player.getLocation()) && section.hasProtection()){ - section.protect(); - player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + 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(player, 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; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 9967c14..f68d3f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.world.ArenaSection; +import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -45,8 +45,8 @@ public class CommandReset implements CommandExecutor { return false; } - for(ArenaSection section : BauSystem.getSections()){ - if(section.inRegion(player.getLocation())){ + for(Region region : Region.getRegions()){ + if(region.inRegion(player.getLocation()) && region.hasProtection()){ try { if(args.length > 0){ Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); @@ -54,9 +54,9 @@ public class CommandReset implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); return false; } - section.reset(schem); + region.reset(player, schem); }else{ - section.fastreset(); + region.fastreset(player); } player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); }catch(Exception e){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index cffac99..d7f060b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -21,16 +21,16 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.world.ArenaSection; +import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; -import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +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 java.io.IOException; +import java.util.logging.Level; public class CommandTestblock implements CommandExecutor { @@ -45,24 +45,23 @@ public class CommandTestblock implements CommandExecutor { return false; } - for(ArenaSection section : BauSystem.getSections()){ - if(section.inRegion(player.getLocation())){ - if(args.length > 0){ - Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if(schem == null){ - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - 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; + } } - try { - section.getTestblock().reset(schem); - } catch (IOException | NoClipboardException e) { - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Laden der Schematic"); - throw new SecurityException("Failed to load Testblock Schematic", e); - } - }else{ - section.getTestblock().reset(); + region.resetTestblock(player, 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 + "§7Testblock zurückgesetzt"); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java deleted file mode 100644 index f1bdc3d..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java +++ /dev/null @@ -1,65 +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.world; - -import de.steamwar.bausystem.BauSystem; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class ArenaSection extends Region { - - private final Region testblock; - private final String protectSchematic; - - private ArenaSection(ConfigurationSection config) { - super(config); - testblock = new Region(Objects.requireNonNull(config.getConfigurationSection("testblock"))); - protectSchematic = config.getString("protection"); - } - - public Region getTestblock(){ - return testblock; - } - - public static List loadFromFile(File file) throws IOException, InvalidConfigurationException { - YamlConfiguration config = new YamlConfiguration(); - config.load(file); - List list = new ArrayList<>(); - for(String section : config.getKeys(false)) - list.add(new ArenaSection(config.getConfigurationSection(section))); - return list; - } - - public boolean hasProtection(){ - return !protectSchematic.equals(""); - } - - public void protect(){ - File file = new File(BauSystem.SECTION_PATH + protectSchematic); - paste(file, minX + sizeX/2, testblock.minY-1, minZ + sizeZ/2, rotate); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 76af805..08e2b86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -20,88 +20,196 @@ package de.steamwar.bausystem.world; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import de.steamwar.bausystem.BauSystem; import de.steamwar.core.Core; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +import org.bukkit.Bukkit; 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.logging.Level; public class Region { - final int sizeX; - private final int sizeY; - final int sizeZ; - final int minX; - final int minY; - final int minZ; + private static final List regions = new ArrayList<>(); - private final String schematic; - final boolean rotate; + static{ + YamlConfiguration config = new YamlConfiguration(); + try { + config.load(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections.yml")); + } catch (InvalidConfigurationException | IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to load sections.yml", e); + } - Region(ConfigurationSection config){ - sizeX = config.getInt("sizeX"); - sizeY = config.getInt("sizeY"); - sizeZ = config.getInt("sizeZ"); + ConfigurationSection prototypes = config.getConfigurationSection("prototypes"); + assert prototypes != null; + for(String prototype : prototypes.getKeys(false)){ + new Prototype(Objects.requireNonNull(prototypes.getConfigurationSection(prototype))); + } + + ConfigurationSection regions = config.getConfigurationSection("regions"); + assert regions != null; + for(String region : regions.getKeys(false)){ + new Region(Objects.requireNonNull(prototypes.getConfigurationSection(region))); + } + } + + public static List getRegions(){ + return regions; + } + + private final int minX; + private final int minY; + private final int minZ; + private final Prototype prototype; + + private Region(ConfigurationSection config){ minX = config.getInt("minX"); minY = config.getInt("minY"); minZ = config.getInt("minZ"); - schematic = config.getString("schematic"); - rotate = config.getBoolean("rotate"); + prototype = Prototype.prototypes.get(config.getString("prototype")); + regions.add(this); } public boolean inRegion(Location l){ - return inRange(l.getX(), minX, sizeX) && inRange(l.getY(), minY, sizeY) && inRange(l.getZ(), minZ, sizeZ); + return prototype.inRegion(this, l); } - private boolean inRange(double l, int min, int size){ - return min <= l && l <= min + size; + public void fastreset(Player player){ + prototype.fastreset(player, this); } - public void fastreset(){ - File file = new File(BauSystem.SECTION_PATH + schematic); - fastpaste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate); + public void reset(Player player, Schematic schem) throws IOException, NoClipboardException { + prototype.reset(player, this, schem); } - public void reset(){ - File file = new File(BauSystem.SECTION_PATH + schematic); - paste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate); + public void resetTestblock(Player player, Schematic schem) throws IOException, NoClipboardException{ + prototype.resetTestblock(player, this, schem); } - public void reset(Schematic schem) throws IOException, NoClipboardException { - paste(schem.load(), minX + sizeX/2, minY, minZ + sizeZ/2, rotate); + public boolean hasProtection(){ + return prototype.hasProtection(); } - static void paste(File file, int x, int y, int z, boolean rotate){ - switch(Core.getVersion()){ - case 15: - Region_15.paste(file, x, y, z, rotate); - break; - default: - Region_12.paste(file, x, y, z, rotate); + public void protect(Player player, Schematic schem) throws IOException, NoClipboardException { + prototype.protect(player, this, schem); + } + + public static class Prototype{ + private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final Map prototypes = new HashMap<>(); + + private final int sizeX; + private final int sizeY; + private final int sizeZ; + + private final int offsetX; + private final int offsetY; + private final int offsetZ; + + private final String schematic; + private final boolean rotate; + + private final Prototype testblock; //nullable + private final String protectSchematic; //nullable + + private Prototype(ConfigurationSection config){ + sizeX = config.getInt("sizeX"); + sizeY = config.getInt("sizeY"); + sizeZ = config.getInt("sizeZ"); + schematic = config.getString("schematic"); + offsetX = config.getInt("offsetX", 0); + offsetY = config.getInt("offsetY", 0); + offsetZ = config.getInt("offsetZ", 0); + rotate = config.getBoolean("rotate", false); + + ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); + testblock = testblockSection != null ? new Prototype(testblockSection) : null; + protectSchematic = config.getString("protection", null); + + if(!config.getName().equals("testblock")) + prototypes.put(config.getName(), this); } - } - private static void fastpaste(File file, int x, int y, int z, boolean rotate){ - switch(Core.getVersion()){ - case 15: - Region_15.fastpaste(file, x, y, z, rotate); - break; - default: - Region_12.paste(file, x, y, z, rotate); + public boolean inRegion(Region region, Location l){ + return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && + inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); } - } - private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ - switch(Core.getVersion()){ - case 15: - Region_15.paste(clipboard, x, y, z, rotate); - break; - default: - Region_12.paste(clipboard, x, y, z, rotate); + public void fastreset(Player player, Region region){ + File file = new File(SECTION_PATH + schematic); + int x = region.minX + offsetX + sizeX/2; + int y = region.minY + offsetY; + int z = region.minZ + offsetZ + sizeZ/2; + switch(Core.getVersion()){ + case 12: + Region_12.paste(player, file, x, y, z, rotate); + break; + case 15: + default: + Region_15.fastpaste(file, x, y, z, rotate); + } + } + + public void reset(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { + int x = region.minX + offsetX + sizeX / 2; + int y = region.minY + offsetY; + int z = region.minZ + offsetZ + sizeZ / 2; + if(schem == null) + paste(player, new File(SECTION_PATH + schematic), x, y, z, rotate); + else + paste(player, schem.load(), x, y, z, rotate); + } + + public boolean hasProtection(){ + return protectSchematic != null; + } + + public void protect(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { + int x = region.minX + offsetX + sizeX / 2; + int y = region.minY + testblock.offsetY - 1; + int z = region.minZ + offsetZ + sizeZ / 2; + if(schem == null) + paste(player, new File(SECTION_PATH + protectSchematic), x, y, z, rotate); + else + paste(player, schem.load(), x, y, z, rotate); + } + + public void resetTestblock(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { + testblock.reset(player, region, schem); + } + + private static boolean inRange(double l, int min, int size){ + return min <= l && l <= min + size; + } + + private static void paste(Player player, File file, int x, int y, int z, boolean rotate){ //Type of protect + switch(Core.getVersion()){ + case 12: + Region_12.paste(player, file, x, y, z, rotate); + break; + case 15: + default: + Region_15.paste(player, file, x, y, z, rotate); + } + } + + private static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ + switch(Core.getVersion()){ + case 12: + Region_12.paste(player, clipboard, x, y, z, rotate); + break; + case 15: + default: + Region_15.paste(player, clipboard, x, y, z, rotate); + } } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index f2239dc..7bfdedf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -23,23 +23,15 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.core.Core; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.logging.Level; public class RegionListener implements Listener { @@ -53,13 +45,7 @@ public class RegionListener implements Listener { if (Welt.noPermission(p, Permission.worldedit)){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier kein WorldEdit benutzen"); e.setCancelled(true); - return; } - - /*if(!CommandFreeze.getInstance().isOn() && !Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")){ - CommandFreeze.getInstance().toggle(); - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), CommandFreeze.getInstance()::toggle, 3); - }*/ } @EventHandler(priority = EventPriority.LOWEST) @@ -86,15 +72,6 @@ public class RegionListener implements Listener { } } - private boolean isWorldEditCommand(String command) { - switch(Core.getVersion()){ - case 15: - return RegionListener_15.isWorldEditCommand(command); - default: - return RegionListener_12.isWorldEditCommand(command); - } - } - @EventHandler public void onSignChange(SignChangeEvent event) { for(int i = 0; i <= 3; ++i) { @@ -106,4 +83,12 @@ public class RegionListener implements Listener { } } + private static boolean isWorldEditCommand(String command) { + switch(Core.getVersion()){ + case 15: + return RegionListener_15.isWorldEditCommand(command); + default: + return RegionListener_12.isWorldEditCommand(command); + } + } } From 9126e6b3034f4f9fd5328451bb2ee0bcb31cb4de Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 12 Dec 2020 17:13:43 +0100 Subject: [PATCH 02/26] Removing changes from player history --- .../steamwar/bausystem/world/Region_12.java | 9 ++-- .../steamwar/bausystem/world/Region_15.java | 9 ++-- .../bausystem/commands/CommandProtect.java | 2 +- .../bausystem/commands/CommandReset.java | 4 +- .../bausystem/commands/CommandTestblock.java | 2 +- .../de/steamwar/bausystem/world/Region.java | 49 +++++++++---------- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java index 0330428..bfd38c6 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.operation.Operations; @@ -31,7 +30,6 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import java.io.File; import java.io.FileInputStream; @@ -41,7 +39,7 @@ import java.util.Objects; class Region_12 { private Region_12(){} - static void paste(Player player, File file, int x, int y, int z, boolean rotate){ + static void paste(File file, int x, int y, int z, boolean rotate){ World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Clipboard clipboard; try { @@ -50,10 +48,10 @@ class Region_12 { throw new SecurityException("Bausystem schematic not found", e); } - paste(player, clipboard, x, y, z, rotate); + paste(clipboard, x, y, z, rotate); } - static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ + static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); @@ -72,6 +70,5 @@ class Region_12 { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); e.flushQueue(); - ((WorldEditPlugin) Bukkit.getServer().getPluginManager() .getPlugin("WorldEdit")).getSession(player).remember(e); } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java index 6839f0e..cbec486 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.function.operation.Operations; @@ -38,7 +37,6 @@ import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; -import org.bukkit.entity.Player; import java.io.File; import java.io.FileInputStream; @@ -48,7 +46,7 @@ import java.util.Objects; class Region_15 { private Region_15(){} - static void paste(Player player, File file, int x, int y, int z, boolean rotate){ + static void paste(File file, int x, int y, int z, boolean rotate){ Clipboard clipboard; try { clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file)).read(); @@ -56,10 +54,10 @@ class Region_15 { throw new SecurityException("Bausystem schematic not found", e); } - paste(player, clipboard, x, y, z, rotate); + paste(clipboard, x, y, z, rotate); } - static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ + static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); @@ -76,7 +74,6 @@ class Region_15 { ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e).to(v).build()); e.flushSession(); - ((WorldEditPlugin) Objects.requireNonNull(Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"))).getSession(player).remember(e); } static void fastpaste(File file, int x, int y, int z, boolean rotate){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 8e0bb6b..f12afb7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -56,7 +56,7 @@ public class CommandProtect implements CommandExecutor { return false; } } - region.protect(player, schem); + region.protect(schem); player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); }catch(Exception e){ player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index f68d3f6..3844887 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -54,9 +54,9 @@ public class CommandReset implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); return false; } - region.reset(player, schem); + region.reset(schem); }else{ - region.fastreset(player); + region.fastreset(); } player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); }catch(Exception e){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index d7f060b..9d0bc15 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -56,7 +56,7 @@ public class CommandTestblock implements CommandExecutor { return false; } } - region.resetTestblock(player, schem); + region.resetTestblock(schem); player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); }catch(Exception e){ player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 08e2b86..034745b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -28,7 +28,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; @@ -81,24 +80,24 @@ public class Region { return prototype.inRegion(this, l); } - public void fastreset(Player player){ - prototype.fastreset(player, this); + public void fastreset(){ + prototype.fastreset(this); } - public void reset(Player player, Schematic schem) throws IOException, NoClipboardException { - prototype.reset(player, this, schem); + public void reset(Schematic schem) throws IOException, NoClipboardException { + prototype.reset(this, schem); } - public void resetTestblock(Player player, Schematic schem) throws IOException, NoClipboardException{ - prototype.resetTestblock(player, this, schem); + public void resetTestblock(Schematic schem) throws IOException, NoClipboardException{ + prototype.resetTestblock(this, schem); } public boolean hasProtection(){ return prototype.hasProtection(); } - public void protect(Player player, Schematic schem) throws IOException, NoClipboardException { - prototype.protect(player, this, schem); + public void protect(Schematic schem) throws IOException, NoClipboardException { + prototype.protect(this, schem); } public static class Prototype{ @@ -143,14 +142,14 @@ public class Region { inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); } - public void fastreset(Player player, Region region){ + public void fastreset(Region region){ File file = new File(SECTION_PATH + schematic); int x = region.minX + offsetX + sizeX/2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ/2; switch(Core.getVersion()){ case 12: - Region_12.paste(player, file, x, y, z, rotate); + Region_12.paste(file, x, y, z, rotate); break; case 15: default: @@ -158,57 +157,57 @@ public class Region { } } - public void reset(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { + public void reset(Region region, Schematic schem) throws IOException, NoClipboardException { int x = region.minX + offsetX + sizeX / 2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(player, new File(SECTION_PATH + schematic), x, y, z, rotate); + paste(new File(SECTION_PATH + schematic), x, y, z, rotate); else - paste(player, schem.load(), x, y, z, rotate); + paste(schem.load(), x, y, z, rotate); } public boolean hasProtection(){ return protectSchematic != null; } - public void protect(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { + public void protect(Region region, Schematic schem) throws IOException, NoClipboardException { int x = region.minX + offsetX + sizeX / 2; int y = region.minY + testblock.offsetY - 1; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(player, new File(SECTION_PATH + protectSchematic), x, y, z, rotate); + paste(new File(SECTION_PATH + protectSchematic), x, y, z, rotate); else - paste(player, schem.load(), x, y, z, rotate); + paste(schem.load(), x, y, z, rotate); } - public void resetTestblock(Player player, Region region, Schematic schem) throws IOException, NoClipboardException { - testblock.reset(player, region, schem); + public void resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException { + testblock.reset(region, schem); } private static boolean inRange(double l, int min, int size){ return min <= l && l <= min + size; } - private static void paste(Player player, File file, int x, int y, int z, boolean rotate){ //Type of protect + private static void paste(File file, int x, int y, int z, boolean rotate){ //Type of protect switch(Core.getVersion()){ case 12: - Region_12.paste(player, file, x, y, z, rotate); + Region_12.paste(file, x, y, z, rotate); break; case 15: default: - Region_15.paste(player, file, x, y, z, rotate); + Region_15.paste(file, x, y, z, rotate); } } - private static void paste(Player player, Clipboard clipboard, int x, int y, int z, boolean rotate){ + private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ switch(Core.getVersion()){ case 12: - Region_12.paste(player, clipboard, x, y, z, rotate); + Region_12.paste(clipboard, x, y, z, rotate); break; case 15: default: - Region_15.paste(player, clipboard, x, y, z, rotate); + Region_15.paste(clipboard, x, y, z, rotate); } } } From 6fe246b23045707647c04d3d022a9528cdc6aec1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 6 Jan 2021 13:48:36 +0100 Subject: [PATCH 03/26] Fix Regions --- BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 034745b..5bc4449 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -55,7 +55,7 @@ public class Region { ConfigurationSection regions = config.getConfigurationSection("regions"); assert regions != null; for(String region : regions.getKeys(false)){ - new Region(Objects.requireNonNull(prototypes.getConfigurationSection(region))); + new Region(Objects.requireNonNull(regions.getConfigurationSection(region))); } } From cbc8a919a62e063fde1a0a129568818cd20329c7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 16 Jan 2021 09:11:06 +0100 Subject: [PATCH 04/26] Hotfix region bug --- .../src/de/steamwar/bausystem/commands/CommandReset.java | 2 +- .../src/de/steamwar/bausystem/commands/CommandTestblock.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 3844887..353fd22 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -46,7 +46,7 @@ public class CommandReset implements CommandExecutor { } for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasProtection()){ + if(region.inRegion(player.getLocation())){ try { if(args.length > 0){ Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 9d0bc15..7543c54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -46,7 +46,7 @@ public class CommandTestblock implements CommandExecutor { } for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation()) && region.hasProtection()){ + if(region.inRegion(player.getLocation())){ try { Schematic schem = null; if(args.length > 0){ From 1afa2b9242fefaf7efd20105326b5f3514c5e44e Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 16 Jan 2021 18:33:51 +0100 Subject: [PATCH 05/26] Fix Advanced Trace mode --- .../steamwar/bausystem/tracer/show/mode/Advanced.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 2b692f7..49b5704 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -47,13 +47,13 @@ public class Advanced extends Basic { if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { for(TNTPosition pos : position.getRecord().getPositions()){ applyOnPosition(pos, updatePointPosition -> - updateEntityMap.computeIfPresent(updatePointPosition, (p, point) -> point.hide(player, false) ? null : point)); + updateEntityMap.computeIfPresent(new RoundedTNTPosition(updatePointPosition), (p, point) -> point.hide(player, false) ? null : point)); } return; } applyOnPosition(position, updatePointPosition -> - updateEntityMap.computeIfAbsent(updatePointPosition, pos -> createEntity(position.getLocation(), false)) + updateEntityMap.computeIfAbsent(new RoundedTNTPosition(updatePointPosition), pos -> createEntity(updatePointPosition, false)) .display(player, position.isExploded())); } @@ -64,13 +64,13 @@ public class Advanced extends Basic { updateEntityMap.clear(); } - private void applyOnPosition(TNTPosition position, Consumer function){ + private void applyOnPosition(TNTPosition position, Consumer function){ if (position.getPreviousLocation() == null) return; if (showModeParameter.isInterpolate_Y()) { Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); if(!position.getLocation().equals(updatePointY)) - function.accept(new RoundedTNTPosition(updatePointY)); + function.accept(updatePointY); } if (showModeParameter.isInterpolate_XZ()){ @@ -79,7 +79,7 @@ public class Advanced extends Basic { ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) : position.getLocation().clone().setX(position.getPreviousLocation().getX()); if(!position.getLocation().equals(updatePointXZ)) - function.accept(new RoundedTNTPosition(updatePointXZ)); + function.accept(updatePointXZ); } } } From b5b0cbf35e95262a741b92206d1ce25c0c64e94d Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 10:33:18 +0100 Subject: [PATCH 06/26] Fix Region with null testblock --- .../steamwar/bausystem/commands/CommandTestblock.java | 4 ++++ .../src/de/steamwar/bausystem/world/Region.java | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 7543c54..ffb1e3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -47,6 +47,10 @@ public class CommandTestblock implements CommandExecutor { for(Region region : Region.getRegions()){ if(region.inRegion(player.getLocation())){ + if (!region.hasTestblock()) { + player.sendMessage(BauSystem.PREFIX + "§cRegion ohne Testblock"); + return false; + } try { Schematic schem = null; if(args.length > 0){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 5bc4449..d066d09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -88,6 +88,10 @@ public class Region { prototype.reset(this, schem); } + public boolean hasTestblock() { + return prototype.hasTestblock(); + } + public void resetTestblock(Schematic schem) throws IOException, NoClipboardException{ prototype.resetTestblock(this, schem); } @@ -167,7 +171,7 @@ public class Region { paste(schem.load(), x, y, z, rotate); } - public boolean hasProtection(){ + public boolean hasProtection() { return protectSchematic != null; } @@ -181,6 +185,10 @@ public class Region { paste(schem.load(), x, y, z, rotate); } + public boolean hasTestblock() { + return testblock != null; + } + public void resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException { testblock.reset(region, schem); } From a22e1d37b92e9b537a1040d125e1f22a4affbec7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:04:46 +0100 Subject: [PATCH 07/26] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandBuildMode.java | 86 +++++++++++++++++++ .../bausystem/commands/CommandTNT.java | 8 ++ .../bausystem/world/BauScoreboard.java | 13 ++- .../de/steamwar/bausystem/world/Region.java | 19 +++- BauSystem_Main/src/plugin.yml | 1 + 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..2563e1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -82,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java new file mode 100644 index 0000000..d65fe6b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -0,0 +1,86 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Region; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityExplodeEvent; + +public class CommandBuildMode extends ToggleCommand { + + public CommandBuildMode() { + super(false); + } + + public static ToggleCommand getInstance() { + return getInstance(CommandBuildMode.class); + } + + @Override + String getNoPermMessage() { + return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; + } + + @Override + String getEnableMessage() { + return "§aBuild mode aktiviert"; + } + + @Override + String getDisableMessage() { + return "§cBuild mode deaktiviert"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + if (!CommandTNT.getInstance().isOn()) { + player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); + return false; + } + return super.onCommand(sender, command, label, args); + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..de342b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,6 +45,14 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } + @Override + public void toggle() { + if (CommandBuildMode.getInstance().isOn()) { + CommandBuildMode.getInstance().toggle(); + } + super.toggle(); + } + @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index c15abc1..e1b775f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.world; +import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -61,7 +62,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus")); + strings.add("§eTNT§8: " + tntString()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -104,4 +105,14 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } + private String tntString() { + if (!CommandTNT.getInstance().isOn()) { + if (CommandBuildMode.getInstance().isOn()) { + return "§eTestblock"; + } + return "§aan"; + } + return "§caus"; + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 5bc4449..b1f4ed4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -80,6 +80,14 @@ public class Region { return prototype.inRegion(this, l); } + public boolean hasBuildRegion() { + return prototype.buildArea != null; + } + + public boolean inBuildRegion(Location l) { + return prototype.buildArea.inRegion(this, l); + } + public void fastreset(){ prototype.fastreset(this); } @@ -101,7 +109,8 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -116,6 +125,8 @@ public class Region { private final boolean rotate; private final Prototype testblock; //nullable + private final Prototype buildArea; //nullable + private final String protectSchematic; //nullable private Prototype(ConfigurationSection config){ @@ -130,9 +141,13 @@ public class Region { ConfigurationSection testblockSection = config.getConfigurationSection("testblock"); testblock = testblockSection != null ? new Prototype(testblockSection) : null; + + ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); + buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + protectSchematic = config.getString("protection", null); - if(!config.getName().equals("testblock")) + if(!config.getName().equals("testblock") && !config.getName().equals("buildArea")) prototypes.put(config.getName(), this); } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..b589f20 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,6 +10,7 @@ commands: debugstick: tnt: fire: + buildmode: trace: tpslimit: testblock: From 3d57e563966928e113bec726fa70000c5d580666 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:05:33 +0100 Subject: [PATCH 08/26] Fix CommandTestblock --- .../de/steamwar/bausystem/commands/CommandTestblock.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index ffb1e3a..6859231 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -46,11 +46,7 @@ public class CommandTestblock implements CommandExecutor { } for(Region region : Region.getRegions()){ - if(region.inRegion(player.getLocation())){ - if (!region.hasTestblock()) { - player.sendMessage(BauSystem.PREFIX + "§cRegion ohne Testblock"); - return false; - } + if(region.inRegion(player.getLocation()) && region.hasTestblock()){ try { Schematic schem = null; if(args.length > 0){ From 0be031f5fed5dab3ed0aaf09d096574fe0c904ef Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 11:25:34 +0100 Subject: [PATCH 09/26] Add CommandBuildMode --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 12 ------------ .../de/steamwar/bausystem/commands/CommandTNT.java | 8 -------- .../de/steamwar/bausystem/world/BauScoreboard.java | 2 +- .../src/de/steamwar/bausystem/world/Region.java | 3 +-- 5 files changed, 3 insertions(+), 24 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 2563e1b..6f8ef7c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("tnt").setExecutor(new CommandTNT()); getCommand("buildmode").setExecutor(new CommandBuildMode()); + getCommand("tnt").setExecutor(new CommandTNT()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java index d65fe6b..51a3454 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java @@ -55,18 +55,6 @@ public class CommandBuildMode extends ToggleCommand { return "§cBuild mode deaktiviert"; } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; - Player player = (Player) sender; - if (!CommandTNT.getInstance().isOn()) { - player.sendMessage(BauSystem.PREFIX + "§cUm den Build mode zu nutzen muss TNT an sein."); - return false; - } - return super.onCommand(sender, command, label, args); - } - @EventHandler public void onEntityExplode(EntityExplodeEvent event) { boolean blocksDestroyed = event.blockList().removeIf(block -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index de342b1..7298c9b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -45,14 +45,6 @@ public class CommandTNT extends ToggleCommand { return "§aTNT-Schaden aktiviert"; } - @Override - public void toggle() { - if (CommandBuildMode.getInstance().isOn()) { - CommandBuildMode.getInstance().toggle(); - } - super.toggle(); - } - @EventHandler public void onExplode(EntityExplodeEvent e) { e.blockList().clear(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index e1b775f..5a696e8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -108,7 +108,7 @@ public class BauScoreboard implements Listener { private String tntString() { if (!CommandTNT.getInstance().isOn()) { if (CommandBuildMode.getInstance().isOn()) { - return "§eTestblock"; + return "§7nur §eTestblock"; } return "§aan"; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index b1f4ed4..f1949b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -109,8 +109,7 @@ public class Region { } public static class Prototype{ - // private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; - private static final String SECTION_PATH = "/home/yoyonow/Dev1.15//UserBau/f75632be-e3ec-4069-9bec-d13ac6891177/"; + private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; From 28b3733b83f1862314893f998db8e0453467c436 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 18:18:18 +0100 Subject: [PATCH 10/26] Simplify CommandTNT --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandBuildMode.java | 74 ------------ .../bausystem/commands/CommandTNT.java | 112 +++++++++++++++--- .../commands/CommandTNTTabComplete.java | 59 +++++++++ .../bausystem/world/BauScoreboard.java | 13 +- BauSystem_Main/src/plugin.yml | 1 - 6 files changed, 159 insertions(+), 102 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 6f8ef7c..96bde54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -81,8 +81,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("buildmode").setExecutor(new CommandBuildMode()); getCommand("tnt").setExecutor(new CommandTNT()); + getCommand("tnt").setTabCompleter(new CommandTNTTabComplete()); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java deleted file mode 100644 index 51a3454..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBuildMode.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.commands; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.world.Region; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityExplodeEvent; - -public class CommandBuildMode extends ToggleCommand { - - public CommandBuildMode() { - super(false); - } - - public static ToggleCommand getInstance() { - return getInstance(CommandBuildMode.class); - } - - @Override - String getNoPermMessage() { - return "§cDu darfst hier den Build mode nicht (de-)aktivieren"; - } - - @Override - String getEnableMessage() { - return "§aBuild mode aktiviert"; - } - - @Override - String getDisableMessage() { - return "§cBuild mode deaktiviert"; - } - - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; - } - } - return false; - }); - if (!blocksDestroyed) { - return; - } - Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(BauSystem.PREFIX + "§cEs ist etwas explodiert und hätte blöcke zerstört.")); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7298c9b..7726448 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -19,34 +19,118 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.Welt; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT extends ToggleCommand { +public class CommandTNT implements CommandExecutor { - public CommandTNT(){ - super(true); + private static TNTMode tntMode = TNTMode.OFF; + + public static TNTMode getTntMode() { + return tntMode; } - public static ToggleCommand getInstance(){ - return getInstance(CommandTNT.class); + public enum TNTMode { + ON("§aan"), + ONLY_TB("§7nur §eTestblock"), + OFF("§caus"); + + private String name; + + TNTMode(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } - @Override - String getNoPermMessage() { + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } - @Override - String getEnableMessage(){ + + private String getEnableMessage() { return "§cTNT-Schaden deaktiviert"; } - @Override - String getDisableMessage(){ + + private String getDisableMessage() { return "§aTNT-Schaden aktiviert"; } - @EventHandler - public void onExplode(EntityExplodeEvent e) { - e.blockList().clear(); + private String getTestblockEnableMessage() { + return "§aTNT-Schaden beim Testblock aktiviert"; } + + private String getDamageMessage() { + return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) return false; + Player player = (Player) sender; + + if (Welt.noPermission(player, Permission.world)) { + player.sendMessage(BauSystem.PREFIX + getNoPermMessage()); + return false; + } + + if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + } + + switch (tntMode) { + case ON: + case ONLY_TB: + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + break; + case OFF: + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + break; + } + return false; + } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + if (tntMode == TNTMode.ON) return; + if (tntMode == TNTMode.OFF) { + event.blockList().clear(); + } else { + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } + } + return false; + }); + if (!blocksDestroyed) { + return; + } + sendToActionBar(getDamageMessage()); + } + } + + private void sendToActionBar(String message) { + Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message))); + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java new file mode 100644 index 0000000..d79f448 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -0,0 +1,59 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.bausystem.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class CommandTNTTabComplete implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return new ArrayList<>(); + return detonaterTabComplete((Player) sender, args); + } + + private List detonaterTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("an"); + + if (args.length >= 2) { + return new ArrayList<>(); + } + return manageList(tabComplete, args, 0); + } + + private List manageList(List strings, String[] args, int index) { + for (int i = strings.size() - 1; i >= 0; i--) { + if (!strings.get(i).startsWith(args[index])) { + strings.remove(i); + } + } + return strings; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5a696e8..8aaf994 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.commands.CommandBuildMode; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.commands.CommandTPSLimiter; @@ -62,7 +61,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - strings.add("§eTNT§8: " + tntString()); + strings.add("§eTNT§8: " + CommandTNT.getTntMode().getName()); strings.add("§eFreeze§8: " + (CommandFreeze.getInstance().isOn() ? "§aan" : "§caus")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); @@ -105,14 +104,4 @@ public class BauScoreboard implements Listener { return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); } - private String tntString() { - if (!CommandTNT.getInstance().isOn()) { - if (CommandBuildMode.getInstance().isOn()) { - return "§7nur §eTestblock"; - } - return "§aan"; - } - return "§caus"; - } - } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index b589f20..bc85fb9 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,7 +10,6 @@ commands: debugstick: tnt: fire: - buildmode: trace: tpslimit: testblock: From 9bb234bf32b8bcbf9f41272c2c490a0d1bdcba9e Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 21:03:04 +0100 Subject: [PATCH 11/26] Fix Region.Prototype.SECTION_PATH --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 3 +++ BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..279e3fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -42,6 +42,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import java.nio.file.Paths; import java.util.UUID; import java.util.logging.Level; @@ -74,6 +75,8 @@ public class BauSystem extends JavaPlugin implements Listener { return; } + System.out.println(Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath()); + getCommand("trace").setExecutor(new CommandTrace()); getCommand("trace").setTabCompleter(new CommandTraceTabCompleter()); getCommand("tpslimit").setExecutor(new CommandTPSLimiter()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index d066d09..f428ee3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -105,7 +105,7 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = "/home/minecraft/backbone/server/UserBau/"; + private static final String SECTION_PATH = Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath() + "/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; From ae6d5ee6713bd591b2ea725e3e4839085e903217 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 13:58:02 +0100 Subject: [PATCH 12/26] Fix PR stuff --- .../bausystem/commands/CommandTNT.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 7726448..94f4d4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -31,9 +31,10 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT implements CommandExecutor { +public class CommandTNT implements CommandExecutor, Listener { private static TNTMode tntMode = TNTMode.OFF; @@ -58,6 +59,10 @@ public class CommandTNT implements CommandExecutor { } + public CommandTNT() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } + private String getNoPermMessage() { return "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"; } @@ -71,11 +76,11 @@ public class CommandTNT implements CommandExecutor { } private String getTestblockEnableMessage() { - return "§aTNT-Schaden beim Testblock aktiviert"; + return "§aTNT-Schaden am Testblock aktiviert"; } private String getDamageMessage() { - return "§cEs ist etwas explodiert und hätte blöcke zerstört"; + return "§cEine Explosion hätte Blöcke im Baubereich zerstört"; } @Override @@ -110,22 +115,25 @@ public class CommandTNT implements CommandExecutor { @EventHandler public void onExplode(EntityExplodeEvent event) { - if (tntMode == TNTMode.ON) return; - if (tntMode == TNTMode.OFF) { - event.blockList().clear(); - } else { - boolean blocksDestroyed = event.blockList().removeIf(block -> { - for (Region region : Region.getRegions()) { - if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { - return true; + switch (tntMode) { + case ON: + break; + case OFF: + event.blockList().clear(); + break; + case ONLY_TB: + boolean blocksDestroyed = event.blockList().removeIf(block -> { + for (Region region : Region.getRegions()) { + if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { + return true; + } } + return false; + }); + if (blocksDestroyed) { + sendToActionBar(getDamageMessage()); } - return false; - }); - if (!blocksDestroyed) { - return; - } - sendToActionBar(getDamageMessage()); + break; } } From 84686357c598977ea13ad19cad11e7f3f0b92fae Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 14:02:01 +0100 Subject: [PATCH 13/26] Fix PR stuff --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 279e3fb..4dbb0a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -75,8 +75,6 @@ public class BauSystem extends JavaPlugin implements Listener { return; } - System.out.println(Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath()); - getCommand("trace").setExecutor(new CommandTrace()); getCommand("trace").setTabCompleter(new CommandTraceTabCompleter()); getCommand("tpslimit").setExecutor(new CommandTPSLimiter()); From 36a601a610f9eda8fe4278d3065d10fc25cdb9f7 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 16:13:32 +0100 Subject: [PATCH 14/26] Fix PR stuff --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 1 - BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 4dbb0a1..9a7276b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -42,7 +42,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import java.nio.file.Paths; import java.util.UUID; import java.util.logging.Level; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index f428ee3..a518b80 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -105,7 +105,6 @@ public class Region { } public static class Prototype{ - private static final String SECTION_PATH = Bukkit.getWorlds().get(0).getWorldFolder().getAbsolutePath() + "/"; private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -147,7 +146,7 @@ public class Region { } public void fastreset(Region region){ - File file = new File(SECTION_PATH + schematic); + File file = new File(schematic); int x = region.minX + offsetX + sizeX/2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ/2; @@ -166,7 +165,7 @@ public class Region { int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(new File(SECTION_PATH + schematic), x, y, z, rotate); + paste(new File(schematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); } @@ -180,7 +179,7 @@ public class Region { int y = region.minY + testblock.offsetY - 1; int z = region.minZ + offsetZ + sizeZ / 2; if(schem == null) - paste(new File(SECTION_PATH + protectSchematic), x, y, z, rotate); + paste(new File(protectSchematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); } From f04bf70087b00500c61556e1f7f05dd66b91b93a Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 14:50:19 +0100 Subject: [PATCH 15/26] Fix Build issues --- .../steamwar/bausystem/commands/CommandInfo.java | 2 +- .../steamwar/bausystem/commands/CommandTNT.java | 16 +++++++++++++--- .../commands/CommandTNTTabComplete.java | 9 +++++++-- .../steamwar/bausystem/world/ScriptListener.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 0b506d9..82b2563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getInstance().isOn() ? "§aAUS" : "§cAN")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 94f4d4e..bbebb25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -68,11 +68,11 @@ public class CommandTNT implements CommandExecutor, Listener { } private String getEnableMessage() { - return "§cTNT-Schaden deaktiviert"; + return "§aTNT-Schaden aktiviert"; } private String getDisableMessage() { - return "§aTNT-Schaden aktiviert"; + return "§cTNT-Schaden deaktiviert"; } private String getTestblockEnableMessage() { @@ -93,11 +93,21 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && args[0].equalsIgnoreCase("on")) { + if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { tntMode = TNTMode.ON; sendToActionBar(getEnableMessage()); return false; } + if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + } + if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + } switch (tntMode) { case ON: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index d79f448..5ce5c30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -34,12 +34,17 @@ public class CommandTNTTabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return detonaterTabComplete((Player) sender, args); + return tntTabComplete((Player) sender, args); } - private List detonaterTabComplete(Player player, String[] args) { + private List tntTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("an"); + tabComplete.add("on"); + tabComplete.add("aus"); + tabComplete.add("off"); + tabComplete.add("testblock"); + tabComplete.add("tb"); if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 762aff6..d0f2fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -284,7 +284,7 @@ public class ScriptListener implements Listener { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; case "tnt": - return CommandTNT.getInstance().isOn() ? 1 : 0; + return CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": return CommandFreeze.getInstance().isOn() ? 1 : 0; case "fire": From bd8a34dd1583fbbe8db6f16c0ef287783fcb5f2e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 24 Jan 2021 14:58:58 +0100 Subject: [PATCH 16/26] Fixing region size --- BauSystem_Main/src/de/steamwar/bausystem/world/Region.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index a518b80..1a13714 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -140,9 +140,9 @@ public class Region { } public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && - inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && - inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); + return inRange(l.getX(), region.minX + offsetX, sizeX) && + inRange(l.getY(), region.minY + offsetY, sizeY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public void fastreset(Region region){ From 7871a88824cd63a2f82328d0a5ed9b61945212da Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 17:02:34 +0100 Subject: [PATCH 17/26] Add CommandTNT by Region.buildAreaEnabled() --- .../de/steamwar/bausystem/commands/CommandTNT.java | 11 ++++++++--- .../bausystem/commands/CommandTNTTabComplete.java | 11 +++++++---- .../src/de/steamwar/bausystem/world/Region.java | 14 +++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index bbebb25..3443dee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -103,7 +103,7 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { + if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { tntMode = TNTMode.ONLY_TB; sendToActionBar(getTestblockEnableMessage()); return false; @@ -116,8 +116,13 @@ public class CommandTNT implements CommandExecutor, Listener { sendToActionBar(getDisableMessage()); break; case OFF: - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); + if (Region.buildAreaEnabled()) { + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + } else { + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + } break; } return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index 5ce5c30..dbc18b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -34,17 +35,19 @@ public class CommandTNTTabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return tntTabComplete((Player) sender, args); + return tntTabComplete(args); } - private List tntTabComplete(Player player, String[] args) { + private List tntTabComplete(String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("an"); tabComplete.add("on"); tabComplete.add("aus"); tabComplete.add("off"); - tabComplete.add("testblock"); - tabComplete.add("tb"); + if (Region.buildAreaEnabled()) { + tabComplete.add("testblock"); + tabComplete.add("tb"); + } if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index f1949b1..6f7ec11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -37,6 +37,11 @@ import java.util.logging.Level; public class Region { private static final List regions = new ArrayList<>(); + private static boolean buildArea = false; + + public static boolean buildAreaEnabled() { + return buildArea; + } static{ YamlConfiguration config = new YamlConfiguration(); @@ -143,6 +148,9 @@ public class Region { ConfigurationSection buildAreaSection = config.getConfigurationSection("buildArea"); buildArea = buildAreaSection != null ? new Prototype(buildAreaSection) : null; + if (buildArea != null) { + Region.buildArea = true; + } protectSchematic = config.getString("protection", null); @@ -151,9 +159,9 @@ public class Region { } public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX + offsetX) && - inRange(l.getY(), region.minY + offsetY, sizeY + offsetY) && - inRange(l.getZ(), region.minZ + offsetZ, sizeZ + offsetZ); + return inRange(l.getX(), region.minX + offsetX, sizeX) && + inRange(l.getY(), region.minY + offsetY, sizeY) && + inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public void fastreset(Region region){ From f887e633adc1a9371ae35b39468cca7a6f124305 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 20:07:19 +0100 Subject: [PATCH 18/26] Add CommandTNT by Region.buildAreaEnabled() --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandTNT.java | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index 82b2563..c6810f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -34,7 +34,7 @@ public class CommandInfo implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + (CommandTNT.getTntMode() == CommandTNT.TNTMode.OFF ? "§cAN" : "§aAUS")); + sender.sendMessage(BauSystem.PREFIX + "TNT-Schaden: " + CommandTNT.getTntMode().getName()); sender.sendMessage(BauSystem.PREFIX + "Feuerschaden: " + (CommandFire.getInstance().isOn() ? "§aAUS" : "§cAN")); sender.sendMessage(BauSystem.PREFIX + "Eingefroren: " + (CommandFreeze.getInstance().isOn() ? "§aJA" : "§cNEIN")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 3443dee..23ab3b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -93,20 +93,27 @@ public class CommandTNT implements CommandExecutor, Listener { return false; } - if (args.length != 0 && (args[0].equalsIgnoreCase("an") || args[0].equalsIgnoreCase("on"))) { - tntMode = TNTMode.ON; - sendToActionBar(getEnableMessage()); - return false; - } - if (args.length != 0 && (args[0].equalsIgnoreCase("aus") || args[0].equalsIgnoreCase("off"))) { - tntMode = TNTMode.OFF; - sendToActionBar(getDisableMessage()); - return false; - } - if (args.length != 0 && Region.buildAreaEnabled() && (args[0].equalsIgnoreCase("testblock") || args[0].equalsIgnoreCase("tb"))) { - tntMode = TNTMode.ONLY_TB; - sendToActionBar(getTestblockEnableMessage()); - return false; + if (args.length != 0) { + switch (args[0].toLowerCase()) { + case "an": + case "on": + tntMode = TNTMode.ON; + sendToActionBar(getEnableMessage()); + return false; + case "aus": + case "off": + tntMode = TNTMode.OFF; + sendToActionBar(getDisableMessage()); + return false; + case "testblock": + case "tb": + if (!Region.buildAreaEnabled()) break; + tntMode = TNTMode.ONLY_TB; + sendToActionBar(getTestblockEnableMessage()); + return false; + default: + break; + } } switch (tntMode) { From 4e4a1eb3e8908c7644990e4c375bfe8b1e157372 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 21:12:36 +0100 Subject: [PATCH 19/26] Add TNTMode to ONLY_TB --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 23ab3b6..e4dd091 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -38,6 +38,12 @@ public class CommandTNT implements CommandExecutor, Listener { private static TNTMode tntMode = TNTMode.OFF; + static { + if (Region.buildAreaEnabled()) { + tntMode = TNTMode.ONLY_TB; + } + } + public static TNTMode getTntMode() { return tntMode; } From 093ab5802ed0c6a108fc8a7a44e4908b9d410202 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 24 Jan 2021 21:15:19 +0100 Subject: [PATCH 20/26] Add TNTMode to ONLY_TB --- .../src/de/steamwar/bausystem/commands/CommandTNT.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index e4dd091..91eb203 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -36,13 +36,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class CommandTNT implements CommandExecutor, Listener { - private static TNTMode tntMode = TNTMode.OFF; - - static { - if (Region.buildAreaEnabled()) { - tntMode = TNTMode.ONLY_TB; - } - } + private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; public static TNTMode getTntMode() { return tntMode; From 1ddc58d1fbd0b583fa4d779c74be0b8acbdb23a6 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:22:22 +0100 Subject: [PATCH 21/26] Hotfix ScriptListener Script Book check --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index d0f2fc8..3fb474c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -55,7 +55,7 @@ public class ScriptListener implements Listener { if(item == null || isNoBook(item) || item.getItemMeta() == null) return; - if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) { + if (CommandScript.BOOK.getItemMeta() != null && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(CommandScript.BOOK.getItemMeta().getDisplayName())) { return; } From 56402bb0120d415714a90f03c8a62b7827060c9a Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:23:51 +0100 Subject: [PATCH 22/26] Optimize CommandTPSLimiter with accuracy --- .../bausystem/commands/CommandTPSLimiter.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 051d4f7..7d2e71f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; +import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -36,10 +37,14 @@ import org.bukkit.scheduler.BukkitTask; public class CommandTPSLimiter implements CommandExecutor { private static double currentTPSLimit = 20; - private static World world = Bukkit.getWorlds().get(0); private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); + private static final long neededDelta = 50; + private static long neededDeltaFix = 50; + + private static World world = Bukkit.getWorlds().get(0); + private BukkitTask tpsLimiter = null; private boolean permissionCheck(Player player) { @@ -104,8 +109,13 @@ public class CommandTPSLimiter implements CommandExecutor { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8), new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14)); - for (int i = 0; i < (20 / currentTPSLimit); i++) { - sleepUntilNextTick(); + + double delay = 50 * (20 / currentTPSLimit); + int loops = (int)Math.ceil(delay / 50.0); + long sleepDelay = (long) delay / loops; + + for (int i = 0; i < loops; i++) { + sleepUntilNextTick(sleepDelay); VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8), new VersionedRunnable(TPSLimit_15::sendTickPackets, 14)); } @@ -113,16 +123,12 @@ public class CommandTPSLimiter implements CommandExecutor { } } - private void sleepUntilNextTick() { + private void sleepUntilNextTick(long neededDelta) { lastTime = currentTime; currentTime = System.nanoTime(); long timeDelta = (currentTime - lastTime) / 1000000; - long neededDelta = 50; - - if (neededDelta - timeDelta < 0) { - return; - } + if (neededDelta - timeDelta < 0) return; try { Thread.sleep(neededDelta - timeDelta); From 47e268fb5400ef7e8889738b74eddfc50d7078aa Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:24:57 +0100 Subject: [PATCH 23/26] Optimize Imports --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 7d2e71f..4f27fe6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; From 55c5c3bda5ab7549a28a6e1cdfdacc02821c7ab7 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:25:36 +0100 Subject: [PATCH 24/26] Remove unused fields --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 4f27fe6..0b9f4d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -39,9 +39,6 @@ public class CommandTPSLimiter implements CommandExecutor { private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); - private static final long neededDelta = 50; - private static long neededDeltaFix = 50; - private static World world = Bukkit.getWorlds().get(0); private BukkitTask tpsLimiter = null; From 8bb76d656fc9a6394da756f9b2a4198ec054615b Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:31:55 +0100 Subject: [PATCH 25/26] Remove unused fields --- .../bausystem/commands/CommandTPSLimiter.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 0b9f4d7..97cee3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -35,11 +35,15 @@ import org.bukkit.scheduler.BukkitTask; public class CommandTPSLimiter implements CommandExecutor { + private static final World WORLD = Bukkit.getWorlds().get(0); private static double currentTPSLimit = 20; + private long lastTime = System.nanoTime(); private long currentTime = System.nanoTime(); - private static World world = Bukkit.getWorlds().get(0); + private double delay = 0; + private int loops = 0; + private long sleepDelay = 0; private BukkitTask tpsLimiter = null; @@ -96,6 +100,10 @@ public class CommandTPSLimiter implements CommandExecutor { } private void tpsLimiter() { + delay = 50 * (20 / currentTPSLimit); + loops = (int)Math.ceil(delay / 50.0); + sleepDelay = (long) delay / loops; + if (currentTPSLimit == 20) { if (tpsLimiter == null) return; tpsLimiter.cancel(); @@ -103,12 +111,8 @@ public class CommandTPSLimiter implements CommandExecutor { } else { if (tpsLimiter != null) return; tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8), - new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14)); - - double delay = 50 * (20 / currentTPSLimit); - int loops = (int)Math.ceil(delay / 50.0); - long sleepDelay = (long) delay / loops; + VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(WORLD), 8), + new VersionedRunnable(() -> TPSLimit_15.createTickCache(WORLD), 14)); for (int i = 0; i < loops; i++) { sleepUntilNextTick(sleepDelay); From fc275166cb135acfbba7de5da3d6aba8b86e5c87 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 10:58:12 +0100 Subject: [PATCH 26/26] Simplify math expressions --- .../de/steamwar/bausystem/commands/CommandTPSLimiter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 97cee3a..7a749c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -100,9 +100,9 @@ public class CommandTPSLimiter implements CommandExecutor { } private void tpsLimiter() { - delay = 50 * (20 / currentTPSLimit); - loops = (int)Math.ceil(delay / 50.0); - sleepDelay = (long) delay / loops; + delay = 20 / currentTPSLimit; + loops = (int)Math.ceil(delay); + sleepDelay = (long) (50 * delay) / loops; if (currentTPSLimit == 20) { if (tpsLimiter == null) return;