mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-30 20:37:52 +01:00
Reintroduced discarding of player data after 1 minute of inactivity
This commit is contained in:
parent
3c44445d9b
commit
c5806da644
@ -9,9 +9,7 @@ public class BaseData extends Data {
|
||||
public final FightData fight;
|
||||
public final TimedData timed;
|
||||
|
||||
private final Data[] data; // for convenience
|
||||
|
||||
protected long lastUsedTime;
|
||||
private final Data[] data; // for convenience
|
||||
|
||||
public boolean armswung;
|
||||
|
||||
@ -26,7 +24,6 @@ public class BaseData extends Data {
|
||||
data = new Data[] {this.blockbreak, this.blockplace, this.chat,
|
||||
this.moving, this.fight, this.timed};
|
||||
|
||||
this.lastUsedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void clearCriticalData() {
|
||||
@ -35,7 +32,4 @@ public class BaseData extends Data {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldBeRemoved(long currentTimeInMilliseconds) {
|
||||
return lastUsedTime + 60000L < currentTimeInMilliseconds;
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,11 @@ import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
||||
public class PlayerManager {
|
||||
|
||||
// Store data between Events
|
||||
private final Map<String, NoCheatPlayer> players;
|
||||
private final NoCheat plugin;
|
||||
private final List<String> removals;
|
||||
private final Map<String, NoCheatPlayerImpl> players;
|
||||
private final NoCheat plugin;
|
||||
|
||||
public PlayerManager(NoCheat plugin) {
|
||||
this.players = new HashMap<String, NoCheatPlayer>();
|
||||
this.removals = new ArrayList<String>(5);
|
||||
this.players = new HashMap<String, NoCheatPlayerImpl>();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -33,14 +31,17 @@ public class PlayerManager {
|
||||
*/
|
||||
public NoCheatPlayer getPlayer(String playerName) {
|
||||
|
||||
NoCheatPlayer p = this.players.get(playerName);
|
||||
NoCheatPlayerImpl p = this.players.get(playerName);
|
||||
|
||||
if(p == null) {
|
||||
// TODO: Differentiate which player"type" should be created, e.g. based on bukkit version
|
||||
// TODO: Differentiate which player"type" should be created, e.g.
|
||||
// based on bukkit version
|
||||
p = new NoCheatPlayerImpl(playerName, plugin, new BaseData());
|
||||
this.players.put(playerName, p);
|
||||
}
|
||||
|
||||
p.setLastUsedTime(System.currentTimeMillis());
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -54,31 +55,6 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if some data hasn't been used for a while and remove it
|
||||
*
|
||||
*/
|
||||
public void cleanDataMap() {
|
||||
synchronized(removals) {
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
for(Entry<String, NoCheatPlayer> p : this.players.entrySet()) {
|
||||
if(p.getValue().getData().shouldBeRemoved(time)) {
|
||||
removals.add(p.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(String p : removals) {
|
||||
this.players.remove(p);
|
||||
}
|
||||
|
||||
removals.clear();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCriticalData(String playerName) {
|
||||
NoCheatPlayer p = this.players.get(playerName);
|
||||
if(p != null) {
|
||||
@ -86,4 +62,19 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanDataMap() {
|
||||
long time = System.currentTimeMillis();
|
||||
List<String> removals = new ArrayList<String>(5);
|
||||
|
||||
for(Entry<String, NoCheatPlayerImpl> e : this.players.entrySet()) {
|
||||
if(e.getValue().shouldBeRemoved(time)) {
|
||||
removals.add(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(String key : removals) {
|
||||
this.players.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
*/
|
||||
public abstract class EventManager {
|
||||
|
||||
protected NoCheat plugin;
|
||||
protected final NoCheat plugin;
|
||||
|
||||
private static class BlockL extends BlockListener {
|
||||
|
||||
|
@ -18,10 +18,14 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
private final NoCheat plugin;
|
||||
private final BaseData data;
|
||||
|
||||
private long lastUsedTime;
|
||||
|
||||
public NoCheatPlayerImpl(String playerName, NoCheat plugin, BaseData data) {
|
||||
this.player = Bukkit.getServer().getPlayer(playerName);
|
||||
this.plugin = plugin;
|
||||
this.data = data;
|
||||
|
||||
this.lastUsedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
@ -57,14 +61,20 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
}
|
||||
|
||||
public float getSpeedAmplifier() {
|
||||
EntityPlayer ep = ((CraftPlayer)player).getHandle();
|
||||
EntityPlayer ep = ((CraftPlayer) player).getHandle();
|
||||
if(ep.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
|
||||
// Taken directly from Minecraft code, should work
|
||||
return 1.0F + 0.2F * ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 1.0F;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLastUsedTime(long currentTimeInMilliseconds) {
|
||||
this.lastUsedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean shouldBeRemoved(long currentTimeInMilliseconds) {
|
||||
return lastUsedTime + 60000L < currentTimeInMilliseconds;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user