blob: 07f66b37538d7c82c6290880aba66ed49644c4bd (
plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package com.earth2me.essentials.anticheat.player;
import com.earth2me.essentials.anticheat.NoCheat;
import com.earth2me.essentials.anticheat.NoCheatPlayer;
import com.earth2me.essentials.anticheat.config.ConfigurationCacheStore;
import com.earth2me.essentials.anticheat.data.DataStore;
import com.earth2me.essentials.anticheat.data.ExecutionHistory;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class NoCheatPlayerImpl implements NoCheatPlayer
{
private Player player;
private final NoCheat plugin;
private final DataStore data;
private ConfigurationCacheStore config;
private long lastUsedTime;
private final ExecutionHistory history;
public NoCheatPlayerImpl(Player player, NoCheat plugin)
{
this.player = player;
this.plugin = plugin;
this.data = new DataStore();
this.history = new ExecutionHistory();
this.lastUsedTime = System.currentTimeMillis();
}
public void refresh(Player player)
{
this.player = player;
this.config = plugin.getConfig(player);
}
public boolean isDead()
{
return this.player.getHealth() <= 0 || this.player.isDead();
}
public boolean hasPermission(String permission)
{
return player.hasPermission(permission);
}
public DataStore getDataStore()
{
return data;
}
public ConfigurationCacheStore getConfigurationStore()
{
return config;
}
public Player getPlayer()
{
return player;
}
public String getName()
{
return player.getName();
}
public int getTicksLived()
{
return player.getTicksLived();
}
public float getSpeedAmplifier()
{
EntityPlayer ep = ((CraftPlayer)player).getHandle();
if (ep.hasEffect(MobEffectList.FASTER_MOVEMENT))
{
// Taken directly from Minecraft code, should work
return 1.0F + 0.2F * (float)(ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1); // TODO
}
else
{
return 1.0F;
}
}
@Override
public float getJumpAmplifier()
{
EntityPlayer ep = ((CraftPlayer)player).getHandle();
if (ep.hasEffect(MobEffectList.JUMP))
{
int amp = ep.getEffect(MobEffectList.JUMP).getAmplifier();
// Very rough estimates only
// TODO
if (amp > 20)
{
return 1.5F * (float)(ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
}
else
{
return 1.2F * (float)(ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
}
}
else
{
return 1.0F;
}
}
public boolean isSprinting()
{
return player.isSprinting();
}
public void setLastUsedTime(long currentTimeInMilliseconds)
{
this.lastUsedTime = currentTimeInMilliseconds;
}
public boolean shouldBeRemoved(long currentTimeInMilliseconds)
{
if (lastUsedTime > currentTimeInMilliseconds)
{
// Should never happen, but if it does, fix it somewhat
lastUsedTime = currentTimeInMilliseconds;
}
return lastUsedTime + 60000L < currentTimeInMilliseconds;
}
public boolean isCreative()
{
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public ExecutionHistory getExecutionHistory()
{
return history;
}
@Override
public void dealFallDamage()
{
EntityPlayer p = ((CraftPlayer)player).getHandle();
p.b(0D, true);
}
}
|