Added method for exception events
This commit is contained in:
parent
4424eb551d
commit
f48c1ca9cc
3 changed files with 113 additions and 108 deletions
|
@ -7,8 +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.lib.EventExceptionCoreHandler;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.EventExceptionHandler;
|
|
||||||
import buttondevteam.lib.TBMCPlayer;
|
import buttondevteam.lib.TBMCPlayer;
|
||||||
|
|
||||||
public class MainPlugin extends JavaPlugin {
|
public class MainPlugin extends JavaPlugin {
|
||||||
|
@ -25,7 +24,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 EventExceptionCoreHandler());
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,8 @@ import java.util.List;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
@ -90,11 +92,15 @@ public final class TBMCCoreAPI {
|
||||||
String body = IOUtils.toString(in, encoding);
|
String body = IOUtils.toString(in, encoding);
|
||||||
in.close();
|
in.close();
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendException(String sourcemsg, Throwable 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterEventsForExceptions(Listener listener, Plugin plugin) {
|
||||||
|
EventExceptionHandler.registerEvents(listener, plugin, new EventExceptionCoreHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,99 +1,99 @@
|
||||||
package buttondevteam.lib.chat;
|
package buttondevteam.lib.chat;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.reflections.scanners.SubTypesScanner;
|
import org.reflections.scanners.SubTypesScanner;
|
||||||
import org.reflections.util.ClasspathHelper;
|
import org.reflections.util.ClasspathHelper;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
import buttondevteam.lib.TBMCPlayer;
|
import buttondevteam.lib.TBMCPlayer;
|
||||||
|
|
||||||
public class TBMCChatAPI {
|
public class TBMCChatAPI {
|
||||||
|
|
||||||
private static HashMap<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>();
|
private static HashMap<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>();
|
||||||
|
|
||||||
public static HashMap<String, TBMCCommandBase> GetCommands() {
|
public static HashMap<String, TBMCCommandBase> GetCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] GetSubCommands(TBMCCommandBase command) {
|
public static String[] GetSubCommands(TBMCCommandBase command) {
|
||||||
ArrayList<String> cmds = new ArrayList<String>();
|
ArrayList<String> cmds = new ArrayList<String>();
|
||||||
cmds.add("§6---- Subcommands ----");
|
cmds.add("§6---- Subcommands ----");
|
||||||
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
|
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
|
||||||
if (cmd.GetCommandPath().startsWith(command.GetCommandPath() + "/")) {
|
if (cmd.GetCommandPath().startsWith(command.GetCommandPath() + "/")) {
|
||||||
int ind = cmd.GetCommandPath().indexOf('/', command.GetCommandPath().length() + 2);
|
int ind = cmd.GetCommandPath().indexOf('/', command.GetCommandPath().length() + 2);
|
||||||
if (ind >= 0)
|
if (ind >= 0)
|
||||||
continue;
|
continue;
|
||||||
cmds.add(cmd.GetCommandPath().replace('/', ' '));
|
cmds.add(cmd.GetCommandPath().replace('/', ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cmds.toArray(new String[cmds.size()]);
|
return cmds.toArray(new String[cmds.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This method adds a plugin's commands to help and sets their executor.
|
* This method adds a plugin's commands to help and sets their executor.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* The <u>command must be registered</u> in the caller plugin's plugin.yml. Otherwise the plugin will output a messsage to console.
|
* The <u>command must be registered</u> in the caller plugin's plugin.yml. Otherwise the plugin will output a messsage to console.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* <i>Using this method after the server is done loading will have no effect.</i>
|
* <i>Using this method after the server is done loading will have no effect.</i>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* The caller plugin
|
* The caller plugin
|
||||||
* @param acmdclass
|
* @param acmdclass
|
||||||
* A command's class to get the package name for commands. The provided class's package and subpackages are scanned for commands.
|
* A command's class to get the package name for commands. The provided class's package and subpackages are scanned for commands.
|
||||||
*/
|
*/
|
||||||
public static void AddCommands(JavaPlugin plugin, Class<? extends TBMCCommandBase> acmdclass) {
|
public static void AddCommands(JavaPlugin plugin, Class<? extends TBMCCommandBase> acmdclass) {
|
||||||
plugin.getLogger().info("Registering commands for " + plugin.getName());
|
plugin.getLogger().info("Registering commands for " + plugin.getName());
|
||||||
Reflections rf = new Reflections(
|
Reflections rf = new Reflections(
|
||||||
new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(plugin.getClass().getClassLoader()))
|
new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(plugin.getClass().getClassLoader()))
|
||||||
.addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner())
|
.addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner())
|
||||||
.filterInputsBy((String pkg) -> pkg.contains(acmdclass.getPackage().getName())));
|
.filterInputsBy((String pkg) -> pkg.contains(acmdclass.getPackage().getName())));
|
||||||
Set<Class<? extends TBMCCommandBase>> cmds = rf.getSubTypesOf(TBMCCommandBase.class);
|
Set<Class<? extends TBMCCommandBase>> cmds = rf.getSubTypesOf(TBMCCommandBase.class);
|
||||||
for (Class<? extends TBMCCommandBase> cmd : cmds) {
|
for (Class<? extends TBMCCommandBase> cmd : cmds) {
|
||||||
try {
|
try {
|
||||||
if (Modifier.isAbstract(cmd.getModifiers()))
|
if (Modifier.isAbstract(cmd.getModifiers()))
|
||||||
continue;
|
continue;
|
||||||
TBMCCommandBase c = cmd.newInstance();
|
TBMCCommandBase c = cmd.newInstance();
|
||||||
c.plugin = plugin;
|
c.plugin = plugin;
|
||||||
commands.put(c.GetCommandPath(), c);
|
commands.put(c.GetCommandPath(), c);
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Add player information for {@link PlayerInfoCommand}. Only mods can see the given information.
|
* Add player information for {@link PlayerInfoCommand}. Only mods can see the given information.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param infoline
|
* @param infoline
|
||||||
*/
|
*/
|
||||||
public void AddPlayerInfoForMods(TBMCPlayer player, String infoline) {
|
public void AddPlayerInfoForMods(TBMCPlayer player, String infoline) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Add player information for hover text at {@link ChatProcessing}. Every online player can see the given information.
|
* Add player information for hover text at {@link ChatProcessing}. Every online player can see the given information.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param infoline
|
* @param infoline
|
||||||
*/
|
*/
|
||||||
public void AddPlayerInfoForHover(TBMCPlayer player, String infoline) {
|
public void AddPlayerInfoForHover(TBMCPlayer player, String infoline) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue