Skip to content

Commit

Permalink
Merge branch 'version/7.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jun 14, 2023
2 parents 3cb1e03 + e90014d commit b079da7
Show file tree
Hide file tree
Showing 28 changed files with 1,059 additions and 74 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.txt
@@ -1,3 +1,14 @@
7.2.15
- [Forge] Fix a bug preventing Forge clients lacking WorldEdit from joining Forge servers with WorldEdit in some cases
- [Forge] Added Console and CommandBlock support
- [Fabric] Added Console and CommandBlock support
- [Sponge] Added CommandBlock support
- Update to 1.20 & 1.20.1
- Fixed extend select mode being lost after using `//paste -s`, `//paste -n`, and `//cli selectworld`
- Fixed convex selection type not correctly clearing selection within WECUI protocol
- Fixed an edge case where API usages of the BlockMap type can lead to multiple values at one location
- Fixed a bug breaking the `round` expression function

7.2.14
- Update to 1.19.4
- Fixed some data values not being returned correctly in expression query functions
Expand Down
Expand Up @@ -210,8 +210,8 @@ public PaperweightAdapter() throws NoSuchFieldException, NoSuchMethodException {
CraftServer.class.cast(Bukkit.getServer());

int dataVersion = CraftMagicNumbers.INSTANCE.getDataVersion();
if (dataVersion != 3463) {
throw new UnsupportedClassVersionError("Not 1.20!");
if (dataVersion != 3463 && dataVersion != 3465) {
throw new UnsupportedClassVersionError("Not 1.20(.1)!");
}

serverWorldsField = CraftServer.class.getDeclaredField("worlds");
Expand Down
4 changes: 2 additions & 2 deletions worldedit-bukkit/build.gradle.kts
Expand Up @@ -42,7 +42,7 @@ dependencies {
"api"(project(":worldedit-libs:bukkit"))
// Technically this is api, but everyone should already have some form of the bukkit API
// Avoid pulling in another one, especially one so outdated.
"localImplementation"("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT") {
"localImplementation"("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}

Expand All @@ -52,7 +52,7 @@ dependencies {
"localImplementation"("org.apache.logging.log4j:log4j-api")

"compileOnly"("org.jetbrains:annotations:20.1.0")
"compileOnly"("io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT") {
"compileOnly"("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") {
exclude("org.slf4j", "slf4j-api")
exclude("junit", "junit")
}
Expand Down
Expand Up @@ -20,11 +20,8 @@
package com.sk89q.worldedit.bukkit;

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;
Expand All @@ -42,22 +39,17 @@

import static com.google.common.base.Preconditions.checkNotNull;

public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements Locatable {

private static final String UUID_PREFIX = "CMD";

public class BukkitBlockCommandSender extends AbstractCommandBlockActor {
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));
}

Expand Down Expand Up @@ -108,21 +100,6 @@ public Locale getLocale() {
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;
Expand Down
Expand Up @@ -36,7 +36,6 @@
public class BukkitConfiguration extends YAMLConfiguration {

public boolean noOpPermissions = false;
public boolean commandBlockSupport = false;
public boolean unsupportedVersionEditing = false;
@Unreported private final WorldEditPlugin plugin;

Expand All @@ -49,7 +48,6 @@ public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
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) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.profile.PlayerProfile;

import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -144,6 +145,11 @@ public UUID getUniqueId() {
return randomUuid;
}

@Override
public PlayerProfile getPlayerProfile() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public boolean isBanned() {
throw new UnsupportedOperationException("Not supported yet.");
Expand Down Expand Up @@ -278,4 +284,9 @@ public void decrementStatistic(Statistic statistic, EntityType entityType, int a
public void setStatistic(Statistic statistic, EntityType entityType, int newValue) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Location getLastDeathLocation() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Expand Up @@ -20,14 +20,20 @@
package com.sk89q.worldedit.blocks;

import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.util.gson.GsonUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Represents a sign block.
Expand Down Expand Up @@ -64,6 +70,11 @@ public SignBlock(BlockState blockState, String[] text) {
this.text = text;
}

private boolean isLegacy() {
int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
return dataVersion < Constants.DATA_VERSION_MC_1_20;
}

/**
* Get the text.
*
Expand Down Expand Up @@ -100,10 +111,17 @@ public String getNbtId() {
@Deprecated
public CompoundTag getNbtData() {
Map<String, Tag<?, ?>> values = new HashMap<>();
values.put("Text1", new StringTag(text[0]));
values.put("Text2", new StringTag(text[1]));
values.put("Text3", new StringTag(text[2]));
values.put("Text4", new StringTag(text[3]));
if (isLegacy()) {
values.put("Text1", new StringTag(text[0]));
values.put("Text2", new StringTag(text[1]));
values.put("Text3", new StringTag(text[2]));
values.put("Text4", new StringTag(text[3]));
} else {
ListTag<?, ?> messages = new ListTag<>(StringTag.class, Arrays.stream(text).map(StringTag::new).collect(Collectors.toList()));
Map<String, Tag<?, ?>> frontTextTag = new HashMap<>();
frontTextTag.put("messages", messages);
values.put("front_text", new CompoundTag(frontTextTag));
}
return new CompoundTag(values);
}

Expand All @@ -125,24 +143,33 @@ public void setNbtData(CompoundTag rootTag) {
throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
}

t = values.get("Text1");
if (t instanceof StringTag) {
text[0] = ((StringTag) t).getValue();
}
if (isLegacy()) {
t = values.get("Text1");
if (t instanceof StringTag) {
text[0] = ((StringTag) t).getValue();
}

t = values.get("Text2");
if (t instanceof StringTag) {
text[1] = ((StringTag) t).getValue();
}
t = values.get("Text2");
if (t instanceof StringTag) {
text[1] = ((StringTag) t).getValue();
}

t = values.get("Text3");
if (t instanceof StringTag) {
text[2] = ((StringTag) t).getValue();
}
t = values.get("Text3");
if (t instanceof StringTag) {
text[2] = ((StringTag) t).getValue();
}

t = values.get("Text4");
if (t instanceof StringTag) {
text[3] = ((StringTag) t).getValue();
t = values.get("Text4");
if (t instanceof StringTag) {
text[3] = ((StringTag) t).getValue();
}
} else {
CompoundTag frontTextTag = (CompoundTag) values.get("front_text");
ListTag<?, ?> messagesTag = frontTextTag.getListTag("messages");
for (int i = 0; i < messagesTag.getValue().size(); i++) {
StringTag tag = (StringTag) messagesTag.getValue().get(i);
text[i] = tag.getValue();
}
}
}

Expand Down
Expand Up @@ -91,6 +91,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();

Expand Down
@@ -0,0 +1,49 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <https://www.gnu.org/licenses/>.
*/

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();
}
}
Expand Up @@ -133,6 +133,7 @@ public void load() {
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));

Expand Down
Expand Up @@ -108,6 +108,9 @@ public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxCha
return editSession.getWorld().generateTree(this, editSession, pos.subtract(0, 1, 0));
}
},
MANGROVE("Mangrove tree", "mangrove"),
TALL_MANGROVE("Tall mangrove tree", "tall_mangrove"),
CHERRY("Cherry blossom", "cherry"),
RANDOM("Random tree", "rand", "random") {
@Override
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
Expand Down
Expand Up @@ -129,6 +129,8 @@ public void load() {
extendedYLimit = config.getBoolean("compat.extended-y-limit", false);

setDefaultLocaleName(config.getString("default-locale", defaultLocaleName));

commandBlockSupport = config.getBoolean("command-block-support", false);
}

public void unload() {
Expand Down
Expand Up @@ -35,8 +35,6 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.util.Substring;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.inject.MapBackedValueStore;
Expand All @@ -46,7 +44,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

import static com.sk89q.worldedit.fabric.FabricAdapter.adaptPlayer;
import static com.sk89q.worldedit.fabric.FabricAdapter.adaptCommandSource;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;

Expand All @@ -62,7 +60,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, or

Command<CommandSourceStack> commandRunner = ctx -> {
WorldEdit.getInstance().getEventBus().post(new com.sk89q.worldedit.event.platform.CommandEvent(
adaptPlayer(ctx.getSource().getPlayerOrException()),
adaptCommandSource(ctx.getSource()),
"/" + ctx.getInput()
));
return 0;
Expand All @@ -82,12 +80,8 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, or

private static Predicate<CommandSourceStack> requirementsFor(org.enginehub.piston.Command mapping) {
return ctx -> {
final Entity entity = ctx.getEntity();
if (!(entity instanceof ServerPlayer)) {
return true;
}
final Actor actor = FabricAdapter.adaptPlayer(((ServerPlayer) entity));
InjectedValueStore store = MapBackedValueStore.create();
final Actor actor = FabricAdapter.adaptCommandSource(ctx);
store.injectValue(Key.of(Actor.class), context -> Optional.of(actor));
return mapping.getCondition().satisfied(store);
};
Expand All @@ -96,7 +90,7 @@ private static Predicate<CommandSourceStack> requirementsFor(org.enginehub.pisto
private static CompletableFuture<Suggestions> suggest(CommandContext<CommandSourceStack> context,
SuggestionsBuilder builder) throws CommandSyntaxException {
CommandSuggestionEvent event = new CommandSuggestionEvent(
FabricAdapter.adaptPlayer(context.getSource().getPlayerOrException()),
FabricAdapter.adaptCommandSource(context.getSource()),
builder.getInput()
);
WorldEdit.getInstance().getEventBus().post(event);
Expand Down

0 comments on commit b079da7

Please sign in to comment.