From 3e6495eb1a721bb6255bdcbd971532ba53962647 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Dec 2019 14:39:12 +0100 Subject: [PATCH] Making BauSystem fully 1.15 compatible --- BauSystem_12/pom.xml | 8 +++- .../bausystem/world/RegionListener_12.java | 17 ++++++++ .../steamwar/bausystem/world/Region_12.java | 23 ++++++++++- BauSystem_15/pom.xml | 4 +- .../bausystem/world/RegionListener_15.java | 15 +++++++ .../steamwar/bausystem/world/Region_15.java | 39 +++++++++++++++++-- BauSystem_Main/pom.xml | 6 --- .../bausystem/world/ArenaSection.java | 26 ++----------- .../de/steamwar/bausystem/world/Region.java | 31 +++------------ .../bausystem/world/RegionListener.java | 17 ++++---- pom.xml | 6 --- 11 files changed, 115 insertions(+), 77 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java diff --git a/BauSystem_12/pom.xml b/BauSystem_12/pom.xml index 50651db..96b45cf 100644 --- a/BauSystem_12/pom.xml +++ b/BauSystem_12/pom.xml @@ -33,6 +33,12 @@ 1.12 provided + + steamwar + WorldEdit + 1.0 + provided + steamwar BauSystem_API @@ -42,7 +48,7 @@ steamwar FAWE - 1.0 + 1.12 provided diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java new file mode 100644 index 0000000..40b7d0f --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/world/RegionListener_12.java @@ -0,0 +1,17 @@ +package de.steamwar.bausystem.world; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import org.bukkit.Bukkit; + +class RegionListener_12 { + private RegionListener_12(){} + + static boolean isWorldEditCommand(String command) { + if (command.startsWith("/")) { + command = command.replaceFirst("/", ""); + } + command = command.toLowerCase(); + return ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")).getWorldEdit().getPlatformManager() + .getCommandManager().getDispatcher().get(command) != null; + } +} 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 1255353..fcf0f83 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java @@ -1,15 +1,36 @@ 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 org.bukkit.Bukkit; +import java.io.File; +import java.io.IOException; +import java.util.Objects; + public class Region_12 { private Region_12(){} - static void paste(Schematic schem, Vector v, AffineTransform aT){ + static void paste(File file, int x, int y, int z, boolean rotate){ + Schematic schem; + try { + schem = FaweAPI.load(file); + }catch(IOException e){ + throw new SecurityException("Bausystem schematic not found", e); + } + Vector dimensions = Objects.requireNonNull(schem.getClipboard()).getDimensions(); + Vector v = new Vector(x, y, z); + 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(new BukkitWorld(Bukkit.getWorlds().get(0)), v, false, true, aT).flushQueue(); } } diff --git a/BauSystem_15/pom.xml b/BauSystem_15/pom.xml index 4e122ef..cb965d0 100644 --- a/BauSystem_15/pom.xml +++ b/BauSystem_15/pom.xml @@ -40,8 +40,8 @@ steamwar - FAWE - 1.14 + WorldEdit + 1.15 provided diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java new file mode 100644 index 0000000..dc74bdd --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/RegionListener_15.java @@ -0,0 +1,15 @@ +package de.steamwar.bausystem.world; + +import com.sk89q.worldedit.WorldEdit; + +class RegionListener_15 { + private RegionListener_15(){} + + static boolean isWorldEditCommand(String command) { + if (command.startsWith("/")) { + command = command.replaceFirst("/", ""); + } + command = command.toLowerCase(); + return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command); + } +} 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 e15f89d..c775ce0 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -1,16 +1,47 @@ package de.steamwar.bausystem.world; -import com.boydti.fawe.object.schematic.Schematic; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.session.ClipboardHolder; import org.bukkit.Bukkit; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Objects; + public class Region_15 { private Region_15(){} - static void paste(Schematic schem, Vector v, AffineTransform aT){ - schem.paste(new BukkitWorld(Bukkit.getWorlds().get(0)), BlockVector3.at(v.getX(), v.getY(), v.getZ()), false, true, aT).flushQueue(); + 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(); + } catch (NullPointerException | IOException e) { + throw new SecurityException("Bausystem schematic not found", e); + } + + BlockVector3 dimensions = clipboard.getDimensions(); + BlockVector3 v = BlockVector3.at(x, y, z); + BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.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); + } + + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1); + ClipboardHolder ch = new ClipboardHolder(clipboard); + ch.setTransform(aT); + Operations.completeBlindly(ch.createPaste(e).to(v).build()); + e.flushSession(); } } diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index 059f2f8..010bca1 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -67,11 +67,5 @@ 1.14 provided - - steamwar - FAWE - 1.0 - provided - \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java index 98b339a..20097e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ArenaSection.java @@ -1,9 +1,5 @@ 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.math.transform.AffineTransform; import de.steamwar.bausystem.BauSystem; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; @@ -13,6 +9,7 @@ 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 { @@ -21,7 +18,7 @@ public class ArenaSection extends Region { private ArenaSection(ConfigurationSection config) { super(config); - testblock = new Region(config.getConfigurationSection("testblock")); + testblock = new Region(Objects.requireNonNull(config.getConfigurationSection("testblock"))); protectSchematic = config.getString("protection"); } @@ -44,23 +41,6 @@ public class ArenaSection extends Region { public void protect(){ File file = new File(BauSystem.SECTION_PATH + protectSchematic); - Schematic schem; - try { - schem = FaweAPI.load(file); - }catch(IOException e){ - e.printStackTrace(); - return; - } - 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); - } - Region.paste(schem, v, aT); + 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 71f66d0..a2a52c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -1,16 +1,11 @@ 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.math.transform.AffineTransform; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.Core; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import java.io.File; -import java.io.IOException; public class Region { final int sizeX; @@ -45,32 +40,16 @@ public class Region { public void reset(){ File file = new File(BauSystem.SECTION_PATH + schematic); - Schematic schem; - try { - schem = FaweAPI.load(file); - }catch(IOException e){ - e.printStackTrace(); - return; - } - Vector dimensions = schem.getClipboard().getDimensions(); - Vector v = new Vector(minX + sizeX/2, minY, 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); - } - paste(schem, v, aT); + paste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate); } - static void paste(Schematic schem, Vector v, AffineTransform aT){ + static void paste(File file, int x, int y, int z, boolean rotate){ switch(Core.getVersion()){ case 15: - Region_15.paste(schem, v, aT); + Region_15.paste(file, x, y, z, rotate); + break; default: - Region_12.paste(schem, v, aT); + Region_12.paste(file, 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 4dc88c6..79cb16c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -1,16 +1,17 @@ package de.steamwar.bausystem.world; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import org.bukkit.Bukkit; +import de.steamwar.core.Core; import org.bukkit.ChatColor; 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.*; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; public class RegionListener implements Listener { @@ -49,12 +50,12 @@ public class RegionListener implements Listener { } private boolean isWorldEditCommand(String command) { - if (command.startsWith("/")) { - command = command.replaceFirst("/", ""); + switch(Core.getVersion()){ + case 15: + return RegionListener_15.isWorldEditCommand(command); + default: + return RegionListener_12.isWorldEditCommand(command); } - command = command.toLowerCase(); - return ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")).getWorldEdit().getPlatformManager() - .getCommandManager().getDispatcher().get(command) != null; } @EventHandler diff --git a/pom.xml b/pom.xml index 1ed6e8e..62d133e 100644 --- a/pom.xml +++ b/pom.xml @@ -48,12 +48,6 @@ 2.0 provided - - steamwar - WorldEdit - 1.0 - provided - steamwar F3NPerm