2011-04-04 01:26:45 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2014-03-20 15:54:07 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2011-04-04 01:26:45 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 21:31:19 +00:00
|
|
|
import com.earth2me.essentials.utils.StringUtil;
|
2011-08-21 18:33:37 +00:00
|
|
|
import java.util.ArrayList;
|
2011-08-21 18:02:01 +00:00
|
|
|
import java.util.List;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-04-04 01:26:45 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
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 class Commandpowertool extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandpowertool()
|
|
|
|
{
|
2011-04-04 01:26:45 +00:00
|
|
|
super("powertool");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-08-29 23:14:03 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
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
|
|
|
{
|
2013-04-30 01:12:59 +00:00
|
|
|
final String command = getFinalArg(args, 0);
|
2014-04-13 00:01:49 +00:00
|
|
|
final ItemStack itemStack = user.getBase().getItemInHand();
|
2013-10-16 19:59:39 +00:00
|
|
|
powertool(server, user.getSource(), user, commandLabel, itemStack, command);
|
2013-04-30 01:12:59 +00:00
|
|
|
}
|
2011-09-10 09:39:35 +00:00
|
|
|
|
2013-04-30 01:12:59 +00:00
|
|
|
@Override
|
2013-10-16 19:59:39 +00:00
|
|
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
2013-04-30 01:12:59 +00:00
|
|
|
{
|
|
|
|
if (args.length < 3) //running from console means inserting a player and item before the standard syntax
|
|
|
|
{
|
|
|
|
throw new Exception("When running from console, usage is: /" + commandLabel + " <player> <itemid> <command>");
|
|
|
|
}
|
|
|
|
|
|
|
|
final User user = getPlayer(server, args, 0, true, true);
|
|
|
|
final ItemStack itemStack = ess.getItemDb().get(args[1]);
|
|
|
|
final String command = getFinalArg(args, 2);
|
|
|
|
powertool(server, sender, user, commandLabel, itemStack, command);
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
protected void powertool(final Server server, final CommandSource sender, final User user, final String commandLabel, final ItemStack itemStack, String command) throws Exception
|
2013-04-30 01:12:59 +00:00
|
|
|
{
|
2011-09-10 09:39:35 +00:00
|
|
|
// check to see if this is a clear all command
|
2011-12-09 21:42:36 +00:00
|
|
|
if (command != null && command.equalsIgnoreCase("d:"))
|
2011-09-10 09:39:35 +00:00
|
|
|
{
|
|
|
|
user.clearAllPowertools();
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("powerToolClearAll"));
|
2011-09-10 09:39:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-04 16:42:03 +00:00
|
|
|
|
2011-08-29 23:14:03 +00:00
|
|
|
if (itemStack == null || itemStack.getType() == Material.AIR)
|
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
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("powerToolAir"));
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
2011-08-21 01:50:48 +00:00
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
|
2011-08-29 23:14:03 +00:00
|
|
|
List<String> powertools = user.getPowertool(itemStack);
|
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 (command != null && !command.isEmpty())
|
|
|
|
{
|
2011-08-27 01:54:45 +00:00
|
|
|
if (command.equalsIgnoreCase("l:"))
|
2011-08-21 01:50:48 +00:00
|
|
|
{
|
2011-08-21 18:02:01 +00:00
|
|
|
if (powertools == null || powertools.isEmpty())
|
2011-08-21 01:50:48 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("powerToolListEmpty", itemName));
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("powerToolList", StringUtil.joinList(powertools), itemName));
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
2012-04-03 23:40:58 +00:00
|
|
|
throw new NoChargeException();
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
|
|
|
if (command.startsWith("r:"))
|
|
|
|
{
|
2012-04-03 23:40:58 +00:00
|
|
|
command = command.substring(2);
|
|
|
|
if (!powertools.contains(command))
|
2011-08-21 01:50:48 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("powerToolNoSuchCommandAssigned", command, itemName));
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
2012-04-03 23:40:58 +00:00
|
|
|
|
|
|
|
powertools.remove(command);
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("powerToolRemove", command, itemName));
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (command.startsWith("a:"))
|
|
|
|
{
|
2013-10-16 19:59:39 +00:00
|
|
|
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.powertool.append"))
|
2011-12-09 21:42:36 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("noPerm", "essentials.powertool.append"));
|
2011-12-09 21:42:36 +00:00
|
|
|
}
|
2011-08-21 18:33:37 +00:00
|
|
|
command = command.substring(2);
|
2011-08-29 23:14:03 +00:00
|
|
|
if (powertools.contains(command))
|
2011-08-21 01:50:48 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("powerToolAlreadySet", command, itemName));
|
2011-08-21 01:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-21 18:33:37 +00:00
|
|
|
else if (powertools != null && !powertools.isEmpty())
|
|
|
|
{
|
|
|
|
// Replace all commands with this one
|
|
|
|
powertools.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
powertools = new ArrayList<String>();
|
|
|
|
}
|
2011-08-21 01:50:48 +00:00
|
|
|
|
2011-08-21 18:33:37 +00:00
|
|
|
powertools.add(command);
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("powerToolAttach", StringUtil.joinList(powertools), itemName));
|
2011-08-21 01:50:48 +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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-29 23:14:03 +00:00
|
|
|
if (powertools != null)
|
|
|
|
{
|
|
|
|
powertools.clear();
|
|
|
|
}
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("powerToolRemoveAll", itemName));
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
2011-08-21 01:50:48 +00:00
|
|
|
|
2012-04-03 23:40:58 +00:00
|
|
|
if (!user.arePowerToolsEnabled())
|
|
|
|
{
|
2012-04-03 23:39:59 +00:00
|
|
|
user.setPowerToolsEnabled(true);
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("powerToolsEnabled"));
|
2012-04-03 23:39:59 +00:00
|
|
|
}
|
2011-08-29 23:14:03 +00:00
|
|
|
user.setPowertool(itemStack, powertools);
|
2011-04-04 01:26:45 +00:00
|
|
|
}
|
|
|
|
}
|