1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package com.earth2me.essentials.anticheat.checks.blockbreak;
import java.util.Locale;
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;
/**
* The reach check will find out if a player interacts with something that's too far away
*
*/
public class ReachCheck extends BlockBreakCheck
{
public ReachCheck(NoCheat plugin)
{
super(plugin, "blockbreak.reach");
}
public boolean check(NoCheatPlayer player, BlockBreakData data, BlockBreakConfig cc)
{
boolean cancel = false;
final SimpleLocation brokenBlock = data.brokenBlockLocation;
// 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, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.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.BB_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);
}
}
}
|