Error handling implemented
This commit is contained in:
parent
3173c62cc5
commit
8e5d371a9f
5 changed files with 161 additions and 154 deletions
2
pom.xml
2
pom.xml
|
@ -98,7 +98,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
<artifactId>Towny</artifactId>
|
<artifactId>Towny</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>master-v1.0-g0f7e08b-32</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<organization>
|
<organization>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.logging.Logger;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.EventExceptionDiscordSender;
|
import buttondevteam.lib.EventExceptionCoreHandler;
|
||||||
import buttondevteam.lib.EventExceptionHandler;
|
import buttondevteam.lib.EventExceptionHandler;
|
||||||
import buttondevteam.lib.TBMCPlayer;
|
import buttondevteam.lib.TBMCPlayer;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public class MainPlugin extends JavaPlugin {
|
||||||
logger = getLogger();
|
logger = getLogger();
|
||||||
|
|
||||||
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
|
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
|
@Override
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -92,7 +92,7 @@ public final class TBMCCoreAPI {
|
||||||
return body;
|
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.getPluginManager().callEvent(new TBMCExceptionEvent(sourcemsg, e));
|
||||||
Bukkit.getLogger().warning(sourcemsg);
|
Bukkit.getLogger().warning(sourcemsg);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
package buttondevteam.lib;
|
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.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import buttondevteam.lib.TBMCPlayer.InfoTarget;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This event gets called (ideally) each time an exception occurs in a TBMC plugin. To call it, use {@link TBMCCoreAPI#SendException(String, Exception)}.
|
* 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 static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private String sourcemsg;
|
private String sourcemsg;
|
||||||
private Exception exception;
|
private Throwable exception;
|
||||||
|
|
||||||
TBMCExceptionEvent(String sourcemsg, Exception exception) {
|
TBMCExceptionEvent(String sourcemsg, Throwable exception) {
|
||||||
this.sourcemsg = sourcemsg;
|
this.sourcemsg = sourcemsg;
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +36,7 @@ public class TBMCExceptionEvent extends Event {
|
||||||
*
|
*
|
||||||
* @return The exception
|
* @return The exception
|
||||||
*/
|
*/
|
||||||
public Exception getException() {
|
public Throwable getException() {
|
||||||
return exception;
|
return exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue