mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2025-01-17 22:01:34 +01:00
Fixes #107 (for bukkit at least)
This commit is contained in:
parent
6993e4d8ed
commit
9f86b8fe33
@ -2,18 +2,16 @@ package com.boydti.fawe.bukkit.v1_8;
|
|||||||
|
|
||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
import com.boydti.fawe.FaweCache;
|
import com.boydti.fawe.FaweCache;
|
||||||
import com.boydti.fawe.bukkit.BukkitPlayer;
|
|
||||||
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
|
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
|
||||||
import com.boydti.fawe.example.CharFaweChunk;
|
import com.boydti.fawe.example.CharFaweChunk;
|
||||||
import com.boydti.fawe.object.BytePair;
|
import com.boydti.fawe.object.BytePair;
|
||||||
import com.boydti.fawe.object.FaweChunk;
|
import com.boydti.fawe.object.FaweChunk;
|
||||||
import com.boydti.fawe.object.FaweLocation;
|
|
||||||
import com.boydti.fawe.object.FawePlayer;
|
|
||||||
import com.boydti.fawe.object.PseudoRandom;
|
import com.boydti.fawe.object.PseudoRandom;
|
||||||
import com.boydti.fawe.object.RunnableVal;
|
import com.boydti.fawe.object.RunnableVal;
|
||||||
import com.boydti.fawe.util.MainUtil;
|
import com.boydti.fawe.util.MainUtil;
|
||||||
import com.boydti.fawe.util.MathMan;
|
import com.boydti.fawe.util.MathMan;
|
||||||
import com.boydti.fawe.util.ReflectionUtils;
|
import com.boydti.fawe.util.ReflectionUtils;
|
||||||
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
import com.sk89q.jnbt.StringTag;
|
import com.sk89q.jnbt.StringTag;
|
||||||
@ -24,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -32,18 +31,22 @@ import net.minecraft.server.v1_8_R3.ChunkCoordIntPair;
|
|||||||
import net.minecraft.server.v1_8_R3.ChunkSection;
|
import net.minecraft.server.v1_8_R3.ChunkSection;
|
||||||
import net.minecraft.server.v1_8_R3.Entity;
|
import net.minecraft.server.v1_8_R3.Entity;
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityTracker;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||||
import net.minecraft.server.v1_8_R3.EntityTypes;
|
import net.minecraft.server.v1_8_R3.EntityTypes;
|
||||||
|
import net.minecraft.server.v1_8_R3.LongHashMap;
|
||||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_8_R3.NibbleArray;
|
import net.minecraft.server.v1_8_R3.NibbleArray;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk;
|
||||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
import net.minecraft.server.v1_8_R3.PlayerChunkMap;
|
||||||
import net.minecraft.server.v1_8_R3.TileEntity;
|
import net.minecraft.server.v1_8_R3.TileEntity;
|
||||||
|
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
|
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
public class BukkitQueue18R3 extends BukkitQueue_0<Chunk, ChunkSection[], char[]> {
|
public class BukkitQueue18R3 extends BukkitQueue_0<Chunk, ChunkSection[], char[]> {
|
||||||
@ -390,27 +393,86 @@ public class BukkitQueue18R3 extends BukkitQueue_0<Chunk, ChunkSection[], char[]
|
|||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
net.minecraft.server.v1_8_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
|
try {
|
||||||
ChunkCoordIntPair pos = nmsChunk.j();
|
net.minecraft.server.v1_8_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
|
||||||
int cx = pos.x;
|
ChunkCoordIntPair pos = nmsChunk.j(); // getPosition()
|
||||||
int cz = pos.z;
|
WorldServer w = (WorldServer) nmsChunk.getWorld();
|
||||||
int view = Bukkit.getViewDistance();
|
PlayerChunkMap chunkMap = w.getPlayerChunkMap();
|
||||||
for (FawePlayer fp : Fawe.get().getCachedPlayers()) {
|
int x = pos.x;
|
||||||
BukkitPlayer bukkitPlayer = (BukkitPlayer) fp;
|
int z = pos.z;
|
||||||
if (!bukkitPlayer.parent.getWorld().equals(world)) {
|
if (!chunkMap.isChunkInUse(x, z)) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
net.minecraft.server.v1_8_R3.EntityPlayer nmsPlayer = ((CraftPlayer) bukkitPlayer.parent).getHandle();
|
HashSet<EntityPlayer> set = new HashSet<EntityPlayer>();
|
||||||
FaweLocation loc = fp.getLocation();
|
EntityTracker tracker = w.getTracker();
|
||||||
int px = loc.x >> 4;
|
// Get players
|
||||||
int pz = loc.z >> 4;
|
|
||||||
int dx = Math.abs(cx - (px));
|
Field fieldChunkMap = chunkMap.getClass().getDeclaredField("d");
|
||||||
int dz = Math.abs(cz - (pz));
|
fieldChunkMap.setAccessible(true);
|
||||||
if ((dx > view) || (dz > view)) {
|
LongHashMap<Object> map = (LongHashMap<Object>) fieldChunkMap.get(chunkMap);
|
||||||
continue;
|
long pair = (long) x + 2147483647L | (long) z + 2147483647L << 32;
|
||||||
|
Object playerChunk = map.getEntry(pair);
|
||||||
|
Field fieldPlayers = playerChunk.getClass().getDeclaredField("b");
|
||||||
|
fieldPlayers.setAccessible(true);
|
||||||
|
HashSet<EntityPlayer> players = new HashSet<>((Collection<EntityPlayer>)fieldPlayers.get(playerChunk));
|
||||||
|
if (players.size() == 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
PlayerConnection con = nmsPlayer.playerConnection;
|
HashSet<EntityTrackerEntry> entities = new HashSet<>();
|
||||||
con.sendPacket(new PacketPlayOutMapChunk(nmsChunk, false, 65535));
|
List<Entity>[] entitieSlices = nmsChunk.getEntitySlices();
|
||||||
|
for (List<Entity> slice : entitieSlices) {
|
||||||
|
if (slice == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Entity ent : slice) {
|
||||||
|
EntityTrackerEntry entry = tracker.trackedEntities.get(ent.getId());
|
||||||
|
if (entry == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entities.add(entry);
|
||||||
|
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ent.getId());
|
||||||
|
for (EntityPlayer player : players) {
|
||||||
|
player.playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (EntityPlayer player : players) {
|
||||||
|
player.playerConnection.networkManager.a();
|
||||||
|
}
|
||||||
|
// Send chunks
|
||||||
|
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(nmsChunk, false, 65535);
|
||||||
|
for (EntityPlayer player : players) {
|
||||||
|
player.playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
// send ents
|
||||||
|
for (List<Entity> slice : entitieSlices) {
|
||||||
|
if (slice == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Entity ent : slice) {
|
||||||
|
EntityTrackerEntry entry = tracker.trackedEntities.get(ent.getId());
|
||||||
|
if (entry == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
TaskManager.IMP.later(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (EntityPlayer player : players) {
|
||||||
|
boolean result = entry.trackedPlayers.remove(player);
|
||||||
|
if (result && ent != player) {
|
||||||
|
entry.updatePlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
MainUtil.handleError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
MainUtil.handleError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import com.sk89q.jnbt.Tag;
|
|||||||
import com.sk89q.worldedit.internal.Constants;
|
import com.sk89q.worldedit.internal.Constants;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -47,7 +46,6 @@ import net.minecraft.server.v1_9_R2.EntityTypes;
|
|||||||
import net.minecraft.server.v1_9_R2.IBlockData;
|
import net.minecraft.server.v1_9_R2.IBlockData;
|
||||||
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
import net.minecraft.server.v1_9_R2.NBTTagCompound;
|
||||||
import net.minecraft.server.v1_9_R2.NibbleArray;
|
import net.minecraft.server.v1_9_R2.NibbleArray;
|
||||||
import net.minecraft.server.v1_9_R2.Packet;
|
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy;
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk;
|
import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk;
|
||||||
import net.minecraft.server.v1_9_R2.PlayerChunk;
|
import net.minecraft.server.v1_9_R2.PlayerChunk;
|
||||||
@ -154,7 +152,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0<Chunk, ChunkSection[], Dat
|
|||||||
player.playerConnection.networkManager.a();
|
player.playerConnection.networkManager.a();
|
||||||
}
|
}
|
||||||
// Send chunks
|
// Send chunks
|
||||||
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(playerChunk.chunk, '\uffff');
|
PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(playerChunk.chunk, 65535);
|
||||||
for (EntityPlayer player : players) {
|
for (EntityPlayer player : players) {
|
||||||
player.playerConnection.sendPacket(packet);
|
player.playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
@ -169,9 +167,6 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0<Chunk, ChunkSection[], Dat
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Method methodE = entry.getClass().getDeclaredMethod("e");
|
|
||||||
methodE.setAccessible(true);
|
|
||||||
Packet p = (Packet) methodE.invoke(entry);
|
|
||||||
TaskManager.IMP.later(new Runnable() {
|
TaskManager.IMP.later(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -179,7 +174,6 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0<Chunk, ChunkSection[], Dat
|
|||||||
boolean result = entry.trackedPlayers.remove(player);
|
boolean result = entry.trackedPlayers.remove(player);
|
||||||
if (result && ent != player) {
|
if (result && ent != player) {
|
||||||
entry.updatePlayer(player);
|
entry.updatePlayer(player);
|
||||||
entry.trackedPlayers.add(player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user