mirror of
https://github.com/sigmasternchen/minecraft-matrix-bridge
synced 2025-03-15 07:58:56 +00:00
Merge pull request #12 from CRTified/feat-multiLineMessages
feat: Add Linebreaks for long matrix messages
This commit is contained in:
commit
d9ae6a7008
1 changed files with 14 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
package at.overflow.bukkit.matrixbridge;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -74,11 +76,19 @@ public class MatrixPlugin extends JavaPlugin implements Listener, Endpoint {
|
|||
|
||||
@Override
|
||||
public void send(String from, String message) {
|
||||
if (message.length() > MAX_LENGTH) {
|
||||
message = message.substring(0, MAX_LENGTH) + " [...]";
|
||||
}
|
||||
|
||||
if(message.length() < MAX_LENGTH) {
|
||||
getServer().broadcastMessage(ChatColor.GREEN + "<" + from + ">" +ChatColor.WHITE + " " + message);
|
||||
} else {
|
||||
int pos = 0;
|
||||
getServer().broadcastMessage(ChatColor.GREEN + "<" + from + ">");
|
||||
while(pos < message.length())
|
||||
{
|
||||
int segLen = min(message.length() - pos, MAX_LENGTH);
|
||||
getServer().broadcastMessage(ChatColor.WHITE + " " + message.substring(pos, pos + segLen));
|
||||
|
||||
pos += segLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue