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/blockplace/ReachCheck.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/blockplace/ReachCheck.java')
-rw-r--r-- | EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/ReachCheck.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/ReachCheck.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/ReachCheck.java new file mode 100644 index 000000000..6e13a9348 --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/ReachCheck.java @@ -0,0 +1,75 @@ +package com.earth2me.essentials.anticheat.checks.blockplace; + +import com.earth2me.essentials.anticheat.NoCheat; +import com.earth2me.essentials.anticheat.NoCheatPlayer; +import com.earth2me.essentials.anticheat.actions.ParameterName; +import com.earth2me.essentials.anticheat.checks.CheckUtil; +import com.earth2me.essentials.anticheat.data.SimpleLocation; +import com.earth2me.essentials.anticheat.data.Statistics.Id; +import java.util.Locale; + + +/** + * The reach check will find out if a player interacts with something that's too far away + * + */ +public class ReachCheck extends BlockPlaceCheck +{ + public ReachCheck(NoCheat plugin) + { + super(plugin, "blockplace.reach"); + } + + public boolean check(NoCheatPlayer player, BlockPlaceData data, BlockPlaceConfig cc) + { + + boolean cancel = false; + + final SimpleLocation placedAgainstBlock = data.blockPlacedAgainst; + + // Distance is calculated from eye location to center of targeted block + // If the player is further away from his target than allowed, the + // difference will be assigned to "distance" + final double distance = CheckUtil.reachCheck(player, placedAgainstBlock.x + 0.5D, placedAgainstBlock.y + 0.5D, placedAgainstBlock.z + 0.5D, player.isCreative() ? cc.reachDistance + 2 : cc.reachDistance); + + if (distance <= 0D) + { + // Player passed the check, reward him + data.reachVL *= 0.9D; + } + else + { + // He failed, increment violation level and statistics + data.reachVL += distance; + incrementStatistics(player, Id.BP_REACH, distance); + + // Remember how much further than allowed he tried to reach for + // logging, if necessary + data.reachdistance = distance; + + // 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.reachActions, data.reachVL); + } + + return cancel; + } + + @Override + public String getParameter(ParameterName wildcard, NoCheatPlayer player) + { + + if (wildcard == ParameterName.VIOLATIONS) + { + return String.format(Locale.US, "%d", (int)getData(player).reachVL); + } + else if (wildcard == ParameterName.REACHDISTANCE) + { + return String.format(Locale.US, "%.2f", getData(player).reachdistance); + } + else + { + return super.getParameter(wildcard, player); + } + } +} |