Fixed chat msg loss <@187257785199624194>

Probably

Also fixed exception filtering
This commit is contained in:
Norbi Peti 2017-04-28 22:41:23 +02:00
parent 1ba108fb21
commit c23d9aee09
3 changed files with 118 additions and 94 deletions

View file

@ -48,7 +48,7 @@ public class ExceptionListener implements Listener {
sb.append(sourcemessage).append("\n"); sb.append(sourcemessage).append("\n");
sb.append("```").append("\n"); sb.append("```").append("\n");
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n")) String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
.filter(s -> !(s.contains(" at ") && ( // .filter(s -> !(s.contains("\tat ") && ( //
s.contains("java.util") // s.contains("java.util") //
|| s.contains("java.lang") // || s.contains("java.lang") //
|| s.contains("net.minecraft.server") // || s.contains("net.minecraft.server") //

View file

@ -28,7 +28,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
return; return;
if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender) if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender)
return; return;
if (e.getChannel().equals(Channel.GlobalChat)) { if (!e.getChannel().equals(Channel.GlobalChat))
return;
synchronized (this) {
final String authorPlayer = DiscordPlugin.sanitizeString(e.getSender() instanceof Player // final String authorPlayer = DiscordPlugin.sanitizeString(e.getSender() instanceof Player //
? ((Player) e.getSender()).getDisplayName() // ? ((Player) e.getSender()).getDisplayName() //
: e.getSender().getName()); : e.getSender().getName());
@ -83,6 +85,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
if (CommandListener.runCommand(event.getMessage(), true)) if (CommandListener.runCommand(event.getMessage(), true))
return; return;
String dmessage = event.getMessage().getContent(); String dmessage = event.getMessage().getContent();
synchronized (this) {
try { try {
DiscordPlayer dp = ChromaGamerBase.getUser(author.getID(), DiscordPlayer.class); DiscordPlayer dp = ChromaGamerBase.getUser(author.getID(), DiscordPlayer.class);
final DiscordSenderBase dsender; final DiscordSenderBase dsender;
@ -97,8 +100,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} else { } else {
TBMCPlayer p = dp.getAs(TBMCPlayer.class); TBMCPlayer p = dp.getAs(TBMCPlayer.class);
if (!UnconnectedSenders.containsKey(author.getID())) if (!UnconnectedSenders.containsKey(author.getID()))
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel(), UnconnectedSenders.put(author.getID(), new DiscordSender(author,
p == null ? null : p.PlayerName().get())); // Display the playername, if found event.getMessage().getChannel(), p == null ? null : p.PlayerName().get())); // Display the playername, if found
dsender = UnconnectedSenders.get(author.getID()); dsender = UnconnectedSenders.get(author.getID());
} }
@ -110,8 +113,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
if (dmessage.startsWith("/")) { if (dmessage.startsWith("/")) {
final String cmd = dmessage.substring(1).toLowerCase(); final String cmd = dmessage.substring(1).toLowerCase();
if (mcp == null if (mcp == null && !Arrays.stream(UnconnectedCmds)
&& !Arrays.stream(UnconnectedCmds).anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) { .anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
// Command not whitelisted // Command not whitelisted
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), // TODO DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), // TODO
"Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n" "Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n"
@ -155,4 +158,5 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
return; return;
} }
} }
}
} }

View file

@ -1,5 +1,11 @@
package buttondevteam.DiscordPlugin; package buttondevteam.DiscordPlugin;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.lang.exception.ExceptionUtils;
import buttondevteam.lib.TBMCCoreAPI;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -7,32 +13,46 @@ import junit.framework.TestSuite;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
public class AppTest public class AppTest extends TestCase {
extends TestCase
{
/** /**
* Create the test case * Create the test case
* *
* @param testName name of the test case * @param testName
* name of the test case
*/ */
public AppTest( String testName ) public AppTest(String testName) {
{ super(testName);
super( testName );
} }
/** /**
* @return the suite of tests being tested * @return the suite of tests being tested
*/ */
public static Test suite() public static Test suite() {
{ return new TestSuite(AppTest.class);
return new TestSuite( AppTest.class );
} }
/** /**
* Rigourous Test :-) * Rigourous Test :-)
*/ */
public void testApp() public void testApp() {
{ /*String sourcemessage = "Test message";
assertTrue( true ); Exception e = new Exception("Test exception");
StringBuilder sb = TBMCCoreAPI.IsTestServer() ? new StringBuilder() : new StringBuilder("").append("\n");
sb.append(sourcemessage).append("\n");
sb.append("```").append("\n");
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
.filter(s -> !(s.contains("\tat ") && ( //
s.contains("java.util") //
|| s.contains("java.lang") //
|| s.contains("net.minecraft.server") //
|| s.contains("sun.reflect") //
|| s.contains("org.bukkit") //
))).collect(Collectors.joining("\n"));
if (stackTrace.length() > 1800)
stackTrace = stackTrace.substring(0, 1800);
sb.append(stackTrace).append("\n");
sb.append("```");
System.out.println(sb.toString()); */
assertTrue(true);
} }
} }