mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Created a wrapper for Player.sendMessage() That automatically applies Quake Colors and Word Wrap
This commit is contained in:
parent
535c42be0b
commit
9713bdc2a5
@ -19,11 +19,23 @@ public class vMinecraftChat {
|
||||
public static void gmsg(String msg){
|
||||
for (Player p : etc.getServer().getPlayerList()) {
|
||||
if (p != null) {
|
||||
p.sendMessage(msg);
|
||||
sendMessage(p, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: sendMessage
|
||||
//Input: String msg: The message to be broadcast to all players
|
||||
//Output: None
|
||||
//Use: Outputs a message to everybody
|
||||
//=====================================================================
|
||||
public static void sendMessage(Player player, String msg){
|
||||
String[] message = applyColors(wordWrap(msg));
|
||||
for(String out : message)
|
||||
player.sendMessage(out + " ");
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: wordWrap
|
||||
//Input: String msg: The message to be wrapped
|
||||
@ -58,7 +70,7 @@ public class vMinecraftChat {
|
||||
System.arraycopy(split, j, temp, 0, i - j);
|
||||
|
||||
//Merge them and add them to the output array.
|
||||
out.add( applyColors(etc.combineSplit(0, temp, " ")) );
|
||||
out.add( etc.combineSplit(0, temp, " ") );
|
||||
}
|
||||
|
||||
//Convert to an array and return
|
||||
@ -251,20 +263,15 @@ public class vMinecraftChat {
|
||||
if(message.startsWith("@"))
|
||||
message = message.substring(1, message.length());
|
||||
|
||||
String[] msg = wordWrap(adminchat + message);
|
||||
|
||||
//Get the player from the playerlist to send the message to.
|
||||
for (Player p: etc.getServer().getPlayerList()) {
|
||||
|
||||
//If p is not null
|
||||
if (p != null) {
|
||||
|
||||
//And if p is an admin or has access to adminchat
|
||||
//And if p is an admin or has access to adminchat send message
|
||||
if (p.isAdmin() || (p.canUseCommand("/adminchat"))) {
|
||||
|
||||
//Output the first line
|
||||
for(String str: msg)
|
||||
p.sendMessage(str);
|
||||
sendMessage(p, adminchat + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -293,12 +300,8 @@ public class vMinecraftChat {
|
||||
//Log the chat
|
||||
log.log(Level.INFO, "<"+player.getName()+"> " +message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(playerName + Colors.LightGreen + message);
|
||||
|
||||
//Output the lines
|
||||
for(String str: msg)
|
||||
gmsg(Colors.LightGreen + str);
|
||||
//Output the message
|
||||
gmsg(playerName + Colors.LightGreen + message);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -319,12 +322,8 @@ public class vMinecraftChat {
|
||||
if (vMinecraftSettings.getInstance().FFF()) {
|
||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(playerName + Colors.Red + message);
|
||||
|
||||
//Output the message
|
||||
for(String str: msg)
|
||||
gmsg(Colors.Red + str);
|
||||
gmsg(playerName + Colors.Red + message);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -347,14 +346,8 @@ public class vMinecraftChat {
|
||||
//Log the chat
|
||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(playerName + message);
|
||||
//Apply colors to the lines
|
||||
applyColors(msg);
|
||||
|
||||
//Output the message
|
||||
for(String str: msg)
|
||||
gmsg(str);
|
||||
gmsg(playerName + message);
|
||||
|
||||
//Loop through the string finding the color codes and inserting them
|
||||
return true;
|
||||
@ -370,10 +363,7 @@ public class vMinecraftChat {
|
||||
//=====================================================================
|
||||
public static boolean emote(Player player, String message)
|
||||
{
|
||||
String temp = message.toString();
|
||||
String[] msg = wordWrap("* " + getName(player) + " " + Colors.White + temp);
|
||||
for(String str: msg)
|
||||
gmsg(str);
|
||||
gmsg("* " + getName(player) + " " + Colors.White + message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -401,7 +391,7 @@ public class vMinecraftChat {
|
||||
for(int x = 0; x< msg.length(); x++)
|
||||
{
|
||||
//If the char is a ^ or <EFBFBD>
|
||||
if(msg.charAt(x) == '^' || msg.charAt(x) == Colors.White.charAt(0))
|
||||
if(msg.charAt(x) == '^')
|
||||
{
|
||||
if(x != msg.length() - 1)
|
||||
{
|
||||
|
@ -318,18 +318,7 @@ public class vMinecraftCommands{
|
||||
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
|
||||
|
||||
//Prepend the player name and cut into lines.
|
||||
String[] message = vMinecraftChat.wordWrap(playerName + str);
|
||||
|
||||
//Output the message
|
||||
for(String msg: message)
|
||||
{
|
||||
if (msg.contains(playerName))
|
||||
vMinecraftChat.gmsg( playerName
|
||||
+ vMinecraftChat.rainbow(
|
||||
msg.substring(playerName.length())));
|
||||
else
|
||||
vMinecraftChat.gmsg(vMinecraftChat.rainbow(msg));
|
||||
}
|
||||
vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(str));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -420,11 +409,10 @@ public class vMinecraftCommands{
|
||||
e.printStackTrace();
|
||||
}
|
||||
int maxPlayers = server.getInt("max-players");
|
||||
|
||||
//Output the player list
|
||||
String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List ("
|
||||
vMinecraftChat.sendMessage(player, Colors.Rose + "Player List ("
|
||||
+ count + "/" + maxPlayers +"): " + tempList);
|
||||
for(String msg: tempOut)
|
||||
player.sendMessage( msg );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user