From ad640532dc75496b3c3648731eccfe4c44faf510 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sun, 24 Oct 2021 12:21:23 +0200 Subject: [PATCH] Update Upstream d48530c Don't allow editing without a Bukkit Impl Adapter. (1920) --- .../worldedit/bukkit/BukkitConfiguration.java | 12 +++++-- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 2 +- .../bukkit/BukkitServerInterface.java | 2 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 9 ++++-- .../UnsupportedVersionEditException.java | 31 +++++++++++++++++++ .../src/main/resources/lang/strings.json | 5 +-- 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java 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 07f2d54c0..fb4130abf 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 @@ -20,6 +20,7 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.util.yaml.YAMLProcessor; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.util.YAMLConfiguration; import com.sk89q.worldedit.util.report.Unreported; import org.apache.logging.log4j.LogManager; @@ -32,10 +33,11 @@ import java.nio.file.Path; */ public class BukkitConfiguration extends YAMLConfiguration { - public boolean noOpPermissions = false; - public boolean commandBlockSupport = false; @Unreported private final WorldEditPlugin plugin; + public boolean noOpPermissions = false; + public boolean commandBlockSupport = false; + public boolean unsupportedVersionEditing = false; public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) { super(config, LogManager.getLogger(plugin.getLogger().getName())); @@ -47,6 +49,12 @@ public class BukkitConfiguration extends YAMLConfiguration { 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) { + WorldEdit.logger.warn("Editing without a Bukkit adapter has been enabled. You will not receive support " + + "for any issues that arise as a result."); + } migrateLegacyFolders(); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 293a85c25..ebf394d43 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -363,7 +363,7 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public void sendAnnouncements() { - if (WorldEditPlugin.getInstance().getLifecycledBukkitImplAdapter() == null) { + if (!WorldEditPlugin.getInstance().getLifecycledBukkitImplAdapter().isValid()) { //FAWE start - swap out EH download url with ours print(Caption.of( "worldedit.version.bukkit.unsupported-adapter", diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index b4efa14fd..83fc8c889 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -97,7 +97,7 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser @SuppressWarnings("deprecation") @Override public int getDataVersion() { - if (plugin.getLifecycledBukkitImplAdapter() != null) { + if (plugin.getLifecycledBukkitImplAdapter().isValid()) { return Bukkit.getUnsafe().getDataVersion(); } return -1; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 27a119cf5..cad10dd42 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; +import com.sk89q.worldedit.bukkit.adapter.UnsupportedVersionEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.util.LogManagerCompat; @@ -488,8 +489,12 @@ public class BukkitWorld extends AbstractWorld { } } } - Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - return BukkitAdapter.adapt(bukkitBlock.getBlockData()); + if (WorldEditPlugin.getInstance().getLocalConfiguration().unsupportedVersionEditing) { + Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + return BukkitAdapter.adapt(bukkitBlock.getBlockData()); + } else { + throw new RuntimeException(new UnsupportedVersionEditException()); + } } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java new file mode 100644 index 000000000..d49545100 --- /dev/null +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java @@ -0,0 +1,31 @@ +/* + * 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.bukkit.adapter; + +import com.fastasyncworldedit.core.configuration.Caption; +import com.sk89q.worldedit.WorldEditException; + +public class UnsupportedVersionEditException extends WorldEditException { + + public UnsupportedVersionEditException() { + super(Caption.of("worldedit.bukkit.no-edit-without-adapter")); + } + +} diff --git a/worldedit-core/src/main/resources/lang/strings.json b/worldedit-core/src/main/resources/lang/strings.json index 075129a14..54b07c8a6 100644 --- a/worldedit-core/src/main/resources/lang/strings.json +++ b/worldedit-core/src/main/resources/lang/strings.json @@ -495,7 +495,6 @@ "worldedit.timezone.set": "Timezone set for this session to: {0}", "worldedit.timezone.current": "The current time in that timezone is: {0}", "worldedit.version.version": "FAWE version:\n - Date {0}\n - Commit {1}\n - Build {2}\n - Platform {3}", - "worldedit.version.bukkit.unsupported-adapter": "This FAWE version does not fully support your version of Bukkit. Block entities (e.g. chests) will be empty, block properties (e.g. rotation) will be missing, and other things may not work.\nUpdate FAWE and your server software to restore this functionality:\n{0}", "worldedit.trace.no-tracing-extents": "Trace: No extent was used.", "worldedit.trace.action-failed": "Trace: Action(s) {0} at {1} discarded by extent {2}", "worldedit.trace.active.already": "Trace mode already active.", @@ -618,5 +617,7 @@ "worldedit.help.no-subcommands": "'{0}' has no sub-commands. (Maybe '{1}' is for a parameter?)", "worldedit.help.subcommand-not-found": "The sub-command '{0}' under '{1}' could not be found.", "worldedit.cli.stopping": "Stopping!", - "worldedit.cli.unknown-command": "Unknown command!" + "worldedit.cli.unknown-command": "Unknown command!", + "worldedit.version.bukkit.unsupported-adapter": "This FastAsyncWorldEdit version does not fully support your version of Bukkit. Block entities (e.g. chests) will be empty, block properties (e.g. rotation) will be missing, and other things may not work. Update FastAsyncWorldEdit to restore this functionality:\n{0}", + "worldedit.bukkit.no-edit-without-adapter": "Editing on unsupported versions is disabled." }