If the debug level is >= 1: stacktrace

This commit is contained in:
main() 2013-03-18 18:02:55 +01:00
parent a8040abd52
commit 4a66a2f5bb
3 changed files with 19 additions and 7 deletions

View File

@ -80,6 +80,7 @@ import com.onarandombox.MultiverseCore.utils.MVPlayerSession;
import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety;
import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation;
import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
import com.onarandombox.MultiverseCore.utils.VaultHandler;
import com.onarandombox.MultiverseCore.utils.WorldManager;
import com.pneumaticraft.commandhandler.CommandHandler;
@ -218,6 +219,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
private BlockSafety blockSafety;
private LocationManipulation locationManipulation;
private SafeTTeleporter safeTTeleporter;
private UnsafeCallWrapper unsafeCallWrapper;
private File serverFolder = new File(System.getProperty("user.dir"));
@ -238,6 +240,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.locationManipulation = new SimpleLocationManipulation();
// Setup our SafeTTeleporter
this.safeTTeleporter = new SimpleSafeTTeleporter(this);
this.unsafeCallWrapper = new UnsafeCallWrapper(this);
}
/**
@ -1285,4 +1288,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
public Buscript getScriptAPI() {
return buscript;
}
public UnsafeCallWrapper getUnsafeCallWrapper() {
return this.unsafeCallWrapper;
}
}

View File

@ -1,15 +1,18 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.Core;
import java.util.concurrent.Callable;
/**
* Wraps calls that could result in exceptions that are not Multiverse's fault.
*/
public final class UnsafeCallWrapper {
private UnsafeCallWrapper() {
throw new UnsupportedOperationException();
public class UnsafeCallWrapper {
private final Core core;
public UnsafeCallWrapper(Core core) {
this.core = core;
}
/**
@ -23,7 +26,7 @@ public final class UnsafeCallWrapper {
* @param <T> The type of the return value.
* @return The return value or null if the call failed.
*/
public static <T> T wrap(Callable<T> callable, String plugin, String action, Object... formatArgs) {
public <T> T wrap(Callable<T> callable, String plugin, String action, Object... formatArgs) {
try {
// We're ready to catch you! JUMP!
return callable.call();
@ -31,8 +34,10 @@ public final class UnsafeCallWrapper {
Object[] actualFormatArgs = new Object[formatArgs.length + 1];
System.arraycopy(formatArgs, 0, actualFormatArgs, 0, formatArgs.length);
actualFormatArgs[formatArgs.length] = t;
Logging.warning(action, actualFormatArgs);
Logging.warning(action, actualFormatArgs);
Logging.warning("This is a bug in %s, NOT a bug in Multiverse!", plugin);
if (core.getMVConfig().getGlobalDebug() >= 1)
t.printStackTrace();
return null;
}
}

View File

@ -251,7 +251,7 @@ public class WorldManager implements MVWorldManager {
if (myPlugin == null) {
return null;
} else {
return UnsafeCallWrapper.wrap(new Callable<ChunkGenerator>() {
return plugin.getUnsafeCallWrapper().wrap(new Callable<ChunkGenerator>() {
@Override
public ChunkGenerator call() throws Exception {
return myPlugin.getDefaultWorldGenerator(worldName, generatorID);
@ -379,7 +379,7 @@ public class WorldManager implements MVWorldManager {
boolean generatorSuccess = true;
if ((world.getGenerator() != null) && (!world.getGenerator().equals("null")))
generatorSuccess = null != UnsafeCallWrapper.wrap(new Callable<Object>() {
generatorSuccess = null != plugin.getUnsafeCallWrapper().wrap(new Callable<Object>() {
@Override
public Object call() throws Exception {
creator.generator(world.getGenerator());