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