3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 01:50:06 +01:00

Add DFUs. Currently used by //restore.

Dieser Commit ist enthalten in:
wizjany 2019-05-13 23:06:50 -04:00
Ursprung 10f7fb6a26
Commit f9d0d340e7
71 geänderte Dateien mit 85 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.registry.Registries;
import org.bukkit.Bukkit;
import org.bukkit.Server;
@ -75,6 +76,14 @@ public class BukkitServerInterface implements MultiUserPlatform {
return -1;
}
@Override
public DataFixer getDataFixer() {
if (plugin.getBukkitImplAdapter() != null) {
return plugin.getBukkitImplAdapter().getDataFixer();
}
return null;
}
@Override
public boolean isValidMobType(String type) {
final EntityType entityType = EntityType.fromName(type);

Datei anzeigen

@ -23,6 +23,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
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.block.BlockStateHolder;
@ -47,6 +48,14 @@ public interface BukkitImplAdapter {
*/
int getDataVersion();
/**
* Get a data fixer, or null if not supported
*
* @return the data fixer
*/
@Nullable
DataFixer getDataFixer();
/**
* Get the block at the given location.
*

Datei anzeigen

@ -157,7 +157,7 @@ public class BukkitImplLoader {
if (BukkitImplAdapter.class.isAssignableFrom(cls)) {
return (BukkitImplAdapter) cls.newInstance();
} else {
log.warn("Failed to load the Bukkit adapter class '" + className +
log.debug("Failed to load the Bukkit adapter class '" + className +
"' because it does not implement " + BukkitImplAdapter.class.getCanonicalName());
}
} catch (ClassNotFoundException e) {

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.World;
import java.util.Collections;
@ -39,4 +40,8 @@ public abstract class AbstractPlatform implements Platform {
return Collections.emptyList();
}
@Override
public DataFixer getDataFixer() {
return null;
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.registry.Registries;
import org.enginehub.piston.CommandManager;
@ -51,6 +52,13 @@ public interface Platform {
*/
int getDataVersion();
/**
* Get a DataFixer capable of upgrading old data.
*
* @return a data fixer, or null if not supported by this platform
*/
DataFixer getDataFixer();
/**
* Checks if a mob type is valid.
*

Datei anzeigen

@ -0,0 +1,34 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world;
import com.google.common.annotations.Beta;
import com.sk89q.jnbt.CompoundTag;
@Beta
public interface DataFixer {
/**
* API SUBJECT TO CHANGE. DON'T USE THIS.
*/
@Beta
CompoundTag fixChunk(CompoundTag originalChunk);
}

Datei anzeigen

@ -35,12 +35,11 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
/**
* The chunk format for Minecraft 1.13 and newer
*/
@ -160,11 +159,13 @@ public class AnvilChunk13 implements Chunk {
* @throws DataException
*/
private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("TileEntities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"TileEntities", ListTag.class).getValue();
tileEntities = new HashMap<>();
for (Tag tag : tags) {
if (!(tag instanceof CompoundTag)) {
throw new InvalidFormatException("CompoundTag expected in TileEntities");

Datei anzeigen

@ -21,9 +21,13 @@ package com.sk89q.worldedit.world.storage;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.chunk.AnvilChunk;
import com.sk89q.worldedit.world.chunk.AnvilChunk13;
@ -42,7 +46,7 @@ public abstract class ChunkStore implements Closeable {
/**
* The DataVersion for Minecraft 1.13
*/
public static final int DATA_VERSION_MC_1_13 = 1519;
private static final int DATA_VERSION_MC_1_13 = 1519;
/**
* {@code >>} - to chunk
@ -102,6 +106,14 @@ public abstract class ChunkStore implements Closeable {
}
int dataVersion = rootTag.getInt("DataVersion");
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if (dataVersion < currentDataVersion) {
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
return new AnvilChunk13((CompoundTag) dataFixer.fixChunk(rootTag).getValue().get("Level"));
}
}
if (dataVersion >= DATA_VERSION_MC_1_13) {
return new AnvilChunk13(tag);
}
@ -114,6 +126,7 @@ public abstract class ChunkStore implements Closeable {
return new OldChunk(world, tag);
}
@Override
public void close() throws IOException {
}