From bb14d93a8db0bac655f80327637c4566ba550520 Mon Sep 17 00:00:00 2001 From: Alexander Brandes Date: Fri, 9 Jun 2023 13:58:45 +0200 Subject: [PATCH] Add Console/CommandBlock support to Fabric/Forge/Sponge (2317) --- .../bukkit/BukkitBlockCommandSender.java | 26 ++-------- .../worldedit/bukkit/BukkitConfiguration.java | 2 - .../sk89q/worldedit/LocalConfiguration.java | 1 + .../platform/AbstractCommandBlockActor.java | 49 +++++++++++++++++++ .../util/PropertiesConfiguration.java | 1 + .../worldedit/util/YAMLConfiguration.java | 2 + 6 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractCommandBlockActor.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index f967fa3fa..3c2e99f42 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -21,11 +21,8 @@ package com.sk89q.worldedit.bukkit; import com.fastasyncworldedit.core.util.TaskManager; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; -import com.sk89q.worldedit.extension.platform.Locatable; -import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extension.platform.AbstractCommandBlockActor; import com.sk89q.worldedit.session.SessionKey; -import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.text.Component; @@ -43,22 +40,20 @@ import java.util.UUID; import static com.google.common.base.Preconditions.checkNotNull; -public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements Locatable { +public class BukkitBlockCommandSender extends AbstractCommandBlockActor { private static final String UUID_PREFIX = "CMD"; private final BlockCommandSender sender; private final WorldEditPlugin plugin; - private final Location location; private final UUID uuid; public BukkitBlockCommandSender(WorldEditPlugin plugin, BlockCommandSender sender) { + super(BukkitAdapter.adapt(checkNotNull(sender).getBlock().getLocation())); checkNotNull(plugin); - checkNotNull(sender); this.plugin = plugin; this.sender = sender; - this.location = BukkitAdapter.adapt(sender.getBlock().getLocation()); this.uuid = UUID.nameUUIDFromBytes((UUID_PREFIX + sender.getName()).getBytes(StandardCharsets.UTF_8)); } @@ -134,21 +129,6 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements return WorldEdit.getInstance().getConfiguration().defaultLocale; } - @Override - public Location getLocation() { - return this.location; - } - - @Override - public boolean setLocation(Location location) { - return false; - } - - @Override - public Extent getExtent() { - return this.location.getExtent(); - } - @Override public UUID getUniqueId() { return uuid; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java index fb4130abf..eaa592395 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java @@ -36,7 +36,6 @@ public class BukkitConfiguration extends YAMLConfiguration { @Unreported private final WorldEditPlugin plugin; public boolean noOpPermissions = false; - public boolean commandBlockSupport = false; public boolean unsupportedVersionEditing = false; public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) { @@ -48,7 +47,6 @@ public class BukkitConfiguration extends YAMLConfiguration { public void load() { super.load(); noOpPermissions = config.getBoolean("no-op-permissions", false); - commandBlockSupport = config.getBoolean("command-block-support", false); unsupportedVersionEditing = "I accept that I will receive no support with this flag enabled.".equals( config.getString("allow-editing-on-unsupported-versions", "false")); if (unsupportedVersionEditing) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 6d178b363..57ec6f186 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -96,6 +96,7 @@ public abstract class LocalConfiguration { public boolean allowSymlinks = false; public boolean serverSideCUI = true; public boolean extendedYLimit = false; + public boolean commandBlockSupport = false; public String defaultLocaleName = "default"; public Locale defaultLocale = Locale.getDefault(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractCommandBlockActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractCommandBlockActor.java new file mode 100644 index 000000000..d18c7028d --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractCommandBlockActor.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.extension.platform; + +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.Location; + +public abstract class AbstractCommandBlockActor extends AbstractNonPlayerActor implements Locatable { + protected static final String UUID_PREFIX = "CMD"; + + private final Location location; + + public AbstractCommandBlockActor(Location location) { + this.location = location; + } + + @Override + public Location getLocation() { + return this.location; + } + + @Override + public boolean setLocation(Location location) { + // Can't move a CommandBlock + return false; + } + + @Override + public Extent getExtent() { + return this.location.getExtent(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index f1785b4f5..f350af03f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -140,6 +140,7 @@ public class PropertiesConfiguration extends LocalConfiguration { serverSideCUI = getBool("server-side-cui", serverSideCUI); extendedYLimit = getBool("extended-y-limit", extendedYLimit); setDefaultLocaleName(getString("default-locale", defaultLocaleName)); + commandBlockSupport = getBool("command-block-support", commandBlockSupport); LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index e10e4ac4f..1a8b0667c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -152,6 +152,8 @@ public class YAMLConfiguration extends LocalConfiguration { extendedYLimit = config.getBoolean("compat.extended-y-limit", false); setDefaultLocaleName(config.getString("default-locale", defaultLocaleName)); + + commandBlockSupport = config.getBoolean("command-block-support", false); } public void unload() {