diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index 219eab8..0000000 --- a/jitpack.yml +++ /dev/null @@ -1,10 +0,0 @@ -jdk: - - oraclejdk8 -#before_install: -# - ./prepareEnvironment.sh -install: - - echo "Downloading Towny JAR..." - - 'wget -O "Towny.jar" --header="Accept-Language: en-us,en;q=0.5" http://palmergames.com/file-repo/Towny%20Advanced/Development/0.91.1.5/Towny.jar' - - mvn install:install-file -Dfile=Towny.jar -DgroupId=com.github.TBMCPlugins.ButtonCore -DartifactId=Towny -Dversion=master-SNAPSHOT -Dpackaging=jar - - mvn clean install -DskipTests -# - rm -r ~/.m2/repository/com/palmergames/Towny/ \ No newline at end of file diff --git a/src/main/java/buttondevteam/core/EventExceptionHandler.java b/src/main/java/buttondevteam/core/EventExceptionHandler.java deleted file mode 100644 index 2c83a23..0000000 --- a/src/main/java/buttondevteam/core/EventExceptionHandler.java +++ /dev/null @@ -1,154 +0,0 @@ -package buttondevteam.core; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.Validate; -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.plugin.EventExecutor; -import org.bukkit.plugin.IllegalPluginAccessException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredListener; - -import com.google.common.collect.Lists; - -public abstract class EventExceptionHandler { // https://gist.github.com/aadnk/5430459 - // For wrapping a registered listener - private static class ExceptionRegisteredListener extends RegisteredListener { - /** - * Represents an event executor that does nothing. This is not really necessary in the current - * implementation of CraftBukkit, but we will take no chances. - */ - private static EventExecutor NULL_EXECUTOR = new EventExecutor() { - @Override - public void execute(Listener listener, Event event) throws EventException { - // Do nothing - } - }; - - private final RegisteredListener delegate; - private final EventExceptionHandler handler; - - public ExceptionRegisteredListener(RegisteredListener delegate, EventExceptionHandler handler) { - super(delegate.getListener(), NULL_EXECUTOR, delegate.getPriority(), - delegate.getPlugin(), delegate.isIgnoringCancelled()); - this.delegate = delegate; - this.handler = handler; - } - - @Override - public void callEvent(Event event) throws EventException { - try { - delegate.callEvent(event); - } catch (EventException e) { - if (!handler.handle(e.getCause(), event)) { - throw e; - } - } catch (Throwable e) { - if (!handler.handle(e, event)) { - doThrow(e); - } - } - } - - // WARNING: HORRIBLE, HORRIBLE HACK to get around checked exceptions - private static void doThrow(Throwable e) { - ExceptionRegisteredListener. doThrowInner(e); - } - - @SuppressWarnings("unchecked") - private static void doThrowInner(Throwable e) throws E { - throw (E) e; - } - } - - /** - * Register Bukkit event handlers with a given exception handler. - * @param listener - a class of event handlers. - * @param plugin - the current plugin. - * @param handler - exception handler. - */ - public static void registerEvents(Listener listener, Plugin plugin, EventExceptionHandler handler) { - Validate.notNull(plugin, "Plugin cannot be NULL."); - - registerEvents(plugin.getServer().getPluginManager(), listener, plugin, handler); - } - - /** - * Register Bukkit event handlers with a given exception handler. - * @param manager - the current plugin manager. - * @param listener - a class of event handlers. - * @param plugin - the current plugin. - * @param handler - exception handler. - */ - public static void registerEvents(PluginManager manager, Listener listener, Plugin plugin, EventExceptionHandler handler) { - Validate.notNull(manager, "Manager cannot be NULL."); - Validate.notNull(listener, "Listener cannot be NULL."); - Validate.notNull(plugin, "Plugin cannot be NULL."); - Validate.notNull(handler, "Handler cannot be NULL."); - - if (!plugin.isEnabled()) { - throw new IllegalPluginAccessException("Plugin attempted to register " + listener + " while not enabled"); - } - - // Create normal listeners - for (Map.Entry, Set> entry : - plugin.getPluginLoader().createRegisteredListeners(listener, plugin).entrySet()) { - - // Wrap these listeners in our exception handler - getHandlerList(entry.getKey()).registerAll(wrapAll(entry.getValue(), handler)); - } - } - - /** - * Wrap every listener in the given collection around an exception handler. - * @param listeners - the listeners to wrap. - * @param handler - the exception handler to add. - * @return The wrapped listeners. - */ - private static Collection wrapAll(Collection listeners, EventExceptionHandler handler) { - List output = Lists.newArrayList(); - - for (RegisteredListener listener : listeners) { - output.add(new ExceptionRegisteredListener(listener, handler)); - } - return output; - } - - /** - * Retrieve the handler list associated with the given class. - * @param clazz - given event class. - * @return Associated handler list. - */ - private static HandlerList getHandlerList(Class clazz) { - // Class must have Event as its superclass - while (clazz.getSuperclass() != null && Event.class.isAssignableFrom(clazz.getSuperclass())) { - try { - Method method = clazz.getDeclaredMethod("getHandlerList"); - method.setAccessible(true); - return (HandlerList) method.invoke(null); - } catch (NoSuchMethodException e) { - // Keep on searching - clazz = clazz.getSuperclass().asSubclass(Event.class); - } catch (Exception e) { - throw new IllegalPluginAccessException(e.getMessage()); - } - } - throw new IllegalPluginAccessException("Unable to find handler list for event " + clazz.getName()); - } - - /** - * Handle a given exception. - * @param ex - the exception to handle. - * @param event - the event that was being handled. - * @return TRUE to indicate that the exception has been handled, FALSE to rethrow it. - */ - public abstract boolean handle(Throwable ex, Event event); -} \ No newline at end of file diff --git a/src/main/java/buttondevteam/core/MainPlugin.java b/src/main/java/buttondevteam/core/MainPlugin.java index 855ad89..1944acc 100644 --- a/src/main/java/buttondevteam/core/MainPlugin.java +++ b/src/main/java/buttondevteam/core/MainPlugin.java @@ -7,6 +7,8 @@ import org.bukkit.event.Event; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; +import buttondevteam.lib.EventExceptionHandler; + public class MainPlugin extends JavaPlugin { public static MainPlugin Instance;