mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Added /msg and /reply
This commit is contained in:
parent
d8de7af3cb
commit
42c7688c1a
@ -61,7 +61,7 @@ public class vMinecraftChat {
|
||||
|
||||
//Loop through the words finding their length and increasing
|
||||
//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;
|
||||
|
||||
|
@ -44,7 +44,11 @@ public class vMinecraftCommands{
|
||||
cl.register("/a", "adminChatToggle", "toggle admin chat for every message");
|
||||
cl.register("/modify", "modifySplit");
|
||||
cl.register("/me", "me");
|
||||
cl.register("/msg", "message");
|
||||
cl.register("/reply", "reply");
|
||||
cl.registerAlias("/playerlist", "/who");
|
||||
cl.registerAlias("/r", "/reply");
|
||||
cl.registerAlias("/w", "/msg");
|
||||
cl.registerAlias("/wrists", "/suicide");
|
||||
cl.registerAlias("/ci", "/clearinventory");
|
||||
}
|
||||
@ -62,6 +66,65 @@ public class vMinecraftCommands{
|
||||
vMinecraftChat.emote(player, str);
|
||||
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)
|
||||
@ -523,7 +586,7 @@ public class vMinecraftCommands{
|
||||
{
|
||||
//Exploit fix for people giving themselves commands
|
||||
if(args[1].equals("commands"))
|
||||
return EXIT_FAIL;
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class vMinecraftUsers {
|
||||
private PropertiesFile properties;
|
||||
String location = "vminecraftusers.txt";
|
||||
|
||||
ArrayList<PlayerList> players = new ArrayList<PlayerList>();
|
||||
public static PlayerList players = new PlayerList();
|
||||
|
||||
|
||||
public void loadUsers(){
|
||||
@ -143,11 +143,11 @@ class PlayerList
|
||||
//Output: PlayerProfile: The profile of 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)
|
||||
{
|
||||
if(ply.getPlayer().equals(player))
|
||||
if(ply.isPlayer(player))
|
||||
return ply;
|
||||
}
|
||||
return null;
|
||||
@ -161,10 +161,11 @@ class PlayerList
|
||||
class PlayerProfile
|
||||
{
|
||||
protected final Logger log = Logger.getLogger("Minecraft");
|
||||
private Player playerName;
|
||||
private String nickName;
|
||||
private String tag;
|
||||
private String suffix;
|
||||
private String playerName,
|
||||
lastMessage,
|
||||
nickName,
|
||||
tag,
|
||||
suffix;
|
||||
private ArrayList<Player> ignoreList;
|
||||
private commandList aliasList;
|
||||
|
||||
@ -181,13 +182,14 @@ class PlayerList
|
||||
//=====================================================================
|
||||
public PlayerProfile(Player player)
|
||||
{
|
||||
//Declare things
|
||||
ignoreList = new ArrayList<Player>();
|
||||
aliasList = new commandList();
|
||||
//Declare things
|
||||
nickName = new String();
|
||||
tag = new String();
|
||||
suffix = new String();
|
||||
ignoreList = new ArrayList<Player>();
|
||||
aliasList = new commandList();
|
||||
String location = "vminecraftusers.txt";
|
||||
|
||||
//Try to apply what we can
|
||||
try {
|
||||
Scanner scanner = new Scanner(new File(location));
|
||||
@ -197,43 +199,55 @@ class PlayerList
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(":");
|
||||
if (!split[0].equalsIgnoreCase(player.getName())) {
|
||||
continue;
|
||||
}
|
||||
nickName = (split[1].split(",").toString());
|
||||
|
||||
if (split.length >= 4) {
|
||||
tag = (split[3]);
|
||||
}
|
||||
|
||||
//Add all the ignored people to the player's ignore list
|
||||
if (split.length >= 5) {
|
||||
for(String name : split[4].split(","))
|
||||
ignoreList.add(etc.getServer().getPlayer(name));
|
||||
}
|
||||
if (split.length >= 6) {
|
||||
//Loop through all the aliases
|
||||
for(String alias : split[5].split(","))
|
||||
{
|
||||
//Break apart the two parts of the alias
|
||||
String[] parts = alias.split("@");
|
||||
if(parts.length > 1)
|
||||
{
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
//If the player name is equal to the name in the list
|
||||
if (split.length > 0 && split[0].equalsIgnoreCase(player.getName())) {
|
||||
|
||||
//Get the tag from the 1st split
|
||||
nickName = (split[1].split(",").toString());
|
||||
|
||||
//Get the tag from the 2nd split
|
||||
suffix = split[2];
|
||||
|
||||
//Get the tag from the 3rd split
|
||||
if (split.length >= 4) {
|
||||
tag = (split[3]);
|
||||
}
|
||||
|
||||
//Add all the ignored people to the player's ignore list
|
||||
if (split.length >= 5) {
|
||||
for(String name : split[4].split(","))
|
||||
ignoreList.add(etc.getServer().getPlayer(name));
|
||||
}
|
||||
|
||||
//Get the alias list, from the 5th split
|
||||
if (split.length >= 6) {
|
||||
//Loop through all the aliases
|
||||
for(String alias : split[5].split(","))
|
||||
{
|
||||
//Break apart the two parts of the alias
|
||||
String[] parts = alias.split("@");
|
||||
if(parts.length > 1)
|
||||
{
|
||||
//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();
|
||||
} 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;
|
||||
}
|
||||
String[] split = line.split(":");
|
||||
if (!split[0].equalsIgnoreCase(playerName.toString())) {
|
||||
if (!split[0].equalsIgnoreCase(playerName)) {
|
||||
continue;
|
||||
}
|
||||
bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList);
|
||||
@ -267,14 +281,16 @@ class PlayerList
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=====================================================================
|
||||
//Function: getPlayer
|
||||
//Function: isPlayer
|
||||
//Input: None
|
||||
//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
|
||||
@ -369,6 +385,28 @@ class PlayerList
|
||||
//Use: Gets a player 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user