mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-30 07:27:29 +02: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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||||
<artifactId>NoCheat</artifactId>
|
<artifactId>NoCheat</artifactId>
|
||||||
<version>2.23</version>
|
<version>2.24</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>NoCheat</name>
|
<name>NoCheat</name>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -16,20 +16,11 @@ public class CCInventory implements ConfigItem {
|
|||||||
|
|
||||||
public CCInventory(Configuration data) {
|
public CCInventory(Configuration data) {
|
||||||
|
|
||||||
/*
|
check = data.getBoolean(Configuration.INVENTORY_CHECK);
|
||||||
* check = data.getBoolean(Configuration.INVENTORY_CHECK);
|
dropCheck = data.getBoolean(Configuration.INVENTORY_DROP_CHECK);
|
||||||
* dropCheck = data.getBoolean(Configuration.INVENTORY_DROP_CHECK);
|
dropTimeFrame = data.getInteger(Configuration.INVENTORY_DROP_TIMEFRAME);
|
||||||
* dropTimeFrame =
|
dropLimit = data.getInteger(Configuration.INVENTORY_DROP_LIMIT);
|
||||||
* data.getInteger(Configuration.INVENTORY_DROP_TIMEFRAME);
|
dropActions = data.getActionList(Configuration.INVENTORY_DROP_ACTIONS);
|
||||||
* dropLimit = data.getInteger(Configuration.INVENTORY_DROP_LIMIT);
|
|
||||||
* dropActions =
|
|
||||||
* data.getActionList(Configuration.INVENTORY_DROP_ACTIONS);
|
|
||||||
*/
|
|
||||||
check = false;
|
|
||||||
dropCheck = false;
|
|
||||||
dropTimeFrame = 0;
|
|
||||||
dropLimit = 0;
|
|
||||||
dropActions = null;
|
|
||||||
|
|
||||||
closebeforeteleports = data.getBoolean(Configuration.INVENTORY_PREVENTITEMDUPE);
|
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.NoCheatPlayer;
|
||||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
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;
|
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||||
|
|
||||||
public class InventoryEventManager extends EventManagerImpl {
|
public class InventoryEventManager extends EventManagerImpl {
|
||||||
@ -23,11 +24,11 @@ public class InventoryEventManager extends EventManagerImpl {
|
|||||||
super(plugin);
|
super(plugin);
|
||||||
|
|
||||||
this.checks = new ArrayList<InventoryCheck>(1);
|
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);
|
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) {
|
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||||
if(InventoryCheck.getConfig(player.getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getPlayer().getWorld()))) {
|
if(InventoryCheck.getConfig(player.getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getPlayer().getWorld()))) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
} catch(NullPointerException e) {
|
} catch(NullPointerException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ public class InventoryEventManager extends EventManagerImpl {
|
|||||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||||
final CCInventory cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
final CCInventory cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||||
|
|
||||||
if(!cc.check || player.hasPermission(Permissions.INVENTORY)) {
|
if(!cc.check || player.hasPermission(Permissions.INVENTORY) || player.isDead()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +67,9 @@ public class InventoryEventManager extends EventManagerImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(cancelled) {
|
if(cancelled) {
|
||||||
event.setCancelled(true);
|
// Cancelling drop events is not save. So don't do it
|
||||||
player.closeInventory();
|
// 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 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)) {
|
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
|
||||||
@ -117,27 +122,6 @@ public class MovingEventManager extends EventManagerImpl {
|
|||||||
return;
|
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
|
// Get some data that's needed from this event, to avoid passing the
|
||||||
// event itself on to the checks (and risk to
|
// event itself on to the checks (and risk to
|
||||||
// accidentally modifying the event there)
|
// 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
|
@Override
|
||||||
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ public class RunflyCheck extends MovingCheck {
|
|||||||
private final RunningCheck runningCheck;
|
private final RunningCheck runningCheck;
|
||||||
|
|
||||||
public RunflyCheck(NoCheat plugin) {
|
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);
|
flyingCheck = new FlyingCheck(plugin);
|
||||||
runningCheck = new RunningCheck(plugin);
|
runningCheck = new RunningCheck(plugin);
|
||||||
@ -20,6 +23,12 @@ public class RunflyCheck extends MovingCheck {
|
|||||||
@Override
|
@Override
|
||||||
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
|
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);
|
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
|
||||||
|
|
||||||
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
|
/********************* 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);
|
private final static OptionNode INVENTORY = new OptionNode("inventory", ROOT, DataType.PARENT);
|
||||||
public final static OptionNode INVENTORY_PREVENTITEMDUPE = new OptionNode("preventitemdupe", INVENTORY, DataType.BOOLEAN);
|
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_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_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER);
|
||||||
public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", 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 ***/
|
/*** INVENTORY ***/
|
||||||
{
|
{
|
||||||
setValue(INVENTORY_PREVENTITEMDUPE, true);
|
setValue(INVENTORY_PREVENTITEMDUPE, true);
|
||||||
/*
|
|
||||||
* setValue(INVENTORY_CHECK, true);
|
setValue(INVENTORY_CHECK, true);
|
||||||
*
|
|
||||||
* setValue(INVENTORY_DROP_CHECK, true);
|
setValue(INVENTORY_DROP_CHECK, true);
|
||||||
* setValue(INVENTORY_DROP_TIMEFRAME, 20);
|
setValue(INVENTORY_DROP_TIMEFRAME, 20);
|
||||||
* setValue(INVENTORY_DROP_LIMIT, 100);
|
setValue(INVENTORY_DROP_LIMIT, 100);
|
||||||
*
|
|
||||||
* ActionList dropActionList = new ActionList();
|
ActionList dropActionList = new ActionList();
|
||||||
* dropActionList.setActions(0,
|
dropActionList.setActions(0, action.getActions("dropLog dropkick".split(" ")));
|
||||||
* action.getActions("dropLog dropCancel".split(" ")));
|
setValue(INVENTORY_DROP_ACTIONS, dropActionList);
|
||||||
* dropActionList.setActions(500,
|
|
||||||
* action.getActions("dropLog dropCancel dropkick".split(" ")));
|
|
||||||
* setValue(INVENTORY_DROP_ACTIONS, dropActionList);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** MOVING ***/
|
/*** MOVING ***/
|
||||||
@ -297,7 +294,6 @@ public class DefaultConfiguration extends Configuration {
|
|||||||
w(w, "special chatCancel 0 0");
|
w(w, "special chatCancel 0 0");
|
||||||
w(w, "special nofallDamage 0 0");
|
w(w, "special nofallDamage 0 0");
|
||||||
w(w, "special fightCancel 0 0");
|
w(w, "special fightCancel 0 0");
|
||||||
w(w, "special dropCancel 0 0");
|
|
||||||
w(w, "");
|
w(w, "");
|
||||||
w(w, "# CONSOLECOMMAND Actions: They will execute a command as if it were typed into the console.");
|
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'");
|
w(w, "# - They start with the word 'consolecommand'");
|
||||||
|
@ -40,7 +40,7 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
|||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
public boolean hasPermission(String permission) {
|
||||||
if(permission == null) {
|
if(permission == null) {
|
||||||
System.out.println("NoCheat: Warning, asked for null permission");
|
// System.out.println("NoCheat: Warning, asked for null permission");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return player.hasPermission(permission);
|
return player.hasPermission(permission);
|
||||||
|
Loading…
Reference in New Issue
Block a user