Don't run chat filtering on the main thread

This commit is contained in:
samczsun 2016-06-16 15:53:35 -04:00
parent 01409af5bd
commit 1893e98036
No known key found for this signature in database
GPG Key ID: B0AFDBD87206805D

View File

@ -22,6 +22,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.lang3.Validate;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -230,16 +231,33 @@ public class Chat extends MiniPlugin
return;
}
for (int i = 0; i < event.getLines().length; i++)
String[] lines = event.getLines();
runAsync(() ->
{
String line = event.getLine(i);
if (line != null && line.length() > 0)
for (int i = 0; i < lines.length; i++)
{
String filteredLine = getFilteredMessage(event.getPlayer(), line);
if (filteredLine != null)
event.setLine(i, filteredLine);
String line = lines[i];
if (line != null && line.length() > 0)
{
String filteredLine = getFilteredMessage(event.getPlayer(), line);
if (filteredLine != null)
{
lines[i] = filteredLine;
}
}
}
}
runSync(() ->
{
Sign sign = (Sign) event.getBlock().getState();
for (int i = 0; i < lines.length; i++)
{
sign.setLine(i, lines[i]);
}
sign.update();
});
});
}
@EventHandler(priority = EventPriority.LOWEST)