Search in sources :

Example 1 with Platform

use of com.sk89q.worldedit.extension.platform.Platform in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorldEdit method registerCommands.

private void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
    PlatformManager manager = WorldEdit.getInstance().getPlatformManager();
    if (manager.getPlatforms().isEmpty()) {
        // We'll register as part of our platform initialization later.
        return;
    }
    // This is a re-register (due to /reload), we must add our commands now
    Platform commandsPlatform = manager.queryCapability(Capability.USER_COMMANDS);
    if (commandsPlatform != platform || !platform.isHookingEvents()) {
        // We're not in control of commands/events -- do not re-register.
        return;
    }
    platform.setNativeDispatcher(dispatcher);
    platform.registerCommands(manager.getPlatformCommandManager().getCommandManager());
}
Also used : PlatformManager(com.sk89q.worldedit.extension.platform.PlatformManager) Platform(com.sk89q.worldedit.extension.platform.Platform)

Example 2 with Platform

use of com.sk89q.worldedit.extension.platform.Platform in project FastAsyncWorldEdit by IntellectualSites.

the class WorldEditPlugin method loadAdapter.

// FAWE end
private void loadAdapter() {
    WorldEdit worldEdit = WorldEdit.getInstance();
    // Attempt to load a Bukkit adapter
    BukkitImplLoader adapterLoader = new BukkitImplLoader();
    try {
        adapterLoader.addFromPath(getClass().getClassLoader());
    } catch (IOException e) {
        LOGGER.warn("Failed to search path for Bukkit adapters");
    }
    try {
        adapterLoader.addFromJar(getFile());
    } catch (IOException e) {
        LOGGER.warn("Failed to search " + getFile() + " for Bukkit adapters", e);
    }
    try {
        BukkitImplAdapter bukkitAdapter = adapterLoader.loadAdapter();
        LOGGER.info("Using " + bukkitAdapter.getClass().getCanonicalName() + " as the Bukkit adapter");
        this.adapter.newValue(bukkitAdapter);
    } catch (AdapterLoadException e) {
        Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
        if (platform instanceof BukkitServerInterface) {
            LOGGER.warn(e.getMessage());
        } else {
            // FAWE start - Identify as FAWE
            LOGGER.info("FastAsyncWorldEdit could not find a Bukkit adapter for this MC version, " + "but it seems that you have another implementation of FastAsyncWorldEdit installed ({}) " + "that handles the world editing.", platform.getPlatformName());
        // FAWE end
        }
        this.adapter.invalidate();
    }
}
Also used : WorldEdit(com.sk89q.worldedit.WorldEdit) Platform(com.sk89q.worldedit.extension.platform.Platform) BukkitImplAdapter(com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter) BukkitImplLoader(com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader) IOException(java.io.IOException) AdapterLoadException(com.sk89q.worldedit.bukkit.adapter.AdapterLoadException)

Example 3 with Platform

use of com.sk89q.worldedit.extension.platform.Platform in project FastAsyncWorldEdit by IntellectualSites.

the class ChunkStoreHelper method getChunk.

/**
 * Convert a chunk NBT tag into a {@link Chunk} implementation.
 *
 * @param rootTag     the root tag of the chunk
 * @param entitiesTag supplier to provide entities tag. Only required for 1.17+ where entities are stored in a separate
 *                    location
 * @return a Chunk implementation
 * @throws DataException if the rootTag is not valid chunk data
 * @since TODO
 */
public static Chunk getChunk(CompoundTag rootTag, Supplier<CompoundTag> entitiesTag) throws DataException {
    // FAWE end
    int dataVersion = rootTag.getInt("DataVersion");
    if (dataVersion == 0) {
        dataVersion = -1;
    }
    final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
    final int currentDataVersion = platform.getDataVersion();
    if ((dataVersion > 0 || hasLevelSections(rootTag)) && dataVersion < currentDataVersion) {
        // only fix up MCA format, DFU doesn't support MCR chunks
        final DataFixer dataFixer = platform.getDataFixer();
        if (dataFixer != null) {
            // FAWE start - CBT
            rootTag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer.fixUp(DataFixer.FixTypes.CHUNK, rootTag.asBinaryTag(), dataVersion));
            // FAWE end
            dataVersion = currentDataVersion;
        }
    }
    if (dataVersion >= Constants.DATA_VERSION_MC_1_18) {
        return new AnvilChunk18(rootTag, entitiesTag);
    }
    Map<String, Tag> children = rootTag.getValue();
    CompoundTag tag = null;
    // Find Level tag
    for (Map.Entry<String, Tag> entry : children.entrySet()) {
        if (entry.getKey().equals("Level")) {
            if (entry.getValue() instanceof CompoundTag) {
                tag = (CompoundTag) entry.getValue();
                break;
            } else {
                throw new ChunkStoreException("CompoundTag expected for 'Level'; got " + entry.getValue().getClass().getName());
            }
        }
    }
    if (tag == null) {
        throw new ChunkStoreException("Missing root 'Level' tag");
    }
    // FAWE start - biome and entity restore
    if (dataVersion >= Constants.DATA_VERSION_MC_1_17) {
        return new AnvilChunk17(tag, entitiesTag);
    }
    // FAWE end
    if (dataVersion >= Constants.DATA_VERSION_MC_1_16) {
        return new AnvilChunk16(tag);
    }
    // FAWE start - biome and entity restore
    if (dataVersion >= Constants.DATA_VERSION_MC_1_15) {
        return new AnvilChunk15(tag);
    }
    // FAWE end
    if (dataVersion >= Constants.DATA_VERSION_MC_1_13) {
        return new AnvilChunk13(tag);
    }
    Map<String, Tag> tags = tag.getValue();
    if (tags.containsKey("Sections")) {
        return new AnvilChunk(tag);
    }
    return new OldChunk(tag);
}
Also used : AnvilChunk18(com.sk89q.worldedit.world.chunk.AnvilChunk18) Platform(com.sk89q.worldedit.extension.platform.Platform) OldChunk(com.sk89q.worldedit.world.chunk.OldChunk) AnvilChunk13(com.sk89q.worldedit.world.chunk.AnvilChunk13) AnvilChunk15(com.sk89q.worldedit.world.chunk.AnvilChunk15) AnvilChunk16(com.sk89q.worldedit.world.chunk.AnvilChunk16) AnvilChunk17(com.sk89q.worldedit.world.chunk.AnvilChunk17) AnvilChunk(com.sk89q.worldedit.world.chunk.AnvilChunk) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) DataFixer(com.sk89q.worldedit.world.DataFixer) Map(java.util.Map) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 4 with Platform

use of com.sk89q.worldedit.extension.platform.Platform in project FastAsyncWorldEdit by IntellectualSites.

the class SpongeWorldEdit method loadAdapter.

private void loadAdapter() {
    WorldEdit worldEdit = WorldEdit.getInstance();
    // Attempt to load a Sponge adapter
    SpongeImplLoader adapterLoader = new SpongeImplLoader();
    try {
        adapterLoader.addFromPath(getClass().getClassLoader());
    } catch (IOException e) {
        logger.warn("Failed to search path for Sponge adapters");
    }
    try {
        adapterLoader.addFromJar(container.getSource().get().toFile());
    } catch (IOException e) {
        logger.warn("Failed to search " + container.getSource().get().toFile() + " for Sponge adapters", e);
    }
    try {
        spongeAdapter = adapterLoader.loadAdapter();
        logger.info("Using " + spongeAdapter.getClass().getCanonicalName() + " as the Sponge adapter");
    } catch (AdapterLoadException e) {
        Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
        if (platform instanceof SpongePlatform) {
            logger.warn(e.getMessage());
        } else {
            logger.info("WorldEdit could not find a Sponge adapter for this MC version, " + "but it seems that you have another implementation of WorldEdit installed (" + platform.getPlatformName() + ") " + "that handles the world editing.");
        }
    }
}
Also used : WorldEdit(com.sk89q.worldedit.WorldEdit) Platform(com.sk89q.worldedit.extension.platform.Platform) SpongeImplLoader(com.sk89q.worldedit.sponge.adapter.SpongeImplLoader) IOException(java.io.IOException) AdapterLoadException(com.sk89q.worldedit.sponge.adapter.AdapterLoadException)

