Prevent thread stacking with syncing up #187
@ -34,11 +34,13 @@ import de.steamwar.fightsystem.Config;
|
|||||||
import de.steamwar.fightsystem.IFightSystem;
|
import de.steamwar.fightsystem.IFightSystem;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||||
|
import net.minecraft.server.v1_15_R1.Block;
|
||||||
|
import net.minecraft.server.v1_15_R1.ChunkSection;
|
||||||
import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk;
|
import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -211,7 +213,7 @@ public class TechHider_15 {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
final int cY = chunkY;
|
final int cY = chunkY;
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(IFightSystem.getPlugin(),
|
Bukkit.getScheduler().runTask(IFightSystem.getPlugin(),
|
||||||
() -> fullChunkHider(p, chunkX, cY, chunkZ));
|
() -> fullChunkHider(p, chunkX, cY, chunkZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,38 +232,38 @@ public class TechHider_15 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void fullChunkHider(Player player, int chunkX, int chunkY, int chunkZ){
|
private static void fullChunkHider(Player player, int chunkX, int chunkY, int chunkZ){
|
||||||
ArrayList<MultiBlockChangeInfo> blockChangeList = new ArrayList<>();
|
if(!player.isOnline())
|
||||||
|
return;
|
||||||
|
|
||||||
Location location = new Location(WORLD, chunkX * 16f, chunkY * 16f, chunkZ * 16f);
|
ArrayList<MultiBlockChangeInfo> blockChangeList = new ArrayList<>();
|
||||||
int maxXp1 = (chunkX+1) * 16;
|
ChunkCoordIntPair chunkCoords = new ChunkCoordIntPair(chunkX, chunkZ);
|
||||||
int maxYp1 = (chunkY+1) * 16;
|
ChunkSection chunk = ((CraftWorld) WORLD).getHandle().getChunkAt(chunkX, chunkZ).getSections()[chunkY]; //This takes ~70ms async.
|
||||||
int maxZp1 = (chunkZ+1) * 16;
|
if(ChunkSection.a(chunk))
|
||||||
while(location.getBlockX() < maxXp1){
|
return;
|
||||||
while(location.getBlockY() < maxYp1){
|
|
||||||
while(location.getBlockZ() < maxZp1){
|
int minY = chunkY * 16;
|
||||||
if(Config.HiddenBlockTags.contains(WORLD.getBlockAt(location).getType().name()))
|
for(int x = 0; x < 16; x++){
|
||||||
blockChangeList.add(new MultiBlockChangeInfo(location, WRAPPED_BLOCK_DATA));
|
for(int y = 0; y < 16; y++){
|
||||||
location.setZ(location.getZ() + 1);
|
for(int z = 0; z < 16; z++){
|
||||||
|
if(Config.HiddenBlocks.contains(Block.REGISTRY_ID.getId(chunk.getType(x, y, z))))
|
||||||
|
blockChangeList.add(new MultiBlockChangeInfo((short)(x << 12 | z << 8 | (y + minY)), WRAPPED_BLOCK_DATA, chunkCoords));
|
||||||
}
|
}
|
||||||
location.setY(location.getY() + 1);
|
|
||||||
location.setZ(chunkZ * 16f);
|
|
||||||
}
|
}
|
||||||
location.setX(location.getX() + 1);
|
|
||||||
location.setY(chunkY * 16f);
|
|
||||||
location.setZ(chunkZ * 16f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(blockChangeList.isEmpty())
|
if(blockChangeList.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.MULTI_BLOCK_CHANGE);
|
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.MULTI_BLOCK_CHANGE);
|
||||||
packet.getChunkCoordIntPairs().write(0, new ChunkCoordIntPair(chunkX, chunkZ));
|
packet.getChunkCoordIntPairs().write(0, chunkCoords);
|
||||||
packet.getMultiBlockChangeInfoArrays().write(0, blockChangeList.toArray(new MultiBlockChangeInfo[0]));
|
packet.getMultiBlockChangeInfoArrays().write(0, blockChangeList.toArray(new MultiBlockChangeInfo[0]));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
throw new SecurityException("Something went wrong sending the multiblockchange packet", e);
|
throw new SecurityException("Something went wrong sending the multiblockchange packet", e);
|
||||||
|
} catch (NullPointerException e){
|
||||||
|
//ignored, player offline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren