SteamWar/SpigotCore
Archiviert
13
0

Expand AntiNocom
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-02-19 21:27:37 +01:00
Ursprung efbed65ab4
Commit 0a90cabf19

Datei anzeigen

@ -28,10 +28,45 @@ import de.steamwar.techhider.TechHider;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.function.Function;
public class AntiNocom { public class AntiNocom {
public AntiNocom() { public AntiNocom() {
TinyProtocol.instance.addFilter(blockDig, this::onDig); TinyProtocol.instance.addFilter(blockDig, this::onDig);
if(Core.getVersion() > 8) {
registerUseItem();
}
}
private void registerUseItem() {
Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem");
Function<Object, Object> getPosition;
if(Core.getVersion() > 12) {
Class<?> movingObjectPositionBlock = Reflection.getClass("{nms.world.phys}.MovingObjectPositionBlock");
Reflection.FieldAccessor<?> useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0);
Reflection.FieldAccessor<?> movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0);
getPosition = (packet) -> movingBlockPosition.get(useItemPosition.get(packet));
} else {
getPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0)::get;
}
TinyProtocol.instance.addFilter(useItem, (player, packet) -> {
Object pos = getPosition.apply(packet);
int x = TechHider.blockPositionX.get(pos);
int z = TechHider.blockPositionZ.get(pos);
if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
SWException.log(player.getName() + " kicked for using item on unloaded block (potential NoCom-DOS attack)", x + " " + z);
return null;
}
return packet;
});
} }
private static final Class<?> blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); private static final Class<?> blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig");