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){
|
public static void gmsg(String msg){
|
||||||
for (Player p : etc.getServer().getPlayerList()) {
|
for (Player p : etc.getServer().getPlayerList()) {
|
||||||
if (p != null) {
|
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
|
//Function: wordWrap
|
||||||
//Input: String msg: The message to be wrapped
|
//Input: String msg: The message to be wrapped
|
||||||
@ -58,7 +70,7 @@ public class vMinecraftChat {
|
|||||||
System.arraycopy(split, j, temp, 0, i - j);
|
System.arraycopy(split, j, temp, 0, i - j);
|
||||||
|
|
||||||
//Merge them and add them to the output array.
|
//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
|
//Convert to an array and return
|
||||||
@ -251,20 +263,15 @@ public class vMinecraftChat {
|
|||||||
if(message.startsWith("@"))
|
if(message.startsWith("@"))
|
||||||
message = message.substring(1, message.length());
|
message = message.substring(1, message.length());
|
||||||
|
|
||||||
String[] msg = wordWrap(adminchat + message);
|
|
||||||
|
|
||||||
//Get the player from the playerlist to send the message to.
|
//Get the player from the playerlist to send the message to.
|
||||||
for (Player p: etc.getServer().getPlayerList()) {
|
for (Player p: etc.getServer().getPlayerList()) {
|
||||||
|
|
||||||
//If p is not null
|
//If p is not null
|
||||||
if (p != 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"))) {
|
if (p.isAdmin() || (p.canUseCommand("/adminchat"))) {
|
||||||
|
sendMessage(p, adminchat + message);
|
||||||
//Output the first line
|
|
||||||
for(String str: msg)
|
|
||||||
p.sendMessage(str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,12 +300,8 @@ public class vMinecraftChat {
|
|||||||
//Log the chat
|
//Log the chat
|
||||||
log.log(Level.INFO, "<"+player.getName()+"> " +message);
|
log.log(Level.INFO, "<"+player.getName()+"> " +message);
|
||||||
|
|
||||||
//Get the multi line array
|
//Output the message
|
||||||
String[] msg = wordWrap(playerName + Colors.LightGreen + message);
|
gmsg(playerName + Colors.LightGreen + message);
|
||||||
|
|
||||||
//Output the lines
|
|
||||||
for(String str: msg)
|
|
||||||
gmsg(Colors.LightGreen + str);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -319,12 +322,8 @@ public class vMinecraftChat {
|
|||||||
if (vMinecraftSettings.getInstance().FFF()) {
|
if (vMinecraftSettings.getInstance().FFF()) {
|
||||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||||
|
|
||||||
//Get the multi line array
|
|
||||||
String[] msg = wordWrap(playerName + Colors.Red + message);
|
|
||||||
|
|
||||||
//Output the message
|
//Output the message
|
||||||
for(String str: msg)
|
gmsg(playerName + Colors.Red + message);
|
||||||
gmsg(Colors.Red + str);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -341,20 +340,14 @@ public class vMinecraftChat {
|
|||||||
{
|
{
|
||||||
//Format the name
|
//Format the name
|
||||||
String playerName = Colors.White + "<"
|
String playerName = Colors.White + "<"
|
||||||
+ getName(player) + Colors.White +"> ";
|
+ getName(player) + Colors.White +"> ";
|
||||||
if(vMinecraftSettings.getInstance().quakeColors()) {
|
if(vMinecraftSettings.getInstance().quakeColors()) {
|
||||||
|
|
||||||
//Log the chat
|
//Log the chat
|
||||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
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
|
//Output the message
|
||||||
for(String str: msg)
|
gmsg(playerName + message);
|
||||||
gmsg(str);
|
|
||||||
|
|
||||||
//Loop through the string finding the color codes and inserting them
|
//Loop through the string finding the color codes and inserting them
|
||||||
return true;
|
return true;
|
||||||
@ -370,10 +363,7 @@ public class vMinecraftChat {
|
|||||||
//=====================================================================
|
//=====================================================================
|
||||||
public static boolean emote(Player player, String message)
|
public static boolean emote(Player player, String message)
|
||||||
{
|
{
|
||||||
String temp = message.toString();
|
gmsg("* " + getName(player) + " " + Colors.White + message);
|
||||||
String[] msg = wordWrap("* " + getName(player) + " " + Colors.White + temp);
|
|
||||||
for(String str: msg)
|
|
||||||
gmsg(str);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,7 +391,7 @@ public class vMinecraftChat {
|
|||||||
for(int x = 0; x< msg.length(); x++)
|
for(int x = 0; x< msg.length(); x++)
|
||||||
{
|
{
|
||||||
//If the char is a ^ or <EFBFBD>
|
//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)
|
if(x != msg.length() - 1)
|
||||||
{
|
{
|
||||||
|
@ -318,18 +318,7 @@ public class vMinecraftCommands{
|
|||||||
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
|
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
|
||||||
|
|
||||||
//Prepend the player name and cut into lines.
|
//Prepend the player name and cut into lines.
|
||||||
String[] message = vMinecraftChat.wordWrap(playerName + str);
|
vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(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));
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -420,11 +409,10 @@ public class vMinecraftCommands{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
int maxPlayers = server.getInt("max-players");
|
int maxPlayers = server.getInt("max-players");
|
||||||
|
|
||||||
//Output the player list
|
//Output the player list
|
||||||
String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List ("
|
vMinecraftChat.sendMessage(player, Colors.Rose + "Player List ("
|
||||||
+ count + "/" + maxPlayers +"): " + tempList);
|
+ count + "/" + maxPlayers +"): " + tempList);
|
||||||
for(String msg: tempOut)
|
|
||||||
player.sendMessage( msg );
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user