mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
Keep track of the world name in NetData, for use with CatchAllAdapter.
Some packets arrive with a null world for a player, possibly sent by plugins - thus attempt to use a stored world name. This is just a hot fix attempt.
This commit is contained in:
parent
b8746efcb7
commit
5e2e11dd10
|
@ -13,6 +13,7 @@ import com.comphenix.protocol.events.PacketEvent;
|
|||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetData;
|
||||
import fr.neatmonster.nocheatplus.checks.net.NetStatic;
|
||||
import fr.neatmonster.nocheatplus.checks.net.PacketFrequency;
|
||||
|
||||
/**
|
||||
|
@ -52,7 +53,7 @@ public class CatchAllAdapter extends BaseAdapter {
|
|||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final NetConfig cc = configFactory.getConfig(player);
|
||||
final NetConfig cc = NetStatic.getWorldConfig(player, configFactory, dataFactory);
|
||||
if (cc.packetFrequencyActive) {
|
||||
final NetData data = dataFactory.getData(player);
|
||||
if (packetFrequency.isEnabled(player, data, cc)
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -211,4 +212,12 @@ public class ProtocolLibComponent implements IDisableListener, INotifyReload, Jo
|
|||
data.clearFlyingQueue();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||
if (!registeredPacketAdapters.isEmpty()) {
|
||||
final Player player = event.getPlayer();
|
||||
dataFactory.getData(player).onWorldChange(player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,6 +91,12 @@ public class NetData extends ACheckData {
|
|||
/** Overall packet frequency. */
|
||||
public final ActionFrequency packetFrequency;
|
||||
|
||||
/**
|
||||
* Keep track of current world name, to be used for asynchronous world
|
||||
* config getting. Set on join and world change, reset on leave.
|
||||
*/
|
||||
public String currentWorldName = null;
|
||||
|
||||
public NetData(final NetConfig config) {
|
||||
super(config);
|
||||
flyingFrequencyAll = new ActionFrequency(config.flyingFrequencySeconds, 1000L);
|
||||
|
@ -106,11 +112,17 @@ public class NetData extends ACheckData {
|
|||
public void onJoin(final Player player) {
|
||||
teleportQueue.clear();
|
||||
clearFlyingQueue();
|
||||
currentWorldName = player.getWorld().getName();
|
||||
}
|
||||
|
||||
public void onLeave(Player player) {
|
||||
teleportQueue.clear();
|
||||
clearFlyingQueue();
|
||||
currentWorldName = null;
|
||||
}
|
||||
|
||||
public void onWorldChange(Player player) {
|
||||
currentWorldName = player.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,9 @@ package fr.neatmonster.nocheatplus.checks.net;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.ds.count.ActionFrequency;
|
||||
|
||||
|
@ -163,4 +166,18 @@ public class NetStatic {
|
|||
return Math.max(0.0, violation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience: Check stored world names in case the world is null.
|
||||
*
|
||||
* NOTE:
|
||||
* @param player
|
||||
* @param configCache
|
||||
* @param dataFactory
|
||||
* @return
|
||||
*/
|
||||
public static NetConfig getWorldConfig(Player player, NetConfigCache configCache, NetDataFactory dataFactory) {
|
||||
final World world = player.getWorld();
|
||||
return configCache.getConfig(world == null ? dataFactory.getData(player).currentWorldName : world.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user