mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Misc fixes for WordWrap
This commit is contained in:
parent
b92bd3b65d
commit
11dc691220
@ -34,9 +34,8 @@ public class vminecraftChat {
|
||||
public static String[] wordWrap(String msg){
|
||||
//Split each word apart
|
||||
String[] split = msg.split(" ");
|
||||
//Create the output array
|
||||
int length = (int)msgLength(msg) / 316;
|
||||
|
||||
//Create an arraylist for the output
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
|
||||
//While i is less than the length of the array of words
|
||||
@ -54,78 +53,20 @@ public class vminecraftChat {
|
||||
i++;
|
||||
|
||||
}
|
||||
String[] temp = new String[i - j];
|
||||
|
||||
//Copy the words in the selection into a new array
|
||||
String[] temp = new String[i - j];
|
||||
System.arraycopy(split, j, temp, 0, i - j);
|
||||
|
||||
//Merge them and add them to the output array
|
||||
out.add( etc.combineSplit(0, temp, " ") );
|
||||
}
|
||||
|
||||
//Convert to an array and return
|
||||
String[] tempout = new String[out.size()];
|
||||
out.toArray(tempout);
|
||||
return tempout;
|
||||
}
|
||||
|
||||
//=====================================================================
|
||||
//Function: wordWrap
|
||||
//Input: Player player: To get the player name
|
||||
// String msg: The message to be wrapped
|
||||
//Output: String[]: The array of substrings
|
||||
//Use: Cuts the message apart into whole words short enough to fit
|
||||
// on one line
|
||||
//=====================================================================
|
||||
public static String[] wordWrap(Player player, String msg){
|
||||
//Split each word apart
|
||||
String[] array = msg.split(" ");
|
||||
//Create the output array
|
||||
String[] out = new String[0];
|
||||
|
||||
//While i is less than the length of the array of words
|
||||
int i = 0;
|
||||
while(i < array.length){
|
||||
int len = 0;
|
||||
if(out.length == 0)
|
||||
len = msgLength("<" + player.getName() + "> ");
|
||||
int j = i;
|
||||
//Loop through the words finding their length and increasing
|
||||
//j, the end point for the sub string
|
||||
while(len <= 316 && j < array.length)
|
||||
{
|
||||
len += msgLength(array[j]) + 4;
|
||||
if( len <= 316)
|
||||
j++;
|
||||
|
||||
}
|
||||
String[] temp = new String[j - i];
|
||||
|
||||
//If it's not the end yet
|
||||
if(j < array.length)
|
||||
{
|
||||
//Copy the words in the selection into a new array
|
||||
System.arraycopy(array, i, temp, 0, j);
|
||||
|
||||
//Merge them and add them to the output array
|
||||
String[] tempOut = new String[out.length + 1];
|
||||
System.arraycopy(out, 0, tempOut, 0, out.length);
|
||||
tempOut[tempOut.length - 1] = etc.combineSplit(0, temp, " ");
|
||||
out = tempOut;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Merge the rest and add them to the output array
|
||||
String[] tempOut = new String[out.length + 1];
|
||||
System.arraycopy(out, 0, tempOut, 0, out.length);
|
||||
tempOut[tempOut.length - 1] = etc.combineSplit(i, array, " ");
|
||||
out = tempOut;
|
||||
}
|
||||
//Make the old front equal to the old end
|
||||
i = j;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int msgLength(String str){
|
||||
int length = 0;
|
||||
for(int x = 0; x<str.length(); x++)
|
||||
@ -290,7 +231,7 @@ public class vminecraftChat {
|
||||
String adminchat = Colors.DarkPurple + "{" + nameColor(player)
|
||||
+ Colors.DarkPurple +"}" + Colors.White + " ";
|
||||
|
||||
String[] msg = wordWrap(player, message.substring(1, message.length()));
|
||||
String[] msg = wordWrap(adminchat + message.substring(1, message.length()));
|
||||
|
||||
//Get the player from the playerlist to send the message to.
|
||||
for (Player p: etc.getServer().getPlayerList()) {
|
||||
@ -337,7 +278,7 @@ public class vminecraftChat {
|
||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(player, message);
|
||||
String[] msg = wordWrap(playerName + message);
|
||||
|
||||
//Output the first line
|
||||
gmsg( playerName + Colors.LightGreen + msg[0]);
|
||||
@ -367,7 +308,7 @@ public class vminecraftChat {
|
||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(player, message);
|
||||
String[] msg = wordWrap(playerName + message);
|
||||
|
||||
//Output the first line
|
||||
gmsg( playerName + Colors.Red + msg[0]);
|
||||
@ -399,7 +340,7 @@ public class vminecraftChat {
|
||||
log.log(Level.INFO, "<"+player.getName()+"> "+message);
|
||||
|
||||
//Get the multi line array
|
||||
String[] msg = wordWrap(player, message);
|
||||
String[] msg = wordWrap(playerName + message);
|
||||
//Apply colors to the lines
|
||||
applyColors(msg);
|
||||
|
||||
|
@ -179,10 +179,11 @@ public class vminecraftCommands{
|
||||
public static boolean rules(Player player, String[] args)
|
||||
{
|
||||
//If the rules exist
|
||||
if(vminecraftSettings.getInstance().cmdRules()) {
|
||||
if(vminecraftSettings.getInstance().cmdRules()
|
||||
&& vminecraftSettings.getInstance().getRules().length != 0) {
|
||||
//Display them
|
||||
for (String str : vminecraftSettings.getInstance().getRules()) {
|
||||
if(str != null)
|
||||
if(str.isEmpty())
|
||||
player.sendMessage(Colors.Blue+str);
|
||||
}
|
||||
return true;
|
||||
@ -202,6 +203,8 @@ public class vminecraftCommands{
|
||||
{
|
||||
//If the command is enabled
|
||||
if(vminecraftSettings.getInstance().cmdFabulous()) {
|
||||
String playerName = "<" + vminecraftChat.nameColor(player)
|
||||
+ Colors.White + "> ";
|
||||
//Make sure a message has been specified
|
||||
if (args.length < 1) {return false;}
|
||||
String str = " ";
|
||||
@ -210,11 +213,10 @@ public class vminecraftCommands{
|
||||
//Output for server
|
||||
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
|
||||
//Prepend the player name
|
||||
String[] message = vminecraftChat.wordWrap(player, str);
|
||||
String[] message = vminecraftChat.wordWrap(playerName + str);
|
||||
|
||||
//Output the first line
|
||||
vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + Colors.White + "> "
|
||||
+ vminecraftChat.rainbow(message[0]));
|
||||
vminecraftChat.gmsg( playerName + vminecraftChat.rainbow(message[0]));
|
||||
|
||||
//Get the rest of the lines and display them.
|
||||
String[] tempOut = new String[message.length - 1];
|
||||
|
@ -42,7 +42,7 @@ public class vminecraftSettings {
|
||||
|
||||
private PropertiesFile properties;
|
||||
String file = "vminecraft.properties";
|
||||
public String rules[] = null;
|
||||
public String rules[] = new String[0];
|
||||
|
||||
//=====================================================================
|
||||
//Function: loadSettings
|
||||
@ -78,7 +78,9 @@ public class vminecraftSettings {
|
||||
writer.write("FFF=true\r\n");
|
||||
writer.write("adminchat=true\r\n");
|
||||
writer.write("cmdEzModo=true\r\n");
|
||||
writer.write("#Adding player names to this list will have them start off in ezmodo\r\n");
|
||||
writer.write("ezModo=\r\n");
|
||||
writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n");
|
||||
writer.write("ezHealth=30\r\n");
|
||||
writer.write("stopFire=false");
|
||||
writer.write("stopTnt=false");
|
||||
@ -100,7 +102,7 @@ public class vminecraftSettings {
|
||||
try {
|
||||
properties.load();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user