Dieser Commit ist enthalten in:
Ursprung
efbed65ab4
Commit
0a90cabf19
@ -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");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren