From b92bd3b65df454e60c462d13c010f5dc0e2fbf35 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 03:05:53 -0600 Subject: [PATCH] Fixed the WordWrap function. So now /who works properly. --- vminecraftChat.java | 50 ++++++++++++++++------------------------- vminecraftCommands.java | 10 ++++----- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index bf7ef6c49..9b11c9198 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -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 out = new ArrayList(); //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]; + + //Copy the words in the selection into a new array + System.arraycopy(split, j, temp, 0, 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); - - //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; } //===================================================================== diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 447339194..ccfec0a58 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -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++; } }