mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 22:14:49 +00:00
Improved logging, fixes issue #23
This commit is contained in:
1 parent
3a0b7369c9
commit
e3f92436ea
9 files changed
+71
-20
No files matched your search
@@ -30,7 +30,7 @@ import java.util.logging.Logger;
|
||||
import net.h31ix.anticheat.event.*;
|
||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.Utilities;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.metrics.Metrics;
|
||||
import net.h31ix.anticheat.metrics.Metrics.Graph;
|
||||
import net.h31ix.anticheat.xray.XRayListener;
|
||||
@@ -70,7 +70,7 @@ public class Anticheat extends JavaPlugin
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
logger = getLogger();
|
||||
logger = this.getLogger();
|
||||
manager = new AnticheatManager(this);
|
||||
config = manager.getConfiguration();
|
||||
checkConfig();
|
||||
@@ -351,4 +351,9 @@ public class Anticheat extends JavaPlugin
|
||||
{
|
||||
return manager.getPlugin().getDescription().getVersion();
|
||||
}
|
||||
|
||||
public Logger getAnticheatLogger()
|
||||
{
|
||||
return this.getLogger();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.PlayerManager;
|
||||
import net.h31ix.anticheat.manage.Utilities;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.manage.*;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.io.IOException;
|
||||
import java.util.logging.*;
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import net.h31ix.anticheat.Configuration;
|
||||
import net.h31ix.anticheat.util.ConsoleFormatter;
|
||||
import net.h31ix.anticheat.util.FileFormatter;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
|
||||
/**
|
||||
@@ -38,8 +40,7 @@ public class AnticheatManager
|
||||
private PlayerManager playerManager = null;
|
||||
private CheckManager checkManager = null;
|
||||
private Backend backend = null;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private static final Logger FILE_LOGGER = Logger.getLogger(AnticheatManager.class.getName());
|
||||
private Logger LOGGER, FILE_LOGGER;
|
||||
private static Handler handler;
|
||||
private static final int LOG_LEVEL_HIGH = 3;
|
||||
|
||||
@@ -47,6 +48,8 @@ public class AnticheatManager
|
||||
{
|
||||
plugin = instance;
|
||||
// now load all the others!!!!!
|
||||
LOGGER = plugin.getAnticheatLogger();
|
||||
FILE_LOGGER = LOGGER;
|
||||
configuration = new Configuration(this);
|
||||
xrayTracker = new XRayTracker();
|
||||
playerManager = new PlayerManager(this);
|
||||
@@ -60,21 +63,25 @@ public class AnticheatManager
|
||||
file.mkdir();
|
||||
}
|
||||
handler = new FileHandler(plugin.getDataFolder()+"/log/anticheat.log.%u.txt",true);
|
||||
handler.setFormatter(new FileFormatter());
|
||||
} catch (IOException ex) {
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
LOGGER.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
handler.setFormatter(new SimpleFormatter());
|
||||
FILE_LOGGER.setUseParentHandlers(false);
|
||||
FILE_LOGGER.addHandler(handler);
|
||||
LOGGER.setUseParentHandlers(false);
|
||||
Handler chandler = new ConsoleHandler();
|
||||
chandler.setFormatter(new ConsoleFormatter());
|
||||
LOGGER.addHandler(chandler);
|
||||
}
|
||||
|
||||
public void log(String message)
|
||||
{
|
||||
if(getConfiguration().logConsole())
|
||||
{
|
||||
LOGGER.log(Level.WARNING,"[AC] ".concat(message));
|
||||
LOGGER.warning(message);
|
||||
}
|
||||
if(getConfiguration().getFileLogLevel() == LOG_LEVEL_HIGH)
|
||||
{
|
||||
@@ -84,7 +91,7 @@ public class AnticheatManager
|
||||
|
||||
public void fileLog(String message)
|
||||
{
|
||||
FILE_LOGGER.log(Level.WARNING, message);
|
||||
FILE_LOGGER.warning(message);
|
||||
}
|
||||
|
||||
public Anticheat getPlugin()
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import com.gmail.nossr50.datatypes.AbilityType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.h31ix.anticheat.Configuration;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class ConsoleFormatter extends Formatter {
|
||||
|
||||
private static final DateFormat format = new SimpleDateFormat("h:mm:ss");
|
||||
private static final String lineSep = System.getProperty("line.separator");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder output = new StringBuilder()
|
||||
.append(record.getMessage()).append(' ');
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class FileFormatter extends Formatter {
|
||||
|
||||
private static final DateFormat format = new SimpleDateFormat("h:mm:ss");
|
||||
private static final String lineSep = System.getProperty("line.separator");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder output = new StringBuilder()
|
||||
.append("[")
|
||||
.append(record.getLevel()).append('|')
|
||||
.append(format.format(new Date(record.getMillis())))
|
||||
.append("]: ")
|
||||
.append(record.getMessage()).append(' ')
|
||||
.append(lineSep);
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+2
-12
@@ -16,12 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -53,19 +51,11 @@ public final class Utilities
|
||||
}
|
||||
if(Anticheat.getManager().getConfiguration().logConsole())
|
||||
{
|
||||
Logger logger = Logger.getLogger("Minecraft");
|
||||
for(String msg : message)
|
||||
{
|
||||
logger.log(Level.INFO,ChatColor.stripColor(msg));
|
||||
Anticheat.getManager().log(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