mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 22:14:49 +00:00
Better file logging options
This commit is contained in:
1 parent
de762de1ba
commit
33dfb97a1b
10 files changed
+154
-25
No files matched your search
@@ -19,11 +19,14 @@
|
||||
package net.h31ix.anticheat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.h31ix.anticheat.manage.PlayerManager;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -39,9 +42,10 @@ public class CommandHandler implements CommandExecutor
|
||||
private static final ChatColor YELLOW = ChatColor.YELLOW;
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private List<Player> high = new ArrayList<Player>();
|
||||
private List<Player> med = new ArrayList<Player>();
|
||||
private List<Player> low = new ArrayList<Player>();
|
||||
private List<String> high = new ArrayList<String>();
|
||||
private List<String> med = new ArrayList<String>();
|
||||
private List<String> low = new ArrayList<String>();
|
||||
private Map<String,Location> spyLocation = new HashMap<String,Location>();
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static final int MED_THRESHOLD = 20;
|
||||
private static final int HIGH_THRESHOLD = 50;
|
||||
@@ -131,11 +135,11 @@ public class CommandHandler implements CommandExecutor
|
||||
{
|
||||
Player player = list.get(0);
|
||||
getPlayers();
|
||||
if(low.contains(player))
|
||||
if(low.contains(player.getName()))
|
||||
{
|
||||
cs.sendMessage(player.getName()+RED+" is already in Low Level!");
|
||||
}
|
||||
else if (med.contains(player) || high.contains(player))
|
||||
else if (med.contains(player.getName()) || high.contains(player.getName()))
|
||||
{
|
||||
playerManager.reset(player);
|
||||
cs.sendMessage(player.getName()+GREEN+" has been reset to Low Level.");
|
||||
@@ -154,6 +158,61 @@ public class CommandHandler implements CommandExecutor
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSpy(CommandSender cs, String [] args)
|
||||
{
|
||||
if(cs instanceof Player)
|
||||
{
|
||||
Player sender = (Player)cs;
|
||||
if(hasPermission(cs,"system.spy") || hasPermission(cs,"mod"))
|
||||
{
|
||||
if(!args[1].equalsIgnoreCase("off"))
|
||||
{
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if(list.size() == 1)
|
||||
{
|
||||
Player player = list.get(0);
|
||||
for(Player p : cs.getServer().getOnlinePlayers())
|
||||
{
|
||||
p.hidePlayer(sender);
|
||||
}
|
||||
sender.setAllowFlight(true);
|
||||
sender.setFlying(true);
|
||||
spyLocation.put(sender.getName(), sender.getLocation());
|
||||
sender.teleport(player);
|
||||
sender.sendMessage(GREEN+"You have been teleported to "+player.getName()+" and made invisible.");
|
||||
sender.sendMessage(GREEN+"To stop spying, type "+WHITE+" /AntiCheat spy off");
|
||||
}
|
||||
else if(list.size() > 1)
|
||||
{
|
||||
cs.sendMessage(RED+"Multiple players found by name: "+WHITE+args[1]+RED+".");
|
||||
}
|
||||
else
|
||||
{
|
||||
cs.sendMessage(RED+"Player: "+WHITE+args[1]+RED+" not found.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.setFlying(false);
|
||||
sender.setAllowFlight(false);
|
||||
if(spyLocation.containsKey(sender.getName()))
|
||||
{
|
||||
sender.teleport(spyLocation.get(sender.getName()));
|
||||
spyLocation.remove(sender.getName());
|
||||
}
|
||||
for(Player p : cs.getServer().getOnlinePlayers())
|
||||
{
|
||||
p.showPlayer(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cs.sendMessage(RED+"Sorry, but you can't spy on a player from the console.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleHelp(CommandSender cs)
|
||||
{
|
||||
if(hasPermission(cs,"system.help") || hasPermission(cs,"admin") || hasPermission(cs,"mod"))
|
||||
@@ -205,25 +264,25 @@ public class CommandHandler implements CommandExecutor
|
||||
if(!low.isEmpty())
|
||||
{
|
||||
cs.sendMessage(GREEN+"----Level: Low (Not likely hacking)----");
|
||||
for(Player player : low)
|
||||
for(String string : low)
|
||||
{
|
||||
cs.sendMessage(GREEN+player.getName());
|
||||
cs.sendMessage(GREEN+string);
|
||||
}
|
||||
}
|
||||
if(!med.isEmpty())
|
||||
{
|
||||
cs.sendMessage(YELLOW+"----Level: Medium (Possibly hacking/lagging)----");
|
||||
for(Player player : med)
|
||||
for(String string : med)
|
||||
{
|
||||
cs.sendMessage(YELLOW+player.getName());
|
||||
cs.sendMessage(YELLOW+string);
|
||||
}
|
||||
}
|
||||
if(!high.isEmpty())
|
||||
{
|
||||
cs.sendMessage(RED+"----Level: High (Probably hacking or bad connection)----");
|
||||
for(Player player : high)
|
||||
for(String string : high)
|
||||
{
|
||||
cs.sendMessage(RED+player.getName());
|
||||
cs.sendMessage(RED+string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +313,11 @@ public class CommandHandler implements CommandExecutor
|
||||
else if(args[0].equalsIgnoreCase("reset"))
|
||||
{
|
||||
handleReset(cs,args);
|
||||
}
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("spy"))
|
||||
{
|
||||
handleSpy(cs,args);
|
||||
}
|
||||
else
|
||||
{
|
||||
cs.sendMessage(RED+"Unrecognized command.");
|
||||
@@ -319,15 +382,15 @@ public class CommandHandler implements CommandExecutor
|
||||
int level = playerManager.getLevel(player);
|
||||
if(level <= MED_THRESHOLD)
|
||||
{
|
||||
low.add(player);
|
||||
low.add(player.getName());
|
||||
}
|
||||
else if(level <= HIGH_THRESHOLD)
|
||||
{
|
||||
med.add(player);
|
||||
med.add(player.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
high.add(player);
|
||||
high.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class Configuration
|
||||
private boolean alertXRay;
|
||||
private boolean autoUpdate;
|
||||
private boolean verboseStartup;
|
||||
private int fileLogLevel = 0;
|
||||
private String updateFolder;
|
||||
private List<String> worlds = new ArrayList<String>();
|
||||
|
||||
@@ -98,7 +99,12 @@ public class Configuration
|
||||
public String updateFolder()
|
||||
{
|
||||
return updateFolder;
|
||||
}
|
||||
}
|
||||
|
||||
public int getFileLogLevel()
|
||||
{
|
||||
return fileLogLevel;
|
||||
}
|
||||
|
||||
public final void load()
|
||||
{
|
||||
@@ -150,6 +156,12 @@ public class Configuration
|
||||
save();
|
||||
}
|
||||
alertXRay = config.getBoolean("XRay.Alert when xray is found");
|
||||
if(config.getString("System.File log level") == null)
|
||||
{
|
||||
config.set("System.File log level", 1);
|
||||
save();
|
||||
}
|
||||
fileLogLevel = config.getInt("System.File log level");
|
||||
}
|
||||
|
||||
public String getResult(String event)
|
||||
|
||||
@@ -40,12 +40,17 @@ public class EventListener implements Listener
|
||||
Anticheat.getManager().log(player.getName()+" "+message);
|
||||
PLAYER_MANAGER.increaseLevel(player);
|
||||
removeDecrease(player);
|
||||
logCheat(type);
|
||||
logCheat(type,player);
|
||||
}
|
||||
|
||||
private void logCheat(CheckType type)
|
||||
private void logCheat(CheckType type,Player player)
|
||||
{
|
||||
usageList.put(type, getCheats(type)+1);
|
||||
type.logUse(player);
|
||||
if(PLUGIN.getManager().getConfiguration().getFileLogLevel() == 2 && type.getUses(player) % 10 == 0)
|
||||
{
|
||||
PLUGIN.getManager().fileLog(player.getName()+" has triggered multiple "+type+" checks.");
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCheck(CheckType type)
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
@@ -81,7 +81,15 @@ public class AnticheatManager
|
||||
if(getConfiguration().logConsole())
|
||||
{
|
||||
LOGGER.log(Level.WARNING,"[AC] ".concat(message));
|
||||
}
|
||||
if(getConfiguration().getFileLogLevel() == 3)
|
||||
{
|
||||
fileLog(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void fileLog(String message)
|
||||
{
|
||||
FILE_LOGGER.log(Level.WARNING, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -50,6 +54,7 @@ public enum CheckType
|
||||
ITEM_SPAM("anticheat.itemspam");
|
||||
|
||||
private final String permission;
|
||||
private static final Map<String,Integer> level = new HashMap<String,Integer>();
|
||||
|
||||
private CheckType(String permission)
|
||||
{
|
||||
@@ -60,4 +65,28 @@ public enum CheckType
|
||||
{
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
public void logUse(Player player)
|
||||
{
|
||||
String name = player.getName();
|
||||
if(level.get(name) == null)
|
||||
{
|
||||
level.put(name, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int amount = level.get(name)+1;
|
||||
level.put(name, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public int getUses(Player player)
|
||||
{
|
||||
int use = 0;
|
||||
if(level.get(player.getName()) != null)
|
||||
{
|
||||
use = level.get(player.getName());
|
||||
}
|
||||
return use;
|
||||
}
|
||||
}
|
||||
@@ -45,11 +45,11 @@ public class PlayerManager
|
||||
|
||||
private static void reactMedium(Player player)
|
||||
{
|
||||
execute("Medium",player);
|
||||
String [] alert = new String[2];
|
||||
alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level.";
|
||||
alert[1] = ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!";
|
||||
Utilities.alert(alert);
|
||||
execute("Medium",player);
|
||||
String [] alert = new String[2];
|
||||
alert[0] = ChatColor.YELLOW+"[ALERT] "+ChatColor.WHITE+player.getName()+ChatColor.YELLOW+" has entered the MEDIUM hack level.";
|
||||
alert[1] = ChatColor.YELLOW+"[ALERT] This means they may be using a hacked client or may have a bad connection!";
|
||||
Utilities.alert(alert);
|
||||
}
|
||||
private static void reactHigh(Player player)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class Utilities
|
||||
{
|
||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.isOp())
|
||||
if(p.hasPermission("anticheat.alert") || p.hasPermission("anticheat.admin") || p.hasPermission("anticheat.mod") || p.isOp())
|
||||
{
|
||||
for(String msg : message)
|
||||
{
|
||||
@@ -61,6 +61,13 @@ public final class Utilities
|
||||
logger.log(Level.INFO,ChatColor.stripColor(msg));
|
||||
}
|
||||
}
|
||||
if(Anticheat.getManager().getConfiguration().getFileLogLevel() > 0)
|
||||
{
|
||||
for(String msg : message)
|
||||
{
|
||||
Anticheat.getManager().fileLog(ChatColor.stripColor(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
public static boolean cantStandAt(Block block)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user