Add logger

This commit is contained in:
Jesse Boyd
2016-05-22 00:45:48 +10:00
parent dc4776d16b
commit 4ceb54b566
8 changed files with 70 additions and 19 deletions

View File

@ -539,7 +539,7 @@ public class MemorySection implements ConfigurationSection {
List<?> list = getList(path);
if (list == null) {
PS.get().IMP.log(path + " is null");
PS.get().log(path + " is null");
return new ArrayList<>(0);
}

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.logger.ILogger;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
@ -20,7 +21,7 @@ import com.intellectualcrafters.plot.util.WorldUtil;
import java.io.File;
import java.util.List;
public interface IPlotMain {
public interface IPlotMain extends ILogger {
/**
* Log a message to console.

View File

@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.logger.ILogger;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
@ -48,7 +49,6 @@ import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap;
import com.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -86,6 +86,7 @@ public class PS {
private static PS instance;
public final IPlotMain IMP;
public ILogger LOGGER;
private final HashSet<Integer> plotAreaHashCheck = new HashSet<>();
/**
* All plot areas mapped by world (quick world access).
@ -130,6 +131,7 @@ public class PS {
PS.instance = this;
this.thread = Thread.currentThread();
this.IMP = iPlotMain;
this.LOGGER = iPlotMain;
this.platform = platform;
this.version = this.IMP.getPluginVersion();
try {
@ -295,6 +297,27 @@ public class PS {
return PS.instance;
}
/**
* Set the logger
* @see com.intellectualcrafters.plot.logger.DelegateLogger
* @see #getLogger()
* @param logger
*/
public void setLogger(ILogger logger) {
if (logger == null) {
throw new IllegalArgumentException("Logger may not be null");
}
LOGGER = logger;
}
/**
* Get the current logger
* @return
*/
public ILogger getLogger() {
return LOGGER;
}
/**
* Log a message to the IPlotMain logger.
*
@ -302,7 +325,7 @@ public class PS {
* @see IPlotMain#log(String)
*/
public static void log(Object message) {
PS.get().IMP.log(StringMan.getString(message));
PS.get().LOGGER.log(StringMan.getString(message));
}
/**

View File

@ -0,0 +1,22 @@
package com.intellectualcrafters.plot.logger;
public class DelegateLogger implements ILogger {
private final ILogger parent;
public DelegateLogger(ILogger parent) {
if (parent == null) {
throw new IllegalArgumentException("Parent cannot be null");
}
this.parent = parent;
}
public ILogger getParent() {
return parent;
}
@Override
public void log(String message) {
parent.log(message);
}
}

View File

@ -0,0 +1,5 @@
package com.intellectualcrafters.plot.logger;
public interface ILogger {
public void log(String message);
}

View File

@ -344,7 +344,7 @@ public abstract class PlotArea {
}
for (Entry<String, Object> stringObjectEntry : options.entrySet()) {
if (!config.contains(stringObjectEntry.getKey())) {
PS.get().IMP.log(stringObjectEntry.toString());
PS.get().log(stringObjectEntry.toString());
config.set(stringObjectEntry.getKey(), stringObjectEntry.getValue());
}
}