From 96d51b3c0ee3536e56b82e794d62b8d83f3681dd Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 11 Jul 2019 18:27:46 +0200 Subject: [PATCH] Fixing path typo --- src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandProtect.java | 36 ++++++++++++++++++ .../bausystem/world/ArenaSection.java | 37 +++++++++++++++++++ src/de/steamwar/bausystem/world/Region.java | 12 +++--- src/plugin.yml | 1 + 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/de/steamwar/bausystem/commands/CommandProtect.java diff --git a/src/de/steamwar/bausystem/BauSystem.java b/src/de/steamwar/bausystem/BauSystem.java index 86da5db..69eb984 100644 --- a/src/de/steamwar/bausystem/BauSystem.java +++ b/src/de/steamwar/bausystem/BauSystem.java @@ -75,6 +75,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("testblock").setExecutor(new CommandTestblock()); getCommand("bau").setExecutor(new CommandBau()); getCommand("bauinfo").setExecutor(new CommandInfo()); + getCommand("protect").setExecutor(new CommandProtect()); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); diff --git a/src/de/steamwar/bausystem/commands/CommandProtect.java b/src/de/steamwar/bausystem/commands/CommandProtect.java new file mode 100644 index 0000000..badc3cd --- /dev/null +++ b/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -0,0 +1,36 @@ +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.Welt; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandProtect implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + + if(!Welt.hasPermission(player, Permission.worldedit)){ + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Boden schützen"); + return false; + } + + for(ArenaSection section : BauSystem.getSections()){ + if(section.inRegion(player.getLocation()) && section.hasProtection()){ + section.protect(); + player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + return false; + } + } + + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); + return false; + } +} \ No newline at end of file diff --git a/src/de/steamwar/bausystem/world/ArenaSection.java b/src/de/steamwar/bausystem/world/ArenaSection.java index 0e47586..d097468 100644 --- a/src/de/steamwar/bausystem/world/ArenaSection.java +++ b/src/de/steamwar/bausystem/world/ArenaSection.java @@ -1,5 +1,13 @@ package de.steamwar.bausystem.world; +import com.boydti.fawe.FaweAPI; +import com.boydti.fawe.object.schematic.Schematic; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.world.World; +import de.steamwar.bausystem.BauSystem; +import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -12,10 +20,12 @@ import java.util.List; public class ArenaSection extends Region { private final Region testblock; + private final String protectSchematic; private ArenaSection(ConfigurationSection config) { super(config); testblock = new Region(config.getConfigurationSection("testblock")); + protectSchematic = config.getString("protection"); } public Region getTestblock(){ @@ -30,4 +40,31 @@ public class ArenaSection extends Region { 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); + Schematic schem; + try { + schem = FaweAPI.load(file); + }catch(IOException e){ + e.printStackTrace(); + return; + } + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + Vector dimensions = schem.getClipboard().getDimensions(); + Vector v = new Vector(minX + sizeX/2, testblock.minY-1, minZ + sizeZ/2); + Vector offset = new Vector(schem.getClipboard().getRegion().getMinimumPoint()).subtract(schem.getClipboard().getOrigin()); + AffineTransform aT = new AffineTransform(); + if(rotate){ + aT = aT.rotateY(180); + v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + }else{ + v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); + } + schem.paste(w, v, false, true, aT).flushQueue(); + } } diff --git a/src/de/steamwar/bausystem/world/Region.java b/src/de/steamwar/bausystem/world/Region.java index e81d83c..5ecdbe0 100644 --- a/src/de/steamwar/bausystem/world/Region.java +++ b/src/de/steamwar/bausystem/world/Region.java @@ -15,16 +15,16 @@ import java.io.File; import java.io.IOException; public class Region { - private final int sizeX; + final int sizeX; private final int sizeY; - private final int sizeZ; + final int sizeZ; - private final int minX; - private final int minY; - private final int minZ; + final int minX; + final int minY; + final int minZ; private final String schematic; - private final boolean rotate; + final boolean rotate; Region(ConfigurationSection config){ sizeX = config.getInt("sizeX"); diff --git a/src/plugin.yml b/src/plugin.yml index d150aba..898a8a6 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -11,6 +11,7 @@ commands: testblock: reset: bau: + protect: bauinfo: speed: nightvision: