mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-21 15:01:29 +01:00
Prevent a disabled "runfly" check from crippling the "morepackets"
check, handle teleportations better, prevent exploiting the relation between "runfly" and "morepackets" check
This commit is contained in:
parent
6f93951028
commit
fa4ca4a75f
@ -9,7 +9,5 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public interface DataItem {
|
public interface DataItem {
|
||||||
|
|
||||||
public void clearCriticalData();
|
|
||||||
|
|
||||||
public abstract void collectData(Map<String, Object> map);
|
public abstract void collectData(Map<String, Object> map);
|
||||||
}
|
}
|
||||||
|
@ -126,10 +126,6 @@ public class NoCheat extends JavaPlugin implements Listener {
|
|||||||
return conf.getConfigurationCacheForWorld(null);
|
return conf.getConfigurationCacheForWorld(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCriticalData(String playerName) {
|
|
||||||
players.clearCriticalData(playerName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
boolean result = CommandHandler.handleCommand(this, sender, command, label, args);
|
boolean result = CommandHandler.handleCommand(this, sender, command, label, args);
|
||||||
@ -159,7 +155,6 @@ public class NoCheat extends JavaPlugin implements Listener {
|
|||||||
conf.cleanup();
|
conf.cleanup();
|
||||||
this.conf = new ConfigurationManager(this, this.getDataFolder());
|
this.conf = new ConfigurationManager(this, this.getDataFolder());
|
||||||
players.cleanDataMap();
|
players.cleanDataMap();
|
||||||
players.clearCriticalData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,15 +2,10 @@ package cc.co.evenprime.bukkit.nocheat.checks;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerPortalEvent;
|
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
@ -30,33 +25,12 @@ public class WorkaroundsListener implements Listener, EventManager {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void teleport(final PlayerTeleportEvent event) {
|
|
||||||
if(event.isCancelled())
|
|
||||||
return;
|
|
||||||
handleTeleportation(event.getPlayer(), event.getTo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void portal(final PlayerPortalEvent event) {
|
|
||||||
if(event.isCancelled())
|
|
||||||
return;
|
|
||||||
handleTeleportation(event.getPlayer(), event.getTo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void respawn(final PlayerRespawnEvent event) {
|
|
||||||
handleTeleportation(event.getPlayer(), event.getRespawnLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void playerMove(final PlayerMoveEvent event) {
|
public void playerMove(final PlayerMoveEvent event) {
|
||||||
// No typo here. I really only handle cancelled events and ignore others
|
// No typo here. I really only handle cancelled events and ignore others
|
||||||
if(!event.isCancelled())
|
if(!event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
handleTeleportation(event.getPlayer(), event.getTo());
|
|
||||||
|
|
||||||
// Fix a common mistake that other developers make (cancelling move
|
// Fix a common mistake that other developers make (cancelling move
|
||||||
// events is crazy, rather set the target location to the from location)
|
// events is crazy, rather set the target location to the from location)
|
||||||
event.setCancelled(false);
|
event.setCancelled(false);
|
||||||
@ -70,10 +44,6 @@ public class WorkaroundsListener implements Listener, EventManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTeleportation(final Player player, final Location to) {
|
|
||||||
plugin.clearCriticalData(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
@ -28,14 +28,6 @@ public class BlockBreakData implements DataItem {
|
|||||||
public boolean armswung = true;
|
public boolean armswung = true;
|
||||||
public final SimpleLocation lastDamagedBlock = new SimpleLocation();
|
public final SimpleLocation lastDamagedBlock = new SimpleLocation();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearCriticalData() {
|
|
||||||
instaBrokenBlockLocation.reset();
|
|
||||||
brokenBlockLocation.reset();
|
|
||||||
directionLastViolationTime = 0;
|
|
||||||
armswung = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collectData(Map<String, Object> map) {
|
public void collectData(Map<String, Object> map) {
|
||||||
map.put("blockbreak.reach.vl", (int) reachTotalVL);
|
map.put("blockbreak.reach.vl", (int) reachTotalVL);
|
||||||
|
@ -27,9 +27,4 @@ public class ChatData implements DataItem {
|
|||||||
map.put("chat.spam.failed", spamFailed);
|
map.put("chat.spam.failed", spamFailed);
|
||||||
map.put("chat.color.failed", colorFailed);
|
map.put("chat.color.failed", colorFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearCriticalData() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,4 @@ public class FightData implements DataItem {
|
|||||||
map.put("fight.noswing.failed", noswingFailed);
|
map.put("fight.noswing.failed", noswingFailed);
|
||||||
map.put("fight.reach.failed", (int) reachFailed);
|
map.put("fight.reach.failed", (int) reachFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearCriticalData() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,4 @@ public class InventoryData implements DataItem {
|
|||||||
map.put("inventory.drop.vl", (int) dropTotalVL);
|
map.put("inventory.drop.vl", (int) dropTotalVL);
|
||||||
map.put("inventory.drop.failed", (int) dropFailed);
|
map.put("inventory.drop.failed", (int) dropFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearCriticalData() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerPortalEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
@ -77,7 +79,7 @@ public class MovingCheckListener implements Listener, EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
protected void teleport(final PlayerTeleportEvent event) {
|
public void teleport(final PlayerTeleportEvent event) {
|
||||||
|
|
||||||
// No typo here, I really want to only handle cancelled events
|
// No typo here, I really want to only handle cancelled events
|
||||||
if(!event.isCancelled())
|
if(!event.isCancelled())
|
||||||
@ -86,15 +88,37 @@ public class MovingCheckListener implements Listener, EventManager {
|
|||||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||||
|
|
||||||
|
// If it was a teleport initialized by NoCheat, do it anyway
|
||||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||||
event.setCancelled(false);
|
event.setCancelled(false);
|
||||||
|
} else {
|
||||||
|
// Only if it wasn't NoCheat, drop data from morepackets check
|
||||||
|
data.clearMorePacketsData();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
|
// Always forget runfly specific data
|
||||||
|
data.teleportTo.reset();
|
||||||
|
data.clearRunFlyData();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void portal(final PlayerPortalEvent event) {
|
||||||
|
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||||
|
data.clearMorePacketsData();
|
||||||
|
data.clearRunFlyData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void portal(final PlayerRespawnEvent event) {
|
||||||
|
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||||
|
data.clearMorePacketsData();
|
||||||
|
data.clearRunFlyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
protected void move(final PlayerMoveEvent event) {
|
public void move(final PlayerMoveEvent event) {
|
||||||
|
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
return;
|
return;
|
||||||
@ -107,7 +131,6 @@ public class MovingCheckListener implements Listener, EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final MovingConfig cc = MovingCheck.getConfig(player.getConfigurationStore());
|
final MovingConfig cc = MovingCheck.getConfig(player.getConfigurationStore());
|
||||||
|
|
||||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||||
|
|
||||||
// Various calculations related to velocity estimates
|
// Various calculations related to velocity estimates
|
||||||
@ -116,7 +139,8 @@ public class MovingCheckListener implements Listener, EventManager {
|
|||||||
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
|
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
|
||||||
// Just because he is allowed now, doesn't mean he will always
|
// Just because he is allowed now, doesn't mean he will always
|
||||||
// be. So forget data about the player related to moving
|
// be. So forget data about the player related to moving
|
||||||
player.getDataStore().get("moving").clearCriticalData();
|
data.clearRunFlyData();
|
||||||
|
data.clearMorePacketsData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +195,7 @@ public class MovingCheckListener implements Listener, EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
protected void velocity(final PlayerVelocityEvent event) {
|
public void velocity(final PlayerVelocityEvent event) {
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
return;
|
return;
|
||||||
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||||
|
@ -48,7 +48,7 @@ public class MovingData implements DataItem {
|
|||||||
public int bunnyhopdelay;
|
public int bunnyhopdelay;
|
||||||
|
|
||||||
public int morePacketsCounter;
|
public int morePacketsCounter;
|
||||||
public int morePacketsBuffer = 50;
|
public int morePacketsBuffer = 30;
|
||||||
public int packets;
|
public int packets;
|
||||||
|
|
||||||
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
|
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
|
||||||
@ -67,16 +67,17 @@ public class MovingData implements DataItem {
|
|||||||
|
|
||||||
public int onIce = 0;
|
public int onIce = 0;
|
||||||
|
|
||||||
@Override
|
public void clearRunFlyData() {
|
||||||
public void clearCriticalData() {
|
|
||||||
teleportTo.reset();
|
|
||||||
jumpPhase = 0;
|
|
||||||
runflySetBackPoint.reset();
|
runflySetBackPoint.reset();
|
||||||
|
jumpPhase = 0;
|
||||||
fallDistance = 0;
|
fallDistance = 0;
|
||||||
lastAddedFallDistance = 0;
|
lastAddedFallDistance = 0;
|
||||||
bunnyhopdelay = 0;
|
bunnyhopdelay = 0;
|
||||||
morePacketsBuffer = 50;
|
}
|
||||||
|
|
||||||
|
public void clearMorePacketsData() {
|
||||||
morePacketsSetbackPoint.reset();
|
morePacketsSetbackPoint.reset();
|
||||||
|
morePacketsBuffer = 30;
|
||||||
lastElapsedIngameSeconds = 0;
|
lastElapsedIngameSeconds = 0;
|
||||||
morePacketsCounter = 0;
|
morePacketsCounter = 0;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class RunflyCheck extends MovingCheck {
|
|||||||
if(player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
if(player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
||||||
// If the player doesn't get checked for movement
|
// If the player doesn't get checked for movement
|
||||||
// reset his critical data
|
// reset his critical data
|
||||||
data.clearCriticalData();
|
data.clearRunFlyData();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
|
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
|
||||||
|
@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.data;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||||
|
|
||||||
public class DataStore {
|
public class DataStore {
|
||||||
@ -20,12 +19,6 @@ public class DataStore {
|
|||||||
dataMap.put(id, data);
|
dataMap.put(id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCriticalData() {
|
|
||||||
for(DataItem data : dataMap.values()) {
|
|
||||||
data.clearCriticalData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void collectData(Map<String, Object> map) {
|
public void collectData(Map<String, Object> map) {
|
||||||
for(DataItem data : dataMap.values()) {
|
for(DataItem data : dataMap.values()) {
|
||||||
data.collectData(map);
|
data.collectData(map);
|
||||||
|
@ -5,9 +5,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||||
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
||||||
@ -46,23 +44,6 @@ public class PlayerManager {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset data that may cause problems after e.g. changing the config
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void clearCriticalData() {
|
|
||||||
for(NoCheatPlayer b : this.players.values()) {
|
|
||||||
b.getDataStore().clearCriticalData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearCriticalData(String playerName) {
|
|
||||||
NoCheatPlayer p = this.players.get(playerName.toLowerCase());
|
|
||||||
if(p != null) {
|
|
||||||
p.getDataStore().clearCriticalData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanDataMap() {
|
public void cleanDataMap() {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
List<String> removals = new ArrayList<String>(5);
|
List<String> removals = new ArrayList<String>(5);
|
||||||
|
Loading…
Reference in New Issue
Block a user