Revert last changes and duplicating code
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
952e83dc29
Commit
abd3246d85
@ -12,6 +12,9 @@ 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_14_R1.PacketPlayOutMapChunk;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
@ -22,7 +25,7 @@ public class TechHider_14 {
|
||||
private TechHider_14(){}
|
||||
|
||||
static void reloadChunk(Player p, ITechHider.ChunkPos chunk){
|
||||
((org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)p).getHandle().playerConnection.sendPacket(new net.minecraft.server.v1_14_R1.PacketPlayOutMapChunk(((org.bukkit.craftbukkit.v1_14_R1.CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535));
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.x(), chunk.z())).getHandle(), 65535));
|
||||
}
|
||||
|
||||
static void start(){
|
||||
|
@ -1,10 +1,26 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
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.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
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.PacketPlayOutMapChunk;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
|
||||
public class TechHider_15 {
|
||||
private TechHider_15(){}
|
||||
|
||||
@ -13,7 +29,113 @@ public class TechHider_15 {
|
||||
}
|
||||
|
||||
static void start(){
|
||||
TechHider_14.chunkHider();
|
||||
chunkHider();
|
||||
}
|
||||
|
||||
static void chunkHider(){
|
||||
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
StructureModifier<Integer> ints = packet.getIntegers();
|
||||
|
||||
int chunkX = ints.read(0);
|
||||
int chunkZ = ints.read(1);
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, chunkX, chunkZ))
|
||||
return;
|
||||
|
||||
PacketContainer cached = ITechHider.packetCache.get(packet);
|
||||
if(cached != null){
|
||||
e.setPacket(cached);
|
||||
return;
|
||||
}
|
||||
|
||||
cached = packet.deepClone();
|
||||
ITechHider.packetCache.put(packet, cached);
|
||||
e.setPacket(cached);
|
||||
StructureModifier<List<NbtBase<?>>> list = cached.getListNbtModifier();
|
||||
List<NbtBase<?>> nmsTags = list.read(0);
|
||||
boolean changed = false;
|
||||
for(int i = nmsTags.size() - 1; i >= 0; i--){
|
||||
NbtBase<?> nbtBase = nmsTags.get(i);
|
||||
if(!(nbtBase instanceof NbtCompound))
|
||||
throw new SecurityException("Hä?" + nbtBase.getClass().getName());
|
||||
NbtCompound nbt = (NbtCompound) nbtBase;
|
||||
if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){
|
||||
nmsTags.remove(i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(changed){
|
||||
list.write(0, nmsTags);
|
||||
}
|
||||
|
||||
changed = false;
|
||||
StructureModifier<byte[]> byteArray = cached.getByteArrays();
|
||||
int primaryBitMask = ints.read(2);
|
||||
int numChunkSections = 0;
|
||||
while(primaryBitMask != 0){
|
||||
numChunkSections += primaryBitMask & 1;
|
||||
primaryBitMask >>= 1;
|
||||
}
|
||||
byte [] data = byteArray.read(0);
|
||||
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100);
|
||||
int i = 0;
|
||||
|
||||
while(numChunkSections > 0){
|
||||
buffer.writeBytes(data, i, 2); // Block count
|
||||
i += 2;
|
||||
byte bitsPerBlock = data[i++];
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
if(bitsPerBlock < 4)
|
||||
bitsPerBlock = 4;
|
||||
else if(bitsPerBlock > 8){
|
||||
bitsPerBlock = 14;
|
||||
buffer.writeByte(data[++i]);
|
||||
}
|
||||
|
||||
if(bitsPerBlock != 14){
|
||||
int paletteLength = ITechHider.readVarInt(data, i);
|
||||
int paletteLengthLength = ITechHider.readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, paletteLengthLength);
|
||||
i += paletteLengthLength;
|
||||
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
|
||||
int blockId = ITechHider.readVarInt(data, i);
|
||||
int actPaletteLength = ITechHider.readVarIntLength(data, i);
|
||||
|
||||
if(Config.HiddenBlocks.contains(blockId)){
|
||||
byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith);
|
||||
buffer.writeBytes(a);
|
||||
changed = true;
|
||||
}else{
|
||||
buffer.writeBytes(data, i, actPaletteLength);
|
||||
}
|
||||
i += actPaletteLength;
|
||||
}
|
||||
int dataArrayLength = ITechHider.readVarInt(data, i);
|
||||
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
|
||||
i += dataArrayLengthLength;
|
||||
i += dataArrayLength * 8;
|
||||
}else{
|
||||
int dataArrayLength = ITechHider.readVarInt(data, i);
|
||||
int dataArrayLengthLength = ITechHider.readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength);
|
||||
i += dataArrayLengthLength;
|
||||
i += dataArrayLength * 8;
|
||||
}
|
||||
numChunkSections--;
|
||||
}
|
||||
buffer.writeBytes(data, i, data.length - i);
|
||||
|
||||
if(changed){
|
||||
data = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(data);
|
||||
byteArray.write(0, data);
|
||||
}
|
||||
}
|
||||
}).start(ITechHider.threadMultiplier * 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren