diff options
author | md_5 <md_5@bigpond.com> | 2012-03-12 10:39:36 +1100 |
---|---|---|
committer | md_5 <md_5@bigpond.com> | 2012-03-12 10:39:36 +1100 |
commit | 78f4820876f42f7b50bf88f64afd45bee939e4e4 (patch) | |
tree | 317cd3bcc63fc9e86a6efbcb5e13a50ed9efbaaf /EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java | |
parent | 26409058467e9f34aa65a08df3c68a58129d22ba (diff) | |
download | Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.gz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.lz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.xz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.zip |
Initial formatted and slightly tweaked version of @evenprime 's NoCheat. Will be intergrated into the main Essentials as soon as possible
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java')
-rw-r--r-- | EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java new file mode 100644 index 000000000..2e9d030f7 --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/DropCheck.java @@ -0,0 +1,71 @@ +package com.earth2me.essentials.anticheat.checks.inventory; + +import com.earth2me.essentials.anticheat.NoCheat; +import com.earth2me.essentials.anticheat.NoCheatPlayer; +import com.earth2me.essentials.anticheat.actions.ParameterName; +import com.earth2me.essentials.anticheat.data.Statistics.Id; +import java.util.Locale; + + +/** + * The DropCheck will find out if a player drops too many items within a short amount of time + * + */ +public class DropCheck extends InventoryCheck +{ + public DropCheck(NoCheat plugin) + { + super(plugin, "inventory.drop"); + } + + public boolean check(NoCheatPlayer player, InventoryData data, InventoryConfig cc) + { + + boolean cancel = false; + + final long time = System.currentTimeMillis(); + + // Has the configured time passed? If so, reset the counter + if (data.dropLastTime + cc.dropTimeFrame <= time) + { + data.dropLastTime = time; + data.dropCount = 0; + data.dropVL = 0; + } + // Security check, if the system time changes + else if (data.dropLastTime > time) + { + data.dropLastTime = Integer.MIN_VALUE; + } + + data.dropCount++; + + // The player dropped more than he should + if (data.dropCount > cc.dropLimit) + { + // Set vl and increment statistics + data.dropVL = data.dropCount - cc.dropLimit; + incrementStatistics(player, Id.INV_DROP, 1); + + // Execute whatever actions are associated with this check and the + // violation level and find out if we should cancel the event + cancel = executeActions(player, cc.dropActions, data.dropVL); + } + + return cancel; + } + + @Override + public String getParameter(ParameterName wildcard, NoCheatPlayer player) + { + + if (wildcard == ParameterName.VIOLATIONS) + { + return String.format(Locale.US, "%d", getData(player).dropVL); + } + else + { + return super.getParameter(wildcard, player); + } + } +} |