Updated for 1.3-DEV and added fast projectile check, fixes issue #27

This commit is contained in:
H31IX committed 2012-06-03 15:43:58 -04:00
1 parent 92dfa04802
commit 0f8ba3a6e9
6 files changed
+53 -8

No files matched your search

@@ -27,10 +27,12 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.*;
import org.bukkit.inventory.PlayerInventory;
@@ -50,6 +52,19 @@ public class PlayerListener extends EventListener
}
}
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event)
{
if(event.getEntity().getShooter() instanceof Player)
{
Player player = (Player)event.getEntity().getShooter();
if(checkManager.willCheck(player, CheckType.FAST_PROJECTILE))
{
backend.logProjectile(player,this);
}
}
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event)
{
@@ -65,6 +65,7 @@ public class AnticheatManager
}
handler = new FileHandler(plugin.getDataFolder()+"/log/anticheat.log.%u.txt",true);
handler.setFormatter(new FileFormatter());
handler.setLevel(Level.INFO);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
@@ -82,7 +83,7 @@ public class AnticheatManager
{
if(getConfiguration().logConsole())
{
LOGGER.warning(ChatColor.stripColor(message)); //This is temporary. Is something wrong with jline?
LOGGER.info(ChatColor.stripColor(message)); //This is temporary. Is something wrong with jline?
}
if(getConfiguration().getFileLogLevel() == LOG_LEVEL_HIGH)
{
@@ -92,7 +93,7 @@ public class AnticheatManager
public void fileLog(String message)
{
FILE_LOGGER.warning(message);
FILE_LOGGER.info(message);
}
public Anticheat getPlugin()
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.h31ix.anticheat.event.EventListener;
import net.h31ix.anticheat.util.Utilities;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -45,6 +46,7 @@ public class Backend
private static final int DROPPED_ITEM_TIME = 2;
private static final int DAMAGE_TIME = 50;
private static final int KNOCKBACK_DAMAGE_TIME = 50;
private static final int PROJECTILE_TIME = 20;
private static final int FASTBREAK_LIMIT = 3;
private static final int FASTBREAK_TIMEMAX = 500;
@@ -59,6 +61,8 @@ public class Backend
private static final int BLOCK_PUNCH_MIN = 5;
private static final int PROJECTILE_MAX = 8;
private static final int CHAT_WARN_LEVEL = 7;
private static final int CHAT_KICK_LEVEL = 10;
private static final int CHAT_BAN_LEVEL = 3;
@@ -114,6 +118,7 @@ public class Backend
private List<String> isInWaterCache = new ArrayList<String>();
private List<String> instantBreakExempt = new ArrayList<String>();
private List<String> isAscending = new ArrayList<String>();
private List<String> trackingProjectiles = new ArrayList<String>();
private Map<String,String> oldMessage = new HashMap<String,String>();
private Map<String,String> lastMessage = new HashMap<String,String>();
private Map<String,Integer> flightViolation = new HashMap<String,Integer>();
@@ -134,6 +139,7 @@ public class Backend
private Map<String,Integer> blockPunches = new HashMap<String,Integer>();
private Map<String,Integer> waterAscensionViolation = new HashMap<String,Integer>();
private Map<String,Integer> waterSpeedViolation = new HashMap<String,Integer>();
private Map<String,Integer> projectilesShot = new HashMap<String,Integer>();
public Backend(AnticheatManager instance)
{
@@ -725,7 +731,7 @@ public class Backend
public void logAnimation(final Player player)
{
logEvent(animated,player,ANIMATION_MIN);
increment(player,blockPunches);
increment(player,blockPunches,BLOCK_PUNCH_MIN);
}
public void resetAnimation(final Player player)
@@ -739,6 +745,28 @@ public class Backend
return animated.contains(player.getName());
}
public void logProjectile(final Player player, final EventListener e)
{
increment(player,projectilesShot,PROJECTILE_MAX);
if(!trackingProjectiles.contains(player.getName()))
{
trackingProjectiles.add(player.getName());
micromanage.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(micromanage.getPlugin(), new Runnable()
{
@Override
public void run()
{
trackingProjectiles.remove(player.getName());
if(projectilesShot.get(player.getName()) >= PROJECTILE_MAX)
{
e.log("tried to fire projectiles too fast",player,CheckType.FAST_PROJECTILE);
}
projectilesShot.put(player.getName(),0);
}
}, PROJECTILE_TIME);
}
}
public void logDamage(final Player player)
{
int time = DAMAGE_TIME;
@@ -867,7 +895,7 @@ public class Backend
}
}
}
public void increment(Player player, Map<String,Integer> map)
public void increment(Player player, Map<String,Integer> map, int num)
{
String name = player.getName();
if(map.get(name) == null)
@@ -877,13 +905,13 @@ public class Backend
else
{
int amount = map.get(name)+1;
if(amount < BLOCK_PUNCH_MIN+1)
if(amount < num+1)
{
map.put(name, amount);
}
else
{
map.put(name, BLOCK_PUNCH_MIN);
map.put(name, num);
}
}
}
@@ -51,6 +51,7 @@ public enum CheckType
FORCEFIELD("anticheat.forcefield"),
XRAY("anticheat.xray"),
LONG_REACH("anticheat.longreach"),
FAST_PROJECTILE("anticheat.projectile"),
ITEM_SPAM("anticheat.itemspam");
private final String permission;