isn't it done client-side?
|
If you noticed in runescape, if you type something like this,
It will turn into thisCode:hi I AM A STRING. and I AM NICE
I found an old method in the server that does this, only partially. This will format all text accurately to runescapes format.Code:Hi I Am A String. And I Am Nice
Code:public static String optimizeText(String text) { boolean endMarker = true; String output = ""; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (endMarker && c >= 'a' && c <= 'z') { c = Character.toUpperCase(c); endMarker = false; } else if (!Character.isWhitespace(text.charAt(i-1)) && i > 1) { c = Character.toLowerCase(c); } if (c == '.' || c == '!' || c == '?') { endMarker = true; } output += c; } return output; }
isn't it done client-side?
This is already in the 'Misc' class in any winterlove-based server.
You should rip the methods from the client, converting it to a long and back, that way you can remove invalid chars and save them being saved with their character info .
Correction.
It will only lowercase the letter if the character before is NOT a white space, so, "i Ii" is allowed because the second I has a whitespace before.Code:if (endMarker && c >= 'a' && c <= 'z') { c = Character.toUpperCase(c); endMarker = false; } else if (!Character.isWhitespace(text.charAt(i-1)) && i > 1) { c = Character.toLowerCase(c); }
Put the method somewhere and test it yourself.
But that method will only capitalize after a period and at the beginning. Even in the client, it will still auto-format everything to lower case unless its after a period. This method improves both, using similar techniques, and allows text formatting that matches to runescapes.
On server load call setYellCharacters().Code:public static ArrayList<Character> yellCharacters = new ArrayList<Character>(); public static void setYellCharacters() { char[] validChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '=', '+', '{', '[', ']', '}', '|', ';', ':', '"', '<', ',', '.', '>', '/', '?', '`', '~', ' ', '\\', 39}; for (int i = 0; i < validChars.length; i++) { yellCharacters.add(validChars[i]); } } public static String filterString(String f, boolean yell) { String raw = f; String build = ""; raw = raw.trim(); if (yell) { for (int i = 0; i < raw.length(); i++) { if (!yellCharacters.contains(raw.charAt(i))) { raw.replace(raw.charAt(i), ' '); } } return raw; } else { for (int i = 0; i < raw.length(); i++) { Character c = raw.charAt(i); if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { build += c; } } return build; } }
This allows dual filtering. If yellMode is false, it will only allow letters, digits, and spaces. Good for name formatting. If its on, it will allow ONLY the characters in the yell array list.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |