Error handling implemented

This commit is contained in:
Norbi Peti 2016-11-02 17:54:49 +01:00
parent 3173c62cc5
commit 8e5d371a9f
5 changed files with 161 additions and 154 deletions

View file

@ -98,7 +98,7 @@
<dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
<artifactId>Towny</artifactId>
<version>master-SNAPSHOT</version>
<version>master-v1.0-g0f7e08b-32</version>
</dependency>
</dependencies>
<organization>

View file

@ -7,7 +7,7 @@ import java.util.logging.Logger;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.discordplugin.EventExceptionDiscordSender;
import buttondevteam.lib.EventExceptionCoreHandler;
import buttondevteam.lib.EventExceptionHandler;
import buttondevteam.lib.TBMCPlayer;
@ -25,7 +25,7 @@ public class MainPlugin extends JavaPlugin {
logger = getLogger();
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
EventExceptionHandler.registerEvents(new PlayerListener(), this, new EventExceptionDiscordSender());
EventExceptionHandler.registerEvents(new PlayerListener(), this, new EventExceptionCoreHandler());
}
@Override

View file

@ -0,0 +1,13 @@
package buttondevteam.lib;
import org.bukkit.event.Event;
public class EventExceptionCoreHandler extends EventExceptionHandler {
@Override
public boolean handle(Throwable ex, Event event) {
TBMCCoreAPI.SendException("An error occured while executing " + event.getEventName() + "!", ex);
return true;
}
}

View file

@ -92,7 +92,7 @@ public final class TBMCCoreAPI {
return body;
}
public static void SendException(String sourcemsg, Exception e) {
public static void SendException(String sourcemsg, Throwable e) {
Bukkit.getPluginManager().callEvent(new TBMCExceptionEvent(sourcemsg, e));
Bukkit.getLogger().warning(sourcemsg);
e.printStackTrace();

View file

@ -1,14 +1,8 @@
package buttondevteam.lib;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import buttondevteam.lib.TBMCPlayer.InfoTarget;
/**
* <p>
* This event gets called (ideally) each time an exception occurs in a TBMC plugin. To call it, use {@link TBMCCoreAPI#SendException(String, Exception)}.
@ -21,9 +15,9 @@ public class TBMCExceptionEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private String sourcemsg;
private Exception exception;
private Throwable exception;
TBMCExceptionEvent(String sourcemsg, Exception exception) {
TBMCExceptionEvent(String sourcemsg, Throwable exception) {
this.sourcemsg = sourcemsg;
this.exception = exception;
}
@ -42,7 +36,7 @@ public class TBMCExceptionEvent extends Event {
*
* @return The exception
*/
public Exception getException() {
public Throwable getException() {
return exception;
}