From ea5081310779d4fa53bc9a99fb43354ad4d34887 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 5 Apr 2012 20:52:31 +1000 Subject: Negate some 1 class packages --- .../essentials/anticheat/LagMeasureTask.java | 99 +++++++++++++ .../com/earth2me/essentials/anticheat/NoCheat.java | 1 - .../essentials/anticheat/NoCheatPlayerImpl.java | 163 +++++++++++++++++++++ .../essentials/anticheat/data/PlayerManager.java | 2 +- .../essentials/anticheat/debug/LagMeasureTask.java | 99 ------------- .../anticheat/player/NoCheatPlayerImpl.java | 151 ------------------- 6 files changed, 263 insertions(+), 252 deletions(-) create mode 100644 EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/LagMeasureTask.java create mode 100644 EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheatPlayerImpl.java delete mode 100644 EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/debug/LagMeasureTask.java delete mode 100644 EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/player/NoCheatPlayerImpl.java (limited to 'EssentialsAntiCheat/src') diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/LagMeasureTask.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/LagMeasureTask.java new file mode 100644 index 000000000..87fa7c0da --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/LagMeasureTask.java @@ -0,0 +1,99 @@ +package com.earth2me.essentials.anticheat; + +import com.earth2me.essentials.anticheat.NoCheat; +import org.bukkit.World; + + +/** + * A task running in the background that measures tick time vs. real time + * + */ +public class LagMeasureTask implements Runnable +{ + private int ingameseconds = 1; + private long lastIngamesecondTime = System.currentTimeMillis(); + private long lastIngamesecondDuration = 2000L; + private boolean skipCheck = false; + private int lagMeasureTaskId = -1; + private final NoCheat plugin; + + public LagMeasureTask(NoCheat plugin) + { + this.plugin = plugin; + } + + public void start() + { + // start measuring with a delay of 10 seconds + lagMeasureTaskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this, 20, 20); + } + + public void run() + { + try + { + boolean oldStatus = skipCheck; + // If the previous second took to long, skip checks during + // this second + skipCheck = lastIngamesecondDuration > 2000; + + if (plugin.getConfig((World)null).logging.debugmessages) + { + if (oldStatus != skipCheck && skipCheck) + { + plugin.getLogger().warning("detected server lag, some checks will not work."); + } + else if (oldStatus != skipCheck && !skipCheck) + { + plugin.getLogger().info("server lag seems to have stopped, reenabling checks."); + } + } + + long time = System.currentTimeMillis(); + lastIngamesecondDuration = time - lastIngamesecondTime; + if (lastIngamesecondDuration < 1000) + { + lastIngamesecondDuration = 1000; + } + else if (lastIngamesecondDuration > 3600000) + { + lastIngamesecondDuration = 3600000; // top limit of 1 + // hour per "second" + } + lastIngamesecondTime = time; + ingameseconds++; + + // Check if some data is outdated now and let it be removed + if (ingameseconds % 62 == 0) + { + plugin.cleanDataMap(); + } + } + catch (Exception e) + { + // Just prevent this thread from dying for whatever reason + } + + } + + public void cancel() + { + if (lagMeasureTaskId != -1) + { + try + { + plugin.getServer().getScheduler().cancelTask(lagMeasureTaskId); + } + catch (Exception e) + { + plugin.getLogger().warning("Couldn't cancel LagMeasureTask: " + e.getMessage()); + } + lagMeasureTaskId = -1; + } + } + + public boolean skipCheck() + { + return skipCheck; + } +} diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheat.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheat.java index 5a05f78bc..ed5521a24 100644 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheat.java +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheat.java @@ -13,7 +13,6 @@ import com.earth2me.essentials.anticheat.config.ConfigurationCacheStore; import com.earth2me.essentials.anticheat.config.ConfigurationManager; import com.earth2me.essentials.anticheat.config.Permissions; import com.earth2me.essentials.anticheat.data.PlayerManager; -import com.earth2me.essentials.anticheat.debug.LagMeasureTask; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheatPlayerImpl.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheatPlayerImpl.java new file mode 100644 index 000000000..8fc81110a --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/NoCheatPlayerImpl.java @@ -0,0 +1,163 @@ +package com.earth2me.essentials.anticheat; + + + +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); + } + + @Override + public boolean isDead() + { + return this.player.getHealth() <= 0 || this.player.isDead(); + } + + @Override + public boolean hasPermission(String permission) + { + return player.hasPermission(permission); + } + + @Override + public DataStore getDataStore() + { + return data; + } + + @Override + public ConfigurationCacheStore getConfigurationStore() + { + return config; + } + + @Override + public Player getPlayer() + { + return player; + } + + @Override + public String getName() + { + return player.getName(); + } + + @Override + public int getTicksLived() + { + return player.getTicksLived(); + } + + @Override + 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; + } + } + + @Override + 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; + } + + @Override + public boolean isCreative() + { + return player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight(); + } + + @Override + public ExecutionHistory getExecutionHistory() + { + return history; + } + + @Override + public void dealFallDamage() + { + EntityPlayer p = ((CraftPlayer)player).getHandle(); + p.b(0D, true); + } +} diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java index 7a13628c6..28dcaacc4 100644 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/data/PlayerManager.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.anticheat.data; import com.earth2me.essentials.anticheat.NoCheat; import com.earth2me.essentials.anticheat.NoCheatPlayer; -import com.earth2me.essentials.anticheat.player.NoCheatPlayerImpl; +import com.earth2me.essentials.anticheat.NoCheatPlayerImpl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/debug/LagMeasureTask.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/debug/LagMeasureTask.java deleted file mode 100644 index 4acb5a5f2..000000000 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/debug/LagMeasureTask.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.earth2me.essentials.anticheat.debug; - -import com.earth2me.essentials.anticheat.NoCheat; -import org.bukkit.World; - - -/** - * A task running in the background that measures tick time vs. real time - * - */ -public class LagMeasureTask implements Runnable -{ - private int ingameseconds = 1; - private long lastIngamesecondTime = System.currentTimeMillis(); - private long lastIngamesecondDuration = 2000L; - private boolean skipCheck = false; - private int lagMeasureTaskId = -1; - private final NoCheat plugin; - - public LagMeasureTask(NoCheat plugin) - { - this.plugin = plugin; - } - - public void start() - { - // start measuring with a delay of 10 seconds - lagMeasureTaskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this, 20, 20); - } - - public void run() - { - try - { - boolean oldStatus = skipCheck; - // If the previous second took to long, skip checks during - // this second - skipCheck = lastIngamesecondDuration > 2000; - - if (plugin.getConfig((World)null).logging.debugmessages) - { - if (oldStatus != skipCheck && skipCheck) - { - plugin.getLogger().warning("detected server lag, some checks will not work."); - } - else if (oldStatus != skipCheck && !skipCheck) - { - plugin.getLogger().info("server lag seems to have stopped, reenabling checks."); - } - } - - long time = System.currentTimeMillis(); - lastIngamesecondDuration = time - lastIngamesecondTime; - if (lastIngamesecondDuration < 1000) - { - lastIngamesecondDuration = 1000; - } - else if (lastIngamesecondDuration > 3600000) - { - lastIngamesecondDuration = 3600000; // top limit of 1 - // hour per "second" - } - lastIngamesecondTime = time; - ingameseconds++; - - // Check if some data is outdated now and let it be removed - if (ingameseconds % 62 == 0) - { - plugin.cleanDataMap(); - } - } - catch (Exception e) - { - // Just prevent this thread from dying for whatever reason - } - - } - - public void cancel() - { - if (lagMeasureTaskId != -1) - { - try - { - plugin.getServer().getScheduler().cancelTask(lagMeasureTaskId); - } - catch (Exception e) - { - plugin.getLogger().warning("Couldn't cancel LagMeasureTask: " + e.getMessage()); - } - lagMeasureTaskId = -1; - } - } - - public boolean skipCheck() - { - return skipCheck; - } -} diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/player/NoCheatPlayerImpl.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/player/NoCheatPlayerImpl.java deleted file mode 100644 index 3417368ab..000000000 --- a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/player/NoCheatPlayerImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -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 || player.getAllowFlight(); - } - - @Override - public ExecutionHistory getExecutionHistory() - { - return history; - } - - @Override - public void dealFallDamage() - { - EntityPlayer p = ((CraftPlayer)player).getHandle(); - p.b(0D, true); - } -} -- cgit v1.2.3