Merge pull request #22 from TBMCPlugins/Ali

Added Debug Messages
This commit is contained in:
alisolarflare 2016-11-21 21:13:42 -05:00 committed by GitHub
commit 85d2506da7
4 changed files with 203 additions and 142 deletions

View file

@ -98,6 +98,10 @@ public class DebugPotato {
int currentLineLength = 0; int currentLineLength = 0;
int wordlength; int wordlength;
int maxLineLength = 40; int maxLineLength = 40;
if (message.length() <= maxLineLength){
newMessage.add(message);
return newMessage;
}
for (String word : splitString) { for (String word : splitString) {
wordlength = word.length(); wordlength = word.length();
if (currentLineLength == 0 || (currentLineLength + wordlength) < maxLineLength) { if (currentLineLength == 0 || (currentLineLength + wordlength) < maxLineLength) {
@ -114,7 +118,7 @@ public class DebugPotato {
public ItemStack toItemStack() { public ItemStack toItemStack() {
ItemStack potato = new ItemStack(Material.BAKED_POTATO); ItemStack potato = new ItemStack(Material.BAKED_POTATO);
ItemMeta meta = potato.getItemMeta(); ItemMeta meta = potato.getItemMeta();
meta.setDisplayName(this.getType() == null ? "Spicy Debug Potato" : this.getType()); meta.setDisplayName(this.getType() == null ? "Null Flavoured Debug Potato" : this.getType());
if (this.getMessage() == null){ if (this.getMessage() == null){
List<String> message = new ArrayList<String>(); List<String> message = new ArrayList<String>();
message.add("nullMessage"); message.add("nullMessage");

View file

@ -1,13 +0,0 @@
package buttondevteam.lib;
import org.bukkit.entity.Player;
/**@deprecated
* Fully Replaced by DebugPotato Class - Construct a DebugPotato*/
public class DebugPotatoAPI {
/**@deprecated Replaced by DebugPotato.send*/
public static void SendDebugPotato(DebugPotato dp, Player player) {
player.getInventory().addItem(dp.toItemStack());
return;
}
}

View file

@ -127,6 +127,7 @@ public final class TBMCCoreAPI {
} }
private static HashMap<String, Throwable> exceptionsToSend = new HashMap<>(); private static HashMap<String, Throwable> exceptionsToSend = new HashMap<>();
private static List<String> debugMessagesToSend = new ArrayList<>();
private static final String[] potatoMessages = new String[] { // private static final String[] potatoMessages = new String[] { //
"Well shit", // "Well shit", //
@ -163,6 +164,13 @@ public final class TBMCCoreAPI {
potato.Send(randomPlayer.get()); 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 * Registers Bukkit events, handling the exceptions occuring in those events
@ -191,4 +199,17 @@ public final class TBMCCoreAPI {
exceptionsToSend.remove(entry.getKey()); 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;
}
}