Merge branch 'version/7.2.x'

This commit is contained in:
Octavia Togami 2021-07-13 14:38:26 -07:00
commit 8a830814df
No known key found for this signature in database
GPG Key ID: CC364524D1983C99
16 changed files with 194 additions and 70 deletions

View File

@ -1,3 +1,12 @@
7.2.6
- Return false instead of erroring when trying to remove player entities via the API
- Fix selections at 0,0,0 or radius of 0 with cyl/ellipse selection modes
- Improve plugin lifecycle for stability
- Add support for 1.17 & 1.17.1
- Skip notifying chunk sections if they don't exist
- Optimise legacy schematic loading
- Add CLI-specific commands, //cli selectworld and //cli await
7.2.5
- Allow /toggleplace to work on any Locatable Actor, e.g. Command Blocks
- Change legacy.json oak stair shape to straight

View File

@ -24,14 +24,6 @@
}
}
configurations.findByName("compileClasspath")?.apply {
resolutionStrategy.componentSelection {
withModule("org.slf4j:slf4j-api") {
reject("No SLF4J allowed on compile classpath")
}
}
}
plugins.withId("java") {
the<JavaPluginExtension>().toolchain {
languageVersion.set(JavaLanguageVersion.of(16))

View File

@ -86,6 +86,16 @@
the<JavaPluginExtension>().withSourcesJar()
}
if (name != "worldedit-fabric") {
configurations["compileClasspath"].apply {
resolutionStrategy.componentSelection {
withModule("org.slf4j:slf4j-api") {
reject("No SLF4J allowed on compile classpath")
}
}
}
}
tasks.named("check").configure {
dependsOn("checkstyleMain", "checkstyleTest")
}

View File

@ -26,12 +26,16 @@
configurations["compileOnly"].extendsFrom(localImplementation)
configurations["testImplementation"].extendsFrom(localImplementation)
configurations.all {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16)
}
dependencies {
"api"(project(":worldedit-core"))
"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.16.1-R0.1-SNAPSHOT") {
"localImplementation"("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT") {
exclude("junit", "junit")
}
@ -41,7 +45,7 @@
"localImplementation"("org.apache.logging.log4j:log4j-api")
"compileOnly"("org.jetbrains:annotations:20.1.0")
"compileOnly"("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") {
"compileOnly"("io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT") {
exclude(group = "org.slf4j", module = "slf4j-api")
}
"implementation"("io.papermc:paperlib:1.0.6")

View File

@ -59,8 +59,6 @@
import org.bukkit.inventory.InventoryHolder;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumMap;
@ -79,8 +77,6 @@ public class BukkitWorld extends AbstractWorld {
private static final boolean HAS_3D_BIOMES;
private static final boolean HAS_MIN_Y;
private static final Method GET_MIN_Y;
private int minY;
private static final Map<Integer, Effect> effects = new HashMap<>();
@ -99,15 +95,12 @@ public class BukkitWorld extends AbstractWorld {
temp = false;
}
HAS_3D_BIOMES = temp;
Method tempGetMinY;
try {
tempGetMinY = World.class.getMethod("getMinHeight");
World.class.getMethod("getMinHeight");
temp = true;
} catch (NoSuchMethodException e) {
tempGetMinY = null;
temp = false;
}
GET_MIN_Y = tempGetMinY;
HAS_MIN_Y = temp;
}
@ -127,13 +120,6 @@ public BukkitWorld(World world) {
} else {
this.worldNativeAccess = null;
}
if (HAS_MIN_Y) {
try {
minY = (int) GET_MIN_Y.invoke(world);
} catch (IllegalAccessException | InvocationTargetException e) {
minY = super.getMinY();
}
}
}
@Override
@ -374,11 +360,10 @@ public int getMaxY() {
@Override
public int getMinY() {
/*if (HAS_MIN_Y) {
if (HAS_MIN_Y) {
return getWorld().getMinHeight();
}
return super.getMinY();*/
return minY;
return super.getMinY();
}
@SuppressWarnings("deprecation")

View File

@ -9,6 +9,9 @@
addJarManifest(WorldEditKind.Standalone("com.sk89q.worldedit.cli.CLIWorldEdit"))
dependencies {
"compileOnly"(project(":worldedit-libs:core:ap"))
"annotationProcessor"(project(":worldedit-libs:core:ap"))
"annotationProcessor"("com.google.guava:guava:${Versions.GUAVA}")
"api"(project(":worldedit-core"))
"implementation"(platform("org.apache.logging.log4j:log4j-bom:2.14.1") {
because("We control Log4J on this platform")

View File

@ -0,0 +1,62 @@
/*
* 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.cli;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.task.Task;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import java.util.concurrent.ExecutionException;
@CommandContainer
public class CLIExtraCommands {
@Command(
name = "selectworld",
desc = "Select the entire world"
)
public void selectWorld(Actor actor, World world, LocalSession session) {
session.setRegionSelector(world, new CuboidRegionSelector(
world, world.getMinimumPoint(), world.getMaximumPoint()
));
actor.printInfo(TextComponent.of("Selected the entire world."));
}
@Command(
name = "await",
desc = "Await all pending tasks"
)
public void await() {
for (Task<?> task : WorldEdit.getInstance().getSupervisor().getTasks()) {
try {
task.get();
} catch (InterruptedException e) {
WorldEdit.logger.warn("Interrupted awaiting task", e);
} catch (ExecutionException e) {
WorldEdit.logger.warn("Error awaiting task", e);
}
}
}
}

View File

@ -19,18 +19,23 @@
package com.sk89q.worldedit.cli;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.cli.data.FileRegistries;
import com.sk89q.worldedit.cli.schematic.ClipboardWorld;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.event.platform.PlatformsRegisteredEvent;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
@ -87,10 +92,29 @@ public CLIWorldEdit() {
private void setupPlatform() {
WorldEdit.getInstance().getPlatformManager().register(platform);
registerCommands();
config = new CLIConfiguration(this);
// There's no other platforms, so fire this immediately
WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent());
this.fileRegistries = new FileRegistries(this);
this.fileRegistries.loadDataFiles();
}
private void registerCommands() {
PlatformCommandManager pcm = WorldEdit.getInstance().getPlatformManager()
.getPlatformCommandManager();
pcm.registerSubCommands(
"cli",
ImmutableList.of(),
"CLI-specific commands",
CLIExtraCommandsRegistration.builder(),
new CLIExtraCommands()
);
}
public void setupRegistries() {
// Blocks
for (Map.Entry<String, FileRegistries.BlockManifest> manifestEntry : fileRegistries.getDataFile().blocks.entrySet()) {
@ -172,7 +196,6 @@ public void onStarted() {
setupRegistries();
WorldEdit.getInstance().loadMappings();
config = new CLIConfiguration(this);
config.load();
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent(platform));
@ -235,8 +258,15 @@ public void saveAllWorlds(boolean force) {
public void run(InputStream inputStream) {
try (Scanner scanner = new Scanner(inputStream)) {
while (scanner.hasNextLine()) {
while (true) {
System.err.print("> ");
if (!scanner.hasNextLine()) {
break;
}
String line = scanner.nextLine();
if (line.isEmpty()) {
continue;
}
if (line.equals("stop")) {
commandSender.printInfo(TranslatableComponent.of("worldedit.cli.stopping"));
break;
@ -280,31 +310,40 @@ public static void main(String[] args) {
if (file == null) {
throw new IllegalArgumentException("A file must be provided!");
}
LOGGER.info(() -> "Loading '" + file + "'...");
if (file.getName().endsWith("level.dat")) {
throw new IllegalArgumentException("level.dat file support is unfinished.");
} else {
ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format != null) {
ClipboardReader dataVersionReader = format
.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ));
int dataVersion = dataVersionReader.getDataVersion()
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
dataVersionReader.close();
int dataVersion;
if (format != BuiltInClipboardFormat.MCEDIT_SCHEMATIC) {
try (ClipboardReader dataVersionReader = format.getReader(
Files.newInputStream(file.toPath(), StandardOpenOption.READ)
)) {
dataVersion = dataVersionReader.getDataVersion()
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
}
} else {
dataVersion = Constants.DATA_VERSION_MC_1_13_2;
}
app.platform.setDataVersion(dataVersion);
app.onStarted();
ClipboardWorld world;
try (ClipboardReader clipboardReader = format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ))) {
ClipboardWorld world = new ClipboardWorld(
world = new ClipboardWorld(
file,
clipboardReader.read(),
file.getName()
);
app.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
}
app.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
} else {
throw new IllegalArgumentException("Unknown file provided!");
}
}
LOGGER.info(() -> "Loaded '" + file + "'");
String scriptFile = cmd.getOptionValue('s');
if (scriptFile != null) {

View File

@ -267,7 +267,7 @@ public int walls(Actor actor, EditSession editSession, @Selection Region region,
public int faces(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern) throws WorldEditException {
int affected = editSession.makeCuboidFaces(region, pattern);
int affected = editSession.makeFaces(region, pattern);
actor.printInfo(TranslatableComponent.of("worldedit.faces.changed", TextComponent.of(affected)));
return affected;
}

View File

@ -279,8 +279,11 @@ private void registerAlwaysInjectedValues() {
});
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance) {
/**
* Internal use only.
*/
public <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance) {
registerSubCommands(name, aliases, desc, registration, instance, m -> {
});
}

View File

@ -48,7 +48,9 @@
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
@ -63,6 +65,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
@ -185,8 +188,7 @@ public Clipboard read() throws IOException {
// Need to pull out tile entities
final ListTag tileEntityTag = getTag(schematic, "TileEntities", ListTag.class);
List<Tag> tileEntities = tileEntityTag == null ? new ArrayList<>() : tileEntityTag.getValue();
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
Map<BlockVector3, BlockState> blockStates = new HashMap<>();
BlockMap<BaseBlock> tileEntityBlocks = BlockMap.createForBaseBlock();
for (Tag tag : tileEntities) {
if (!(tag instanceof CompoundTag)) {
@ -224,10 +226,16 @@ public Clipboard read() throws IOException {
}
BlockVector3 vec = BlockVector3.at(x, y, z);
if (t != null) {
tileEntitiesMap.put(vec, t.getValue());
// Insert into the map if we have changed the block or have a tag
BlockState blockToInsert = newBlock != null
? newBlock
: (t != null ? block : null);
if (blockToInsert != null) {
BaseBlock baseBlock = t != null
? blockToInsert.toBaseBlock(new CompoundTag(t.getValue()))
: blockToInsert.toBaseBlock();
tileEntityBlocks.put(vec, baseBlock);
}
blockStates.put(vec, newBlock);
}
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
@ -240,15 +248,15 @@ public Clipboard read() throws IOException {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector3 pt = BlockVector3.at(x, y, z);
BlockState state = blockStates.computeIfAbsent(pt, p -> getBlockState(blocks[index], blockData[index]));
BaseBlock state = Optional.ofNullable(tileEntityBlocks.get(pt))
.orElseGet(() -> {
BlockState blockState = getBlockState(blocks[index], blockData[index]);
return blockState == null ? null : blockState.toBaseBlock();
});
try {
if (state != null) {
if (tileEntitiesMap.containsKey(pt)) {
clipboard.setBlock(region.getMinimumPoint().add(pt), state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
}
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
} else {
short block = blocks[index];
byte data = blockData[index];

View File

@ -53,12 +53,12 @@ private Constants() {
public static final int DATA_VERSION_MC_1_13_2 = 1631;
/**
* The DataVersion for Minecraft 1.16
* The DataVersion for Minecraft 1.14
*/
public static final int DATA_VERSION_MC_1_14 = 1952;
/**
* The DataVersion for Minecraft 1.16
* The DataVersion for Minecraft 1.15
*/
public static final int DATA_VERSION_MC_1_15 = 2225;

View File

@ -142,11 +142,11 @@ default void setCurrentSideEffectSet(SideEffectSet sideEffectSet) {
boolean updateTileEntity(NP position, CompoundBinaryTag tag);
void notifyBlockUpdate(NP position, NBS oldState, NBS newState);
void notifyBlockUpdate(NC chunk, NP position, NBS oldState, NBS newState);
boolean isChunkTicking(NC chunk);
void markBlockChanged(NP position);
void markBlockChanged(NC chunk, NP position);
void notifyNeighbors(NP pos, NBS oldState, NBS newState);
@ -170,10 +170,10 @@ default void markAndNotifyBlock(NP pos, NC chunk, NBS oldState, NBS newState, Si
// Remove redundant branches
if (isChunkTicking(chunk)) {
if (sideEffectSet.shouldApply(SideEffect.ENTITY_AI)) {
notifyBlockUpdate(pos, oldState, newState);
notifyBlockUpdate(chunk, pos, oldState, newState);
} else if (sideEffectSet.shouldApply(SideEffect.NETWORK)) {
// If we want to skip entity AI, just mark the block for sending
markBlockChanged(pos);
markBlockChanged(chunk, pos);
}
}

View File

@ -25,9 +25,9 @@
accessWidener("src/main/resources/worldedit.accesswidener")
}
val minecraftVersion = "1.17"
val yarnMappings = "1.17+build.1:v2"
val loaderVersion = "0.11.3"
val minecraftVersion = "1.17.1"
val yarnMappings = "1.17.1+build.1:v2"
val loaderVersion = "0.11.6"
configurations.all {
resolutionStrategy {
@ -55,7 +55,7 @@
"modImplementation"("net.fabricmc:fabric-loader:$loaderVersion")
// [1] declare fabric-api dependency...
"fabricApi"("net.fabricmc.fabric-api:fabric-api:0.34.9+1.17")
"fabricApi"("net.fabricmc.fabric-api:fabric-api:0.36.1+1.17")
// [2] Load the API dependencies from the fabric mod json...
@Suppress("UNCHECKED_CAST")

View File

@ -116,8 +116,10 @@ public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
}
@Override
public void notifyBlockUpdate(BlockPos position, BlockState oldState, BlockState newState) {
getWorld().updateListeners(position, oldState, newState, UPDATE | NOTIFY);
public void notifyBlockUpdate(WorldChunk chunk, BlockPos position, BlockState oldState, BlockState newState) {
if (chunk.getSectionArray()[world.get().getSectionIndex(position.getY())] != null) {
getWorld().updateListeners(position, oldState, newState, UPDATE | NOTIFY);
}
}
@Override
@ -126,8 +128,10 @@ public boolean isChunkTicking(WorldChunk chunk) {
}
@Override
public void markBlockChanged(BlockPos position) {
((ServerChunkManager) getWorld().getChunkManager()).markForUpdate(position);
public void markBlockChanged(WorldChunk chunk, BlockPos position) {
if (chunk.getSectionArray()[world.get().getSectionIndex(position.getY())] != null) {
((ServerChunkManager) getWorld().getChunkManager()).markForUpdate(position);
}
}
@Override

View File

@ -25,6 +25,7 @@
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.storage.ChunkStore;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
@ -104,8 +105,10 @@ public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
}
@Override
public void notifyBlockUpdate(BlockPos position, BlockState oldState, BlockState newState) {
getWorld().notifyBlockUpdate(position, oldState, newState, UPDATE | NOTIFY);
public void notifyBlockUpdate(Chunk chunk, BlockPos position, BlockState oldState, BlockState newState) {
if (chunk.getSections()[position.getY() >> ChunkStore.CHUNK_SHIFTS] != null) { // TODO 1.17 - world.get().getSectionIndex(position.getY())
getWorld().notifyBlockUpdate(position, oldState, newState, UPDATE | NOTIFY);
}
}
@Override
@ -114,8 +117,10 @@ public boolean isChunkTicking(Chunk chunk) {
}
@Override
public void markBlockChanged(BlockPos position) {
((ServerChunkProvider) getWorld().getChunkProvider()).markBlockChanged(position);
public void markBlockChanged(Chunk chunk, BlockPos position) {
if (chunk.getSections()[position.getY() >> ChunkStore.CHUNK_SHIFTS] != null) { // TODO 1.17 - world.get().getSectionIndex(position.getY())
((ServerChunkProvider) getWorld().getChunkProvider()).markBlockChanged(position);
}
}
@Override