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
|
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);
}
}
}
|