mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-01 05:18:00 +01:00
Drop check - kick players for dropping too many items in a short
timeframe + Support permission changes better in playermove checks
This commit is contained in:
parent
e8d8341d3b
commit
4a9bc95aad
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||
<artifactId>NoCheat</artifactId>
|
||||
<version>2.23</version>
|
||||
<version>2.24</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>NoCheat</name>
|
||||
<properties>
|
||||
|
@ -16,20 +16,11 @@ public class CCInventory implements ConfigItem {
|
||||
|
||||
public CCInventory(Configuration data) {
|
||||
|
||||
/*
|
||||
* check = data.getBoolean(Configuration.INVENTORY_CHECK);
|
||||
* dropCheck = data.getBoolean(Configuration.INVENTORY_DROP_CHECK);
|
||||
* dropTimeFrame =
|
||||
* data.getInteger(Configuration.INVENTORY_DROP_TIMEFRAME);
|
||||
* dropLimit = data.getInteger(Configuration.INVENTORY_DROP_LIMIT);
|
||||
* dropActions =
|
||||
* data.getActionList(Configuration.INVENTORY_DROP_ACTIONS);
|
||||
*/
|
||||
check = false;
|
||||
dropCheck = false;
|
||||
dropTimeFrame = 0;
|
||||
dropLimit = 0;
|
||||
dropActions = null;
|
||||
check = data.getBoolean(Configuration.INVENTORY_CHECK);
|
||||
dropCheck = data.getBoolean(Configuration.INVENTORY_DROP_CHECK);
|
||||
dropTimeFrame = data.getInteger(Configuration.INVENTORY_DROP_TIMEFRAME);
|
||||
dropLimit = data.getInteger(Configuration.INVENTORY_DROP_LIMIT);
|
||||
dropActions = data.getActionList(Configuration.INVENTORY_DROP_ACTIONS);
|
||||
|
||||
closebeforeteleports = data.getBoolean(Configuration.INVENTORY_PREVENTITEMDUPE);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
public class InventoryEventManager extends EventManagerImpl {
|
||||
@ -23,11 +24,11 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
super(plugin);
|
||||
|
||||
this.checks = new ArrayList<InventoryCheck>(1);
|
||||
|
||||
// Don't use this check now, it's buggy
|
||||
//this.checks.add(new DropCheck(plugin));
|
||||
|
||||
//registerListener(Event.Type.PLAYER_DROP_ITEM, Priority.Lowest, true, plugin.getPerformance(EventType.INVENTORY));
|
||||
// Don't use this check now, it's buggy
|
||||
this.checks.add(new DropCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.PLAYER_DROP_ITEM, Priority.Lowest, true, plugin.getPerformance(EventType.INVENTORY));
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true, null);
|
||||
}
|
||||
|
||||
@ -35,12 +36,12 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
|
||||
try {
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
if(InventoryCheck.getConfig(player.getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getPlayer().getWorld()))) {
|
||||
player.closeInventory();
|
||||
}
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
if(InventoryCheck.getConfig(player.getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getPlayer().getWorld()))) {
|
||||
player.closeInventory();
|
||||
}
|
||||
} catch(NullPointerException e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +51,7 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final CCInventory cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.INVENTORY)) {
|
||||
if(!cc.check || player.hasPermission(Permissions.INVENTORY) || player.isDead()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -66,8 +67,9 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
}
|
||||
|
||||
if(cancelled) {
|
||||
event.setCancelled(true);
|
||||
player.closeInventory();
|
||||
// Cancelling drop events is not save. So don't do it
|
||||
// and kick players instead by default
|
||||
//event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,11 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
|
||||
final CCMoving cc = MovingCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
// Various calculations related to velocity estimates
|
||||
updateVelocities(data);
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
|
||||
// Just because he is allowed now, doesn't mean he will always
|
||||
// be. So forget data about the player related to moving
|
||||
@ -117,27 +122,6 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
return;
|
||||
}
|
||||
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
|
||||
if(data.horizVelocityCounter > 0) {
|
||||
data.horizVelocityCounter--;
|
||||
} else {
|
||||
data.horizFreedom *= 0.90;
|
||||
}
|
||||
|
||||
if(data.vertVelocity <= 0.1) {
|
||||
data.vertVelocityCounter--;
|
||||
}
|
||||
if(data.vertVelocityCounter > 0) {
|
||||
|
||||
data.vertFreedom += data.vertVelocity;
|
||||
data.vertVelocity *= 0.90;
|
||||
} else {
|
||||
// Counter has run out, now reduce the vert freedom over time
|
||||
data.vertFreedom *= 0.90;
|
||||
}
|
||||
|
||||
// Get some data that's needed from this event, to avoid passing the
|
||||
// event itself on to the checks (and risk to
|
||||
// accidentally modifying the event there)
|
||||
@ -167,6 +151,27 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVelocities(MovingData data) {
|
||||
|
||||
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
|
||||
if(data.horizVelocityCounter > 0) {
|
||||
data.horizVelocityCounter--;
|
||||
} else if(data.horizFreedom > 0.001) {
|
||||
data.horizFreedom *= 0.90;
|
||||
}
|
||||
|
||||
if(data.vertVelocity <= 0.1) {
|
||||
data.vertVelocityCounter--;
|
||||
}
|
||||
if(data.vertVelocityCounter > 0) {
|
||||
data.vertFreedom += data.vertVelocity;
|
||||
data.vertVelocity *= 0.90;
|
||||
} else if(data.vertFreedom > 0.001) {
|
||||
// Counter has run out, now reduce the vert freedom over time
|
||||
data.vertFreedom *= 0.93;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
||||
|
||||
|
@ -11,7 +11,10 @@ public class RunflyCheck extends MovingCheck {
|
||||
private final RunningCheck runningCheck;
|
||||
|
||||
public RunflyCheck(NoCheat plugin) {
|
||||
super(plugin, "moving.runfly", Permissions.MOVING_RUNFLY);
|
||||
// Permission field intentionally left blank here
|
||||
// We check in the actual "check" method, because
|
||||
// we have to do something beside skipping the test
|
||||
super(plugin, "moving.runfly", null);
|
||||
|
||||
flyingCheck = new FlyingCheck(plugin);
|
||||
runningCheck = new RunningCheck(plugin);
|
||||
@ -20,6 +23,12 @@ public class RunflyCheck extends MovingCheck {
|
||||
@Override
|
||||
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
|
||||
|
||||
if(player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
||||
// If the player doesn't get checked for movement
|
||||
// reset his critical data
|
||||
data.clearCriticalData();
|
||||
return null;
|
||||
}
|
||||
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
|
||||
|
||||
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
|
||||
|
@ -36,9 +36,9 @@ public abstract class Configuration {
|
||||
|
||||
private final static OptionNode INVENTORY = new OptionNode("inventory", ROOT, DataType.PARENT);
|
||||
public final static OptionNode INVENTORY_PREVENTITEMDUPE = new OptionNode("preventitemdupe", INVENTORY, DataType.BOOLEAN);
|
||||
public static final OptionNode INVENTORY_CHECK = new OptionNode("check", INACTIVE, DataType.BOOLEAN);
|
||||
public static final OptionNode INVENTORY_CHECK = new OptionNode("check", INVENTORY, DataType.BOOLEAN);
|
||||
|
||||
private final static OptionNode INVENTORY_DROP = new OptionNode("drop", INACTIVE, DataType.PARENT);
|
||||
private final static OptionNode INVENTORY_DROP = new OptionNode("drop", INVENTORY, DataType.PARENT);
|
||||
public final static OptionNode INVENTORY_DROP_CHECK = new OptionNode("check", INVENTORY_DROP, DataType.BOOLEAN);
|
||||
public final static OptionNode INVENTORY_DROP_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER);
|
||||
public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", INVENTORY_DROP, DataType.INTEGER);
|
||||
|
@ -38,20 +38,17 @@ public class DefaultConfiguration extends Configuration {
|
||||
/*** INVENTORY ***/
|
||||
{
|
||||
setValue(INVENTORY_PREVENTITEMDUPE, true);
|
||||
/*
|
||||
* setValue(INVENTORY_CHECK, true);
|
||||
*
|
||||
* setValue(INVENTORY_DROP_CHECK, true);
|
||||
* setValue(INVENTORY_DROP_TIMEFRAME, 20);
|
||||
* setValue(INVENTORY_DROP_LIMIT, 100);
|
||||
*
|
||||
* ActionList dropActionList = new ActionList();
|
||||
* dropActionList.setActions(0,
|
||||
* action.getActions("dropLog dropCancel".split(" ")));
|
||||
* dropActionList.setActions(500,
|
||||
* action.getActions("dropLog dropCancel dropkick".split(" ")));
|
||||
* setValue(INVENTORY_DROP_ACTIONS, dropActionList);
|
||||
*/
|
||||
|
||||
setValue(INVENTORY_CHECK, true);
|
||||
|
||||
setValue(INVENTORY_DROP_CHECK, true);
|
||||
setValue(INVENTORY_DROP_TIMEFRAME, 20);
|
||||
setValue(INVENTORY_DROP_LIMIT, 100);
|
||||
|
||||
ActionList dropActionList = new ActionList();
|
||||
dropActionList.setActions(0, action.getActions("dropLog dropkick".split(" ")));
|
||||
setValue(INVENTORY_DROP_ACTIONS, dropActionList);
|
||||
|
||||
}
|
||||
|
||||
/*** MOVING ***/
|
||||
@ -297,7 +294,6 @@ public class DefaultConfiguration extends Configuration {
|
||||
w(w, "special chatCancel 0 0");
|
||||
w(w, "special nofallDamage 0 0");
|
||||
w(w, "special fightCancel 0 0");
|
||||
w(w, "special dropCancel 0 0");
|
||||
w(w, "");
|
||||
w(w, "# CONSOLECOMMAND Actions: They will execute a command as if it were typed into the console.");
|
||||
w(w, "# - They start with the word 'consolecommand'");
|
||||
|
@ -40,7 +40,7 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
if(permission == null) {
|
||||
System.out.println("NoCheat: Warning, asked for null permission");
|
||||
// System.out.println("NoCheat: Warning, asked for null permission");
|
||||
return false;
|
||||
}
|
||||
return player.hasPermission(permission);
|
||||
|
Loading…
Reference in New Issue
Block a user