From ea878355950169027d20929f95db018dd09117f0 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Sat, 21 Jul 2018 15:51:16 +0200 Subject: [PATCH] Update to WorldEdit for 1.13 --- pom.xml | 12 +++- .../java/de/diddiz/LogBlock/QueryParams.java | 4 +- .../de/diddiz/worldedit/RegionContainer.java | 37 ++++++++--- .../worldedit/WorldEditLoggingHook.java | 64 ++++++++++--------- 4 files changed, 73 insertions(+), 44 deletions(-) diff --git a/pom.xml b/pom.xml index 93108f9..3ef5044 100644 --- a/pom.xml +++ b/pom.xml @@ -53,9 +53,15 @@ ${project.basedir}/LogBlockQuestioner.jar - com.sk89q - worldedit - 6.0.0-SNAPSHOT + com.sk89q.worldedit + worldedit-core + 7.0.0-SNAPSHOT + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.0.0-SNAPSHOT provided diff --git a/src/main/java/de/diddiz/LogBlock/QueryParams.java b/src/main/java/de/diddiz/LogBlock/QueryParams.java index b9d5114..3d0a151 100644 --- a/src/main/java/de/diddiz/LogBlock/QueryParams.java +++ b/src/main/java/de/diddiz/LogBlock/QueryParams.java @@ -9,6 +9,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import com.sk89q.worldedit.bukkit.BukkitAdapter; + import java.util.*; import static de.diddiz.LogBlock.Session.getSession; @@ -768,7 +770,7 @@ public final class QueryParams implements Cloneable { public void setSelection(RegionContainer container) { this.sel = container; - world = sel.getSelection().getWorld(); + world = BukkitAdapter.adapt(sel.getSelection().getWorld()); } public void setPlayer(String playerName) { diff --git a/src/main/java/de/diddiz/worldedit/RegionContainer.java b/src/main/java/de/diddiz/worldedit/RegionContainer.java index 3258434..1b86f7c 100644 --- a/src/main/java/de/diddiz/worldedit/RegionContainer.java +++ b/src/main/java/de/diddiz/worldedit/RegionContainer.java @@ -1,8 +1,13 @@ package de.diddiz.worldedit; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.bukkit.selections.CuboidSelection; -import com.sk89q.worldedit.bukkit.selections.Selection; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -10,32 +15,46 @@ import org.bukkit.plugin.Plugin; public class RegionContainer { - private Selection selection; + private Region selection; - public RegionContainer(Selection sel) { + public RegionContainer(Region sel) { this.selection = sel; } public static RegionContainer fromPlayerSelection(Player player, Plugin plugin) { - final Selection selection = ((WorldEditPlugin) plugin).getSelection(player); + LocalSession session = ((WorldEditPlugin) plugin).getSession(player); + com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(player.getWorld()); + if (!weWorld.equals(session.getSelectionWorld())) { + throw new IllegalArgumentException("No selection defined"); + } + Region selection; + try { + selection = session.getSelection(weWorld); + } catch (IncompleteRegionException e) { + throw new IllegalArgumentException("No selection defined"); + } if (selection == null) { throw new IllegalArgumentException("No selection defined"); } - if (!(selection instanceof CuboidSelection)) { + if (!(selection instanceof CuboidRegion)) { throw new IllegalArgumentException("You have to define a cuboid selection"); } return new RegionContainer(selection); } public static RegionContainer fromCorners(World world, Location first, Location second) { - return new RegionContainer(new CuboidSelection(world, first, second)); + com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world); + Vector firstVector = BukkitAdapter.asVector(first); + Vector secondVector = BukkitAdapter.asVector(second); + + return new RegionContainer(new CuboidRegion(weWorld, firstVector, secondVector)); } - public Selection getSelection() { + public Region getSelection() { return selection; } - public void setSelection(Selection selection) { + public void setSelection(Region selection) { this.selection = selection; } } diff --git a/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java b/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java index 976f05b..d8d0169 100644 --- a/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java +++ b/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java @@ -3,17 +3,26 @@ package de.diddiz.worldedit; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.util.eventbus.Subscribe; +import com.sk89q.worldedit.world.block.BlockStateHolder; + import de.diddiz.LogBlock.LogBlock; import de.diddiz.LogBlock.Logging; import de.diddiz.LogBlock.config.Config; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.block.data.BlockData; import java.util.logging.Level; @@ -75,41 +84,34 @@ public class WorldEditLoggingHook { return; } - event.setExtent(new AbstractLoggingExtent(event.getExtent()) { + event.setExtent(new AbstractDelegateExtent(event.getExtent()) { @Override - protected void onBlockChange(Vector pt, BaseBlock block) { + public final boolean setBlock(Vector position, @SuppressWarnings("rawtypes") BlockStateHolder block) throws WorldEditException { + onBlockChange(position, block); + return super.setBlock(position, block); + } + + protected void onBlockChange(Vector pt, BlockStateHolder block) { if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) { return; } - // FIXME wait for updated worldedit - // Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); - // Block origin = location.getBlock(); - // Material typeBefore = origin.getType(); - // byte dataBefore = origin.getData(); - // // If we're dealing with a sign, store the block state to read the text off - // BlockState stateBefore = null; - // if (typeBefore == Material.SIGN || typeBefore == Material.WALL_SIGN) { - // stateBefore = origin.getState(); - // } - // - // // Check to see if we've broken a sign - // if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN || typeBefore == Material.WALL_SIGN)) { - // plugin.getConsumer().queueSignBreak(lbActor, (Sign) stateBefore); - // if (block.getType() != Material.AIR.getId()) { - // plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData()); - // } - // } else { - // if (dataBefore != 0) { - // plugin.getConsumer().queueBlockBreak(lbActor, location, typeBefore, dataBefore); - // if (block.getType() != Material.AIR.getId()) { - // plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData()); - // } - // } else { - // plugin.getConsumer().queueBlock(lbActor, location, typeBefore, block.getType(), (byte) block.getData()); - // } - // } + Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + Block origin = location.getBlock(); + Material typeBefore = origin.getType(); + + // Check to see if we've broken a sign + if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN || typeBefore == Material.WALL_SIGN)) { + BlockState stateBefore = origin.getState(); + plugin.getConsumer().queueSignBreak(lbActor, (Sign) stateBefore); + } else if (!origin.isEmpty()) { + plugin.getConsumer().queueBlockBreak(lbActor, location, origin.getBlockData()); + } + BlockData newBlock = BukkitAdapter.adapt(block); + if (newBlock != null && newBlock.getMaterial() != Material.AIR) { + plugin.getConsumer().queueBlockPlace(lbActor, location, newBlock); + } } }); }