forked from SteamWar/SteamWar
Add tinyProtocol Handler for techhider
This commit is contained in:
@@ -26,6 +26,8 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a very tiny alternative to ProtocolLib.
|
* Represents a very tiny alternative to ProtocolLib.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -58,6 +60,7 @@ public class TinyProtocol {
|
|||||||
|
|
||||||
public static final TinyProtocol instance = new TinyProtocol(Core.getInstance());
|
public static final TinyProtocol instance = new TinyProtocol(Core.getInstance());
|
||||||
private final Map<Class<?>, List<BiFunction<Player, Object, Object>>> packetFilters = new HashMap<>();
|
private final Map<Class<?>, List<BiFunction<Player, Object, Object>>> packetFilters = new HashMap<>();
|
||||||
|
private final Set<BiFunction<Player, Object, Object>> globalFilters = new HashSet<>();
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
// enforce init
|
// enforce init
|
||||||
@@ -235,6 +238,10 @@ public class TinyProtocol {
|
|||||||
packetFilters.getOrDefault(packetType, Collections.emptyList()).remove(filter);
|
packetFilters.getOrDefault(packetType, Collections.emptyList()).remove(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addGlobalFilter(BiFunction<Player, Object, Object> filter) {
|
||||||
|
globalFilters.add(filter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet to a particular player.
|
* Send a packet to a particular player.
|
||||||
*
|
*
|
||||||
@@ -469,6 +476,11 @@ public class TinyProtocol {
|
|||||||
if (packet == null) break;
|
if (packet == null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (BiFunction<Player, Object, Object> filter : globalFilters) {
|
||||||
|
packet = filter.apply(player, packet);
|
||||||
|
if (packet == null) break;
|
||||||
|
}
|
||||||
|
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -449,6 +449,18 @@ public abstract class TechHider {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.packetProcessors = processors;
|
this.packetProcessors = processors;
|
||||||
|
|
||||||
|
TinyProtocol.instance.addGlobalFilter((player, packet) -> {
|
||||||
|
if(bypassingPackets.contains(packet.getClass())) {
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
else if(packetProcessors.containsKey(packet.getClass())) {
|
||||||
|
return packetProcessors.get(packet.getClass()).apply(player, packet);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet<? extends PacketListener> processAddEntityPacket(Player player, ClientboundAddEntityPacket packet) {
|
private Packet<? extends PacketListener> processAddEntityPacket(Player player, ClientboundAddEntityPacket packet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user