diff --git a/vminecraftChat.java b/vminecraftChat.java index 9b11c9198..ab429e889 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -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 out = new ArrayList(); //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 "+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); diff --git a/vminecraftCommands.java b/vminecraftCommands.java index ccfec0a58..8d9ef4792 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -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,19 +203,20 @@ 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 = ""; + String str = " "; //Merge the message again str = etc.combineSplit(0, args, " "); //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]; diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 70b96f79f..8ff4917b3 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -31,8 +31,8 @@ public class vminecraftSettings { globalmessages = false, cmdSay = false, cmdWho = false, - stopFire = false, - stopTnt = false, + stopFire = false, + stopTnt = false, cmdEzModo = false; //An array of players currently in ezmodo @@ -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,10 +78,12 @@ 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"); + writer.write("stopFire=false"); + writer.write("stopTnt=false"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); @@ -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); } } @@ -121,8 +123,8 @@ public class vminecraftSettings { globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); - stopFire = properties.getBoolean("stopFire",true); - stopTnt = properties.getBoolean("stopTNT",true); + stopFire = properties.getBoolean("stopFire",true); + stopTnt = properties.getBoolean("stopTNT",true); rules = properties.getString("rules", "").split("@"); String[] tempEz = properties.getString("ezModo").split(","); @@ -165,8 +167,8 @@ public class vminecraftSettings { public boolean cmdMasstp() {return cmdMasstp;} public boolean cmdEzModo() {return cmdEzModo;} public boolean cmdWho() {return cmdWho;} - public boolean stopFire() {return stopFire;} - public boolean stopTnt() {return stopTnt;} + public boolean stopFire() {return stopFire;} + public boolean stopTnt() {return stopTnt;} //EzModo functions public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}