Search in sources :

Example 1 with MagicErrorEvent

use of com.elmakers.mine.bukkit.api.event.MagicErrorEvent in project MagicPlugin by elBukkit.

the class MagicLogger method log.

@Override
public void log(LogRecord record) {
    if (silent)
        return;
    if (!capture || (!record.getLevel().equals(Level.WARNING) && !record.getLevel().equals(Level.SEVERE)) || record.getThrown() != null) {
        super.log(record);
    }
    Server server = Bukkit.getServer();
    CompatibilityUtils compatibility = CompatibilityLib.isInitialized() ? CompatibilityLib.getCompatibilityUtils() : null;
    String message = record.getMessage();
    if (message != null) {
        message = message.replace("[Magic] ", "");
    }
    LogMessage logMessage = new LogMessage(context, message);
    if (record.getLevel().equals(Level.WARNING)) {
        synchronized (warnings) {
            pendingWarningCount++;
            warnings.add(logMessage);
            if (server != null) {
                MagicWarningEvent event = new MagicWarningEvent(record, context, pendingWarningCount, capture);
                if (compatibility != null && compatibility.isPrimaryThread()) {
                    server.getPluginManager().callEvent(event);
                } else if (plugin != null && plugin.isEnabled()) {
                    server.getScheduler().runTask(plugin, new CallEventTask(event));
                }
            }
        }
    } else if (record.getLevel().equals(Level.SEVERE)) {
        synchronized (errors) {
            pendingErrorCount++;
            errors.add(logMessage);
            if (server != null) {
                MagicErrorEvent event = new MagicErrorEvent(record, context, pendingErrorCount, capture);
                if (compatibility != null && compatibility.isPrimaryThread()) {
                    server.getPluginManager().callEvent(event);
                } else if (plugin != null && plugin.isEnabled()) {
                    server.getScheduler().runTask(plugin, new CallEventTask(event));
                }
            }
        }
    }
}
Also used : MagicWarningEvent(com.elmakers.mine.bukkit.api.event.MagicWarningEvent) CallEventTask(com.elmakers.mine.bukkit.tasks.CallEventTask) Server(org.bukkit.Server) MagicErrorEvent(com.elmakers.mine.bukkit.api.event.MagicErrorEvent) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)

Aggregations

MagicErrorEvent (com.elmakers.mine.bukkit.api.event.MagicErrorEvent)1 MagicWarningEvent (com.elmakers.mine.bukkit.api.event.MagicWarningEvent)1 CallEventTask (com.elmakers.mine.bukkit.tasks.CallEventTask)1 CompatibilityUtils (com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)1 Server (org.bukkit.Server)1