mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-29 02:16:42 +00:00
merge 1.16
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.bukkit.util.CommandInfo;
|
||||
import com.sk89q.bukkit.util.CommandRegistration;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
@ -30,6 +31,7 @@ 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.extension.platform.Watchdog;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.registry.Registries;
|
||||
@ -44,8 +46,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -218,6 +220,18 @@ public class BukkitServerInterface implements MultiUserPlatform {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private static final Set<SideEffect> SUPPORTED_SIDE_EFFECTS = Sets.immutableEnumSet(
|
||||
SideEffect.NEIGHBORS
|
||||
);
|
||||
|
||||
@Override
|
||||
public Set<SideEffect> getSupportedSideEffects() {
|
||||
if (plugin.getBukkitImplAdapter() != null) {
|
||||
return plugin.getBukkitImplAdapter().getSupportedSideEffects();
|
||||
}
|
||||
return SUPPORTED_SIDE_EFFECTS;
|
||||
}
|
||||
|
||||
public void unregisterCommands() {
|
||||
dynamicCommands.unregisterCommands();
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -33,11 +35,14 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -48,15 +53,7 @@ import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.*;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.TreeType;
|
||||
@ -83,6 +80,7 @@ public class BukkitWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
private final WeakReference<World> worldRef;
|
||||
private final WorldNativeAccess<?, ?, ?> worldNativeAccess;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
@ -91,6 +89,12 @@ public class BukkitWorld extends AbstractWorld {
|
||||
*/
|
||||
public BukkitWorld(World world) {
|
||||
this.worldRef = new WeakReference<>(world);
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
this.worldNativeAccess = adapter.createWorldNativeAccess(world);
|
||||
} else {
|
||||
this.worldNativeAccess = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -479,26 +483,22 @@ public class BukkitWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, SideEffectSet sideEffects) {
|
||||
if (worldNativeAccess != null) {
|
||||
try {
|
||||
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
|
||||
return worldNativeAccess.setBlock(position, block, sideEffects);
|
||||
} catch (Exception e) {
|
||||
if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) {
|
||||
logger.warn("Tried to set a corrupt tile entity at " + position.toString());
|
||||
logger.warn(((BaseBlock) block).getNbtData().toString());
|
||||
logger.warn("Tried to set a corrupt tile entity at " + position.toString() +
|
||||
": " + ((BaseBlock) block).getNbtData(), e);
|
||||
} else {
|
||||
logger.warn("Failed to set block via adapter, falling back to generic", e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
bukkitBlock.setBlockData(BukkitAdapter.adapt(block), false);
|
||||
return true;
|
||||
}
|
||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
bukkitBlock.setBlockData(BukkitAdapter.adapt(block), sideEffects.doesApplyAny());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -512,14 +512,17 @@ public class BukkitWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean notifyAndLightBlock(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState previousType) throws WorldEditException {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.notifyAndLightBlock(BukkitAdapter.adapt(getWorld(), position), previousType);
|
||||
return true;
|
||||
public Set<SideEffect> applySideEffects(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState previousType,
|
||||
SideEffectSet sideEffectSet) {
|
||||
if (worldNativeAccess != null) {
|
||||
worldNativeAccess.applySideEffects(position, previousType, sideEffectSet);
|
||||
return Sets.intersection(
|
||||
WorldEditPlugin.getInstance().getInternalPlatform().getSupportedSideEffects(),
|
||||
sideEffectSet.getSideEffectsToApply()
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,8 +33,8 @@ import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_15_R1;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_15_R2;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_16_R1;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
@ -371,8 +371,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
||||
BukkitImplLoader adapterLoader = new BukkitImplLoader();
|
||||
try {
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_14_R4.class);
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_15_R1.class);
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_15_R2.class);
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_16_R1.class);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
@ -30,19 +30,21 @@ import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -95,23 +97,12 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
||||
BaseBlock getBlock(Location location);
|
||||
|
||||
/**
|
||||
* Set the block at the given location.
|
||||
* Create a {@link WorldNativeAccess} for the given world reference.
|
||||
*
|
||||
* @param location the location
|
||||
* @param state the block
|
||||
* @param notifyAndLight notify and light if set
|
||||
* @return true if a block was likely changed
|
||||
* @param world the world reference
|
||||
* @return the native access object
|
||||
*/
|
||||
<B extends BlockStateHolder<B>> boolean setBlock(Location location, B state, boolean notifyAndLight);
|
||||
|
||||
/**
|
||||
* Notifies the simulation that the block at the given location has
|
||||
* been changed and it must be re-lighted (and issue other events).
|
||||
*
|
||||
* @param position position of the block
|
||||
* @param previousType the type of the previous block that was there
|
||||
*/
|
||||
void notifyAndLightBlock(Location position, BlockState previousType);
|
||||
WorldNativeAccess<?, ?, ?> createWorldNativeAccess(World world);
|
||||
|
||||
/**
|
||||
* Get the state for the given entity.
|
||||
@ -186,6 +177,13 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
||||
*/
|
||||
BaseItemStack adapt(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get the {@link SideEffect}s that this adapter supports.
|
||||
*
|
||||
* @return The side effects that are supported
|
||||
*/
|
||||
Set<SideEffect> getSupportedSideEffects();
|
||||
|
||||
default OptionalInt getInternalBlockStateId(BlockData data) {
|
||||
// return OptionalInt.empty();
|
||||
return getInternalBlockStateId(BukkitAdapter.adapt(data));
|
||||
|
@ -155,11 +155,20 @@ public class BukkitImplLoader {
|
||||
*/
|
||||
public BukkitImplAdapter loadAdapter() throws AdapterLoadException {
|
||||
for (String className : adapterCandidates) {
|
||||
System.out.println("Candidate: " + className);
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
if (cls.isSynthetic()) continue;
|
||||
if (cls.isSynthetic()){
|
||||
System.out.println(className + " is synthetic, continuing");
|
||||
continue;
|
||||
}else{
|
||||
System.out.println(className + " is not synthetic");
|
||||
}
|
||||
if (BukkitImplAdapter.class.isAssignableFrom(cls)) {
|
||||
System.out.println(className + " is assignable from BukkitImplAdapter, returning");
|
||||
return (BukkitImplAdapter) cls.newInstance();
|
||||
}else{
|
||||
System.out.println(className + " is NOT assignable from BukkitImplAdapter, returning");
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.warn("Failed to load the Bukkit adapter class '" + className +
|
||||
@ -170,6 +179,8 @@ public class BukkitImplLoader {
|
||||
} catch (Throwable e) {
|
||||
if (className.equals(customCandidate)) {
|
||||
log.warn("Failed to load the Bukkit adapter class '" + className + "'", e);
|
||||
}else{
|
||||
log.warn(className + " is not custom candidate.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -65,15 +66,6 @@ public interface IDelegateBukkitImplAdapter<T> extends BukkitImplAdapter<T> {
|
||||
return getParent().getBlock(location);
|
||||
}
|
||||
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(Location location, B state, boolean notifyAndLight) {
|
||||
return getParent().setBlock(location, state, notifyAndLight);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void notifyAndLightBlock(Location position, BlockState previousType) {
|
||||
getParent().notifyAndLightBlock(position, previousType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
default BaseEntity getEntity(Entity entity) {
|
||||
|
@ -24,10 +24,7 @@ import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BlockMaterial_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BukkitAdapter_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BukkitGetBlocks_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.MapChunkUtil_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.*;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.nbt.LazyCompoundTag_1_14;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -42,11 +39,13 @@ import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
@ -69,8 +68,10 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
@ -149,8 +150,8 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(Location location, B state, boolean notifyAndLight) {
|
||||
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
|
||||
public Set<SideEffect> getSupportedSideEffects() {
|
||||
return SideEffectSet.defaults().getSideEffectsToApply();
|
||||
}
|
||||
|
||||
public boolean setBlock(org.bukkit.Chunk chunk, int x, int y, int z, BlockStateHolder state, boolean update) {
|
||||
@ -204,6 +205,12 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||
return new FAWEWorldNativeAccess_1_14(this,
|
||||
new WeakReference<>(((CraftWorld) world).getHandle()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getEntityId(Entity entity) {
|
||||
MinecraftKey minecraftkey = EntityTypes.getName(entity.getEntityType());
|
||||
@ -292,11 +299,6 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
return material.getCraftBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyAndLightBlock(Location position, BlockState previousType) {
|
||||
this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true);
|
||||
}
|
||||
|
||||
private MapChunkUtil_1_14 mapUtil = new MapChunkUtil_1_14();
|
||||
|
||||
@Override
|
||||
|
@ -26,10 +26,7 @@ import com.boydti.fawe.beta.IQueueChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.BlockMaterial_1_15_2;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.BukkitAdapter_1_15_2;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.BukkitGetBlocks_1_15_2;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.MapChunkUtil_1_15_2;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.*;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -44,9 +41,12 @@ import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -71,8 +71,10 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
@ -158,11 +160,11 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(Location location, B state, boolean notifyAndLight) {
|
||||
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
|
||||
public Set<SideEffect> getSupportedSideEffects() {
|
||||
return SideEffectSet.defaults().getSideEffectsToApply();
|
||||
}
|
||||
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(org.bukkit.Chunk chunk, int x, int y, int z, B state, boolean update) {
|
||||
public boolean setBlock(org.bukkit.Chunk chunk, int x, int y, int z, BlockStateHolder state, boolean update) {
|
||||
CraftChunk craftChunk = (CraftChunk) chunk;
|
||||
Chunk nmsChunk = craftChunk.getHandle();
|
||||
World nmsWorld = nmsChunk.getWorld();
|
||||
@ -213,6 +215,12 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||
return new FAWEWorldNativeAccess_1_15_2(this,
|
||||
new WeakReference<>(((CraftWorld) world).getHandle()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getEntityId(Entity entity) {
|
||||
MinecraftKey minecraftkey = EntityTypes.getName(entity.getEntityType());
|
||||
@ -301,11 +309,6 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I
|
||||
return material.getCraftBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyAndLightBlock(Location position, BlockState previousType) {
|
||||
this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true);
|
||||
}
|
||||
|
||||
private MapChunkUtil_1_15_2 mapUtil = new MapChunkUtil_1_15_2();
|
||||
|
||||
@Override
|
||||
|
@ -26,11 +26,8 @@ import com.boydti.fawe.beta.IQueueChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15.BlockMaterial_1_15;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15.BukkitAdapter_1_15;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15.BukkitGetBlocks_1_15;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15.MapChunkUtil_1_15;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_15.nbt.LazyCompoundTag_1_15;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.*;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
@ -44,35 +41,39 @@ import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import net.minecraft.server.v1_15_R1.*;
|
||||
import net.minecraft.server.v1_16_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
@ -81,16 +82,16 @@ import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final Spigot_v1_15_R1 parent;
|
||||
public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final Spigot_v1_16_R1 parent;
|
||||
private char[] ibdToStateOrdinal;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Code that may break between versions of Minecraft
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public FAWE_Spigot_v1_15_R1() throws NoSuchFieldException, NoSuchMethodException {
|
||||
this.parent = new Spigot_v1_15_R1();
|
||||
public FAWE_Spigot_v1_16_R1() throws NoSuchFieldException, NoSuchMethodException {
|
||||
this.parent = new Spigot_v1_16_R1();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,11 +100,11 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
}
|
||||
|
||||
private synchronized boolean init() {
|
||||
if (ibdToStateOrdinal != null) return false;
|
||||
if (ibdToStateOrdinal != null && ibdToStateOrdinal[1] != 0) return false;
|
||||
ibdToStateOrdinal = new char[Block.REGISTRY_ID.a()]; // size
|
||||
for (int i = 0; i < ibdToStateOrdinal.length; i++) {
|
||||
BlockState state = BlockTypesCache.states[i];
|
||||
BlockMaterial_1_15 material = (BlockMaterial_1_15) state.getMaterial();
|
||||
BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial();
|
||||
int id = Block.REGISTRY_ID.getId(material.getState());
|
||||
ibdToStateOrdinal[id] = state.getOrdinalChar();
|
||||
}
|
||||
@ -113,13 +114,15 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BlockType blockType) {
|
||||
Block block = getBlock(blockType);
|
||||
return new BlockMaterial_1_15(block);
|
||||
return new BlockMaterial_1_16_1(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BlockState state) {
|
||||
IBlockData bs = ((CraftBlockData) Bukkit.createBlockData(state.getAsString())).getState();
|
||||
return new BlockMaterial_1_15(bs.getBlock(), bs);
|
||||
return new BlockMaterial_1_16_1(bs.getBlock(), bs);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Block getBlock(BlockType blockType) {
|
||||
@ -156,24 +159,24 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(Location location, B state, boolean notifyAndLight) {
|
||||
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
|
||||
public Set<SideEffect> getSupportedSideEffects() {
|
||||
return SideEffectSet.defaults().getSideEffectsToApply();
|
||||
}
|
||||
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(org.bukkit.Chunk chunk, int x, int y, int z, B state, boolean update) {
|
||||
public boolean setBlock(org.bukkit.Chunk chunk, int x, int y, int z, BlockStateHolder state, boolean update) {
|
||||
CraftChunk craftChunk = (CraftChunk) chunk;
|
||||
Chunk nmsChunk = craftChunk.getHandle();
|
||||
World nmsWorld = nmsChunk.getWorld();
|
||||
|
||||
BlockPosition blockPos = new BlockPosition(x, y, z);
|
||||
IBlockData blockData = ((BlockMaterial_1_15) state.getMaterial()).getState();
|
||||
IBlockData blockData = ((BlockMaterial_1_16_1) state.getMaterial()).getState();
|
||||
ChunkSection[] sections = nmsChunk.getSections();
|
||||
int y4 = y >> 4;
|
||||
ChunkSection section = sections[y4];
|
||||
|
||||
IBlockData existing;
|
||||
if (section == null) {
|
||||
existing = ((BlockMaterial_1_15) BlockTypes.AIR.getDefaultState().getMaterial()).getState();
|
||||
existing = ((BlockMaterial_1_16_1) BlockTypes.AIR.getDefaultState().getMaterial()).getState();
|
||||
} else {
|
||||
existing = section.getType(x & 15, y & 15, z & 15);
|
||||
}
|
||||
@ -194,7 +197,7 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
tag.set("x", NBTTagInt.a(x));
|
||||
tag.set("y", NBTTagInt.a(y));
|
||||
tag.set("z", NBTTagInt.a(z));
|
||||
tileEntity.load(tag); // readTagIntoTileEntity - load data
|
||||
tileEntity.load(tileEntity.getBlock(), tag); // readTagIntoTileEntity - load data
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -211,6 +214,12 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
|
||||
return new FAWEWorldNativeAccess_1_16(this,
|
||||
new WeakReference<>(((CraftWorld)world).getHandle()));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getEntityId(Entity entity) {
|
||||
MinecraftKey minecraftkey = EntityTypes.getName(entity.getEntityType());
|
||||
@ -245,7 +254,7 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||
BlockMaterial_1_15 material = (BlockMaterial_1_15) state.getMaterial();
|
||||
BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial();
|
||||
IBlockData mcState = material.getCraftBlockData().getState();
|
||||
return OptionalInt.of(Block.REGISTRY_ID.getId(mcState));
|
||||
}
|
||||
@ -286,7 +295,7 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
} catch (NullPointerException e) {
|
||||
init();
|
||||
return adaptToChar(ibd);
|
||||
} catch (ArrayIndexOutOfBoundsException e1) {
|
||||
} catch(ArrayIndexOutOfBoundsException e1){
|
||||
Fawe.debug("Attempted to convert " + ibd.getBlock() + " with ID " + Block.REGISTRY_ID.getId(ibd) + " to char. ibdToStateOrdinal length: " + ibdToStateOrdinal.length + ". Defaulting to air!");
|
||||
return 0;
|
||||
}
|
||||
@ -295,21 +304,16 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> BlockData adapt(B state) {
|
||||
BlockMaterial_1_15 material = (BlockMaterial_1_15) state.getMaterial();
|
||||
BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial();
|
||||
return material.getCraftBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyAndLightBlock(Location position, BlockState previousType) {
|
||||
this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true);
|
||||
}
|
||||
|
||||
private MapChunkUtil_1_15 mapUtil = new MapChunkUtil_1_15();
|
||||
private MapChunkUtil_1_16_1 mapUtil = new MapChunkUtil_1_16_1();
|
||||
|
||||
@Override
|
||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket packet) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
PlayerChunk map = BukkitAdapter_1_15.getPlayerChunk(nmsWorld, packet.getChunkX(), packet.getChunkZ());
|
||||
PlayerChunk map = BukkitAdapter_1_16_1.getPlayerChunk(nmsWorld, packet.getChunkX(), packet.getChunkZ());
|
||||
if (map != null && map.hasBeenLoaded()) {
|
||||
boolean flag = false;
|
||||
PlayerChunk.d players = map.players;
|
||||
@ -362,91 +366,93 @@ public final class FAWE_Spigot_v1_15_R1 extends CachedBukkitAdapter implements I
|
||||
|
||||
@Override
|
||||
public NBTBase fromNative(Tag foreign) {
|
||||
if (foreign instanceof LazyCompoundTag_1_15) {
|
||||
return ((LazyCompoundTag_1_15) foreign).get();
|
||||
if (foreign instanceof LazyCompoundTag_1_16_1) {
|
||||
return ((LazyCompoundTag_1_16_1) foreign).get();
|
||||
}
|
||||
return parent.fromNative(foreign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerate(org.bukkit.World world, Region region, EditSession editSession) {
|
||||
WorldServer originalWorld = ((CraftWorld) world).getHandle();
|
||||
ChunkProviderServer provider = originalWorld.getChunkProvider();
|
||||
if (!(provider instanceof ChunkProviderServer)) {
|
||||
return false;
|
||||
}
|
||||
// WorldServer originalWorld = ((CraftWorld) world).getHandle();
|
||||
// ChunkProviderServer provider = originalWorld.getChunkProvider();
|
||||
// if (!(provider instanceof ChunkProviderServer)) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// File saveFolder = Files.createTempDir();
|
||||
// // register this just in case something goes wrong
|
||||
// // normally it should be deleted at the end of this method
|
||||
// saveFolder.deleteOnExit();
|
||||
// try {
|
||||
// MinecraftServer server = originalWorld.getServer().getServer();
|
||||
// Convertable.ConversionSession originalDataManager = server.convertable;
|
||||
//// Convertable.ConversionSession saveHandler = new Convertable.ConversionSession(world.getName(), world.);
|
||||
// WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null),
|
||||
// server.dataConverterManager, getDataVersion(), null);
|
||||
// newWorldData.setName(UUID.randomUUID().toString());
|
||||
//
|
||||
// ChunkGenerator gen = world.getGenerator();
|
||||
// Environment env = world.getEnvironment();
|
||||
// try (WorldServer freshWorld = new WorldServer(server,
|
||||
// server.executorService, originalDataManager,
|
||||
// newWorldData,
|
||||
// originalWorld.worldProvider.getDimensionManager(),
|
||||
// originalWorld.getMethodProfiler(),
|
||||
// server.worldLoadListenerFactory.create(11),
|
||||
// env,
|
||||
// gen){
|
||||
// @Override
|
||||
// public boolean addEntityChunk(Entity entity) {
|
||||
// //Fixes #320; Prevent adding entities so we aren't attempting to spawn them asynchronously
|
||||
// return false;
|
||||
// }
|
||||
// }) {
|
||||
//
|
||||
// // Pre-gen all the chunks
|
||||
// // We need to also pull one more chunk in every direction
|
||||
// Fawe.get().getQueueHandler().startSet(true);
|
||||
// try {
|
||||
// IQueueExtent<IQueueChunk> extent = new SingleThreadQueueExtent();
|
||||
// extent.init(null, (x, z) -> new BukkitGetBlocks_1_16_1(freshWorld, x, z) {
|
||||
// @Override
|
||||
// public Chunk ensureLoaded(World nmsWorld, int X, int Z) {
|
||||
// Chunk cached = nmsWorld.getChunkIfLoaded(X, Z);
|
||||
// if (cached != null) return cached;
|
||||
// Future<Chunk> future = Fawe.get().getQueueHandler().sync((Supplier<Chunk>) () -> freshWorld.getChunkAt(X, Z));
|
||||
// while (!future.isDone()) {
|
||||
// // this feels so dirty
|
||||
// freshWorld.getChunkProvider().runTasks();
|
||||
// }
|
||||
// try {
|
||||
// return future.get();
|
||||
// } catch (InterruptedException | ExecutionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }, null);
|
||||
// for (BlockVector3 vec : region) {
|
||||
// editSession.setBlock(vec, extent.getFullBlock(vec));
|
||||
// }
|
||||
// } finally {
|
||||
// Fawe.get().getQueueHandler().endSet(true);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// } catch (MaxChangedBlocksException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } finally {
|
||||
// saveFolder.delete();
|
||||
// }
|
||||
// return true;
|
||||
|
||||
File saveFolder = Files.createTempDir();
|
||||
// register this just in case something goes wrong
|
||||
// normally it should be deleted at the end of this method
|
||||
saveFolder.deleteOnExit();
|
||||
try {
|
||||
MinecraftServer server = originalWorld.getServer().getServer();
|
||||
WorldNBTStorage originalDataManager = originalWorld.getDataManager();
|
||||
WorldNBTStorage saveHandler = new WorldNBTStorage(saveFolder, originalDataManager.getDirectory().getName(), server, originalDataManager.getDataFixer());
|
||||
WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null),
|
||||
server.dataConverterManager, getDataVersion(), null);
|
||||
newWorldData.setName(UUID.randomUUID().toString());
|
||||
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
Environment env = world.getEnvironment();
|
||||
try (WorldServer freshWorld = new WorldServer(server,
|
||||
server.executorService, saveHandler,
|
||||
newWorldData,
|
||||
originalWorld.worldProvider.getDimensionManager(),
|
||||
originalWorld.getMethodProfiler(),
|
||||
server.worldLoadListenerFactory.create(11),
|
||||
env,
|
||||
gen){
|
||||
@Override
|
||||
public boolean addEntityChunk(net.minecraft.server.v1_15_R1.Entity entity) {
|
||||
//Fixes #320; Prevent adding entities so we aren't attempting to spawn them asynchronously
|
||||
return false;
|
||||
}
|
||||
}) {
|
||||
|
||||
// Pre-gen all the chunks
|
||||
// We need to also pull one more chunk in every direction
|
||||
Fawe.get().getQueueHandler().startSet(true);
|
||||
try {
|
||||
IQueueExtent<IQueueChunk> extent = new SingleThreadQueueExtent();
|
||||
extent.init(null, (x, z) -> new BukkitGetBlocks_1_15(freshWorld, x, z) {
|
||||
@Override
|
||||
public Chunk ensureLoaded(World nmsWorld, int X, int Z) {
|
||||
Chunk cached = nmsWorld.getChunkIfLoaded(X, Z);
|
||||
if (cached != null) return cached;
|
||||
Future<Chunk> future = Fawe.get().getQueueHandler().sync((Supplier<Chunk>) () -> freshWorld.getChunkAt(X, Z));
|
||||
while (!future.isDone()) {
|
||||
// this feels so dirty
|
||||
freshWorld.getChunkProvider().runTasks();
|
||||
}
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
for (BlockVector3 vec : region) {
|
||||
editSession.setBlock(vec, extent.getFullBlock(vec));
|
||||
}
|
||||
} finally {
|
||||
Fawe.get().getQueueHandler().endSet(true);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
saveFolder.delete();
|
||||
}
|
||||
return true;
|
||||
return false; //TODO: rework or remove for 1.16
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkGet get(org.bukkit.World world, int chunkX, int chunkZ) {
|
||||
return new BukkitGetBlocks_1_15(world, chunkX, chunkZ);
|
||||
return new BukkitGetBlocks_1_16_1(world, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
Reference in New Issue
Block a user