2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-18 17:42:26 +00:00
|
|
|
import com.earth2me.essentials.*;
|
2011-03-19 22:39:51 +00:00
|
|
|
import java.util.List;
|
2011-11-18 17:42:26 +00:00
|
|
|
import java.util.logging.Logger;
|
2011-03-19 22:39:51 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class EssentialsCommand implements IEssentialsCommand
|
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
private final transient String name;
|
|
|
|
protected transient IEssentials ess;
|
2011-05-09 09:31:36 +00:00
|
|
|
protected final static Logger logger = Logger.getLogger("Minecraft");
|
2011-03-19 22:39:51 +00:00
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
protected EssentialsCommand(final String name)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
this.name = name;
|
2011-06-01 10:40:12 +00:00
|
|
|
}
|
2011-07-07 20:05:08 +00:00
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
public void setEssentials(final IEssentials ess)
|
2011-06-01 10:40:12 +00:00
|
|
|
{
|
|
|
|
this.ess = ess;
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
protected User getPlayer(final Server server, final String[] args, final int pos) throws NoSuchFieldException, NotEnoughArgumentsException
|
2011-07-07 20:05:08 +00:00
|
|
|
{
|
|
|
|
return getPlayer(server, args, pos, false);
|
|
|
|
}
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
protected User getPlayer(final Server server, final String[] args, final int pos, final boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
if (args.length <= pos)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
final User user = ess.getUser(args[pos]);
|
2011-07-18 21:16:58 +00:00
|
|
|
if (user != null)
|
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
if (!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden()))
|
2011-07-18 21:16:58 +00:00
|
|
|
{
|
|
|
|
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
|
|
|
}
|
|
|
|
return user;
|
2011-07-07 20:05:08 +00:00
|
|
|
}
|
2011-08-08 12:40:30 +00:00
|
|
|
final List<Player> matches = server.matchPlayer(args[pos]);
|
2011-07-07 20:05:08 +00:00
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
if (!matches.isEmpty())
|
2011-05-13 21:10:49 +00:00
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
for (Player player : matches)
|
2011-05-13 21:10:49 +00:00
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
final User userMatch = ess.getUser(player);
|
|
|
|
if (userMatch.getDisplayName().startsWith(args[pos]) && (getOffline || !userMatch.isHidden()))
|
|
|
|
{
|
|
|
|
return userMatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final User userMatch = ess.getUser(matches.get(0));
|
|
|
|
if (getOffline || !userMatch.isHidden())
|
|
|
|
{
|
|
|
|
return userMatch;
|
2011-05-13 21:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 12:40:30 +00:00
|
|
|
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-08-08 12:40:30 +00:00
|
|
|
public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-08-27 21:14:49 +00:00
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
|
|
|
charge.isAffordableFor(user);
|
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
|
|
|
run(server, user, commandLabel, args);
|
2011-08-27 21:14:49 +00:00
|
|
|
charge.charge(user);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final 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
|
|
|
run(server, (CommandSender)user.getBase(), commandLabel, args);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-08-08 12:40:30 +00:00
|
|
|
public final void run(final Server server, final CommandSender sender, final String commandLabel, final Command cmd, final 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
|
|
|
run(server, sender, commandLabel, args);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-05-15 01:30:54 +00:00
|
|
|
throw new Exception(Util.format("onlyPlayers", commandLabel));
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 12:40:30 +00:00
|
|
|
public static String getFinalArg(final String[] args, final int start)
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-08-08 12:40:30 +00:00
|
|
|
final StringBuilder bldr = new StringBuilder();
|
2011-03-19 22:39:51 +00:00
|
|
|
for (int i = start; i < args.length; i++)
|
|
|
|
{
|
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 (i != start)
|
|
|
|
{
|
|
|
|
bldr.append(" ");
|
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
bldr.append(args[i]);
|
|
|
|
}
|
|
|
|
return bldr.toString();
|
|
|
|
}
|
|
|
|
}
|