Added /msg and /reply

This commit is contained in:
cerevisiae 2010-12-07 22:00:32 -06:00
parent d8de7af3cb
commit 42c7688c1a
3 changed files with 151 additions and 50 deletions

View File

@ -61,7 +61,7 @@ public class vMinecraftChat {
//Loop through the words finding their length and increasing //Loop through the words finding their length and increasing
//j, the end point for the sub string //j, the end point for the sub string
while(len <= lineLength && !split.isEmpty()) while(split.get(0) != null && len <= lineLength && !split.isEmpty())
{ {
int wordLength = msgLength(split.get(0)) + 4; int wordLength = msgLength(split.get(0)) + 4;

View File

@ -44,7 +44,11 @@ public class vMinecraftCommands{
cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); cl.register("/a", "adminChatToggle", "toggle admin chat for every message");
cl.register("/modify", "modifySplit"); cl.register("/modify", "modifySplit");
cl.register("/me", "me"); cl.register("/me", "me");
cl.register("/msg", "message");
cl.register("/reply", "reply");
cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/playerlist", "/who");
cl.registerAlias("/r", "/reply");
cl.registerAlias("/w", "/msg");
cl.registerAlias("/wrists", "/suicide"); cl.registerAlias("/wrists", "/suicide");
cl.registerAlias("/ci", "/clearinventory"); cl.registerAlias("/ci", "/clearinventory");
} }
@ -62,6 +66,65 @@ public class vMinecraftCommands{
vMinecraftChat.emote(player, str); vMinecraftChat.emote(player, str);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
//=====================================================================
//Function: message (/msg, /w, /whisper)
//Input: Player player: The player using the command
//Output: int: Exit Code
//Use: Send a message to a player
//=====================================================================
public static int message(Player player, String[] args)
{
String msg = etc.combineSplit(1, args, " ");
Player toPlayer = etc.getServer().matchPlayer(args[0]);
if (args.length < 1) {
return EXIT_FAIL;
} else if (toPlayer != null) {
//Send the message to the targeted player and the sender
vMinecraftChat.sendMessage(player, toPlayer,
Colors.LightGreen + "[" + Colors.White + "From:"
+ vMinecraftChat.getName(player) + Colors.LightGreen + "]" + msg);
vMinecraftChat.sendMessage(player, player,
Colors.LightGreen + "[" + Colors.White + "To:"
+ vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "]" + msg);
//Set the last massager for each player
vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
} else {
vMinecraftChat.sendMessage(player, player, Colors.Red
+ "No player by the name of " + args[0] + " could be found.");
}
return EXIT_SUCCESS;
}
//=====================================================================
//Function: reply (/r, /reply)
//Input: Player player: The player using the command
//Output: int: Exit Code
//Use: Send a message to a player
//=====================================================================
public static int reply(Player player, String[] args)
{
Player toPlayer = vMinecraftUsers.players.findProfile(player).getMessage();
if (toPlayer != null) {
String msg = etc.combineSplit(1, args, " ");
//Send the message to the targeted player and the sender
vMinecraftChat.sendMessage(player, toPlayer,
Colors.LightGreen + "[" + Colors.White + "From:"
+ vMinecraftChat.getName(player) + Colors.LightGreen + "] " + msg);
vMinecraftChat.sendMessage(player, player,
Colors.LightGreen + "[" + Colors.White + "To:"
+ vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "] " + msg);
//Set the last messager for each player
vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
} else {
vMinecraftChat.sendMessage(player, player,
Colors.Red + "That person is no longer logged in.");
}
return EXIT_SUCCESS;
}
//===================================================================== //=====================================================================
//Function: adminChatToggle (/a) //Function: adminChatToggle (/a)
@ -523,7 +586,7 @@ public class vMinecraftCommands{
{ {
//Exploit fix for people giving themselves commands //Exploit fix for people giving themselves commands
if(args[1].equals("commands")) if(args[1].equals("commands"))
return EXIT_FAIL; return EXIT_SUCCESS;
return EXIT_CONTINUE; return EXIT_CONTINUE;
} }

View File

@ -11,7 +11,7 @@ public class vMinecraftUsers {
private PropertiesFile properties; private PropertiesFile properties;
String location = "vminecraftusers.txt"; String location = "vminecraftusers.txt";
ArrayList<PlayerList> players = new ArrayList<PlayerList>(); public static PlayerList players = new PlayerList();
public void loadUsers(){ public void loadUsers(){
@ -143,11 +143,11 @@ class PlayerList
//Output: PlayerProfile: The profile of the specified player //Output: PlayerProfile: The profile of the specified player
//Use: Get the profile for the specified player //Use: Get the profile for the specified player
//===================================================================== //=====================================================================
private PlayerProfile findProfile(Player player) public PlayerProfile findProfile(Player player)
{ {
for(PlayerProfile ply : players) for(PlayerProfile ply : players)
{ {
if(ply.getPlayer().equals(player)) if(ply.isPlayer(player))
return ply; return ply;
} }
return null; return null;
@ -161,10 +161,11 @@ class PlayerList
class PlayerProfile class PlayerProfile
{ {
protected final Logger log = Logger.getLogger("Minecraft"); protected final Logger log = Logger.getLogger("Minecraft");
private Player playerName; private String playerName,
private String nickName; lastMessage,
private String tag; nickName,
private String suffix; tag,
suffix;
private ArrayList<Player> ignoreList; private ArrayList<Player> ignoreList;
private commandList aliasList; private commandList aliasList;
@ -181,13 +182,14 @@ class PlayerList
//===================================================================== //=====================================================================
public PlayerProfile(Player player) public PlayerProfile(Player player)
{ {
//Declare things //Declare things
ignoreList = new ArrayList<Player>();
aliasList = new commandList();
nickName = new String(); nickName = new String();
tag = new String(); tag = new String();
suffix = new String(); suffix = new String();
ignoreList = new ArrayList<Player>();
aliasList = new commandList();
String location = "vminecraftusers.txt"; String location = "vminecraftusers.txt";
//Try to apply what we can //Try to apply what we can
try { try {
Scanner scanner = new Scanner(new File(location)); Scanner scanner = new Scanner(new File(location));
@ -197,43 +199,55 @@ class PlayerList
continue; continue;
} }
String[] split = line.split(":"); String[] split = line.split(":");
if (!split[0].equalsIgnoreCase(player.getName())) {
continue; //If the player name is equal to the name in the list
} if (split.length > 0 && split[0].equalsIgnoreCase(player.getName())) {
nickName = (split[1].split(",").toString());
//Get the tag from the 1st split
if (split.length >= 4) { nickName = (split[1].split(",").toString());
tag = (split[3]);
} //Get the tag from the 2nd split
suffix = split[2];
//Add all the ignored people to the player's ignore list
if (split.length >= 5) { //Get the tag from the 3rd split
for(String name : split[4].split(",")) if (split.length >= 4) {
ignoreList.add(etc.getServer().getPlayer(name)); tag = (split[3]);
} }
if (split.length >= 6) {
//Loop through all the aliases //Add all the ignored people to the player's ignore list
for(String alias : split[5].split(",")) if (split.length >= 5) {
{ for(String name : split[4].split(","))
//Break apart the two parts of the alias ignoreList.add(etc.getServer().getPlayer(name));
String[] parts = alias.split("@"); }
if(parts.length > 1)
{ //Get the alias list, from the 5th split
//Get the arguments for the alias if there are any if (split.length >= 6) {
String[] command = parts[1].split(" "); //Loop through all the aliases
String[] args = null; for(String alias : split[5].split(","))
if(command.length > 1) {
System.arraycopy(command, 1, args, 0, command.length - 2); //Break apart the two parts of the alias
String[] parts = alias.split("@");
//Register the alias to the player's aliasList if(parts.length > 1)
aliasList.registerAlias(parts[0], command[0], args); {
} //Get the arguments for the alias if there are any
} String[] command = parts[1].split(" ");
String[] args = null;
if(command.length > 1)
System.arraycopy(command, 1, args,
0, command.length - 2);
//Register the alias to the player's aliasList
aliasList.registerAlias(parts[0], command[0], args);
}
}
}
break;
} }
} }
scanner.close(); scanner.close();
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); log.log(Level.SEVERE, "Exception while reading "
+ location + " (Are you sure you formatted it correctly?)", e);
} }
} }
@ -255,7 +269,7 @@ class PlayerList
continue; continue;
} }
String[] split = line.split(":"); String[] split = line.split(":");
if (!split[0].equalsIgnoreCase(playerName.toString())) { if (!split[0].equalsIgnoreCase(playerName)) {
continue; continue;
} }
bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList); bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList);
@ -267,14 +281,16 @@ class PlayerList
} }
} }
//===================================================================== //=====================================================================
//Function: getPlayer //Function: isPlayer
//Input: None //Input: None
//Output: Player: The player this profile belongs to //Output: Player: The player this profile belongs to
//Use: Finds if the specified player is in the ignore list //Use: Finds if this profile belongs to a specified player
//===================================================================== //=====================================================================
public Player getPlayer(){return playerName;} public boolean isPlayer(Player player)
{
return player.getName().equals(playerName);
}
//===================================================================== //=====================================================================
//Function: isIgnored //Function: isIgnored
@ -369,6 +385,28 @@ class PlayerList
//Use: Gets a player tag //Use: Gets a player tag
//===================================================================== //=====================================================================
public String getTag() { return tag; } public String getTag() { return tag; }
//=====================================================================
//Function: setMessage
//Input: String newName: The name of the player they last messaged
// or recieved a message from.
//Output: None
//Use: Sets a player tag
//=====================================================================
public void setMessage(Player newName){ lastMessage = newName.getName(); }
//=====================================================================
//Function: getMessage
//Input: None
//Output: String: The player name
//Use: Gets the name of the player they last messaged or recieved
// a message from.
//=====================================================================
public Player getMessage()
{
return etc.getServer().matchPlayer(lastMessage);
}
} }
} }