Adapt to LogUtil use.

This commit is contained in:
asofold 2012-11-09 08:47:24 +01:00
parent b158d5369a
commit 8ac003508f
17 changed files with 65 additions and 51 deletions

View File

@ -52,8 +52,8 @@ import fr.neatmonster.nocheatplus.permissions.PermissionUtil.CommandProtectionEn
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
import fr.neatmonster.nocheatplus.utilities.TickTask;
import fr.neatmonster.nocheatplus.utilities.Updates;
@ -218,7 +218,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI
if (listener instanceof IHaveMethodOrder){
// TODO: Might log the order too, might prevent registration ?
// TODO: Alternative: queue listeners and register after startup (!)
CheckUtils.logWarning("[NoCheatPlus] Listener demands registration order, but listeners are not managed: " + listener.getClass().getName());
LogUtil.logWarning("[NoCheatPlus] Listener demands registration order, but listeners are not managed: " + listener.getClass().getName());
}
}
}
@ -283,9 +283,9 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI
listenerManager.setRegisterDirectly(false);
listenerManager.clear();
// Tell the server administrator the we finished unloading NoCheatPlus.
CheckUtils.logInfo("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
}
// Tell the server administrator the we finished unloading NoCheatPlus.
LogUtil.logInfo("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
}
/**
* Does not undo 100%, but restore old permission, permission-message, label (unlikely to be changed), permission default.
@ -442,10 +442,10 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI
}
});
}
// Tell the server administrator that we finished loading NoCheatPlus now.
CheckUtils.logInfo("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
}
// Tell the server administrator that we finished loading NoCheatPlus now.
LogUtil.logInfo("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
}
// public void onPlayerJoinLow(final PlayerJoinEvent event) {
// /*

View File

@ -9,7 +9,7 @@ import fr.neatmonster.nocheatplus.actions.types.CancelAction;
import fr.neatmonster.nocheatplus.actions.types.CommandAction;
import fr.neatmonster.nocheatplus.actions.types.DummyAction;
import fr.neatmonster.nocheatplus.actions.types.LogAction;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/*
* MMP"""""""MM dP oo MM""""""""`M dP
@ -98,7 +98,7 @@ public class ActionFactory {
}
list.setActions(vl, createActions(def.split("\\s+")));
} catch (final Exception e) {
CheckUtils.logWarning("[NoCheatPlus] Couldn't parse action definition 'vl:" + s + "'.");
LogUtil.logWarning("[NoCheatPlus] Couldn't parse action definition 'vl:" + s + "'.");
}
}
@ -121,7 +121,7 @@ public class ActionFactory {
try {
actions.add(createAction(def));
} catch (final IllegalArgumentException e) {
CheckUtils.logWarning("[NoCheatPlus] Failed to create action: " + e.getMessage());
LogUtil.logWarning("[NoCheatPlus] Failed to create action: " + e.getMessage());
actions.add(new DummyAction(def));
}
}
@ -152,7 +152,7 @@ public class ActionFactory {
delay = Integer.parseInt(parts[1]);
repeat = Integer.parseInt(parts[2]);
} catch (final Exception e) {
CheckUtils.logWarning("[NoCheatPlus] Couldn't parse details of command '" + definition
LogUtil.logWarning("[NoCheatPlus] Couldn't parse details of command '" + definition
+ "', will use default values instead.");
delay = 0;
repeat = 0;
@ -189,7 +189,7 @@ public class ActionFactory {
toChat = parts[3].contains("i");
toFile = parts[3].contains("f");
} catch (final Exception e) {
CheckUtils.logWarning("[NoCheatPlus] Couldn't parse details of log action '" + definition
LogUtil.logWarning("[NoCheatPlus] Couldn't parse details of log action '" + definition
+ "', will use default values instead.");
e.printStackTrace();
delay = 0;

View File

@ -4,7 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandException;
import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/*
* MM'""""'YMM dP
@ -54,7 +54,7 @@ public class CommandAction extends ActionWithParameters {
try {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (final CommandException e) {
CheckUtils.logWarning("[NoCheatPlus] Failed to execute the command '" + command + "': " + e.getMessage()
LogUtil.logWarning("[NoCheatPlus] Failed to execute the command '" + command + "': " + e.getMessage()
+ ", please check if everything is setup correct.");
} catch (final Exception e) {
// I don't care in this case, your problem if your command fails.

View File

@ -10,6 +10,7 @@ import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/*
* M""MMMMMMMM MMP"""""""MM dP oo
@ -77,7 +78,7 @@ public class LogAction extends ActionWithParameters {
otherPlayer.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE
+ CheckUtils.replaceColors(message));
if (toConsole && configurationFile.getBoolean(ConfPaths.LOGGING_CONSOLE))
CheckUtils.logInfo("[NoCheatPlus] " + CheckUtils.removeColors(message));
LogUtil.logInfo("[NoCheatPlus] " + CheckUtils.removeColors(message));
if (toFile && configurationFile.getBoolean(ConfPaths.LOGGING_FILE))
CheckUtils.fileLogger.info(CheckUtils.removeColors(message));
}

View File

@ -3,7 +3,7 @@ package fr.neatmonster.nocheatplus.checks;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
public abstract class AsyncCheck extends Check {
@ -17,7 +17,7 @@ public abstract class AsyncCheck extends Check {
if (!type.isEnabled(player) || type.hasCachedPermission(player))
return false;
} catch (final Exception e) {
CheckUtils.scheduleOutput(e);
LogUtil.scheduleLogSevere(e);
}
return !NCPExemptionManager.isExempted(player, type);
}

View File

@ -20,6 +20,7 @@ import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/**
* Some alternative more or less advanced analysis methods.
@ -293,7 +294,7 @@ public class Text extends AsyncCheck implements INotifyReload{
debugParts.add("Normal: min=" + CheckUtils.fdec3.format(cc.textFreqNormMin) +", weight=" + CheckUtils.fdec3.format(cc.textFreqNormWeight) + " => accumulated=" + CheckUtils.fdec3.format(accumulated));
debugParts.add("Short-term: min=" + CheckUtils.fdec3.format(cc.textFreqShortTermMin) +", weight=" + CheckUtils.fdec3.format(cc.textFreqShortTermWeight) + " => accumulated=" + CheckUtils.fdec3.format(shortTermAccumulated));
debugParts.add("vl: " + CheckUtils.fdec3.format(data.textVL));
CheckUtils.scheduleOutputJoined(debugParts, " | ");
LogUtil.scheduleLogInfo(debugParts, " | ");
debugParts.clear();
}

View File

@ -20,6 +20,7 @@ import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
public class CombinedConfig extends ACheckConfig {
@ -81,7 +82,7 @@ public class CombinedConfig extends ACheckConfig {
}
catch (final Exception e){
error = true;
CheckUtils.logWarning("[NoCheatPlus] Bad damage cause (combined.invulnerable.ignore): " + input);
LogUtil.logWarning("[NoCheatPlus] Bad damage cause (combined.invulnerable.ignore): " + input);
}
}
// Read modifiers for causes.
@ -99,11 +100,11 @@ public class CombinedConfig extends ACheckConfig {
}
catch (final Exception e){
error = true;
CheckUtils.logWarning("[NoCheatPlus] Bad damage cause (combined.invulnerable.modifiers): " + input);
LogUtil.logWarning("[NoCheatPlus] Bad damage cause (combined.invulnerable.modifiers): " + input);
}
}
invulnerableModifierDefault = defaultMod;
if (error) CheckUtils.logInfo("[NoCheatPlus] Damage causes can be: " + CheckUtils.join(Arrays.asList(DamageCause.values()), ", "));
if (error) LogUtil.logInfo("[NoCheatPlus] Damage causes can be: " + CheckUtils.join(Arrays.asList(DamageCause.values()), ", "));
invulnerableTriggerAlways = config.getBoolean(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_ALWAYS);
invulnerableTriggerFallDistance = config.getBoolean(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_FALLDISTANCE);
yawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE);

View File

@ -46,6 +46,7 @@ import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/*
@ -492,7 +493,7 @@ public class MovingListener implements Listener {
if (!restored){
// TODO: correct the location ?
NoCheatPlus.denyLogin(player.getName(), 24L * 60L * 60L * 1000L);
CheckUtils.logSevere("[NCP] could not restore location for " + player.getName() + " deny login for 24 hours");
LogUtil.logSevere("[NCP] could not restore location for " + player.getName() + " deny login for 24 hours");
}
// TODO: reset the bounding box of the player ?
CheckUtils.onIllegalMove(player);

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
public class BanCommand extends DelayableCommand {
@ -41,7 +41,7 @@ public class BanCommand extends DelayableCommand {
player.kickPlayer(reason);
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name);
offlinePlayer.setBanned(true);
CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Banned " + offlinePlayer.getName() + " : " + reason);
LogUtil.logInfo("[NoCheatPlus] (" + sender.getName() + ") Banned " + offlinePlayer.getName() + " : " + reason);
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
public class KickCommand extends DelayableCommand {
@ -38,7 +38,7 @@ public class KickCommand extends DelayableCommand {
Player player = Bukkit.getPlayerExact(name);
if (player == null) return;
player.kickPlayer(reason);
CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " : " + reason);
LogUtil.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " : " + reason);
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
public class TempKickCommand extends DelayableCommand {
@ -51,6 +51,6 @@ public class TempKickCommand extends DelayableCommand {
NoCheatPlus.denyLogin(name, duration);
if (player == null) return;
player.kickPlayer(reason);
CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " for " + duration/60000 +" minutes: " + reason);
LogUtil.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " for " + duration/60000 +" minutes: " + reason);
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.Plugin;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/**
* listener registered for one event only. Allows to delegate to other registered listeners.
@ -87,7 +87,7 @@ public class GenericListener<E extends Event> implements Listener, EventExecutor
}
@Override
public final void execute(final Listener listener, final Event event){
public void execute(final Listener listener, final Event event){
if (!clazz.isAssignableFrom(event.getClass())){
// Strange but true.
return;
@ -102,15 +102,25 @@ public class GenericListener<E extends Event> implements Listener, EventExecutor
if (!isCancellable || !entry.ignoreCancelled || !cancellable.isCancelled()) entry.method.invoke(entry.listener, event);
} catch (Throwable t) {
// IllegalArgumentException IllegalAccessException InvocationTargetException
final EventException e = new EventException(t, "GenericListener<" + clazz.getName() +"> @" + priority +" encountered an exception for " + entry.listener.getClass().getName() + " with method " + entry.method.toGenericString());
// TODO: log it / more details!
if (event.isAsynchronous()) CheckUtils.scheduleOutput(e);
else CheckUtils.logSevere(e);
onError(entry, event, t);
}
}
}
private void onError(final MethodEntry entry, final Event event, final Throwable t) {
final String descr = "GenericListener<" + clazz.getName() +"> @" + priority +" encountered an exception for " + entry.listener.getClass().getName() + " with method " + entry.method.toGenericString();
try{
final EventException e = new EventException(t, descr);
// TODO: log it / more details!
if (event.isAsynchronous()) LogUtil.scheduleLogSevere(e);
else LogUtil.logSevere(e);
}
catch (Throwable t2){
LogUtil.scheduleLogSevere("Could not log exception: " + descr);
}
}
public void register(Plugin plugin) {
if (registered) return;
Bukkit.getPluginManager().registerEvent(clazz, this, priority, this, plugin, false);

View File

@ -16,7 +16,7 @@ import org.bukkit.plugin.Plugin;
import fr.neatmonster.nocheatplus.components.ComponentWithName;
import fr.neatmonster.nocheatplus.event.GenericListener.MethodEntry;
import fr.neatmonster.nocheatplus.event.GenericListener.MethodEntry.MethodOrder;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LogUtil;
/**
* This class allows to register event-listeners which will all be called form within one event handler per event+priority combination.<br>
@ -135,17 +135,17 @@ public class ListenerManager {
try{
method.setAccessible(true);
} catch (SecurityException e){
CheckUtils.logWarning("[ListenerManager] Can not set method accessible: " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
LogUtil.logWarning("[ListenerManager] Can not set method accessible: " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
}
}
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length != 1){
CheckUtils.logWarning("[ListenerManager] Bad method signature (number of arguments not 1): " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
LogUtil.logWarning("[ListenerManager] Bad method signature (number of arguments not 1): " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
continue;
}
Class<?> eventType = argTypes[0];
if (!Event.class.isAssignableFrom(eventType)){
CheckUtils.logWarning("[ListenerManager] Bad method signature (argument does not extend Event): " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
LogUtil.logWarning("[ListenerManager] Bad method signature (argument does not extend Event): " + method.toGenericString() +" registered in " + clazz.getName()+ ", ignoring it!");
continue;
}
Class<? extends Event> checkedEventType = eventType.asSubclass(Event.class);

View File

@ -531,8 +531,8 @@ public class BlockProperties {
public static void dumpBlocks(boolean all) {
List<String> missing = new LinkedList<String>();
if (all) {
CheckUtils.logInfo("[NoCheatPlus] Dump block properties for fastbreak check:");
CheckUtils.logInfo("--- Present entries -------------------------------");
LogUtil.logInfo("[NoCheatPlus] Dump block properties for fastbreak check:");
LogUtil.logInfo("--- Present entries -------------------------------");
}
for (int i = 0; i < blocks.length; i++){
String mat;
@ -548,13 +548,13 @@ public class BlockProperties {
if (mat.equals("?")) continue;
missing.add("* MISSING "+i + "(" + mat +") ");
}
else if (all) CheckUtils.logInfo(i + ": (" + mat + ") " + blocks[i].toString());
else if (all) LogUtil.logInfo(i + ": (" + mat + ") " + blocks[i].toString());
}
if (!missing.isEmpty()){
Bukkit.getLogger().warning("[NoCheatPlus] The block breaking data is incomplete, default to allow instant breaking:");
CheckUtils.logWarning("--- Missing entries -------------------------------");
LogUtil.logWarning("--- Missing entries -------------------------------");
for (String spec : missing){
CheckUtils.logWarning(spec);
LogUtil.logWarning(spec);
}
}
}
@ -1016,7 +1016,7 @@ public class BlockProperties {
// Ignore passable.
for (final String input : config.getStringList(pathPrefix + ConfPaths.SUB_IGNOREPASSABLE)){
final Integer id = ConfigFile.parseTypeId(input);
if (id == null || id < 0 || id >= 4096) CheckUtils.logWarning("[NoCheatplus] Bad block id (" + pathPrefix + ConfPaths.SUB_IGNOREPASSABLE + "): " + input);
if (id == null || id < 0 || id >= 4096) LogUtil.logWarning("[NoCheatplus] Bad block id (" + pathPrefix + ConfPaths.SUB_IGNOREPASSABLE + "): " + input);
else blockFlags[id] |= F_IGN_PASSABLE;
}
}

View File

@ -41,7 +41,7 @@ public class LagMeasureTask implements Runnable {
try {
Bukkit.getServer().getScheduler().cancelTask(instance.lagMeasureTaskId);
} catch (final Exception e) {
CheckUtils.logWarning("[NoCheatPlus] Couldn't cancel LagMeasureTask: " + e.getMessage() + ".");
LogUtil.logWarning("[NoCheatPlus] Couldn't cancel LagMeasureTask: " + e.getMessage() + ".");
}
instance.lagMeasureTaskId = -1;
}
@ -98,9 +98,9 @@ public class LagMeasureTask implements Runnable {
// Show the debug messages.
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUG))
if (oldStatus != skipCheck && skipCheck)
CheckUtils.logInfo("[NoCheatPlus] Detected server lag, some checks will not work.");
LogUtil.logInfo("[NoCheatPlus] Detected server lag, some checks will not work.");
else if (oldStatus != skipCheck && !skipCheck)
CheckUtils.logInfo("[NoCheatPlus] Server lag seems to have stopped, reenabling checks.");
LogUtil.logInfo("[NoCheatPlus] Server lag seems to have stopped, reenabling checks.");
final long time = System.currentTimeMillis();
lastInGameSecondDuration = time - lastInGameSecondTime;

View File

@ -81,7 +81,7 @@ public final class Stats {
if ( ts > tsStats+periodStats){
tsStats = ts;
// print out stats !
CheckUtils.logInfo(getStatsStr());
LogUtil.logInfo(getStatsStr());
}
}
}

View File

@ -177,7 +177,7 @@ public class TickTask implements Runnable {
if (!delayedActions.isEmpty()) executeActions();
if (!permissionUpdates.isEmpty()) updatePermissions();
if (timeLast > time) {
CheckUtils.logSevere("[NoCheatPlus] System time ran backwards (" + timeLast + "->" + time + "), clear all data and history...");
LogUtil.logSevere("[NoCheatPlus] System time ran backwards (" + timeLast + "->" + time + "), clear all data and history...");
DataManager.clearData(CheckType.ALL);
}
timeLast = time;