Fixed chat msg loss <@187257785199624194>
Probably Also fixed exception filtering
This commit is contained in:
parent
1ba108fb21
commit
c23d9aee09
3 changed files with 118 additions and 94 deletions
|
@ -48,7 +48,7 @@ public class ExceptionListener implements Listener {
|
|||
sb.append(sourcemessage).append("\n");
|
||||
sb.append("```").append("\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.lang") //
|
||||
|| s.contains("net.minecraft.server") //
|
||||
|
|
|
@ -28,7 +28,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
return;
|
||||
if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender)
|
||||
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 //
|
||||
? ((Player) e.getSender()).getDisplayName() //
|
||||
: e.getSender().getName());
|
||||
|
@ -83,6 +85,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
if (CommandListener.runCommand(event.getMessage(), true))
|
||||
return;
|
||||
String dmessage = event.getMessage().getContent();
|
||||
synchronized (this) {
|
||||
try {
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getID(), DiscordPlayer.class);
|
||||
final DiscordSenderBase dsender;
|
||||
|
@ -97,8 +100,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
} else {
|
||||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||
if (!UnconnectedSenders.containsKey(author.getID()))
|
||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel(),
|
||||
p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author,
|
||||
event.getMessage().getChannel(), p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
||||
dsender = UnconnectedSenders.get(author.getID());
|
||||
}
|
||||
|
||||
|
@ -110,8 +113,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
|
||||
if (dmessage.startsWith("/")) {
|
||||
final String cmd = dmessage.substring(1).toLowerCase();
|
||||
if (mcp == null
|
||||
&& !Arrays.stream(UnconnectedCmds).anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||
if (mcp == null && !Arrays.stream(UnconnectedCmds)
|
||||
.anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||
// Command not whitelisted
|
||||
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"
|
||||
|
@ -156,3 +159,4 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
@ -7,32 +13,46 @@ import junit.framework.TestSuite;
|
|||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
public class AppTest extends TestCase {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
public static Test suite() {
|
||||
return new TestSuite(AppTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
public void testApp() {
|
||||
/*String sourcemessage = "Test message";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue