Full 1.14 untested support (with techhider)
Dieser Commit ist enthalten in:
Ursprung
5b9070fc4d
Commit
691f3d8cfa
@ -6,48 +6,26 @@ 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.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
||||
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.IFightSystem;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import javafx.util.Pair;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
|
||||
class TechHider_12 {
|
||||
private TechHider_12(){}
|
||||
|
||||
private static final short obfuscateShift4;
|
||||
private static final Set<Integer> hiddenBlocks;
|
||||
|
||||
static{
|
||||
//noinspection deprecation
|
||||
obfuscateShift4 = (short)(SWItem.getMaterial(Config.ObfuscateWith).getId() << 4);
|
||||
|
||||
Set<Integer> hBs = new HashSet<>();
|
||||
for(String mat : Config.HiddenBlocks){
|
||||
//noinspection deprecation
|
||||
hBs.add(Material.getMaterial(mat).getId());
|
||||
}
|
||||
hiddenBlocks = Collections.unmodifiableSet(hBs);
|
||||
}
|
||||
private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4);
|
||||
|
||||
static void reloadChunk(Player p, Pair<Integer, Integer> chunk){
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535));
|
||||
@ -55,9 +33,6 @@ class TechHider_12 {
|
||||
|
||||
static void start(){
|
||||
chunkHider();
|
||||
multiBlockHider();
|
||||
blockHider();
|
||||
blockActionHider();
|
||||
}
|
||||
|
||||
private static void chunkHider(){
|
||||
@ -122,7 +97,7 @@ class TechHider_12 {
|
||||
int actPaletteLength = ITechHider.readVarIntLength(data, i);
|
||||
|
||||
int blockId = actPalette >> 4;
|
||||
if(hiddenBlocks.contains(blockId)){
|
||||
if(Config.HiddenBlocks.contains(blockId)){
|
||||
byte[] a = ITechHider.writeVarInt(obfuscateShift4);
|
||||
buffer.writeBytes(a);
|
||||
changed = true;
|
||||
@ -156,91 +131,4 @@ class TechHider_12 {
|
||||
}
|
||||
}).start(ITechHider.threadMultiplier * 4);
|
||||
}
|
||||
|
||||
private static void multiBlockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
|
||||
Player p = e.getPlayer();
|
||||
ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0);
|
||||
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
||||
return;
|
||||
|
||||
PacketContainer cached = ITechHider.packetCache.get(packet);
|
||||
if(cached != null){
|
||||
e.setPacket(cached);
|
||||
return;
|
||||
}
|
||||
|
||||
cached = packet.shallowClone();
|
||||
ITechHider.packetCache.put(packet, cached);
|
||||
e.setPacket(cached);
|
||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
||||
MultiBlockChangeInfo[] changes = blockStructure.read(0).clone();
|
||||
boolean changed = false;
|
||||
for(MultiBlockChangeInfo mbci : changes){
|
||||
WrappedBlockData block = mbci.getData();
|
||||
//noinspection deprecation
|
||||
if(hiddenBlocks.contains(block.getType().getId())){
|
||||
changed = true;
|
||||
block.setType(ITechHider.obfuscateMaterial);
|
||||
mbci.setData(block);
|
||||
}
|
||||
}
|
||||
|
||||
if(changed){
|
||||
blockStructure.write(0, changes);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||
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<WrappedBlockData> blockStructure = cached.getBlockData();
|
||||
WrappedBlockData block = blockStructure.read(0);
|
||||
//noinspection deprecation
|
||||
if(hiddenBlocks.contains(block.getType().getId())){
|
||||
block.setType(ITechHider.obfuscateMaterial);
|
||||
blockStructure.write(0, block);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockActionHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
138
FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java
Normale Datei
138
FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java
Normale Datei
@ -0,0 +1,138 @@
|
||||
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.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.IFightSystem;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import javafx.util.Pair;
|
||||
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;
|
||||
|
||||
import static de.steamwar.fightsystem.utils.ITechHider.bypass;
|
||||
|
||||
public class TechHider_14 {
|
||||
private TechHider_14(){}
|
||||
|
||||
static void reloadChunk(Player p, Pair<Integer, Integer> chunk){
|
||||
((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)p.getWorld().getChunkAt(chunk.getKey(), chunk.getValue())).getHandle(), 65535));
|
||||
}
|
||||
|
||||
static void start(){
|
||||
chunkHider();
|
||||
}
|
||||
|
||||
private 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> list = cached.getSpecificModifier(List.class);
|
||||
List nmsTags = list.read(1);
|
||||
boolean changed = false;
|
||||
for(int i = nmsTags.size() - 1; i >= 0; i--){
|
||||
NbtCompound nbt = NbtFactory.fromNMSCompound(nmsTags.get(i));
|
||||
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);
|
||||
}
|
||||
}
|
@ -93,9 +93,10 @@ public class Config {
|
||||
public static final String LeaderDefault;
|
||||
|
||||
//tech hider parameter
|
||||
public static final List<String> HiddenBlocks;
|
||||
public static final List<Integer> HiddenBlocks;
|
||||
public static final List<String> HiddenBlockEntities;
|
||||
public static final String ObfuscateWith;
|
||||
public static final int ObfuscateWith;
|
||||
public static final String ObfuscateWithTag;
|
||||
|
||||
//event parameter
|
||||
private static final int EventKampfID;
|
||||
@ -163,9 +164,10 @@ public class Config {
|
||||
MemberDefault = config.getString("Kits.MemberDefault");
|
||||
LeaderDefault = config.getString("Kits.LeaderDefault");
|
||||
|
||||
HiddenBlocks = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlocks"));
|
||||
HiddenBlocks = Collections.unmodifiableList(config.getIntegerList("Techhider.HiddenBlocks"));
|
||||
HiddenBlockEntities = Collections.unmodifiableList(config.getStringList("Techhider.HiddenBlockEntities"));
|
||||
ObfuscateWith = config.getString("Techhider.ObfuscateWith");
|
||||
ObfuscateWith = config.getInt("Techhider.ObfuscateWith");
|
||||
ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag");
|
||||
|
||||
if(schemsizeX < 0){
|
||||
SchemsizeX = -schemsizeX;
|
||||
|
@ -6,7 +6,6 @@ import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.IFightSystem;
|
||||
import de.steamwar.fightsystem.fight.IFight;
|
||||
import de.steamwar.fightsystem.fight.IFightTeam;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -50,7 +49,7 @@ public class ITechHider {
|
||||
arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ);
|
||||
arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1;
|
||||
|
||||
obfuscateMaterial = SWItem.getMaterial(Config.ObfuscateWith);
|
||||
obfuscateMaterial = Material.getMaterial(Config.ObfuscateWithTag);
|
||||
Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1);
|
||||
|
||||
if(Config.event())
|
||||
|
@ -3,10 +3,17 @@ 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.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
|
||||
import com.comphenix.protocol.wrappers.MultiBlockChangeInfo;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.IFightSystem;
|
||||
import javafx.util.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@ -57,14 +64,107 @@ public class TechHider {
|
||||
if(disabled())
|
||||
return;
|
||||
|
||||
blockActionHider();
|
||||
blockHider();
|
||||
multiBlockHider();
|
||||
switch(Core.getVersion()){
|
||||
case 8:
|
||||
break;
|
||||
case 14:
|
||||
TechHider_14.start();
|
||||
break;
|
||||
default:
|
||||
TechHider_12.start();
|
||||
}
|
||||
}
|
||||
|
||||
private static void multiBlockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
|
||||
Player p = e.getPlayer();
|
||||
ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0);
|
||||
if(bypass(p, pos.getChunkX(), pos.getChunkZ()))
|
||||
return;
|
||||
|
||||
PacketContainer cached = ITechHider.packetCache.get(packet);
|
||||
if(cached != null){
|
||||
e.setPacket(cached);
|
||||
return;
|
||||
}
|
||||
|
||||
cached = packet.shallowClone();
|
||||
ITechHider.packetCache.put(packet, cached);
|
||||
e.setPacket(cached);
|
||||
StructureModifier<MultiBlockChangeInfo[]> blockStructure = cached.getMultiBlockChangeInfoArrays();
|
||||
MultiBlockChangeInfo[] changes = blockStructure.read(0).clone();
|
||||
boolean changed = false;
|
||||
for(MultiBlockChangeInfo mbci : changes){
|
||||
WrappedBlockData block = mbci.getData();
|
||||
//noinspection deprecation
|
||||
if(Config.HiddenBlocks.contains(block.getType().getId())){
|
||||
changed = true;
|
||||
block.setType(ITechHider.obfuscateMaterial);
|
||||
mbci.setData(block);
|
||||
}
|
||||
}
|
||||
|
||||
if(changed){
|
||||
blockStructure.write(0, changes);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||
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<WrappedBlockData> blockStructure = cached.getBlockData();
|
||||
WrappedBlockData block = blockStructure.read(0);
|
||||
//noinspection deprecation
|
||||
if(Config.HiddenBlocks.contains(block.getType().getId())){
|
||||
block.setType(ITechHider.obfuscateMaterial);
|
||||
blockStructure.write(0, block);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void blockActionHider(){
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent e) {
|
||||
PacketContainer packet = e.getPacket();
|
||||
BlockPosition pos = packet.getBlockPositionModifier().read(0);
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ())))
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Pair<Integer, Integer>> prepareChunkReload(Player p){
|
||||
if(disabled())
|
||||
return Collections.emptyList();
|
||||
@ -92,6 +192,9 @@ public class TechHider {
|
||||
case 8:
|
||||
TechHider_8.reloadChunk(p, chunk);
|
||||
break;
|
||||
case 14:
|
||||
TechHider_14.reloadChunk(p, chunk);
|
||||
break;
|
||||
default:
|
||||
TechHider_12.reloadChunk(p, chunk);
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren