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());
}
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();
}
}
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);
}
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.");
}
}
}
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.");
}
Aggregations