SteamWar/FightSystem
Archiviert
13
1

Prevent thread stacking with syncing up

Sending mbc-Packet sync takes now around 0-2ms, so its okeyish

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-09-07 11:52:02 +02:00
Ursprung 13e4d94501
Commit 9a8ea2f1d4

Datei anzeigen

@ -34,11 +34,13 @@ import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.IFightSystem;
import io.netty.buffer.ByteBuf;
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 org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
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.entity.Player;
@ -211,7 +213,7 @@ public class TechHider_15 {
}*/
final int cY = chunkY;
Bukkit.getScheduler().runTaskAsynchronously(IFightSystem.getPlugin(),
Bukkit.getScheduler().runTask(IFightSystem.getPlugin(),
() -> 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){
ArrayList<MultiBlockChangeInfo> blockChangeList = new ArrayList<>();
if(!player.isOnline())
return;
Location location = new Location(WORLD, chunkX * 16f, chunkY * 16f, chunkZ * 16f);
int maxXp1 = (chunkX+1) * 16;
int maxYp1 = (chunkY+1) * 16;
int maxZp1 = (chunkZ+1) * 16;
while(location.getBlockX() < maxXp1){
while(location.getBlockY() < maxYp1){
while(location.getBlockZ() < maxZp1){
if(Config.HiddenBlockTags.contains(WORLD.getBlockAt(location).getType().name()))
blockChangeList.add(new MultiBlockChangeInfo(location, WRAPPED_BLOCK_DATA));
location.setZ(location.getZ() + 1);
ArrayList<MultiBlockChangeInfo> blockChangeList = new ArrayList<>();
ChunkCoordIntPair chunkCoords = new ChunkCoordIntPair(chunkX, chunkZ);
ChunkSection chunk = ((CraftWorld) WORLD).getHandle().getChunkAt(chunkX, chunkZ).getSections()[chunkY]; //This takes ~70ms async.
if(ChunkSection.a(chunk))
return;
int minY = chunkY * 16;
for(int x = 0; x < 16; x++){
for(int y = 0; y < 16; y++){
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())
return;
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]));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
} catch (InvocationTargetException e) {
throw new SecurityException("Something went wrong sending the multiblockchange packet", e);
} catch (NullPointerException e){
//ignored, player offline
}
}
}