mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Merge branch 'commanding-pipeline' of https://github.com/IntellectualSites/FastAsyncWorldEdit-1.13 into commanding-pipeline
Conflicts: worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java worldedit-core/src/main/java/com/boydti/fawe/beta/filters/DistrFilter.java worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/ChunkCache.java worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/ParallelQueueExtent.java worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/MCAWriter.java worldedit-core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java
This commit is contained in:
@ -20,6 +20,7 @@ repositories {
|
||||
maven { url = uri("https://repo.destroystokyo.com/repository/maven-public//") }
|
||||
maven { url = uri("http://repo.dmulloy2.net/content/groups/public/") }
|
||||
maven { url = uri("http://ci.ender.zone/plugin/repository/everything/") }
|
||||
maven { url = uri("https://repo.inventivetalent.org/content/groups/public/")}
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
@ -49,6 +50,9 @@ dependencies {
|
||||
exclude("com.sk89q.worldedit.worldedit-libs", "bukkit")
|
||||
exclude("com.sk89q.worldedit.worldedit-libs", "core")
|
||||
}
|
||||
"implementation"("org.inventivetalent:mapmanager:1.7.3-SNAPSHOT") { isTransitive = false }
|
||||
"implementation"("org.inventivetalent:mapmanager:1.7.3-SNAPSHOT") { isTransitive = false }
|
||||
|
||||
"implementation"("com.massivecraft:factions:2.8.0") { isTransitive = false }
|
||||
"implementation"("com.drtshock:factions:1.6.9.5") { isTransitive = false }
|
||||
"implementation"("com.github.TechFortress:GriefPrevention:16.12.0") { isTransitive = false }
|
||||
|
@ -2,7 +2,9 @@ package com.boydti.fawe.bukkit;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.IFawe;
|
||||
import com.boydti.fawe.beta.implementation.QueueHandler;
|
||||
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
|
||||
import com.boydti.fawe.beta.implementation.cache.preloader.AsyncPreloader;
|
||||
import com.boydti.fawe.beta.implementation.cache.preloader.Preloader;
|
||||
import com.boydti.fawe.bukkit.adapter.BukkitQueueHandler;
|
||||
import com.boydti.fawe.bukkit.listener.BrushListener;
|
||||
import com.boydti.fawe.bukkit.listener.BukkitImageListener;
|
||||
@ -54,14 +56,14 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class FaweBukkit implements IFawe, Listener {
|
||||
|
||||
// private final WorldEditPlugin plugin;
|
||||
private final Plugin plugin;
|
||||
private VaultUtil vault;
|
||||
private ItemUtil itemUtil;
|
||||
|
||||
private boolean listeningImages;
|
||||
private BukkitImageListener imageListener;
|
||||
//private CFIPacketListener packetListener;
|
||||
|
||||
public static boolean PAPER;
|
||||
|
||||
public VaultUtil getVault() {
|
||||
return this.vault;
|
||||
@ -69,6 +71,13 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
|
||||
public FaweBukkit(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.Namespaced");
|
||||
PAPER = true;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
// TODO no paper
|
||||
}
|
||||
try {
|
||||
Settings.IMP.TICK_LIMITER.ENABLED = !Bukkit.hasWhitelist();
|
||||
Fawe.set(this);
|
||||
@ -103,7 +112,6 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
} catch (ClassNotFoundException e) {
|
||||
new ChunkListener_9();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -129,15 +137,15 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
PluginManager manager = Bukkit.getPluginManager();
|
||||
|
||||
if (manager.getPlugin("PacketListenerApi") == null) {
|
||||
File output = new File(plugin.getDataFolder().getParentFile(), "PacketListenerAPI_v3.6.0-SNAPSHOT.jar");
|
||||
byte[] jarData = Jars.PL_v3_6_0.download();
|
||||
File output = new File(plugin.getDataFolder().getParentFile(), "PacketListenerAPI_v3.7.3-SNAPSHOT.jar");
|
||||
byte[] jarData = Jars.PL_v3_7_3.download();
|
||||
try (FileOutputStream fos = new FileOutputStream(output)) {
|
||||
fos.write(jarData);
|
||||
}
|
||||
}
|
||||
if (manager.getPlugin("MapManager") == null) {
|
||||
File output = new File(plugin.getDataFolder().getParentFile(), "MapManager_v1.4.0-SNAPSHOT.jar");
|
||||
byte[] jarData = Jars.MM_v1_4_0.download();
|
||||
File output = new File(plugin.getDataFolder().getParentFile(), "MapManager_v1.7.3-SNAPSHOT.jar");
|
||||
byte[] jarData = Jars.MM_v1_7_3.download();
|
||||
try (FileOutputStream fos = new FileOutputStream(output)) {
|
||||
fos.write(jarData);
|
||||
}
|
||||
@ -397,4 +405,12 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
return null;
|
||||
// return ((BlocksHubBukkit) blocksHubPlugin).getApi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preloader getPreloader() {
|
||||
if (PAPER) {
|
||||
return new AsyncPreloader();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.boydti.fawe.bukkit.adapter;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.implementation.QueueHandler;
|
||||
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
|
||||
import com.boydti.fawe.bukkit.listener.ChunkListener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.adapter.mc1_14;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.bukkit.FaweBukkit;
|
||||
import com.boydti.fawe.bukkit.adapter.DelegateLock;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.collection.BitArray4096;
|
||||
@ -10,6 +11,7 @@ import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import net.jpountz.util.UnsafeUtils;
|
||||
import net.minecraft.server.v1_14_R1.Block;
|
||||
import net.minecraft.server.v1_14_R1.Chunk;
|
||||
@ -21,6 +23,7 @@ import net.minecraft.server.v1_14_R1.DataPaletteBlock;
|
||||
import net.minecraft.server.v1_14_R1.DataPaletteLinear;
|
||||
import net.minecraft.server.v1_14_R1.GameProfileSerializer;
|
||||
import net.minecraft.server.v1_14_R1.IBlockData;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunk;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunkMap;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
|
||||
@ -78,7 +81,7 @@ public class BukkitAdapter_1_14 {
|
||||
fieldDirtyBits.setAccessible(true);
|
||||
|
||||
{
|
||||
Field tmp = null;
|
||||
Field tmp;
|
||||
try {
|
||||
tmp = DataPaletteBlock.class.getDeclaredField("writeLock");
|
||||
} catch (NoSuchFieldException paper) {
|
||||
@ -133,8 +136,6 @@ public class BukkitAdapter_1_14 {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean PAPER = true;
|
||||
|
||||
public static Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) {
|
||||
Chunk nmsChunk = nmsWorld.getChunkIfLoaded(X, Z);
|
||||
if (nmsChunk != null) {
|
||||
@ -143,7 +144,7 @@ public class BukkitAdapter_1_14 {
|
||||
if (Fawe.isMainThread()) {
|
||||
return nmsWorld.getChunkAt(X, Z);
|
||||
}
|
||||
if (PAPER) {
|
||||
if (FaweBukkit.PAPER) {
|
||||
CraftWorld craftWorld = nmsWorld.getWorld();
|
||||
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(X, Z, true);
|
||||
try {
|
||||
@ -154,15 +155,14 @@ public class BukkitAdapter_1_14 {
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Throwable e) {
|
||||
System.out.println("Error, cannot load chunk async (paper not installed?)");
|
||||
PAPER = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// TODO optimize
|
||||
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(X, Z));
|
||||
}
|
||||
|
||||
private static PlayerChunk getPlayerChunk(net.minecraft.server.v1_14_R1.WorldServer nmsWorld, final int cx, final int cz) {
|
||||
public static PlayerChunk getPlayerChunk(net.minecraft.server.v1_14_R1.WorldServer nmsWorld, final int cx, final int cz) {
|
||||
PlayerChunkMap chunkMap = nmsWorld.getChunkProvider().playerChunkMap;
|
||||
PlayerChunk playerChunk = chunkMap.visibleChunks.get(ChunkCoordIntPair.pair(cx, cz));
|
||||
if (playerChunk == null) {
|
||||
@ -274,7 +274,7 @@ public class BukkitAdapter_1_14 {
|
||||
for (int i = 0; i < num_palette; i++) {
|
||||
final int ordinal = paletteToBlock[i];
|
||||
blockToPalette[ordinal] = Integer.MAX_VALUE;
|
||||
final BlockState state = BlockTypes.states[ordinal];
|
||||
final BlockState state = BlockTypesCache.states[ordinal];
|
||||
final IBlockData ibd = ((BlockMaterial_1_14) state.getMaterial()).getState();
|
||||
palette.a(ibd);
|
||||
}
|
||||
|
@ -3,11 +3,10 @@ package com.boydti.fawe.bukkit.adapter.mc1_14;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IChunkSet;
|
||||
import com.boydti.fawe.beta.implementation.QueueHandler;
|
||||
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
|
||||
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
|
||||
import com.boydti.fawe.bukkit.adapter.DelegateLock;
|
||||
import com.boydti.fawe.object.collection.AdaptedMap;
|
||||
import com.boydti.fawe.object.collection.AdaptedSetCollection;
|
||||
import com.boydti.fawe.object.collection.BitArray4096;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -58,7 +57,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
public Chunk nmsChunk;
|
||||
public CraftWorld world;
|
||||
public int X, Z;
|
||||
private boolean forceLoad;
|
||||
// private boolean forceLoad;
|
||||
|
||||
public BukkitGetBlocks_1_14(World world, int X, int Z, boolean forceLoad) {
|
||||
this.world = (CraftWorld) world;
|
||||
@ -76,6 +75,15 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public int getX() {
|
||||
return X;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return Z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiomeType(int x, int z) {
|
||||
BiomeBase base = getChunk().getBiomeIndex()[(z << 4) + x];
|
||||
@ -304,7 +312,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
System.out.println("Failed to set chunk section:" + X + "," + Z + " layer: " + layer);
|
||||
continue;
|
||||
} else {
|
||||
updateGet(this, nmsChunk, sections, newSection, setArr, layer);
|
||||
updateGet(this, nmsChunk, sections, newSection, getArr, layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
package com.boydti.fawe.bukkit.adapter.mc1_14;
|
||||
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import net.minecraft.server.v1_14_R1.NBTBase;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapChunkUtil_1_14 {
|
||||
private static final Field fieldX;
|
||||
|
||||
private static final Field fieldZ;
|
||||
|
||||
private static final Field fieldHeightMap;
|
||||
|
||||
private static final Field fieldBitMask;
|
||||
|
||||
private static final Field fieldChunkData;
|
||||
|
||||
private static final Field fieldBlockEntities;
|
||||
|
||||
private static final Field fieldFull;
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
fieldX = PacketPlayOutMapChunk.class.getDeclaredField("a");
|
||||
fieldZ = PacketPlayOutMapChunk.class.getDeclaredField("b");
|
||||
fieldBitMask = PacketPlayOutMapChunk.class.getDeclaredField("c");
|
||||
fieldHeightMap = PacketPlayOutMapChunk.class.getDeclaredField("d");
|
||||
fieldChunkData = PacketPlayOutMapChunk.class.getDeclaredField("e");
|
||||
fieldBlockEntities = PacketPlayOutMapChunk.class.getDeclaredField("f");
|
||||
fieldFull = PacketPlayOutMapChunk.class.getDeclaredField("g");
|
||||
|
||||
fieldX.setAccessible(true);
|
||||
fieldZ.setAccessible(true);
|
||||
fieldBitMask.setAccessible(true);
|
||||
fieldHeightMap.setAccessible(true);
|
||||
fieldBlockEntities.setAccessible(true);
|
||||
fieldFull.setAccessible(true);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketPlayOutMapChunk create(BukkitImplAdapter<NBTBase> adapter, ChunkPacket packet) {
|
||||
PacketPlayOutMapChunk nmsPacket = new PacketPlayOutMapChunk();
|
||||
|
||||
try {
|
||||
fieldX.setInt(nmsPacket, packet.getChunkX());
|
||||
fieldZ.setInt(nmsPacket, packet.getChunkZ());
|
||||
|
||||
fieldBitMask.set(nmsPacket, packet.getChunk().getBitMask());
|
||||
NBTBase heightMap = adapter.fromNative(packet.getHeightMap());
|
||||
fieldHeightMap.set(nmsPacket, heightMap);
|
||||
fieldChunkData.set(nmsPacket, packet.get());
|
||||
|
||||
Map<BlockVector3, CompoundTag> tiles = packet.getChunk().getTiles();
|
||||
ArrayList<NBTTagCompound> nmsTiles = new ArrayList<>(tiles.size());
|
||||
for (Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) {
|
||||
NBTBase nmsTag = adapter.fromNative(entry.getValue());
|
||||
nmsTiles.add((NBTTagCompound) nmsTag);
|
||||
}
|
||||
fieldBlockEntities.set(nmsPacket, nmsTiles);
|
||||
fieldFull.set(nmsPacket, packet.isFull());
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return nmsPacket;
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@
|
||||
package com.boydti.fawe.bukkit.adapter.mc1_14;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
@ -62,6 +64,7 @@ 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.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import net.minecraft.server.v1_14_R1.Block;
|
||||
@ -75,6 +78,7 @@ import net.minecraft.server.v1_14_R1.Chunk;
|
||||
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
|
||||
import net.minecraft.server.v1_14_R1.ChunkSection;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_14_R1.EnumDirection;
|
||||
import net.minecraft.server.v1_14_R1.EnumHand;
|
||||
@ -102,7 +106,9 @@ import net.minecraft.server.v1_14_R1.NBTTagLongArray;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagShort;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagString;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityStatus;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutTileEntityData;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunk;
|
||||
import net.minecraft.server.v1_14_R1.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_14_R1.TileEntity;
|
||||
import net.minecraft.server.v1_14_R1.Vec3D;
|
||||
@ -132,10 +138,12 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -171,7 +179,7 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
|
||||
if (idbToStateOrdinal != null) return false;
|
||||
idbToStateOrdinal = new char[Block.REGISTRY_ID.a()]; // size
|
||||
for (int i = 0; i < idbToStateOrdinal.length; i++) {
|
||||
BlockState state = BlockTypes.states[i];
|
||||
BlockState state = BlockTypesCache.states[i];
|
||||
BlockMaterial_1_14 material = (BlockMaterial_1_14) state.getMaterial();
|
||||
int id = Block.REGISTRY_ID.getId(material.getState());
|
||||
idbToStateOrdinal[id] = state.getOrdinalChar();
|
||||
@ -590,6 +598,13 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||
BlockMaterial_1_14 material = (BlockMaterial_1_14) state.getMaterial();
|
||||
IBlockData mcState = material.getCraftBlockData().getState();
|
||||
return OptionalInt.of(Block.REGISTRY_ID.getId(mcState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState adapt(BlockData blockData) {
|
||||
CraftBlockData cbd = ((CraftBlockData) blockData);
|
||||
@ -598,7 +613,7 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
|
||||
}
|
||||
|
||||
public BlockState adapt(IBlockData ibd) {
|
||||
return BlockTypes.states[adaptToInt(ibd)];
|
||||
return BlockTypesCache.states[adaptToInt(ibd)];
|
||||
}
|
||||
|
||||
public int adaptToInt(IBlockData ibd) {
|
||||
@ -648,6 +663,35 @@ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements Bukkit
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket packet) {
|
||||
WorldServer nmsWorld = ((CraftWorld) world).getHandle();
|
||||
PlayerChunk map = BukkitAdapter_1_14.getPlayerChunk(nmsWorld, packet.getChunkX(), packet.getChunkZ());
|
||||
if (map != null && map.hasBeenLoaded()) {
|
||||
boolean flag = false;
|
||||
PlayerChunk.d players = map.players;
|
||||
Stream<EntityPlayer> stream = players.a(new ChunkCoordIntPair(packet.getChunkX(), packet.getChunkZ()), flag);
|
||||
|
||||
EntityPlayer checkPlayer = player == null ? null : ((CraftPlayer) player).getHandle();
|
||||
stream.filter(entityPlayer -> checkPlayer == null || entityPlayer == checkPlayer)
|
||||
.forEach(entityPlayer -> {
|
||||
synchronized (packet) {
|
||||
PacketPlayOutMapChunk nmsPacket = (PacketPlayOutMapChunk) packet.getNativePacket();
|
||||
if (nmsPacket == null) {
|
||||
nmsPacket = MapChunkUtil_1_14.create(this, packet);
|
||||
packet.setNativePacket(nmsPacket);
|
||||
}
|
||||
try {
|
||||
FaweCache.IMP.CHUNK_FLAG.get().set(true);
|
||||
entityPlayer.playerConnection.sendPacket(nmsPacket);
|
||||
} finally {
|
||||
FaweCache.IMP.CHUNK_FLAG.get().set(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumDirection adapt(Direction face) {
|
||||
switch (face) {
|
||||
case NORTH: return EnumDirection.NORTH;
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.boydti.fawe.bukkit.adapter.mc1_14.test;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestChunkPacketSend {
|
||||
public TestChunkPacketSend(Plugin plugin) {
|
||||
// Disable all sound effects
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
protocolManager.addPacketListener(
|
||||
new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
if (event.getPacketType() != PacketType.Play.Server.MAP_CHUNK) {
|
||||
return;
|
||||
}
|
||||
PacketContainer packet = event.getPacket();
|
||||
StructureModifier<Byte> bytes = packet.getBytes();
|
||||
StructureModifier<WrappedBlockData> blockData = packet.getBlockData();
|
||||
List<WrappedBlockData> values = blockData.getValues();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package com.boydti.fawe.bukkit.chat;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
/**
|
||||
* Represents a wrapper around an array class of an arbitrary reference type,
|
||||
* which properly implements "value" hash code and equality functions.
|
||||
* <p>
|
||||
* This class is intended for use as a key to a map.
|
||||
* </p>
|
||||
*
|
||||
* @param <E> The type of elements in the array.
|
||||
* @author Glen Husman
|
||||
* @see Arrays
|
||||
*/
|
||||
public final class ArrayWrapper<E> {
|
||||
|
||||
/**
|
||||
* Creates an array wrapper with some elements.
|
||||
*
|
||||
* @param elements The elements of the array.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public ArrayWrapper(E... elements) {
|
||||
setArray(elements);
|
||||
}
|
||||
|
||||
private E[] _array;
|
||||
|
||||
/**
|
||||
* Retrieves a reference to the wrapped array instance.
|
||||
*
|
||||
* @return The array wrapped by this instance.
|
||||
*/
|
||||
public E[] getArray() {
|
||||
return _array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this wrapper to wrap a new array instance.
|
||||
*
|
||||
* @param array The new wrapped array.
|
||||
*/
|
||||
public void setArray(E[] array) {
|
||||
Validate.notNull(array, "The array must not be null.");
|
||||
_array = array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this object has a value equivalent to another object.
|
||||
*
|
||||
* @see Arrays#equals(Object[], Object[])
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ArrayWrapper)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(_array, ((ArrayWrapper) other)._array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hash code represented by this objects value.
|
||||
*
|
||||
* @return This object's hash code.
|
||||
* @see Arrays#hashCode(Object[])
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an iterable element collection to an array of elements.
|
||||
* The iteration order of the specified object will be used as the array element order.
|
||||
*
|
||||
* @param list The iterable of objects which will be converted to an array.
|
||||
* @param c The type of the elements of the array.
|
||||
* @return An array of elements in the specified iterable.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
|
||||
int size = -1;
|
||||
if (list instanceof Collection<?>) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection coll = (Collection) list;
|
||||
size = coll.size();
|
||||
}
|
||||
|
||||
|
||||
if (size < 0) {
|
||||
size = 0;
|
||||
// Ugly hack: Count it ourselves
|
||||
for (@SuppressWarnings("unused") T element : list) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
T[] result = (T[]) Array.newInstance(c, size);
|
||||
int i = 0;
|
||||
for (T element : list) { // Assumes iteration order is consistent
|
||||
result[i++] = element; // Assign array element at index THEN increment counter
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.boydti.fawe.bukkit.chat;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Represents an object that can be serialized to a JSON writer instance.
|
||||
*/
|
||||
interface JsonRepresentedObject {
|
||||
|
||||
/**
|
||||
* Writes the JSON representation of this object to the specified writer.
|
||||
* @param writer The JSON writer which will receive the object.
|
||||
* @throws IOException If an error occurs writing to the stream.
|
||||
*/
|
||||
public void writeJson(JsonWriter writer) throws IOException;
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.boydti.fawe.bukkit.chat;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
/**
|
||||
* Represents a JSON string value.
|
||||
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
|
||||
* All writes merely write the represented string value.
|
||||
*/
|
||||
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
||||
|
||||
private String _value;
|
||||
|
||||
public JsonString(CharSequence value) {
|
||||
_value = value == null ? null : value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeJson(JsonWriter writer) throws IOException {
|
||||
writer.value(getValue());
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public Map<String, Object> serialize() {
|
||||
HashMap<String, Object> theSingleValue = new HashMap<>();
|
||||
theSingleValue.put("stringValue", _value);
|
||||
return theSingleValue;
|
||||
}
|
||||
|
||||
public static JsonString deserialize(Map<String, Object> map) {
|
||||
return new JsonString(map.get("stringValue").toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
package com.boydti.fawe.bukkit.chat;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* A class containing static utility methods and caches which are intended as reflective conveniences.
|
||||
* Unless otherwise noted, upon failure methods will return {@code null}.
|
||||
*/
|
||||
public final class Reflection {
|
||||
|
||||
/**
|
||||
* Stores loaded classes from the {@code net.minecraft.server} package.
|
||||
*/
|
||||
private static final Map<String, Class<?>> _loadedNMSClasses = new HashMap<>();
|
||||
/**
|
||||
* Stores loaded classes from the {@code org.bukkit.craftbukkit} package (and subpackages).
|
||||
*/
|
||||
private static final Map<String, Class<?>> _loadedOBCClasses = new HashMap<>();
|
||||
private static final Map<Class<?>, Map<String, Field>> _loadedFields = new HashMap<>();
|
||||
/**
|
||||
* Contains loaded methods in a cache.
|
||||
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
||||
*/
|
||||
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
|
||||
private static String _versionString;
|
||||
|
||||
private Reflection() { }
|
||||
|
||||
/**
|
||||
* Gets the version string from the package name of the CraftBukkit server implementation.
|
||||
* This is needed to bypass the JAR package name changing on each update.
|
||||
*
|
||||
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
|
||||
*/
|
||||
public synchronized static String getVersion() {
|
||||
if (_versionString == null) {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
return _versionString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
|
||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
|
||||
*
|
||||
* @param className The name of the class, excluding the package, within NMS.
|
||||
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
|
||||
*/
|
||||
public synchronized static Class<?> getNMSClass(String className) {
|
||||
if (_loadedNMSClasses.containsKey(className)) {
|
||||
return _loadedNMSClasses.get(className);
|
||||
}
|
||||
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
_loadedNMSClasses.put(className, null);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
_loadedNMSClasses.put(className, clazz);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
|
||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
|
||||
*
|
||||
* @param className The name of the class, excluding the package, within OBC. This name may contain a subpackage name, such as {@code inventory.CraftItemStack}.
|
||||
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
|
||||
*/
|
||||
public synchronized static Class<?> getOBCClass(String className) {
|
||||
if (_loadedOBCClasses.containsKey(className)) {
|
||||
return _loadedOBCClasses.get(className);
|
||||
}
|
||||
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
_loadedOBCClasses.put(className, null);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
_loadedOBCClasses.put(className, clazz);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the NMS handle of a CraftBukkit object.
|
||||
* <p>
|
||||
* The only match currently attempted by this method is a retrieval by using a parameterless {@code getHandle()} method implemented by the runtime type of the specified object.
|
||||
* </p>
|
||||
*
|
||||
* @param obj The object for which to retrieve an NMS handle.
|
||||
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
||||
*/
|
||||
public synchronized static Object getHandle(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
|
||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||
* returned will be an instance or static field.
|
||||
* <p>
|
||||
* A global caching mechanism within this class is used to store fields. Combined with synchronization, this guarantees that
|
||||
* no field will be reflectively looked up twice.
|
||||
* </p>
|
||||
* <p>
|
||||
* If a field is deemed suitable for return, {@link Field#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
|
||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||
* </p>
|
||||
*
|
||||
* @param clazz The class which contains the field to retrieve.
|
||||
* @param name The declared name of the field in the class.
|
||||
* @return A field object with the specified name declared by the specified class.
|
||||
* @see Class#getDeclaredField(String)
|
||||
*/
|
||||
public synchronized static Field getField(Class<?> clazz, String name) {
|
||||
Map<String, Field> loaded;
|
||||
if (!_loadedFields.containsKey(clazz)) {
|
||||
loaded = new HashMap<>();
|
||||
_loadedFields.put(clazz, loaded);
|
||||
} else {
|
||||
loaded = _loadedFields.get(clazz);
|
||||
}
|
||||
if (loaded.containsKey(name)) {
|
||||
// If the field is loaded (or cached as not existing), return the relevant value, which might be null
|
||||
return loaded.get(name);
|
||||
}
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
loaded.put(name, field);
|
||||
return field;
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
// Error loading
|
||||
e.printStackTrace();
|
||||
// Cache field as not existing
|
||||
loaded.put(name, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
|
||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||
* returned will be an instance or static field.
|
||||
* <p>
|
||||
* A global caching mechanism within this class is used to store method. Combined with synchronization, this guarantees that
|
||||
* no method will be reflectively looked up twice.
|
||||
* <p>
|
||||
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
|
||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||
* <p>
|
||||
* This method does <em>not</em> search superclasses of the specified type for methods with the specified signature.
|
||||
* Callers wishing this behavior should use {@link Class#getDeclaredMethod(String, Class...)}.
|
||||
*
|
||||
* @param clazz The class which contains the method to retrieve.
|
||||
* @param name The declared name of the method in the class.
|
||||
* @param args The formal argument types of the method.
|
||||
* @return A method object with the specified name declared by the specified class.
|
||||
*/
|
||||
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
if (!_loadedMethods.containsKey(clazz)) {
|
||||
_loadedMethods.put(clazz, new HashMap<>());
|
||||
}
|
||||
|
||||
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
|
||||
if (!loadedMethodNames.containsKey(name)) {
|
||||
loadedMethodNames.put(name, new HashMap<>());
|
||||
}
|
||||
|
||||
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
|
||||
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
|
||||
if (loadedSignatures.containsKey(wrappedArg)) {
|
||||
return loadedSignatures.get(wrappedArg);
|
||||
}
|
||||
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
|
||||
m.setAccessible(true);
|
||||
loadedSignatures.put(wrappedArg, m);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
loadedSignatures.put(wrappedArg, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.bukkit.listener;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.command.CFICommands;
|
||||
import com.boydti.fawe.object.RunnableVal3;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
@ -15,20 +16,32 @@ import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.event.platform.BlockInteractEvent;
|
||||
import com.sk89q.worldedit.event.platform.Interaction;
|
||||
import com.sk89q.worldedit.extension.platform.PlatformManager;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The CFIPacketListener handles packets for editing the VirtualWorld
|
||||
@ -45,99 +58,90 @@ public class CFIPacketListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
this.protocolmanager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
// TODO NOT IMPLEMENTED
|
||||
// // Direct digging to the virtual world
|
||||
// registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
// @Override
|
||||
// public void run(Builder event, URI gen, String pt) {
|
||||
// try {
|
||||
// Player plr = event.getPlayer();
|
||||
// BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint());
|
||||
// if (!sendBlockChange(plr, gen, pt, Interaction.HIT)) {
|
||||
// gen.setBlock(pt, BlockTypes.AIR.getDefaultState());
|
||||
// }
|
||||
// } catch (WorldEditException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // Direct placing to the virtual world
|
||||
// RunnableVal3<PacketEvent, VirtualWorld, BlockVector3> placeTask = new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
// @Override
|
||||
// public void run(Builder event, URI gen, String pt) {
|
||||
// try {
|
||||
// Player plr = event.getPlayer();
|
||||
// List<EnumWrappers.Hand> hands = event.getPacket().getHands().getValues();
|
||||
//
|
||||
// EnumWrappers.Hand enumHand = hands.isEmpty() ? EnumWrappers.Hand.MAIN_HAND : hands.get(0);
|
||||
// PlayerInventory inv = plr.getInventory();
|
||||
// ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand();
|
||||
// if (hand.getType().isBlock()) {
|
||||
// Material type = hand.getType();
|
||||
// switch (type) {
|
||||
// case AIR:
|
||||
// case CAVE_AIR:
|
||||
// case VOID_AIR:
|
||||
// break;
|
||||
// default: {
|
||||
// BlockStateHolder block = BukkitAdapter.asBlockState(hand);
|
||||
// if (block != null) {
|
||||
// gen.setBlock(pt, block);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// pt = getRelPos(event, gen);
|
||||
// sendBlockChange(plr, gen, pt, Interaction.OPEN);
|
||||
// } catch (WorldEditException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// registerBlockEvent(PacketType.Play.Client.BLOCK_PLACE, true, placeTask);
|
||||
// registerBlockEvent(PacketType.Play.Client.USE_ITEM, true, placeTask);
|
||||
//
|
||||
// // Cancel block change packets where the real world overlaps with the virtual one
|
||||
// registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
// @Override
|
||||
// public void run(Builder event, URI gen, String pt) {
|
||||
// // Do nothing
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // Modify chunk packets where the real world overlaps with the virtual one
|
||||
// protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) {
|
||||
// @Override
|
||||
// public void onPacketSending(PacketEvent event) {
|
||||
// if (!event.isServerPacket()) return;
|
||||
//
|
||||
// VirtualWorld gen = getGenerator(event);
|
||||
// if (gen != null) {
|
||||
// BlockVector3 origin = gen.getOrigin().toBlockPoint();
|
||||
// PacketContainer packet = event.getPacket();
|
||||
// StructureModifier<Integer> ints = packet.getIntegers();
|
||||
// int cx = ints.read(0);
|
||||
// int cz = ints.read(1);
|
||||
//
|
||||
// int ocx = origin.getBlockX() >> 4;
|
||||
// int ocz = origin.getBlockZ() >> 4;
|
||||
//
|
||||
// if (gen.contains(BlockVector3.at((cx - ocx) << 4, 0, (cz - ocz) << 4))) {
|
||||
// event.setCancelled(true);
|
||||
//
|
||||
// Player plr = event.getPlayer();
|
||||
//
|
||||
// FaweQueue queue = SetQueue.IMP.getNewQueue(plr.getWorld().getName(), true, false);
|
||||
//
|
||||
// FaweChunk toSend = gen.getSnapshot(cx - ocx, cz - ocz);
|
||||
// toSend.setLoc(gen, cx, cz);
|
||||
// queue.sendChunkUpdate(toSend, FawePlayer.wrap(plr));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// Direct digging to the virtual world
|
||||
registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
@Override
|
||||
public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
|
||||
try {
|
||||
Player plr = event.getPlayer();
|
||||
BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint());
|
||||
if (!sendBlockChange(plr, gen, pt, Interaction.HIT)) {
|
||||
gen.setBlock(pt, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
} catch (WorldEditException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Direct placing to the virtual world
|
||||
RunnableVal3<PacketEvent, VirtualWorld, BlockVector3> placeTask = new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
@Override
|
||||
public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
|
||||
try {
|
||||
Player plr = event.getPlayer();
|
||||
List<EnumWrappers.Hand> hands = event.getPacket().getHands().getValues();
|
||||
|
||||
EnumWrappers.Hand enumHand = hands.isEmpty() ? EnumWrappers.Hand.MAIN_HAND : hands.get(0);
|
||||
PlayerInventory inv = plr.getInventory();
|
||||
ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand();
|
||||
if (hand.getType().isBlock()) {
|
||||
Material type = hand.getType();
|
||||
switch (type) {
|
||||
case AIR:
|
||||
case CAVE_AIR:
|
||||
case VOID_AIR:
|
||||
break;
|
||||
default: {
|
||||
BlockStateHolder block = BukkitAdapter.asBlockState(hand);
|
||||
if (block != null) {
|
||||
gen.setBlock(pt, block);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pt = getRelPos(event, gen);
|
||||
sendBlockChange(plr, gen, pt, Interaction.OPEN);
|
||||
} catch (WorldEditException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
registerBlockEvent(PacketType.Play.Client.BLOCK_PLACE, true, placeTask);
|
||||
registerBlockEvent(PacketType.Play.Client.USE_ITEM, true, placeTask);
|
||||
|
||||
// Cancel block change packets where the real world overlaps with the virtual one
|
||||
registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3<PacketEvent, VirtualWorld, BlockVector3>() {
|
||||
@Override
|
||||
public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
|
||||
// Modify chunk packets where the real world overlaps with the virtual one
|
||||
protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
if (!event.isServerPacket() || FaweCache.IMP.CHUNK_FLAG.get().get()) return;
|
||||
VirtualWorld gen = getGenerator(event);
|
||||
if (gen != null) {
|
||||
BlockVector3 origin = gen.getOrigin().toBlockPoint();
|
||||
PacketContainer packet = event.getPacket();
|
||||
StructureModifier<Integer> ints = packet.getIntegers();
|
||||
int cx = ints.read(0);
|
||||
int cz = ints.read(1);
|
||||
|
||||
int ocx = origin.getBlockX() >> 4;
|
||||
int ocz = origin.getBlockZ() >> 4;
|
||||
|
||||
if (gen.contains(BlockVector3.at((cx - ocx) << 4, 0, (cz - ocz) << 4))) {
|
||||
event.setCancelled(true);
|
||||
gen.refreshChunk(cx - ocx, cz - ocz);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// The following few listeners are to ignore block collisions where the virtual and real world overlap
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
package com.boydti.fawe.bukkit.listener;
|
||||
|
||||
public class ChunkCache {
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
package com.boydti.fawe.bukkit.preloader;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.PluginBase;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PluginPreloader extends PluginBase {
|
||||
private World world;
|
||||
private Set<BlockVector2> loaded;
|
||||
private int index;
|
||||
private AtomicBoolean invalidator;
|
||||
private final Object invalidatorLock;
|
||||
|
||||
public PluginPreloader() {
|
||||
invalidator = new AtomicBoolean();
|
||||
invalidatorLock = new Object();
|
||||
}
|
||||
|
||||
public AtomicBoolean invalidate() {
|
||||
synchronized (invalidatorLock) {
|
||||
invalidator.set(false);
|
||||
return invalidator = new AtomicBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void unload() {
|
||||
World oldWorld = world;
|
||||
if (oldWorld != null) {
|
||||
Set<BlockVector2> toUnload = loaded;
|
||||
if (loaded != null && index > 0) {
|
||||
Iterator<BlockVector2> iter = toUnload.iterator();
|
||||
Fawe.get().getQueueHandler().sync(() -> {
|
||||
for (int i = 0; i < index && iter.hasNext(); i++) {
|
||||
BlockVector2 chunk = iter.next();
|
||||
world.removePluginChunkTicket(chunk.getX(), chunk.getZ(), this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.world = null;
|
||||
this.loaded = null;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
public void update(Region region) {
|
||||
AtomicBoolean invalidator = invalidate();
|
||||
synchronized (this) {
|
||||
com.sk89q.worldedit.world.World weWorld = region.getWorld();
|
||||
if (weWorld == null) {
|
||||
return;
|
||||
}
|
||||
unload();
|
||||
index = 0;
|
||||
world = BukkitAdapter.adapt(weWorld);
|
||||
loaded = region.getChunks();
|
||||
Iterator<BlockVector2> iter = loaded.iterator();
|
||||
|
||||
if (!invalidator.get()) return;
|
||||
Fawe.get().getQueueHandler().syncWhenFree(() -> {
|
||||
for (; iter.hasNext() && invalidator.get();index++) {
|
||||
BlockVector2 chunk = iter.next();
|
||||
if (!world.isChunkLoaded(chunk.getX(), chunk.getZ())) {
|
||||
world.addPluginChunkTicket(chunk.getX(), chunk.getZ(), this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
invalidate();
|
||||
unload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getDataFolder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PluginDescriptionFile getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FileConfiguration getConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable InputStream getResource(@NotNull String filename) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDefaultConfig() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveResource(@NotNull String resourcePath, boolean replace) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PluginLoader getPluginLoader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Server getServer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaggable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNaggable(boolean canNag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Logger getLogger() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,173 +19,173 @@ import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
//import org.inventivetalent.mapmanager.MapManagerPlugin;
|
||||
//import org.inventivetalent.mapmanager.controller.MapController;
|
||||
//import org.inventivetalent.mapmanager.controller.MultiMapController;
|
||||
//import org.inventivetalent.mapmanager.manager.MapManager;
|
||||
//import org.inventivetalent.mapmanager.wrapper.MapWrapper;
|
||||
import org.inventivetalent.mapmanager.MapManagerPlugin;
|
||||
import org.inventivetalent.mapmanager.controller.MapController;
|
||||
import org.inventivetalent.mapmanager.controller.MultiMapController;
|
||||
import org.inventivetalent.mapmanager.manager.MapManager;
|
||||
import org.inventivetalent.mapmanager.wrapper.MapWrapper;
|
||||
|
||||
public class BukkitImageViewer implements ImageViewer {
|
||||
// private final MapManager mapManager;
|
||||
// private final Player player;
|
||||
// private BufferedImage last;
|
||||
private final MapManager mapManager;
|
||||
private final Player player;
|
||||
private BufferedImage last;
|
||||
private ItemFrame[][] frames;
|
||||
// private boolean reverse;
|
||||
private boolean reverse;
|
||||
|
||||
public BukkitImageViewer(Player player) {
|
||||
// mapManager = ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager();
|
||||
// this.player = player;
|
||||
mapManager = ((MapManagerPlugin) Bukkit.getPluginManager().getPlugin("MapManager")).getMapManager();
|
||||
this.player = player;
|
||||
}
|
||||
//
|
||||
|
||||
public void selectFrame(ItemFrame start) {
|
||||
// Location pos1 = start.getLocation().clone();
|
||||
// Location pos2 = start.getLocation().clone();
|
||||
//
|
||||
// BlockFace facing = start.getFacing();
|
||||
// int planeX = facing.getModX() == 0 ? 1 : 0;
|
||||
// int planeY = facing.getModY() == 0 ? 1 : 0;
|
||||
// int planeZ = facing.getModZ() == 0 ? 1 : 0;
|
||||
//
|
||||
// ItemFrame[][] res = find(pos1, pos2, facing);
|
||||
// Location tmp;
|
||||
// while (true) {
|
||||
// if (res != null) {
|
||||
// frames = res;
|
||||
// }
|
||||
// tmp = pos1.clone().subtract(planeX, planeY, planeZ);
|
||||
// if ((res = find(tmp, pos2, facing)) != null) {
|
||||
// pos1 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// tmp = pos2.clone().add(planeX, planeY, planeZ);
|
||||
// if ((res = find(pos1, tmp, facing)) != null) {
|
||||
// pos2 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// tmp = pos1.clone().subtract(planeX, 0, planeZ);
|
||||
// if ((res = find(tmp, pos2, facing)) != null) {
|
||||
// pos1 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// tmp = pos2.clone().add(planeX, 0, planeZ);
|
||||
// if ((res = find(pos1, tmp, facing)) != null) {
|
||||
// pos2 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// tmp = pos1.clone().subtract(0, 1, 0);
|
||||
// if ((res = find(tmp, pos2, facing)) != null) {
|
||||
// pos1 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// tmp = pos2.clone().add(0, 1, 0);
|
||||
// if ((res = find(pos1, tmp, facing)) != null) {
|
||||
// pos2 = tmp;
|
||||
// continue;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
Location pos1 = start.getLocation().clone();
|
||||
Location pos2 = start.getLocation().clone();
|
||||
|
||||
BlockFace facing = start.getFacing();
|
||||
int planeX = facing.getModX() == 0 ? 1 : 0;
|
||||
int planeY = facing.getModY() == 0 ? 1 : 0;
|
||||
int planeZ = facing.getModZ() == 0 ? 1 : 0;
|
||||
|
||||
ItemFrame[][] res = find(pos1, pos2, facing);
|
||||
Location tmp;
|
||||
while (true) {
|
||||
if (res != null) {
|
||||
frames = res;
|
||||
}
|
||||
tmp = pos1.clone().subtract(planeX, planeY, planeZ);
|
||||
if ((res = find(tmp, pos2, facing)) != null) {
|
||||
pos1 = tmp;
|
||||
continue;
|
||||
}
|
||||
tmp = pos2.clone().add(planeX, planeY, planeZ);
|
||||
if ((res = find(pos1, tmp, facing)) != null) {
|
||||
pos2 = tmp;
|
||||
continue;
|
||||
}
|
||||
tmp = pos1.clone().subtract(planeX, 0, planeZ);
|
||||
if ((res = find(tmp, pos2, facing)) != null) {
|
||||
pos1 = tmp;
|
||||
continue;
|
||||
}
|
||||
tmp = pos2.clone().add(planeX, 0, planeZ);
|
||||
if ((res = find(pos1, tmp, facing)) != null) {
|
||||
pos2 = tmp;
|
||||
continue;
|
||||
}
|
||||
tmp = pos1.clone().subtract(0, 1, 0);
|
||||
if ((res = find(tmp, pos2, facing)) != null) {
|
||||
pos1 = tmp;
|
||||
continue;
|
||||
}
|
||||
tmp = pos2.clone().add(0, 1, 0);
|
||||
if ((res = find(pos1, tmp, facing)) != null) {
|
||||
pos2 = tmp;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
public ItemFrame[][] getItemFrames() {
|
||||
return frames;
|
||||
}
|
||||
//
|
||||
// private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) {
|
||||
// try {
|
||||
// Location distance = pos2.clone().subtract(pos1).add(1, 1, 1);
|
||||
// int width = Math.max(distance.getBlockX(), distance.getBlockZ());
|
||||
// ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()];
|
||||
//
|
||||
// World world = pos1.getWorld();
|
||||
//
|
||||
// this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST);
|
||||
// int v = 0;
|
||||
// for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) {
|
||||
// int h = 0;
|
||||
// for (double z = pos1.getZ(); z <= pos2.getZ(); z++) {
|
||||
// for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) {
|
||||
// Location pos = new Location(world, x, y, z);
|
||||
// Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
|
||||
// boolean contains = false;
|
||||
// for (Entity ent : entities) {
|
||||
// if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
|
||||
// ItemFrame itemFrame = (ItemFrame) ent;
|
||||
// itemFrame.setRotation(Rotation.NONE);
|
||||
// contains = true;
|
||||
// frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!contains) return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return frames;
|
||||
// } catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) {
|
||||
try {
|
||||
Location distance = pos2.clone().subtract(pos1).add(1, 1, 1);
|
||||
int width = Math.max(distance.getBlockX(), distance.getBlockZ());
|
||||
ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()];
|
||||
|
||||
World world = pos1.getWorld();
|
||||
|
||||
this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST);
|
||||
int v = 0;
|
||||
for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) {
|
||||
int h = 0;
|
||||
for (double z = pos1.getZ(); z <= pos2.getZ(); z++) {
|
||||
for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) {
|
||||
Location pos = new Location(world, x, y, z);
|
||||
Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
|
||||
boolean contains = false;
|
||||
for (Entity ent : entities) {
|
||||
if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
|
||||
ItemFrame itemFrame = (ItemFrame) ent;
|
||||
itemFrame.setRotation(Rotation.NONE);
|
||||
contains = true;
|
||||
frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return frames;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void view(Drawable drawable) {
|
||||
// view(null, drawable);
|
||||
view(null, drawable);
|
||||
}
|
||||
//
|
||||
// private void view(@Nullable BufferedImage image, @Nullable Drawable drawable) {
|
||||
// if (image == null && drawable == null) throw new IllegalArgumentException("An image or drawable must be provided. Both cannot be null");
|
||||
// boolean initializing = last == null;
|
||||
//
|
||||
// if (this.frames != null) {
|
||||
// if (image == null && drawable != null) image = drawable.draw();
|
||||
// last = image;
|
||||
// int width = frames.length;
|
||||
// int height = frames[0].length;
|
||||
// BufferedImage scaled = ImageUtil.getScaledInstance(image, 128 * width, 128 * height, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
|
||||
// MapWrapper mapWrapper = mapManager.wrapMultiImage(scaled, width, height);
|
||||
// MultiMapController controller = (MultiMapController) mapWrapper.getController();
|
||||
// controller.addViewer(player);
|
||||
// controller.sendContent(player);
|
||||
// controller.showInFrames(player, frames, true);
|
||||
// } else {
|
||||
// int slot = getMapSlot(player);
|
||||
// if (slot == -1) {
|
||||
// if (initializing) {
|
||||
// player.getInventory().setItemInMainHand(new ItemStack(Material.MAP));
|
||||
// } else {
|
||||
// return;
|
||||
// }
|
||||
// } else if (player.getInventory().getHeldItemSlot() != slot) {
|
||||
// player.getInventory().setHeldItemSlot(slot);
|
||||
// }
|
||||
// if (image == null && drawable != null) image = drawable.draw();
|
||||
// last = image;
|
||||
// BufferedImage scaled = ImageUtil.getScaledInstance(image, 128, 128, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
|
||||
// MapWrapper mapWrapper = mapManager.wrapImage(scaled);
|
||||
// MapController controller = mapWrapper.getController();
|
||||
// controller.addViewer(player);
|
||||
// controller.sendContent(player);
|
||||
// controller.showInHand(player, true);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private int getMapSlot(Player player) {
|
||||
// PlayerInventory inventory = player.getInventory();
|
||||
// for (int i = 0; i < 9; i++) {
|
||||
// ItemStack item = inventory.getItem(i);
|
||||
// if (item != null && item.getType() == Material.MAP) {
|
||||
// return i;
|
||||
// }
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
|
||||
private void view(@Nullable BufferedImage image, @Nullable Drawable drawable) {
|
||||
if (image == null && drawable == null) throw new IllegalArgumentException("An image or drawable must be provided. Both cannot be null");
|
||||
boolean initializing = last == null;
|
||||
|
||||
if (this.frames != null) {
|
||||
if (image == null && drawable != null) image = drawable.draw();
|
||||
last = image;
|
||||
int width = frames.length;
|
||||
int height = frames[0].length;
|
||||
BufferedImage scaled = ImageUtil.getScaledInstance(image, 128 * width, 128 * height, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
|
||||
MapWrapper mapWrapper = mapManager.wrapMultiImage(scaled, width, height);
|
||||
MultiMapController controller = (MultiMapController) mapWrapper.getController();
|
||||
controller.addViewer(player);
|
||||
controller.sendContent(player);
|
||||
controller.showInFrames(player, frames, true);
|
||||
} else {
|
||||
int slot = getMapSlot(player);
|
||||
if (slot == -1) {
|
||||
if (initializing) {
|
||||
player.getInventory().setItemInMainHand(new ItemStack(Material.MAP));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (player.getInventory().getHeldItemSlot() != slot) {
|
||||
player.getInventory().setHeldItemSlot(slot);
|
||||
}
|
||||
if (image == null && drawable != null) image = drawable.draw();
|
||||
last = image;
|
||||
BufferedImage scaled = ImageUtil.getScaledInstance(image, 128, 128, RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
|
||||
MapWrapper mapWrapper = mapManager.wrapImage(scaled);
|
||||
MapController controller = mapWrapper.getController();
|
||||
controller.addViewer(player);
|
||||
controller.sendContent(player);
|
||||
controller.showInHand(player, true);
|
||||
}
|
||||
}
|
||||
|
||||
private int getMapSlot(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack item = inventory.getItem(i);
|
||||
if (item != null && item.getType() == Material.MAP) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
// if (last != null) view(last, null);
|
||||
if (last != null) view(last, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// last = null;
|
||||
last = null;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -57,7 +58,7 @@ public class AsyncBlock implements Block {
|
||||
}
|
||||
|
||||
public int getPropertyId() {
|
||||
return world.getBlock(x, y, z).getInternalId() >> BlockTypes.BIT_OFFSET;
|
||||
return world.getBlock(x, y, z).getInternalId() >> BlockTypesCache.BIT_OFFSET;
|
||||
}
|
||||
|
||||
public int getCombinedId() {
|
||||
@ -105,7 +106,7 @@ public class AsyncBlock implements Block {
|
||||
|
||||
@Deprecated
|
||||
public boolean setTypeIdAndPropertyId(int id, int propertyId) {
|
||||
return setCombinedId(id + (propertyId << BlockTypes.BIT_OFFSET));
|
||||
return setCombinedId(id + (propertyId << BlockTypesCache.BIT_OFFSET));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -9,6 +9,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -42,7 +43,7 @@ public class AsyncBlockState implements BlockState {
|
||||
}
|
||||
|
||||
public int getPropertyId() {
|
||||
return state.getInternalId() >> BlockTypes.BIT_OFFSET;
|
||||
return state.getInternalId() >> BlockTypesCache.BIT_OFFSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,12 +159,12 @@ public class AsyncBlockState implements BlockState {
|
||||
|
||||
@Override
|
||||
public byte getRawData() {
|
||||
return (byte) (state.getInternalId() >> BlockTypes.BIT_OFFSET);
|
||||
return (byte) (state.getInternalId() >> BlockTypesCache.BIT_OFFSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRawData(byte data) {
|
||||
int combinedId = getTypeId() + (data << BlockTypes.BIT_OFFSET);
|
||||
int combinedId = getTypeId() + (data << BlockTypesCache.BIT_OFFSET);
|
||||
state = com.sk89q.worldedit.world.block.BlockState.getFromInternalId(combinedId).toBaseBlock(state.getNbtData());
|
||||
this.blockData = BukkitAdapter.adapt(state);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public enum BukkitAdapter {
|
||||
*/
|
||||
public static Player adapt(com.sk89q.worldedit.entity.Player player) {
|
||||
player = PlayerProxy.unwrap(player);
|
||||
return ((BukkitPlayer) player).getPlayer();
|
||||
return player == null ? null : ((BukkitPlayer) player).getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||
|
||||
@ -93,6 +94,10 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||
this.material = bukkitMaterial;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return material.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
switch (material) {
|
||||
@ -132,4 +137,9 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -62,23 +57,44 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
private Player player;
|
||||
private WorldEditPlugin plugin;
|
||||
|
||||
public BukkitPlayer(Player player) {
|
||||
this(WorldEditPlugin.getInstance(), player);
|
||||
super(getExistingMap(WorldEditPlugin.getInstance(), player));
|
||||
this.plugin = WorldEditPlugin.getInstance();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public BukkitPlayer(WorldEditPlugin plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (Settings.IMP.CLIPBOARD.USE_DISK) {
|
||||
loadClipboardFromDisk();
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> getExistingMap(WorldEditPlugin plugin, Player player) {
|
||||
BukkitPlayer cached = plugin.getCachedPlayer(player);
|
||||
if (cached != null) {
|
||||
return cached.getRawMeta();
|
||||
}
|
||||
return new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return player.getUniqueId();
|
||||
@ -87,16 +103,16 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
@Override
|
||||
public BaseItemStack getItemInHand(HandSide handSide) {
|
||||
ItemStack itemStack = handSide == HandSide.MAIN_HAND
|
||||
? player.getInventory().getItemInMainHand()
|
||||
: player.getInventory().getItemInOffHand();
|
||||
? getPlayer().getInventory().getItemInMainHand()
|
||||
: getPlayer().getInventory().getItemInOffHand();
|
||||
return BukkitAdapter.adapt(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
|
||||
ItemStack itemStack = handSide == HandSide.MAIN_HAND
|
||||
? player.getInventory().getItemInMainHand()
|
||||
: player.getInventory().getItemInOffHand();
|
||||
? getPlayer().getInventory().getItemInMainHand()
|
||||
: getPlayer().getInventory().getItemInOffHand();
|
||||
return BukkitAdapter.asBlockState(itemStack).toBaseBlock();
|
||||
}
|
||||
|
||||
@ -107,18 +123,18 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return player.getDisplayName();
|
||||
return getPlayer().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
final PlayerInventory inv = getPlayer().getInventory();
|
||||
ItemStack newItem = BukkitAdapter.adapt(itemStack);
|
||||
if (itemStack.getType().getId().equalsIgnoreCase(WorldEdit.getInstance().getConfiguration().wandItem)) {
|
||||
inv.remove(newItem);
|
||||
}
|
||||
final ItemStack item = player.getInventory().getItemInMainHand();
|
||||
player.getInventory().setItemInMainHand(newItem);
|
||||
final ItemStack item = getPlayer().getInventory().getItemInMainHand();
|
||||
getPlayer().getInventory().setItemInMainHand(newItem);
|
||||
HashMap<Integer, ItemStack> overflow = inv.addItem(item);
|
||||
if (!overflow.isEmpty()) {
|
||||
TaskManager.IMP.sync(new RunnableVal<Object>() {
|
||||
@ -128,7 +144,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
ItemStack stack = entry.getValue();
|
||||
if (stack.getType() != Material.AIR && stack.getAmount() > 0) {
|
||||
Item
|
||||
dropped = player.getWorld().dropItem(player.getLocation(), stack);
|
||||
dropped = getPlayer().getWorld().dropItem(getPlayer().getLocation(), stack);
|
||||
PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped);
|
||||
if (event.isCancelled()) {
|
||||
dropped.remove();
|
||||
@ -138,45 +154,45 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
}
|
||||
});
|
||||
}
|
||||
player.updateInventory();
|
||||
getPlayer().updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
for (String part : msg.split("\n")) {
|
||||
player.sendMessage(part);
|
||||
getPlayer().sendMessage(part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String msg) {
|
||||
for (String part : msg.split("\n")) {
|
||||
player.sendMessage("\u00A7d" + part);
|
||||
getPlayer().sendMessage("\u00A7d" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDebug(String msg) {
|
||||
for (String part : msg.split("\n")) {
|
||||
player.sendMessage("\u00A77" + part);
|
||||
getPlayer().sendMessage("\u00A77" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printError(String msg) {
|
||||
for (String part : msg.split("\n")) {
|
||||
player.sendMessage("§c" + part);
|
||||
getPlayer().sendMessage("§c" + part);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(Component component) {
|
||||
TextAdapter.sendComponent(player, WorldEditText.format(component));
|
||||
TextAdapter.sendComponent(getPlayer(), WorldEditText.format(component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector3 pos, float pitch, float yaw) {
|
||||
org.bukkit.World world = player.getWorld();
|
||||
org.bukkit.World world = getPlayer().getWorld();
|
||||
if (pos instanceof com.sk89q.worldedit.util.Location) {
|
||||
com.sk89q.worldedit.util.Location loc = (com.sk89q.worldedit.util.Location) pos;
|
||||
Extent extent = loc.getExtent();
|
||||
@ -184,42 +200,41 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
world = Bukkit.getWorld(((World) extent).getName());
|
||||
}
|
||||
}
|
||||
player.teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
|
||||
getPlayer().teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getPermissionsResolver().getGroups(player);
|
||||
return plugin.getPermissionsResolver().getGroups(getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockBag getInventoryBlockBag() {
|
||||
return new BukkitPlayerBlockBag(player);
|
||||
return new BukkitPlayerBlockBag(getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode getGameMode() {
|
||||
return GameModes.get(player.getGameMode().name().toLowerCase(Locale.ROOT));
|
||||
return GameModes.get(getPlayer().getGameMode().name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode gameMode) {
|
||||
player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase(Locale.ROOT)));
|
||||
getPlayer().setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|
||||
|| plugin.getPermissionsResolver().hasPermission(
|
||||
player.getWorld().getName(), player, perm);
|
||||
|| plugin.getPermissionsResolver().hasPermission(player.getWorld().getName(), player, perm);
|
||||
}
|
||||
|
||||
@Override public boolean togglePermission(String permission) {
|
||||
if (this.hasPermission(permission)) {
|
||||
player.addAttachment(plugin).setPermission(permission, false);
|
||||
getPlayer().addAttachment(plugin).setPermission(permission, false);
|
||||
return false;
|
||||
} else {
|
||||
player.addAttachment(plugin).setPermission(permission, true);
|
||||
getPlayer().addAttachment(plugin).setPermission(permission, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -231,19 +246,19 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
* - The `/wea` command will give/remove the required bypass permission
|
||||
*/
|
||||
if (Fawe.<FaweBukkit>imp().getVault() == null || Fawe.<FaweBukkit> imp().getVault().permission == null) {
|
||||
player.addAttachment(Fawe.<FaweBukkit> imp().getPlugin()).setPermission(permission, value);
|
||||
getPlayer().addAttachment(Fawe.<FaweBukkit> imp().getPlugin()).setPermission(permission, value);
|
||||
} else if (value) {
|
||||
if (!Fawe.<FaweBukkit> imp().getVault().permission.playerAdd(player, permission)) {
|
||||
player.addAttachment(Fawe.<FaweBukkit> imp().getPlugin()).setPermission(permission, value);
|
||||
getPlayer().addAttachment(Fawe.<FaweBukkit> imp().getPlugin()).setPermission(permission, value);
|
||||
}
|
||||
} else if (!Fawe.<FaweBukkit>imp().getVault().permission.playerRemove(player, permission)) {
|
||||
player.addAttachment(Fawe.<FaweBukkit>imp().getPlugin()).setPermission(permission, value);
|
||||
getPlayer().addAttachment(Fawe.<FaweBukkit>imp().getPlugin()).setPermission(permission, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return BukkitAdapter.adapt(player.getWorld());
|
||||
return BukkitAdapter.adapt(getPlayer().getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -253,21 +268,30 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
if (params.length > 0) {
|
||||
send = send + "|" + StringUtil.joinString(params, "|");
|
||||
}
|
||||
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
||||
getPlayer().sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
if (!player.isValid()) {
|
||||
Player tmp = Bukkit.getPlayer(getUniqueId());
|
||||
if (tmp != null) {
|
||||
player = tmp;
|
||||
} else {
|
||||
System.out.println("Invalid player " + player.getName());
|
||||
new Exception().printStackTrace();
|
||||
}
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedToFly() {
|
||||
return player.getAllowFlight();
|
||||
return getPlayer().getAllowFlight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlying(boolean flying) {
|
||||
player.setFlying(flying);
|
||||
getPlayer().setFlying(flying);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -277,7 +301,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public com.sk89q.worldedit.util.Location getLocation() {
|
||||
Location nativeLocation = player.getLocation();
|
||||
Location nativeLocation = getPlayer().getLocation();
|
||||
Vector3 position = BukkitAdapter.asVector(nativeLocation);
|
||||
return new com.sk89q.worldedit.util.Location(
|
||||
getWorld(),
|
||||
@ -288,7 +312,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public boolean setLocation(com.sk89q.worldedit.util.Location location) {
|
||||
return player.teleport(BukkitAdapter.adapt(location));
|
||||
return getPlayer().teleport(BukkitAdapter.adapt(location));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -299,7 +323,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public SessionKey getSessionKey() {
|
||||
return new SessionKeyImpl(this.player.getUniqueId(), player.getName());
|
||||
return new SessionKeyImpl(getUniqueId(), getName());
|
||||
}
|
||||
|
||||
private static class SessionKeyImpl implements SessionKey {
|
||||
@ -342,11 +366,11 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
|
||||
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
|
||||
Location loc = new Location(getPlayer().getWorld(), pos.getX(), pos.getY(), pos.getZ());
|
||||
if (block == null) {
|
||||
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
|
||||
getPlayer().sendBlockChange(loc, getPlayer().getWorld().getBlockAt(loc).getBlockData());
|
||||
} else {
|
||||
player.sendBlockChange(loc, BukkitAdapter.adapt(block));
|
||||
getPlayer().sendBlockChange(loc, BukkitAdapter.adapt(block));
|
||||
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
@ -361,8 +385,13 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public void sendTitle(String title, String sub) {
|
||||
player.sendTitle(ChatColor.GOLD + title, ChatColor.GOLD + sub, 0, 70, 20);
|
||||
getPlayer().sendTitle(ChatColor.GOLD + title, ChatColor.GOLD + sub, 0, 70, 20);
|
||||
Bukkit.getServer().dispatchCommand(player, "title " + getName() + " subtitle [{\"text\":\"" + sub + "\",\"color\":\"gold\"}]");
|
||||
Bukkit.getServer().dispatchCommand(player, "title " + getName() + " title [{\"text\":\"" + title + "\",\"color\":\"gold\"}]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
getPlayer().removeMetadata("WE", WorldEditPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,10 @@ package com.sk89q.worldedit.bukkit;
|
||||
|
||||
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.boydti.fawe.bukkit.FaweBukkit;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BukkitGetBlocks_1_14;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -31,6 +34,7 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
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.history.change.BlockChange;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -52,6 +56,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
@ -317,8 +322,19 @@ public class BukkitWorld extends AbstractWorld {
|
||||
@Override
|
||||
public void checkLoadedChunk(BlockVector3 pt) {
|
||||
World world = getWorld();
|
||||
|
||||
world.getChunkAt(pt.getBlockX() >> 4, pt.getBlockZ() >> 4);
|
||||
int X = pt.getBlockX() >> 4;
|
||||
int Z = pt.getBlockZ() >> 4;
|
||||
if (Fawe.isMainThread()) {
|
||||
world.getChunkAt(X, Z);
|
||||
} else if (!world.isChunkLoaded(X, Z)) {
|
||||
if (FaweBukkit.PAPER) {
|
||||
world.getChunkAtAsync(X, Z, true);
|
||||
} else {
|
||||
Fawe.get().getQueueHandler().sync(() -> {
|
||||
world.getChunkAt(X, Z);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -516,11 +532,18 @@ public class BukkitWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChunk(int chunkX, int chunkZ, int bitMask) {
|
||||
public void refreshChunk(int X, int Z) {
|
||||
getWorld().refreshChunk(X, Z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkGet get(int chunkX, int chunkZ) {
|
||||
return new BukkitGetBlocks_1_14(getWorldChecked(), chunkX, chunkZ, Settings.IMP.QUEUE.POOL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFakeChunk(Player player, ChunkPacket packet) {
|
||||
org.bukkit.entity.Player bukkitPlayer = BukkitAdapter.adapt(player);
|
||||
WorldEditPlugin.getInstance().getBukkitImplAdapter().sendFakeChunk(getWorld(), bukkitPlayer, packet);
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
@ -559,15 +560,26 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
||||
* @return a wrapped player
|
||||
*/
|
||||
public BukkitPlayer wrapPlayer(Player player) {
|
||||
synchronized (player) {
|
||||
@NotNull List<MetadataValue> meta = player.getMetadata("WE");
|
||||
if (meta == null || meta.isEmpty()) {
|
||||
BukkitPlayer wePlayer = new BukkitPlayer(this, player);
|
||||
player.setMetadata("WE", new FixedMetadataValue(this, wePlayer));
|
||||
return wePlayer;
|
||||
BukkitPlayer wePlayer = getCachedPlayer(player);
|
||||
if (wePlayer == null) {
|
||||
synchronized (player) {
|
||||
wePlayer = getCachedPlayer(player);
|
||||
if (wePlayer == null) {
|
||||
wePlayer = new BukkitPlayer(this, player);
|
||||
player.setMetadata("WE", new FixedMetadataValue(this, wePlayer));
|
||||
return wePlayer;
|
||||
}
|
||||
}
|
||||
return (BukkitPlayer) meta.get(0).value();
|
||||
}
|
||||
return wePlayer;
|
||||
}
|
||||
|
||||
public BukkitPlayer getCachedPlayer(Player player) {
|
||||
List<MetadataValue> meta = player.getMetadata("WE");
|
||||
if (meta == null || meta.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return (BukkitPlayer) meta.get(0).value();
|
||||
}
|
||||
|
||||
public Actor wrapCommandSender(CommandSender sender) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.bukkit.adapter;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.bukkit.FaweBukkit;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
@ -141,6 +142,13 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
|
||||
*/
|
||||
void sendFakeOP(Player player);
|
||||
|
||||
/**
|
||||
* Send a fake chunk packet to a player
|
||||
* @param player
|
||||
* @param packet
|
||||
*/
|
||||
void sendFakeChunk(org.bukkit.World world, Player player, ChunkPacket packet);
|
||||
|
||||
/**
|
||||
* Simulates a player using an item.
|
||||
*
|
||||
|
@ -6,6 +6,7 @@ import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import java.util.List;
|
||||
@ -58,7 +59,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
|
||||
@Override
|
||||
public BlockType adapt(Material material) {
|
||||
try {
|
||||
return BlockTypes.values[blockTypes[material.ordinal()]];
|
||||
return BlockTypesCache.values[blockTypes[material.ordinal()]];
|
||||
} catch (NullPointerException e) {
|
||||
if (init()) return adapt(material);
|
||||
throw e;
|
||||
|
@ -154,3 +154,76 @@ permissions:
|
||||
worldedit.extinguish: true
|
||||
worldedit.calc: true
|
||||
worldedit.fill: true
|
||||
fawe.voxelbrush:
|
||||
default: op
|
||||
children:
|
||||
voxelsniper.brush.ball: true
|
||||
voxelsniper.brush.biome: true
|
||||
voxelsniper.brush.blendball: true
|
||||
voxelsniper.brush.blenddisc: true
|
||||
voxelsniper.brush.blendvoxel: true
|
||||
voxelsniper.brush.blendvoxeldisc: true
|
||||
voxelsniper.brush.blob: true
|
||||
voxelsniper.brush.blockreset: true
|
||||
voxelsniper.brush.blockresetsurface: true
|
||||
voxelsniper.brush.canyon: true
|
||||
voxelsniper.brush.canyonselection: true
|
||||
voxelsniper.brush.checkervoxeldisc: true
|
||||
voxelsniper.brush.cleansnow: true
|
||||
voxelsniper.brush.clonestamp: true
|
||||
voxelsniper.brush.copypasta: true
|
||||
voxelsniper.brush.cylinder: true
|
||||
voxelsniper.brush.disc: true
|
||||
voxelsniper.brush.discface: true
|
||||
voxelsniper.brush.dome: true
|
||||
voxelsniper.brush.drain: true
|
||||
voxelsniper.brush.ellipse: true
|
||||
voxelsniper.brush.ellipsoid: true
|
||||
voxelsniper.brush.eraser: true
|
||||
voxelsniper.brush.erode: true
|
||||
voxelsniper.brush.extrude: true
|
||||
voxelsniper.brush.filldown: true
|
||||
voxelsniper.brush.flatocean: true
|
||||
voxelsniper.brush.heatray: true
|
||||
voxelsniper.brush.jaggedline: true
|
||||
voxelsniper.brush.line: true
|
||||
voxelsniper.brush.move: true
|
||||
voxelsniper.brush.ocean: true
|
||||
voxelsniper.brush.overlay: true
|
||||
voxelsniper.brush.pull: true
|
||||
voxelsniper.brush.randomerode: true
|
||||
voxelsniper.brush.ring: true
|
||||
voxelsniper.brush.rot2d: true
|
||||
voxelsniper.brush.rot2dvert: true
|
||||
voxelsniper.brush.rot3d: true
|
||||
voxelsniper.brush.ruler: true
|
||||
voxelsniper.brush.scanner: true
|
||||
voxelsniper.brush.set: true
|
||||
voxelsniper.brush.setredstoneflip: true
|
||||
voxelsniper.brush.setredstonerotate: true
|
||||
voxelsniper.brush.shellball: true
|
||||
voxelsniper.brush.shellset: true
|
||||
voxelsniper.brush.shellvoxel: true
|
||||
voxelsniper.brush.signoverwrite: true
|
||||
voxelsniper.brush.snipe: true
|
||||
voxelsniper.brush.snowcone: true
|
||||
voxelsniper.brush.spiralstaircase: true
|
||||
voxelsniper.brush.splatterball: true
|
||||
voxelsniper.brush.splatterdisc: true
|
||||
voxelsniper.brush.splatteroverlay: true
|
||||
voxelsniper.brush.splattervoxel: true
|
||||
voxelsniper.brush.splattervoxeldisc: true
|
||||
voxelsniper.brush.spline: true
|
||||
voxelsniper.brush.stamp: true
|
||||
voxelsniper.brush.stencil: true
|
||||
voxelsniper.brush.stencillist: true
|
||||
voxelsniper.brush.threepointcircle: true
|
||||
voxelsniper.brush.triangle: true
|
||||
voxelsniper.brush.underlay: true
|
||||
voxelsniper.brush.voltmeter: true
|
||||
voxelsniper.brush.voxel: true
|
||||
voxelsniper.brush.voxeldisc: true
|
||||
voxelsniper.brush.voxeldiscface: true
|
||||
voxelsniper.brush.warp: true
|
||||
voxelsniper.goto: true
|
||||
voxelsniper.sniper: true
|
||||
|
Reference in New Issue
Block a user