Made repeating exceptions only send once

This commit is contained in:
Norbi Peti 2016-12-18 01:13:09 +01:00
parent e6dd2ff979
commit f7b1090670

View file

@ -1,6 +1,8 @@
package buttondevteam.discordplugin.listeners;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang.exception.ExceptionUtils;
@ -11,9 +13,23 @@ import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCExceptionEvent;
public class ExceptionListener implements Listener {
private List<Throwable> lastthrown = new ArrayList<>();
private List<String> lastsourcemsg = new ArrayList<>();
@EventHandler
public void onException(TBMCExceptionEvent e) {
if (lastthrown.stream()
.anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace())
&& e.getException().getMessage().equals(ex.getMessage()))
&& lastsourcemsg.contains(e.getSourceMessage()))
return;
SendException(e.getException(), e.getSourceMessage());
if (lastthrown.size() >= 10)
lastthrown.remove(0);
if (lastsourcemsg.size() >= 10)
lastsourcemsg.remove(0);
lastthrown.add(e.getException());
lastsourcemsg.add(e.getSourceMessage());
e.setHandled();
}