2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-04-05 15:57:54 +00:00
|
|
|
import com.earth2me.essentials.Console;
|
2011-11-21 02:55:26 +01:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-04-05 15:57:54 +00:00
|
|
|
import com.earth2me.essentials.IReplyTo;
|
2011-07-18 03:42:21 +02:00
|
|
|
import com.earth2me.essentials.User;
|
2012-01-16 19:42:15 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2011-11-18 17:42:26 +00:00
|
|
|
import java.util.List;
|
|
|
|
import org.bukkit.Server;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2011-03-19 22:39:51 +00:00
|
|
|
public class Commandmsg extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandmsg()
|
|
|
|
{
|
|
|
|
super("msg");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
if (args.length < 2 || args[0].trim().isEmpty() || args[1].trim().isEmpty())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 20:25:36 +00:00
|
|
|
String message = getFinalArg(args, 1);
|
2011-08-08 15:34:10 +02:00
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
|
|
|
User user = ess.getUser(sender);
|
|
|
|
if (user.isMuted())
|
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
throw new Exception(_("voiceSilenced"));
|
2011-08-08 15:34:10 +02:00
|
|
|
}
|
2012-01-16 20:25:36 +00:00
|
|
|
if (user.isAuthorized("essentials.msg.color"))
|
|
|
|
{
|
2012-01-18 23:35:30 +00:00
|
|
|
message = Util.replaceColor(message);
|
2012-01-16 20:25:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message = Util.stripColor(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-18 23:35:30 +00:00
|
|
|
message = Util.replaceColor(message);
|
2011-08-08 15:34:10 +02:00
|
|
|
}
|
|
|
|
|
2012-01-16 19:42:15 +00:00
|
|
|
final String translatedMe = _("me");
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2012-01-16 19:42:15 +00:00
|
|
|
final IReplyTo replyTo = sender instanceof Player ? ess.getUser((Player)sender) : Console.getConsoleReplyTo();
|
|
|
|
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2011-04-05 15:57:54 +00:00
|
|
|
if (args[0].equalsIgnoreCase(Console.NAME))
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
sender.sendMessage(_("msgFormat", translatedMe, Console.NAME, message));
|
2011-04-05 15:57:54 +00:00
|
|
|
CommandSender cs = Console.getCommandSender(server);
|
2011-11-21 02:55:26 +01:00
|
|
|
cs.sendMessage(_("msgFormat", senderName, translatedMe, message));
|
2011-04-05 15:57:54 +00:00
|
|
|
replyTo.setReplyTo(cs);
|
|
|
|
Console.getConsoleReplyTo().setReplyTo(sender);
|
2011-04-05 18:28:18 +00:00
|
|
|
return;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2012-01-16 19:42:15 +00:00
|
|
|
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2012-01-16 19:42:15 +00:00
|
|
|
if (matchedPlayers.isEmpty())
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
throw new Exception(_("playerNotFound"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2011-08-08 15:34:10 +02:00
|
|
|
|
2011-07-20 21:36:23 +02:00
|
|
|
int i = 0;
|
2012-01-16 19:42:15 +00:00
|
|
|
for (Player matchedPlayer : matchedPlayers)
|
2011-07-20 21:36:23 +02:00
|
|
|
{
|
2012-01-16 19:42:15 +00:00
|
|
|
final User u = ess.getUser(matchedPlayer);
|
2011-07-20 21:36:23 +02:00
|
|
|
if (u.isHidden())
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2012-01-16 19:42:15 +00:00
|
|
|
if (i == matchedPlayers.size())
|
2011-07-20 21:36:23 +02:00
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
throw new Exception(_("playerNotFound"));
|
2011-07-20 21:36:23 +02:00
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2012-01-16 19:42:15 +00:00
|
|
|
for (Player matchedPlayer : matchedPlayers)
|
2011-07-20 21:36:23 +02:00
|
|
|
{
|
2012-01-16 19:42:15 +00:00
|
|
|
sender.sendMessage(_("msgFormat", translatedMe, matchedPlayer.getDisplayName(), message));
|
|
|
|
final User matchedUser = ess.getUser(matchedPlayer);
|
|
|
|
if (sender instanceof Player && (matchedUser.isIgnoredPlayer(((Player)sender).getName()) || matchedUser.isHidden()))
|
2011-05-15 11:40:46 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-16 19:42:15 +00:00
|
|
|
matchedPlayer.sendMessage(_("msgFormat", senderName, translatedMe, message));
|
|
|
|
replyTo.setReplyTo(ess.getUser(matchedPlayer));
|
|
|
|
ess.getUser(matchedPlayer).setReplyTo(sender);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|