Example 5 with Platform

use of com.sk89q.worldedit.extension.platform.Platform in project FastAsyncWorldEdit by IntellectualSites.

the class SpongeSchematicReader method read.

@Override
public Clipboard read() throws IOException {
    CompoundTag schematicTag = getBaseTag();
    Map<String, Tag> schematic = schematicTag.getValue();
    final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
    int liveDataVersion = platform.getDataVersion();
    if (schematicVersion == 1) {
        // this is a relatively safe assumption unless someone imports a schematic from 1.12, e.g. sponge 7.1-
        dataVersion = Constants.DATA_VERSION_MC_1_13_2;
        fixer = platform.getDataFixer();
        return readVersion1(schematicTag);
    } else if (schematicVersion == 2) {
        dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
        if (dataVersion < 0) {
            LOGGER.warn("Schematic has an unknown data version ({}). Data may be incompatible.", dataVersion);
            // Do not DFU unknown data
            dataVersion = liveDataVersion;
        }
        if (dataVersion > liveDataVersion) {
            LOGGER.warn("Schematic was made in a newer Minecraft version ({} > {}). Data may be incompatible.", dataVersion, liveDataVersion);
        } else if (dataVersion < liveDataVersion) {
            fixer = platform.getDataFixer();
            if (fixer != null) {
                LOGGER.info("Schematic was made in an older Minecraft version ({} < {}), will attempt DFU.", dataVersion, liveDataVersion);
            } else {
                LOGGER.info("Schematic was made in an older Minecraft version ({} < {}), but DFU is not available. Data may be incompatible.", dataVersion, liveDataVersion);
            }
        }
        BlockArrayClipboard clip = readVersion1(schematicTag);
        return readVersion2(clip, schematicTag);
    }
    throw new IOException("This schematic version is not supported; Version: " + schematicVersion + ", DataVersion: " + dataVersion + "." + "It's very likely your schematic has an invalid file extension, if the schematic has been created on a version lower than" + "1.13.2, the extension MUST be `.schematic`, elsewise the schematic can't be read properly.");
}
Also used : Platform(com.sk89q.worldedit.extension.platform.Platform) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) NamedTag(com.sk89q.jnbt.NamedTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IOException(java.io.IOException) CompoundTag(com.sk89q.jnbt.CompoundTag) IntTag(com.sk89q.jnbt.IntTag)

Aggregations

Platform (com.sk89q.worldedit.extension.platform.Platform)5 IOException (java.io.IOException)3 CompoundTag (com.sk89q.jnbt.CompoundTag)2 Tag (com.sk89q.jnbt.Tag)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)1 IntArrayTag (com.sk89q.jnbt.IntArrayTag)1 IntTag (com.sk89q.jnbt.IntTag)1 ListTag (com.sk89q.jnbt.ListTag)1 NamedTag (com.sk89q.jnbt.NamedTag)1 ShortTag (com.sk89q.jnbt.ShortTag)1 StringTag (com.sk89q.jnbt.StringTag)1 AdapterLoadException (com.sk89q.worldedit.bukkit.adapter.AdapterLoadException)1 BukkitImplAdapter (com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter)1 BukkitImplLoader (com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader)1 PlatformManager (com.sk89q.worldedit.extension.platform.PlatformManager)1 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)1 AdapterLoadException (com.sk89q.worldedit.sponge.adapter.AdapterLoadException)1 SpongeImplLoader (com.sk89q.worldedit.sponge.adapter.SpongeImplLoader)1 DataFixer (com.sk89q.worldedit.world.DataFixer)1