From 1ece69a6e24e122fb592343d4e64dd6e2e1ff8c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 22 Jul 2023 15:50:19 +0200 Subject: [PATCH] Fix IncompleteRegionException for ColorReplaceCommand and TypeReplaceCommand Signed-off-by: yoyosource --- .../worldedit/ColorReplaceCommand.java | 19 ++++--- .../worldedit/TypeReplaceCommand.java | 57 ++++++++++--------- 2 files changed, 43 insertions(+), 33 deletions(-) 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 13439c0e..010498a8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.worldedit; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; @@ -73,14 +74,18 @@ public class ColorReplaceCommand extends SWCommand { replacements.put("minecraft:" + from.getValue().name().toLowerCase() + "_" + type.toLowerCase(), "minecraft:" + to.name().toLowerCase() + "_" + type.toLowerCase()); } - Region region = WorldEditUtils.getRegion(player); - EditSession editSession = WorldEditUtils.getEditSession(player); + try { + Region region = WorldEditUtils.getRegion(player); + EditSession editSession = WorldEditUtils.getEditSession(player); - SpecialReplace specialReplace = new SpecialReplace(editSession, replacements, from.getKey()); - int affected = editSession.replaceBlocks(region, specialReplace, specialReplace); - editSession.flushSession(); - WorldEditUtils.addToPlayer(player, editSession); - BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); + SpecialReplace specialReplace = new SpecialReplace(editSession, replacements, from.getKey()); + int affected = editSession.replaceBlocks(region, specialReplace, specialReplace); + editSession.flushSession(); + WorldEditUtils.addToPlayer(player, editSession); + BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); + } catch (IncompleteRegionException e) { + BukkitAdapter.adapt(player).printError(TranslatableComponent.of("worldedit.error.incomplete-region")); + } } @ClassMapper(value = Pair.class, local = true) 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 556a6a67..0cc939d6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.worldedit; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; @@ -72,33 +73,37 @@ public class TypeReplaceCommand extends SWCommand { return; } - Region region = WorldEditUtils.getRegion(player); - EditSession editSession = WorldEditUtils.getEditSession(player); + try { + Region region = WorldEditUtils.getRegion(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) { - Wall wall = (Wall) oldBlockData; - Fence fence = (Fence) newBlockData; - fence.setWaterlogged(wall.isWaterlogged()); - fence.setFace(BlockFace.NORTH, wall.getHeight(BlockFace.NORTH) != Wall.Height.NONE); - fence.setFace(BlockFace.EAST, wall.getHeight(BlockFace.EAST) != Wall.Height.NONE); - fence.setFace(BlockFace.SOUTH, wall.getHeight(BlockFace.SOUTH) != Wall.Height.NONE); - fence.setFace(BlockFace.WEST, wall.getHeight(BlockFace.WEST) != Wall.Height.NONE); - } - if (newBlockData instanceof Wall && oldBlockData instanceof Fence) { - Wall wall = (Wall) newBlockData; - Fence fence = (Fence) oldBlockData; - wall.setWaterlogged(fence.isWaterlogged()); - wall.setHeight(BlockFace.NORTH, fence.hasFace(BlockFace.NORTH) ? Wall.Height.LOW : Wall.Height.NONE); - wall.setHeight(BlockFace.EAST, fence.hasFace(BlockFace.EAST) ? Wall.Height.LOW : Wall.Height.NONE); - wall.setHeight(BlockFace.SOUTH, fence.hasFace(BlockFace.SOUTH) ? Wall.Height.LOW : Wall.Height.NONE); - wall.setHeight(BlockFace.WEST, fence.hasFace(BlockFace.WEST) ? Wall.Height.LOW : Wall.Height.NONE); - } - }); - int affected = editSession.replaceBlocks(region, specialReplace, specialReplace); - editSession.flushSession(); - WorldEditUtils.addToPlayer(player, editSession); - BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); + SpecialReplace specialReplace = new SpecialReplace(editSession, to.replacements(from.getValue()), from.getKey(), (oldBlockData, newBlockData) -> { + if (newBlockData instanceof Fence && oldBlockData instanceof Wall) { + Wall wall = (Wall) oldBlockData; + Fence fence = (Fence) newBlockData; + fence.setWaterlogged(wall.isWaterlogged()); + fence.setFace(BlockFace.NORTH, wall.getHeight(BlockFace.NORTH) != Wall.Height.NONE); + fence.setFace(BlockFace.EAST, wall.getHeight(BlockFace.EAST) != Wall.Height.NONE); + fence.setFace(BlockFace.SOUTH, wall.getHeight(BlockFace.SOUTH) != Wall.Height.NONE); + fence.setFace(BlockFace.WEST, wall.getHeight(BlockFace.WEST) != Wall.Height.NONE); + } + if (newBlockData instanceof Wall && oldBlockData instanceof Fence) { + Wall wall = (Wall) newBlockData; + Fence fence = (Fence) oldBlockData; + wall.setWaterlogged(fence.isWaterlogged()); + wall.setHeight(BlockFace.NORTH, fence.hasFace(BlockFace.NORTH) ? Wall.Height.LOW : Wall.Height.NONE); + wall.setHeight(BlockFace.EAST, fence.hasFace(BlockFace.EAST) ? Wall.Height.LOW : Wall.Height.NONE); + wall.setHeight(BlockFace.SOUTH, fence.hasFace(BlockFace.SOUTH) ? Wall.Height.LOW : Wall.Height.NONE); + wall.setHeight(BlockFace.WEST, fence.hasFace(BlockFace.WEST) ? Wall.Height.LOW : Wall.Height.NONE); + } + }); + int affected = editSession.replaceBlocks(region, specialReplace, specialReplace); + editSession.flushSession(); + WorldEditUtils.addToPlayer(player, editSession); + BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); + } catch (IncompleteRegionException e) { + BukkitAdapter.adapt(player).printError(TranslatableComponent.of("worldedit.error.incomplete-region")); + } } @ClassMapper(value = Pair.class, local = true)