Added Debug Messages #22

Merged
alisolarflare merged 3 commits from Ali into master 2016-11-22 02:13:42 +00:00
2 changed files with 70 additions and 0 deletions
Showing only changes of commit 1adc2f1b4c - Show all commits

View file

@ -127,6 +127,7 @@ public final class TBMCCoreAPI {
}
private static HashMap<String, Throwable> exceptionsToSend = new HashMap<>();
private static List<String> debugMessagesToSend = new ArrayList<>();
private static final String[] potatoMessages = new String[] { //
"Well shit", //
@ -163,6 +164,13 @@ public final class TBMCCoreAPI {
potato.Send(randomPlayer.get());
}
}
public static void sendDebugMessage(String debugMessage){
SendUnsentDebugMessages();
TBMCDebugMessageEvent event = new TBMCDebugMessageEvent(debugMessage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isSent())
debugMessagesToSend.add(debugMessage);
}
/**
* Registers Bukkit events, handling the exceptions occuring in those events
@ -191,4 +199,17 @@ public final class TBMCCoreAPI {
exceptionsToSend.remove(entry.getKey());
}
}
public static void SendUnsentDebugMessages() {
if (debugMessagesToSend.size() > 20) {
debugMessagesToSend.clear(); // Don't call more and more DebugMessages if all the handler plugins are unloaded
Bukkit.getLogger().warning("Unhandled Debug Message list is over 20! Clearing!");
}
for (String message : debugMessagesToSend) {
TBMCDebugMessageEvent event = new TBMCDebugMessageEvent(message);
Bukkit.getPluginManager().callEvent(event);
if (event.isSent())
debugMessagesToSend.remove(message);
}
}
}

View file

@ -0,0 +1,49 @@
package buttondevteam.lib;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class TBMCDebugMessageEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private String message;
private boolean sent;
public TBMCDebugMessageEvent(String message) {
this.message = message;
}
/**
* Gets the message (where did this exception occur, etc.)
*
* @return The message
*/
public String getDebugMessage() {
return message;
}
/**
* Gets if this event was handled
*
* @return True if it was handled
*/
public boolean isSent() {
return sent;
}
/**
* Flags the event as handled
*/
public void setSent() {
this.sent = true;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}