From d0dab38d55e8e4dc692ce6b5edefdc5d5893748e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Dec 2022 16:34:40 +0100 Subject: [PATCH] Fix various WorldEdit stuff Signed-off-by: yoyosource --- .../features/script/ScriptExecutor.java | 7 +++---- .../script/custom/command/MenuCommand.java | 2 +- .../features/slaves/laufbau/Laufbau.java | 2 +- .../slaves/laufbau/LaufbauCommand.java | 2 +- .../features/slaves/panzern/Panzern.java | 19 ++++++++++++------- .../slaves/panzern/PanzernCommand.java | 4 ++-- .../worldedit/ColorReplaceCommand.java | 6 +----- .../worldedit/TypeReplaceCommand.java | 6 +----- .../bausystem/utils/WorldEditUtils.java | 4 ++-- 9 files changed, 24 insertions(+), 28 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 236c969e..785c042b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -178,12 +178,11 @@ public final class ScriptExecutor { Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); if (!strings[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + strings[0])) { - EditSession editSession = WorldEditUtils.getEditSession(player.getWorld()); - WorldEditUtils.addToPlayer(player, editSession); + EditSession editSession = WorldEditUtils.getEditSession(player); Actor actor = BukkitAdapter.adapt(player); WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); - editSession.close(); - WorldEdit.getInstance().flushBlockBag(actor, editSession); + editSession.flushSession(); + WorldEditUtils.addToPlayer(player, editSession); } else { Bukkit.getServer().dispatchCommand(player, command); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java index b5fbd637..5583f360 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java @@ -57,7 +57,7 @@ class MenuCommand implements CustomCommand, MenuScript { return true; } - public boolean equals(CustomScript.MenuCommand menuCommand) { + public boolean equals(MenuCommand menuCommand) { if (menuCommand.args.length != args.length) { return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java index d1e37613..a2506042 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java @@ -56,7 +56,7 @@ public class Laufbau { filteringTracesState = new FilteringTracesState(world, this::inRegion); - editSession = WorldEditUtils.getEditSession(world); + editSession = WorldEditUtils.getEditSession(player); elements = BlockBoundingBox.elements.stream().filter(blockBoundingBox -> { return !LaufbauUtils.isDeactivated(player, blockBoundingBox); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java index b7f2de60..f1b69ba6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/LaufbauCommand.java @@ -54,7 +54,7 @@ public class LaufbauCommand extends SWCommand { while (true) { if (!laufbau.hasNext()) { BauSystem.MESSAGE.send("LAUFBAU_DONE", player); - laufbau.getEditSession().close(); + laufbau.getEditSession().flushSession(); WorldEditUtils.addToPlayer(player, laufbau.getEditSession()); cancel(); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/Panzern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/Panzern.java index 1fdfd82a..3b8461df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/Panzern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/Panzern.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.slaves.panzern; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.bausystem.utils.WorldEditUtils; @@ -32,6 +33,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.util.*; @@ -50,12 +52,11 @@ public class Panzern { private Set current = new LinkedHashSet<>(); private Set emptyBlocks = new HashSet<>(); + private Set doneBlocks = new HashSet<>(); private World world; private Location pos1; private Location pos2; - private Material blockMaterial; - private Material slabMaterial; private BaseBlock blockType; private BaseBlock slabType; @@ -66,7 +67,7 @@ public class Panzern { @Getter private EditSession editSession; - public Panzern(Location pos1, Location pos2, Location possibleSource, Material blockMaterial, Material slabMaterial) { + public Panzern(Player player, Location pos1, Location pos2, Location possibleSource, Material blockMaterial, Material slabMaterial) { this.world = pos1.getWorld(); this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ())); this.pos2 = new Location(world, Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ())); @@ -76,13 +77,11 @@ public class Panzern { current.add(this.pos1); current.add(this.pos2); } - this.blockMaterial = blockMaterial; - this.slabMaterial = slabMaterial; blockType = BlockTypes.get("minecraft:" + blockMaterial.name().toLowerCase()).getDefaultState().toBaseBlock(); slabType = BlockTypes.get("minecraft:" + slabMaterial.name().toLowerCase()).getDefaultState().toBaseBlock(); - editSession = WorldEditUtils.getEditSession(world); + editSession = WorldEditUtils.getEditSession(player); } public boolean hasNext() { @@ -140,9 +139,15 @@ public class Panzern { emptyBlocks.add(currentBlock.getLocation().toVector()); break; } + doneBlocks.add(currentBlock.getLocation().toVector()); adjacent.forEach((blockFace, temp) -> { - if (temp.getType().isAir() && !emptyBlocks.contains(temp.getLocation().toVector())) { + if (doneBlocks.contains(temp.getLocation().toVector())) { + return; + } + BlockState blockState = editSession.getBlock(BukkitAdapter.asBlockVector(temp.getLocation())); + boolean isAir = blockState.getBlockType() == BlockTypes.AIR; + if (isAir && !emptyBlocks.contains(temp.getLocation().toVector())) { current.add(temp.getLocation()); } }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java index e05ca76a..ed8ca2d5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java @@ -59,7 +59,7 @@ public class PanzernCommand extends SWCommand { BauSystem.MESSAGE.send("PANZERN_NO_WORLDEDIT", player); return; } - Panzern panzern = new Panzern(selection.getKey(), selection.getValue(), player.getLocation(), blockMaterial, slabMaterial); + Panzern panzern = new Panzern(player, selection.getKey(), selection.getValue(), player.getLocation(), blockMaterial, slabMaterial); new BukkitRunnable() { @Override public void run() { @@ -69,7 +69,7 @@ public class PanzernCommand extends SWCommand { while (true) { if (!panzern.hasNext()) { BauSystem.MESSAGE.send("PANZERN_DONE", player); - panzern.getEditSession().close(); + panzern.getEditSession().flushSession(); WorldEditUtils.addToPlayer(player, panzern.getEditSession()); cancel(); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java index 849d5891..00e0035c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.worldedit; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; @@ -36,7 +35,6 @@ import de.steamwar.command.TypeMapper; import de.steamwar.linkage.Linked; import lombok.SneakyThrows; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -69,15 +67,13 @@ public class ColorReplaceCommand extends SWCommand { return; } - World world = player.getWorld(); - Map replacements = new HashMap<>(); for (String type : types) { replacements.put("minecraft:" + from.getValue().name().toLowerCase() + "_" + type.toLowerCase(), "minecraft:" + to.name().toLowerCase() + "_" + type.toLowerCase()); } Region region = WorldEditUtils.getRegion(player); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player)); + EditSession editSession = WorldEditUtils.getEditSession(player); SpecialReplace specialReplace = new SpecialReplace(editSession, replacements, from.getKey()); int affected = editSession.replaceBlocks(region, specialReplace, specialReplace); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java index 93b784b7..668a1b50 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.worldedit; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; @@ -37,7 +36,6 @@ import de.steamwar.linkage.MinVersion; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.Fence; import org.bukkit.block.data.type.Wall; @@ -73,10 +71,8 @@ public class TypeReplaceCommand extends SWCommand { return; } - World world = player.getWorld(); - Region region = WorldEditUtils.getRegion(player); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), -1, BukkitAdapter.adapt(player)); + EditSession editSession = WorldEditUtils.getEditSession(player); SpecialReplace specialReplace = new SpecialReplace(editSession, to.replacements(from.getValue()), from.getKey(), (oldBlockData, newBlockData) -> { if (newBlockData instanceof Fence && oldBlockData instanceof Wall) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index cc3a6ef6..ec464ef4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -40,8 +40,8 @@ import org.bukkit.entity.Player; @UtilityClass public class WorldEditUtils { - public EditSession getEditSession(World world) { - return WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), Integer.MAX_VALUE); + public EditSession getEditSession(Player player) { + return WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(player.getWorld()), -1, BukkitAdapter.adapt(player)); } public void addToPlayer(Player player, EditSession editSession) {