From 64faa95b3b0d61d9438cb82f8aef6645106fca09 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 20 Nov 2016 01:37:24 +0100 Subject: [PATCH] Added bug potatoes... --- .../java/buttondevteam/lib/TBMCCoreAPI.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java index a968a6e..01cdf23 100644 --- a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java +++ b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java @@ -13,11 +13,14 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Random; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; @@ -125,6 +128,13 @@ public final class TBMCCoreAPI { private static HashMap exceptionsToSend = new HashMap<>(); + private static final String[] potatoMessages = new String[] { // + "Well shit", // + "Wait what", // + "Hwat", // + "Wat" // + }; + /** * Send exception to the {@link TBMCExceptionEvent}. * @@ -141,6 +151,13 @@ public final class TBMCCoreAPI { exceptionsToSend.put(sourcemsg, e); Bukkit.getLogger().warning(sourcemsg); e.printStackTrace(); + Optional randomPlayer = Bukkit.getOnlinePlayers().stream().findAny(); + if (randomPlayer.isPresent()) + DebugPotatoAPI.SendDebugPotato(randomPlayer.get(), + new String[] { // + "§b§o" + potatoMessages[new Random().nextInt(potatoMessages.length)], // + "§c§o" + sourcemsg, // + "§a§oFind a dev to fix this issue" }); } /** @@ -159,6 +176,10 @@ public final class TBMCCoreAPI { * Send exceptions that haven't been sent (their events didn't get handled). This method is used by the DiscordPlugin's ready event */ public static void SendUnsentExceptions() { + if (exceptionsToSend.size() > 20) { + exceptionsToSend.clear(); // Don't call more and more events if all the handler plugins are unloaded + Bukkit.getLogger().warning("Unhandled exception list is over 20! Clearing!"); + } for (Entry entry : exceptionsToSend.entrySet()) { TBMCExceptionEvent event = new TBMCExceptionEvent(entry.getKey(), entry.getValue()); Bukkit.getPluginManager().callEvent(event);