mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +02:00
Track the current world name in ChatData for now.
This commit is contained in:
parent
9dd01a6d59
commit
cf04ee5a5d
|
@ -24,7 +24,6 @@ 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;
|
||||
|
@ -214,12 +213,4 @@ public class ProtocolLibComponent implements IDisableListener, INotifyReload, Jo
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||
if (!registeredPacketAdapters.isEmpty()) {
|
||||
final Player player = event.getPlayer();
|
||||
dataFactory.getData(player).onWorldChange(player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,6 +103,12 @@ public class ChatData extends AsyncCheckData {
|
|||
public int relogWarnings;
|
||||
public long relogWarningTime;
|
||||
|
||||
/**
|
||||
* 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 ChatData(final ChatConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
|
|
@ -101,8 +101,10 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
|
|||
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
ChatData.getData(player).currentWorldName = player.getWorld().getName();
|
||||
// Tell TickTask to update cached permissions.
|
||||
TickTask.requestPermissionUpdate(event.getPlayer().getName(), CheckType.CHAT);
|
||||
TickTask.requestPermissionUpdate(player.getName(), CheckType.CHAT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +214,7 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean checkUntrackedLocation(final Player player, final String message, final MovingConfig mcc) {
|
||||
final Location loc = player.getLocation(useLoc);
|
||||
boolean cancel = false;
|
||||
|
@ -282,6 +284,7 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
|
|||
public void playerJoins(final Player player) {
|
||||
final ChatConfig cc = ChatConfig.getConfig(player);
|
||||
final ChatData data = ChatData.getData(player);
|
||||
data.currentWorldName = player.getWorld().getName();
|
||||
synchronized (data) {
|
||||
if (captcha.isEnabled(player) && captcha.shouldCheckCaptcha(cc, data)) {
|
||||
// shouldCheckCaptcha: only if really enabled.
|
||||
|
@ -294,6 +297,7 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
|
|||
|
||||
@Override
|
||||
public void playerLeaves(final Player player) {
|
||||
ChatData.getData(player).currentWorldName = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,13 +91,6 @@ 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.
|
||||
*/
|
||||
// TODO: Remove? (Despite future use cases where this is nice to have.)
|
||||
public String currentWorldName = null;
|
||||
|
||||
public NetData(final NetConfig config) {
|
||||
super(config);
|
||||
flyingFrequencyAll = new ActionFrequency(config.flyingFrequencySeconds, 1000L);
|
||||
|
@ -113,17 +106,11 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,11 +44,6 @@ public class NetDataFactory implements CheckDataFactory, ICanHandleTimeRunningBa
|
|||
if (data != null) {
|
||||
return data;
|
||||
} else {
|
||||
/*
|
||||
* TODO: Bootstrap problem with NetStatic and null worlds :) -> move
|
||||
* world tracking to basic data (e.g. PlayerData), needs thread
|
||||
* safety.
|
||||
*/
|
||||
data = new NetData((NetConfig) CheckType.NET.getConfigFactory().getConfig(player));
|
||||
dataMap.put(player.getName(), data);
|
||||
return data;
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.chat.ChatData;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.ds.count.ActionFrequency;
|
||||
|
||||
|
@ -181,7 +182,8 @@ public class NetStatic {
|
|||
world = player.getWorld();
|
||||
}
|
||||
catch (UnsupportedOperationException e) {}
|
||||
return configCache.getConfig(world == null ? dataFactory.getData(player).currentWorldName : world.getName());
|
||||
// TODO: Abusing ChatData for tracking world names. Should be in PlayerData or some generic data.
|
||||
return configCache.getConfig(world == null ? ChatData.getData(player).currentWorldName : world.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user