Fixed the WordWrap function. So now /who works properly.

This commit is contained in:
cerevisiae 2010-11-29 03:05:53 -06:00
parent 8a86cef94a
commit b92bd3b65d
2 changed files with 23 additions and 37 deletions

View File

@ -1,3 +1,4 @@
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -32,51 +33,38 @@ public class vminecraftChat {
//=====================================================================
public static String[] wordWrap(String msg){
//Split each word apart
String[] array = msg.split(" ");
String[] split = msg.split(" ");
//Create the output array
String[] out = new String[0];
int length = (int)msgLength(msg) / 316;
ArrayList<String> out = new ArrayList<String>();
//While i is less than the length of the array of words
int i = 0;
while(i < array.length){
while(i < split.length){
int len = 0;
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)
while(len <= 316 && i < split.length)
{
len += msgLength(array[j]) + 4;
len += msgLength(split[i]) + 4;
if( len <= 316)
j++;
i++;
}
String[] temp = new String[j - i];
String[] temp = new String[i - j];
//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);
//Copy the words in the selection into a new array
System.arraycopy(split, j, temp, 0, i - 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;
//Merge them and add them to the output array
out.add( etc.combineSplit(0, temp, " ") );
}
return out;
String[] tempout = new String[out.size()];
out.toArray(tempout);
return tempout;
}
//=====================================================================

View File

@ -36,8 +36,6 @@ public class vminecraftCommands{
cl.register("/ezmodo", "invuln", "Toggle invulnerability");
cl.register("/ezlist", "ezlist", "List invulnerable players");
cl.registerAlias("/playerlist", "/who");
cl.registerAlias("/it", "/i", new String[] {"%0", "100"});
cl.registerAlias("/wood", "/i", new String[] {"wood"});
}
@ -215,7 +213,7 @@ public class vminecraftCommands{
String[] message = vminecraftChat.wordWrap(player, str);
//Output the first line
vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + "> "
vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + Colors.White + "> "
+ vminecraftChat.rainbow(message[0]));
//Get the rest of the lines and display them.
@ -261,8 +259,8 @@ public class vminecraftCommands{
player.sendMessage(Colors.Blue + "Whois results for " +
vminecraftChat.nameColor(playerTarget));
//Group
player.sendMessage(Colors.Blue + "Groups: " +
playerTarget.getGroups());
for(String group: playerTarget.getGroups())
player.sendMessage(Colors.Blue + "Groups: " + group);
//Admin
player.sendMessage(Colors.Blue+"Admin: " +
String.valueOf(playerTarget.canIgnoreRestrictions()));
@ -303,7 +301,7 @@ public class vminecraftCommands{
if(count == 0)
tempList += vminecraftChat.nameColor(p);
else
tempList += ", " + vminecraftChat.nameColor(p);
tempList += Colors.White + ", " + vminecraftChat.nameColor(p);
count++;
}
}