From dfcaac5045c1b3268e148523d160e1486d995a41 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 12 Sep 2022 18:26:18 +0200 Subject: [PATCH] Fix stuff and rebuild Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 8 +++++++ BauSystem_Main/src/BauSystem_de.properties | 8 +++++++ .../worldedit/ColorReplaceCommand.java | 17 +++++++++++++-- .../features/worldedit/SpecialReplace.java | 21 ++++++++++++++++--- .../worldedit/TypeReplaceCommand.java | 19 ++++++++++++++--- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9a709a1f..42859e9c 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1291,3 +1291,11 @@ XRAY_HELP = §8/§exray §8- §7Toggle Xray XRAY_GLOBAL = §cNo xray in global region XRAY_ON = §aXray activated XRAY_OFF = §cXray deactivated + + +# WorldEdit +COLORREPLACE_HELP = §8/§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Replace all blocks of one color with another +COLORREPLACE_NO_PERMS = §cYou do not have the permission to use this command + +TYPEREPLACE_HELP = §8/§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another +TYPEREPLACE_NO_PERMS = §cYou do not have the permission to use this command diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 37dda73a..91b85b17 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1270,3 +1270,11 @@ XRAY_HELP = §8/§exray §8- §7Xray umschalten XRAY_GLOBAL = §cKein Xray in der globalen region XRAY_ON = §aXray aktiviert XRAY_OFF = §cXray deaktiviert + + +# WorldEdit +COLORREPLACE_HELP = §8/§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Ersetzt eine Farbe mit einer anderen +COLORREPLACE_NO_PERMS = §cDu hast keine Rechte um Farben zu ersetzen + +TYPEREPLACE_HELP = §8/§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen +TYPEREPLACE_NO_PERMS = §cDu hast keine Rechte um Blockgruppen zu ersetzen 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 734b8b7d..eaca541b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -26,11 +26,13 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import lombok.SneakyThrows; import org.bukkit.Material; import org.bukkit.World; @@ -58,9 +60,9 @@ public class ColorReplaceCommand extends SWCommand { } } - @Register + @Register(description = "COLORREPLACE_HELP") @SneakyThrows - public void genericCommand(Player player, Color from, Color to) { + public void genericCommand(@Validator Player player, Color from, Color to) { if (from == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; @@ -81,4 +83,15 @@ public class ColorReplaceCommand extends SWCommand { editSession.flushSession(); BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); } + + @ClassValidator(Player.class) + public TypeValidator playerValidator() { + return (commandSender, player, messageSender) -> { + if (Permission.WORLDEDIT.hasPermission(player)) { + return true; + } + messageSender.send("COLORREPLACE_NO_PERMS"); + return false; + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SpecialReplace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SpecialReplace.java index 3baf0c25..0e193db4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SpecialReplace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/SpecialReplace.java @@ -20,13 +20,16 @@ package de.steamwar.bausystem.features.worldedit; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.blocks.SignBlock; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import org.bukkit.Bukkit; +import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; import javax.annotation.Nullable; @@ -40,7 +43,8 @@ public class SpecialReplace implements Mask, Pattern { private BiConsumer blockDataMerger; public SpecialReplace(EditSession editSession, Map replacements) { - this(editSession, replacements, (_1, _2) -> {}); + this(editSession, replacements, (_1, _2) -> { + }); } public SpecialReplace(EditSession editSession, Map replacements, BiConsumer blockDataMerger) { @@ -62,7 +66,14 @@ public class SpecialReplace implements Mask, Pattern { @Override public BaseBlock applyBlock(BlockVector3 position) { - String s = BukkitAdapter.adapt(editSession.getFullBlock(position)).getAsString(); + BaseBlock block = editSession.getFullBlock(position); + String[] signText = null; + if (block.getBlockType().getId().endsWith("sign")) { + Sign sign = (Sign) BukkitAdapter.adapt(editSession.getWorld()).getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()).getState(); + signText = sign.getLines(); + } + BlockData blockData = BukkitAdapter.adapt(block); + String s = blockData.getAsString(); String rest = ""; if (s.contains("[")) { int i = s.indexOf("["); @@ -70,7 +81,11 @@ public class SpecialReplace implements Mask, Pattern { s = s.substring(0, i); } try { - return BukkitAdapter.adapt(Bukkit.createBlockData(replacements.getOrDefault(s, s) + rest)).toBaseBlock(); + BaseBlock newBlock = BukkitAdapter.adapt(Bukkit.createBlockData(replacements.getOrDefault(s, s) + rest)).toBaseBlock(); + if (newBlock.getBlockType().getId().endsWith("sign")) { + newBlock = new SignBlock(newBlock.toImmutableState(), signText).toBaseBlock(); + } + return newBlock; } catch (IllegalArgumentException e) { try { BlockData newBlockData = Bukkit.createBlockData(replacements.getOrDefault(s, s)); 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 41d36e2f..a2f4e07b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -26,16 +26,19 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.MinVersion; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.BlockFace; +import org.bukkit.block.Sign; import org.bukkit.block.data.type.Fence; import org.bukkit.block.data.type.Wall; import org.bukkit.entity.Player; @@ -53,9 +56,9 @@ public class TypeReplaceCommand extends SWCommand { super("/typereplace", "/tr"); } - @Register + @Register(description = "TYPEREPLACE_HELP") @SneakyThrows - public void genericCommand(Player player, Type from, Type to) { + public void genericCommand(@Validator Player player, Type from, Type to) { if (from == to) { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(0)})); return; @@ -91,6 +94,17 @@ public class TypeReplaceCommand extends SWCommand { BukkitAdapter.adapt(player).printInfo(TranslatableComponent.of("worldedit.replace.replaced", new Component[]{TextComponent.of(affected)})); } + @ClassValidator(Player.class) + public TypeValidator playerValidator() { + return (commandSender, player, messageSender) -> { + if (Permission.WORLDEDIT.hasPermission(player)) { + return true; + } + messageSender.send("TYPEREPLACE_NO_PERMS"); + return false; + }; + } + @AllArgsConstructor private enum Type { IRON(IRON_BLOCK, null, null, null, null, null, null, IRON_BARS, IRON_DOOR, IRON_TRAPDOOR, null, HEAVY_WEIGHTED_PRESSURE_PLATE, null, null, null, null), @@ -228,7 +242,6 @@ public class TypeReplaceCommand extends SWCommand { if (leaves != null && from.leaves != null) { replacements.put("minecraft:" + from.leaves.name().toLowerCase(), "minecraft:" + leaves.name().toLowerCase()); } - System.out.println(replacements); return replacements; } }