SteamWar/FightSystem
Archiviert
13
1

Optimizing techhider with cache, switching to asyncChatEvent, Survival in preparation phase

Dieser Commit ist enthalten in:
Lixfel 2019-11-03 17:26:51 +01:00
Ursprung c00e276fea
Commit 40589ec351
3 geänderte Dateien mit 39 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -143,7 +143,7 @@ public class FightTeam {
invited.remove(player); invited.remove(player);
team.addEntry(player.getName()); team.addEntry(player.getName());
player.setGameMode(GameMode.ADVENTURE); player.setGameMode(GameMode.SURVIVAL);
player.teleport(spawn); player.teleport(spawn);
if(KitManager.getKits(false).size() > 1) if(KitManager.getKits(false).size() > 1)
player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build());

Datei anzeigen

@ -7,12 +7,12 @@ import de.steamwar.fightsystem.utils.Config;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
public class PlayerChatListener extends BasicListener { public class PlayerChatListener extends BasicListener {
@EventHandler @EventHandler
public void handlePlayerChat(PlayerChatEvent event) { public void handlePlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String message = event.getMessage(); String message = event.getMessage();

Datei anzeigen

@ -27,14 +27,14 @@ import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
public class TechHider { public class TechHider {
private TechHider(){} private TechHider(){}
private static Map<PacketContainer, PacketContainer> packetCache = new HashMap<>();
private static int arenaMinX; private static int arenaMinX;
private static int arenaMaxX; private static int arenaMaxX;
private static int arenaMinZ; private static int arenaMinZ;
@ -107,6 +107,8 @@ public class TechHider {
if(disabled()) if(disabled())
return; return;
Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), packetCache::clear, 1, 1);
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
@Override @Override
public void onPacketSending(PacketEvent e) { public void onPacketSending(PacketEvent e) {
@ -119,9 +121,16 @@ public class TechHider {
if(bypass(p, chunkX, chunkZ)) if(bypass(p, chunkX, chunkZ))
return; return;
packet = packet.deepClone(); PacketContainer cached = packetCache.get(packet);
e.setPacket(packet); if(cached != null){
StructureModifier<List> list = packet.getSpecificModifier(List.class); e.setPacket(cached);
return;
}
cached = packet.deepClone();
packetCache.put(packet, cached);
e.setPacket(cached);
StructureModifier<List> list = cached.getSpecificModifier(List.class);
List nmsTags = list.read(0); List nmsTags = list.read(0);
boolean changed = false; boolean changed = false;
for(int i = nmsTags.size() - 1; i >= 0; i--){ for(int i = nmsTags.size() - 1; i >= 0; i--){
@ -136,7 +145,7 @@ public class TechHider {
} }
changed = false; changed = false;
StructureModifier<byte[]> byteArray = packet.getByteArrays(); StructureModifier<byte[]> byteArray = cached.getByteArrays();
byte [] data = byteArray.read(0); byte [] data = byteArray.read(0);
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100);
int i = 0; int i = 0;
@ -222,9 +231,16 @@ public class TechHider {
if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ()))) if(bypass(p, posToChunk(pos.getX()), posToChunk(pos.getZ())))
return; return;
packet = packet.deepClone(); PacketContainer cached = packetCache.get(packet);
e.setPacket(packet); if(cached != null){
StructureModifier<WrappedBlockData> blockStructure = packet.getBlockData(); e.setPacket(cached);
return;
}
cached = packet.deepClone();
packetCache.put(packet, cached);
e.setPacket(cached);
StructureModifier<WrappedBlockData> blockStructure = cached.getBlockData();
WrappedBlockData block = blockStructure.read(0); WrappedBlockData block = blockStructure.read(0);
if(Config.HiddenBlocks.contains(block.getType().getId())){ if(Config.HiddenBlocks.contains(block.getType().getId())){
block.setType(obfuscateMaterial); block.setType(obfuscateMaterial);
@ -242,9 +258,16 @@ public class TechHider {
if(bypass(p, pos.getChunkX(), pos.getChunkZ())) if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
return; return;
packet = packet.shallowClone(); PacketContainer cached = packetCache.get(packet);
e.setPacket(packet); if(cached != null){
StructureModifier<MultiBlockChangeInfo[]> blockStructure = packet.getMultiBlockChangeInfoArrays(); e.setPacket(cached);
return;
}
cached = packet.shallowClone();
packetCache.put(packet, cached);
e.setPacket(cached);
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); MultiBlockChangeInfo[] changes = blockStructure.read(0).clone();
boolean changed = false; boolean changed = false;
for(MultiBlockChangeInfo mbci : changes){ for(MultiBlockChangeInfo mbci : changes){