SteamWar/BauSystem2.0
Archiviert
12
0

Fix IncompleteRegionException for ColorReplaceCommand and TypeReplaceCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-07-22 15:50:19 +02:00
Ursprung 27798df7ce
Commit 1ece69a6e2
2 geänderte Dateien mit 43 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -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)

Datei anzeigen

@ -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)