Fixed some bugs

This commit is contained in:
cerevisiae 2010-11-28 17:43:42 -06:00
parent 66740290d3
commit 343c170d59
4 changed files with 347 additions and 161 deletions

View File

@ -23,6 +23,175 @@ public class vminecraftChat {
} }
} }
//=====================================================================
//Function: wordWrap
//Input: 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(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;
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;
}
//=====================================================================
//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++)
{
if("i;,.:|!".indexOf(str.charAt(x)) != -1)
{
length+=2;
}
else if("l'".indexOf(str.charAt(x)) != -1)
{
length+=3;
}
else if("tI[]".indexOf(str.charAt(x)) != -1)
{
length+=4;
}
else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
{
length+=5;
}
else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
{
length+=6;
}
else if("@~".indexOf(str.charAt(x)) != -1)
{
length+=7;
}
else if(str.charAt(x)==' ')
{
length+=4;
}
}
return length;
}
public static String rainbow(String msg){
String temp = "";
//The array of colors to use
String[] rainbow = new String[] {Colors.Red, Colors.Rose,
Colors.Yellow, Colors.Green, Colors.Blue,
Colors.LightPurple, Colors.Purple};
int counter=0;
//Loop through the message applying the colors
for(int x=0; x<msg.length(); x++)
{
temp+=rainbow[counter]+msg.charAt(x);
if(msg.charAt(x)!=' ') counter++;
if(counter==7) counter = 0;
}
return temp;
}
//===================================================================== //=====================================================================
//Function: nameColor //Function: nameColor
//Input: Player player: The player to get name as color //Input: Player player: The player to get name as color
@ -117,53 +286,6 @@ public class vminecraftChat {
return color; return color;
} }
//=====================================================================
//Function: lengthCheck
//Input: String str: The message to make sure isn't too long
//Output: boolean: If the message is too long
//Use: Check if a message is too long
//=====================================================================
public static boolean lengthCheck(String str)
{
int length = 0;
for(int x = 0; x<str.length(); x++)
{
if("i;,.:|!".indexOf(str.charAt(x)) != -1)
{
length+=2;
}
else if("l'".indexOf(str.charAt(x)) != -1)
{
length+=3;
}
else if("tI[]".indexOf(str.charAt(x)) != -1)
{
length+=4;
}
else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
{
length+=5;
}
else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
{
length+=6;
}
else if("@~".indexOf(str.charAt(x)) != -1)
{
length+=7;
}
else if(str.charAt(x)==' ')
{
length+=4;
}
}
if(length<=316)
{
return true;
} else { return false; }
}
//===================================================================== //=====================================================================
//Function: adminChat //Function: adminChat
//Input: Player player: The player talking //Input: Player player: The player talking
@ -177,8 +299,10 @@ public class vminecraftChat {
if(player.isAdmin() || player.canUseCommand("/adminchat")) if(player.isAdmin() || player.canUseCommand("/adminchat"))
{ {
//Special formatting for adminchat {Username} //Special formatting for adminchat {Username}
String adminchat = Colors.DarkPurple + "{" + player.getColor() String adminchat = Colors.DarkPurple + "{" + nameColor(player)
+ player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; + Colors.DarkPurple +"}" + Colors.White + " ";
String[] msg = wordWrap(player, message.substring(1, message.length()));
//Get the player from the playerlist to send the message to. //Get the player from the playerlist to send the message to.
for (Player p: etc.getServer().getPlayerList()) { for (Player p: etc.getServer().getPlayerList()) {
@ -189,9 +313,14 @@ public class vminecraftChat {
//And if p is an admin or has access to adminchat //And if p is an admin or has access to adminchat
if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { if (p.isAdmin() || (p.canUseCommand("/adminchat"))) {
//Send them the message //Output the first line
p.sendMessage(adminchat p.sendMessage(adminchat + msg[0]);
+ message.substring(1, message.length()));
//Get the rest of the lines and display them.
String[] tempOut = new String[msg.length - 1];
System.arraycopy(msg, 1, tempOut, 0, tempOut.length);
for(String str: tempOut)
p.sendMessage(str);
} }
} }
} }
@ -218,8 +347,19 @@ public class vminecraftChat {
if(vminecraftSettings.getInstance().greentext()) { if(vminecraftSettings.getInstance().greentext()) {
//Log the chat //Log the chat
log.log(Level.INFO, "<"+player.getName()+"> "+message); log.log(Level.INFO, "<"+player.getName()+"> "+message);
//Output the message
gmsg(playerName + Colors.LightGreen + message); //Get the multi line array
String[] msg = wordWrap(player, message);
//Output the first line
gmsg( playerName + Colors.LightGreen + msg[0]);
//Get the rest of the lines and display them.
String[] tempOut = new String[msg.length - 1];
System.arraycopy(msg, 1, tempOut, 0, tempOut.length);
for(String str: tempOut)
gmsg(Colors.LightGreen + str);
return true;
} }
return false; return false;
} }
@ -237,7 +377,18 @@ public class vminecraftChat {
String playerName = "<" + nameColor(player) + Colors.White +"> "; String playerName = "<" + nameColor(player) + Colors.White +"> ";
if (vminecraftSettings.getInstance().FFF()) { if (vminecraftSettings.getInstance().FFF()) {
log.log(Level.INFO, "<"+player.getName()+"> "+message); log.log(Level.INFO, "<"+player.getName()+"> "+message);
gmsg(playerName + Colors.Red + message);
//Get the multi line array
String[] msg = wordWrap(player, message);
//Output the first line
gmsg( playerName + Colors.Red + msg[0]);
//Get the rest of the lines and display them.
String[] tempOut = new String[msg.length - 1];
System.arraycopy(msg, 1, tempOut, 0, tempOut.length);
for(String str: tempOut)
gmsg(Colors.Red + str);
return true; return true;
} }
return false; return false;
@ -254,28 +405,68 @@ public class vminecraftChat {
{ {
//Format the name //Format the name
String playerName = "<" + nameColor(player) + Colors.White +"> "; String playerName = "<" + nameColor(player) + Colors.White +"> ";
if(vminecraftSettings.getInstance().quakeColors()&&message.length()>2 && vminecraftChat.lengthCheck(playerName + message)) { if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) {
//Loop through the string finding the color codes and inserting them
String temp = "";
for(int x = 0; x< message.length(); x++)
{
if(message.charAt(x)=='^' && x != message.length() - 1)
{
temp += vminecraftChat.colorChange(message.charAt(x+1));
x++;
}
else{
temp+=message.charAt(x);
}
}
//Log the chat //Log the chat
log.log(Level.INFO, "<"+player.getName()+"> "+message); log.log(Level.INFO, "<"+player.getName()+"> "+message);
//Broadcast the message //Get the multi line array
gmsg(playerName + temp + " "); String[] msg = wordWrap(player, message);
//Apply colors to the lines
applyColors(msg);
//Output the first line
gmsg( playerName + msg[0]);
//Get the rest of the lines and display them.
String[] tempOut = new String[msg.length - 1];
System.arraycopy(msg, 1, tempOut, 0, tempOut.length);
for(String str: tempOut)
gmsg(str);
//Loop through the string finding the color codes and inserting them
return true; return true;
} }
return false; return false;
} }
//=====================================================================
//Function: applyColors
//Input: String[] message: The lines to be colored
//Output: String[]: The lines, but colorful
//Use: Colors each line
//=====================================================================
private static String[] applyColors(String[] message)
{
//The color to start the line with
String recentColor = Colors.White;
//Go through each line
int counter = 0;
for(String msg: message)
{
//Start the line with the most recent color
String temp = recentColor;
//Loop through looking for a color code
for(int x = 0; x< msg.length(); x++)
{
if(msg.charAt(x)=='^' && x != msg.length() - 1)
{
//Set the most recent color to the new color
recentColor = vminecraftChat.colorChange(msg.charAt(x+1));
temp += recentColor;
x++;
}
else{
temp += msg.charAt(x);
}
}
//Replace the message with the colorful message
message[counter] = temp;
counter++;
}
return message;
}
} }

View File

@ -62,8 +62,12 @@ public class vminecraftCommands{
//Find the player by name //Find the player by name
Player playerTarget = etc.getServer().matchPlayer(args[0]); Player playerTarget = etc.getServer().matchPlayer(args[0]);
//Target player isn't found
if(playerTarget == null)
player.sendMessage(Colors.Rose + "Can't find user "
+ args[0] + ".");
//If it's you, return witty message //If it's you, return witty message
if (player.getName().equalsIgnoreCase(args[0])) else if (player.getName().equalsIgnoreCase(args[0]))
player.sendMessage(Colors.Rose + "You're already here!"); player.sendMessage(Colors.Rose + "You're already here!");
//If the player is higher rank than you, inform the user //If the player is higher rank than you, inform the user
@ -72,15 +76,12 @@ public class vminecraftCommands{
"That player has higher permissions than you."); "That player has higher permissions than you.");
//If the player exists transport the user to the player //If the player exists transport the user to the player
else if (playerTarget != null) { else {
log.log(Level.INFO, player.getName() + " teleported to " + log.log(Level.INFO, player.getName() + " teleported to " +
playerTarget.getName()); playerTarget.getName());
player.teleportTo(playerTarget); player.teleportTo(playerTarget);
//Otherwise inform the user that the player doesn't exist //Otherwise inform the user that the player doesn't exist
} else {
player.sendMessage(Colors.Rose + "Can't find user "
+ args[0] + ".");
} }
} }
return true; return true;
@ -133,19 +134,20 @@ public class vminecraftCommands{
} else { } else {
//Get the player by name //Get the player by name
Player playerTarget = etc.getServer().matchPlayer(args[0]); Player playerTarget = etc.getServer().matchPlayer(args[0]);
//If the target doesn't exist
if(playerTarget == null)
player.sendMessage(Colors.Rose + "Can't find user " + args[0] + ".");
//If the player has a higher rank than the user, return error //If the player has a higher rank than the user, return error
if (!player.hasControlOver(playerTarget)) { else if (!player.hasControlOver(playerTarget))
player.sendMessage(Colors.Red + "That player has higher permissions than you."); player.sendMessage(Colors.Red + "That player has higher permissions than you.");
//If the user teleports themselves, mock them //If the user teleports themselves, mock them
}else if (player.getName().equalsIgnoreCase(args[0])) { else if (player.getName().equalsIgnoreCase(args[0]))
player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!"); player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
//If the target exists, teleport them to the user //If the target exists, teleport them to the user
}else if (playerTarget != null) { else {
log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self."); log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
playerTarget.teleportTo(player); playerTarget.teleportTo(player);
//Otherwise inform the user that the target doens't exist.
} else {
player.sendMessage(Colors.Rose + "Can't find user " + args[0] + ".");
} }
} }
return true; return true;
@ -186,6 +188,7 @@ public class vminecraftCommands{
if(vminecraftSettings.getInstance().cmdRules()) { if(vminecraftSettings.getInstance().cmdRules()) {
//Display them //Display them
for (String str : vminecraftSettings.getInstance().getRules()) { for (String str : vminecraftSettings.getInstance().getRules()) {
if(str != null)
player.sendMessage(Colors.Blue+str); player.sendMessage(Colors.Blue+str);
} }
return true; return true;
@ -207,40 +210,24 @@ public class vminecraftCommands{
if(vminecraftSettings.getInstance().cmdFabulous()) { if(vminecraftSettings.getInstance().cmdFabulous()) {
//Make sure a message has been specified //Make sure a message has been specified
if (args.length < 1) {return false;} if (args.length < 1) {return false;}
String str = "", String str = "";
temp = "";
//Merge the message again //Merge the message again
str = etc.combineSplit(0, args, " "); str = etc.combineSplit(0, args, " ");
String playerName = "<" + player.getName() + "> ";
String temp2 = playerName + str;
//The array of colors to use
String[] rainbow = new String[] {Colors.Red, Colors.Rose,
Colors.Yellow, Colors.Green, Colors.Blue,
Colors.LightPurple, Colors.Purple};
int counter=0;
//If the message isn't too long
if(vminecraftChat.lengthCheck(temp2))
{
//Output for server //Output for server
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
//Loop through the message applying the colors
for(int x=0; x<str.length(); x++)
{
temp+=rainbow[counter]+str.charAt(x);
if(str.charAt(x)!=' ') counter++;
if(counter==7) counter = 0;
}
//Prepend the player name //Prepend the player name
String message = playerName + temp; String[] message = vminecraftChat.wordWrap(player, str);
//Output the message
vminecraftChat.gmsg(message); //Output the first line
vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + "> "
+ vminecraftChat.rainbow(message[0]));
//Get the rest of the lines and display them.
String[] tempOut = new String[message.length - 1];
System.arraycopy(message, 1, tempOut, 0, tempOut.length);
for(String msg: tempOut)
vminecraftChat.gmsg(vminecraftChat.rainbow(msg));
//Otherwise the message is too long, output error to user
} else {
player.sendMessage(Colors.Rose + "Message is too long");
}
return true; return true;
} }
return false; return false;
@ -259,9 +246,9 @@ public class vminecraftCommands{
//If the command is enabled //If the command is enabled
if (vminecraftSettings.getInstance().cmdWhoIs()) { if (vminecraftSettings.getInstance().cmdWhoIs()) {
//If a player is specified //If a player is specified
if (args.length < 1) { if (args.length < 1)
player.sendMessage(Colors.Rose + "Usage is /whois [player]"); player.sendMessage(Colors.Rose + "Usage is /whois [player]");
} else {
//Get the player by name //Get the player by name
Player playerTarget = null; Player playerTarget = null;
for( Player p : etc.getServer().getPlayerList()) for( Player p : etc.getServer().getPlayerList())
@ -276,7 +263,7 @@ public class vminecraftCommands{
//Displaying the information //Displaying the information
player.sendMessage(Colors.Blue + "Whois results for " + player.sendMessage(Colors.Blue + "Whois results for " +
vminecraftChat.nameColor(playerTarget) + "."); vminecraftChat.nameColor(playerTarget));
//Group //Group
player.sendMessage(Colors.Blue + "Groups: " + player.sendMessage(Colors.Blue + "Groups: " +
playerTarget.getGroups()); playerTarget.getGroups());
@ -293,6 +280,7 @@ public class vminecraftCommands{
} else { } else {
player.sendMessage(Colors.Rose+"Player not found."); player.sendMessage(Colors.Rose+"Player not found.");
} }
}
return true; return true;
} }
return false; return false;
@ -315,12 +303,14 @@ public class vminecraftCommands{
String tempList = ""; String tempList = "";
for( Player p : etc.getServer().getPlayerList()) for( Player p : etc.getServer().getPlayerList())
{ {
if(p != null){
if(count == 0) if(count == 0)
tempList += vminecraftChat.nameColor(p); tempList += vminecraftChat.nameColor(p);
else else
tempList += ", " + vminecraftChat.nameColor(p); tempList += ", " + vminecraftChat.nameColor(p);
count++; count++;
} }
}
//Get the max players from the config //Get the max players from the config
PropertiesFile server = new PropertiesFile("server.properties"); PropertiesFile server = new PropertiesFile("server.properties");
try { try {
@ -329,10 +319,11 @@ public class vminecraftCommands{
e.printStackTrace(); e.printStackTrace();
} }
int maxPlayers = server.getInt("max-players"); int maxPlayers = server.getInt("max-players");
//Output the player list //Output the player list
vminecraftChat.gmsg( Color.red + "Player List (" + count + "/" + maxPlayers + String[] tempOut = vminecraftChat.wordWrap(Colors.Rose + "Player List ("
"): " + tempList); + count + "/" + maxPlayers +"): " + tempList);
for(String msg: tempOut)
player.sendMessage( msg );
return true; return true;
} }
@ -376,8 +367,11 @@ public class vminecraftCommands{
if(vminecraftSettings.getInstance().cmdEzModo()) { if(vminecraftSettings.getInstance().cmdEzModo()) {
//Get the player by name //Get the player by name
Player playerTarget = etc.getServer().matchPlayer(args[0]); Player playerTarget = etc.getServer().matchPlayer(args[0]);
//If the player doesn't exist don't run
if(playerTarget == null)
return false;
//If the player isn't invulnerable kill them //If the player isn't invulnerable kill them
if (!vminecraftSettings.getInstance().isEzModo(player.getName())) { if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
playerTarget.setHealth(0); playerTarget.setHealth(0);
vminecraftChat.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); vminecraftChat.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName());
//Otherwise output error to the user //Otherwise output error to the user

View File

@ -29,18 +29,19 @@ public class vminecraftListener extends PluginListener {
public boolean onChat(Player player, String message){ public boolean onChat(Player player, String message){
//Quote (Greentext) //Quote (Greentext)
if (message.startsWith(">")) if (message.startsWith("@"))
vminecraftChat.quote(player, message); return vminecraftChat.adminChat(player, message);
else if (message.startsWith(">"))
return vminecraftChat.quote(player, message);
//Rage (FFF) //Rage (FFF)
else if (message.startsWith("FFF")) else if (message.startsWith("FFF"))
vminecraftChat.rage(player, message); return vminecraftChat.rage(player, message);
//Send through quakeColors otherwise //Send through quakeColors otherwise
else else
vminecraftChat.quakeColors(player, message); return vminecraftChat.quakeColors(player, message);
return false;
} }
//===================================================================== //=====================================================================

View File

@ -105,7 +105,7 @@ public class vminecraftSettings {
cmdPromote = properties.getBoolean("cmdPromote",true); cmdPromote = properties.getBoolean("cmdPromote",true);
cmdDemote = properties.getBoolean("cmdDemote",true); cmdDemote = properties.getBoolean("cmdDemote",true);
cmdWhoIs = properties.getBoolean("cmdWhoIs",true); cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
cmdWhoIs = properties.getBoolean("cmdWho",true); cmdWho = properties.getBoolean("cmdWho",true);
cmdRules = properties.getBoolean("cmdRules",true); cmdRules = properties.getBoolean("cmdRules",true);
cmdTp = properties.getBoolean("cmdTp",true); cmdTp = properties.getBoolean("cmdTp",true);
cmdMasstp = properties.getBoolean("cmdMasstp",true); cmdMasstp = properties.getBoolean("cmdMasstp",true);