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/InstantEatCheck.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/InstantEatCheck.java')
-rw-r--r-- | EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/InstantEatCheck.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/InstantEatCheck.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/InstantEatCheck.java new file mode 100644 index 000000000..05a668dd7 --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/inventory/InstantEatCheck.java @@ -0,0 +1,78 @@ +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; +import org.bukkit.event.entity.FoodLevelChangeEvent; + + +/** + * The InstantEatCheck will find out if a player eats his food too fast + */ +public class InstantEatCheck extends InventoryCheck +{ + public InstantEatCheck(NoCheat plugin) + { + super(plugin, "inventory.instanteat"); + } + + public boolean check(NoCheatPlayer player, FoodLevelChangeEvent event, InventoryData data, InventoryConfig cc) + { + + // Hunger level change seems to not be the result of eating + if (data.foodMaterial == null || event.getFoodLevel() <= player.getPlayer().getFoodLevel()) + { + return false; + } + + boolean cancelled = false; + + long time = System.currentTimeMillis(); + // rough estimation about how long it should take to eat + long expectedTimeWhenEatingFinished = data.lastEatInteractTime + 700; + + if (expectedTimeWhenEatingFinished < time) + { + // Acceptable, reduce VL to reward the player + data.instantEatVL *= 0.60D; + } + else if (data.lastEatInteractTime > time) + { + // Security test, if time ran backwards, reset + data.lastEatInteractTime = 0; + } + else + { + // Player was too fast, increase violation level and statistics + int vl = ((int)(expectedTimeWhenEatingFinished - time)) / 100; + data.instantEatVL += vl; + incrementStatistics(player, Id.INV_EAT, vl); + + // Execute whatever actions are associated with this check and the + // violation level and find out if we should cancel the event + cancelled = executeActions(player, cc.eatActions, data.instantEatVL); + } + + return cancelled; + } + + @Override + public String getParameter(ParameterName wildcard, NoCheatPlayer player) + { + + if (wildcard == ParameterName.VIOLATIONS) + { + return String.format(Locale.US, "%d", (int)getData(player).instantEatVL); + } + else if (wildcard == ParameterName.FOOD) + { + return getData(player).foodMaterial.toString(); + } + else + { + return super.getParameter(wildcard, player); + } + } +} |