Made repeating exceptions only send once
This commit is contained in:
parent
e6dd2ff979
commit
f7b1090670
1 changed files with 16 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||||
|
@ -11,9 +13,23 @@ import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.lib.TBMCExceptionEvent;
|
import buttondevteam.lib.TBMCExceptionEvent;
|
||||||
|
|
||||||
public class ExceptionListener implements Listener {
|
public class ExceptionListener implements Listener {
|
||||||
|
private List<Throwable> lastthrown = new ArrayList<>();
|
||||||
|
private List<String> lastsourcemsg = new ArrayList<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onException(TBMCExceptionEvent e) {
|
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());
|
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();
|
e.setHandled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue