diff options
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java')
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 6bc0649e9..e3b25177a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,34 +1,37 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.IEssentialsModule; -import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.economy.Trade; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IEssentialsModule; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.permissions.AbstractSuperpermsPermission; import java.util.List; import java.util.logging.Logger; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; -public abstract class EssentialsCommand implements IEssentialsCommand +public abstract class EssentialsCommand extends AbstractSuperpermsPermission implements IEssentialsCommand { - private final transient String name; + protected transient String commandName; protected transient IEssentials ess; protected transient IEssentialsModule module; - protected final static Logger logger = Logger.getLogger("Minecraft"); + protected transient Server server; + protected transient Logger logger; + private transient String permission; + private transient Permission bukkitPerm; - protected EssentialsCommand(final String name) - { - this.name = name; - } - - @Override - public void setEssentials(final IEssentials ess) + public void init(final IEssentials ess, final String commandName) { this.ess = ess; + this.logger = ess.getLogger(); + this.server = ess.getServer(); + this.commandName = commandName; + this.permission = "essentials." + commandName; } @Override @@ -37,18 +40,12 @@ public abstract class EssentialsCommand implements IEssentialsCommand this.module = module; } - @Override - public String getName() - { - return name; - } - - protected User getPlayer(final Server server, final String[] args, final int pos) throws NoSuchFieldException, NotEnoughArgumentsException + protected IUser getPlayer(final String[] args, final int pos) throws NoSuchFieldException, NotEnoughArgumentsException { - return getPlayer(server, args, pos, false); + return getPlayer(args, pos, false); } - protected User getPlayer(final Server server, final String[] args, final int pos, final boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException + protected IUser getPlayer(final String[] args, final int pos, final boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException { if (args.length <= pos) { @@ -58,7 +55,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand { throw new NoSuchFieldException(_("playerNotFound")); } - final User user = ess.getUser(args[pos]); + final IUser user = ess.getUser(args[pos]); if (user != null) { if (!getOffline && (!user.isOnline() || user.isHidden())) @@ -73,13 +70,13 @@ public abstract class EssentialsCommand implements IEssentialsCommand { for (Player player : matches) { - final User userMatch = ess.getUser(player); + final IUser userMatch = ess.getUser(player); if (userMatch.getDisplayName().startsWith(args[pos]) && (getOffline || !userMatch.isHidden())) { return userMatch; } } - final User userMatch = ess.getUser(matches.get(0)); + final IUser userMatch = ess.getUser(matches.get(0)); if (getOffline || !userMatch.isHidden()) { return userMatch; @@ -89,28 +86,28 @@ public abstract class EssentialsCommand implements IEssentialsCommand } @Override - public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception + public final void run(final IUser user, final Command cmd, final String commandLabel, final String[] args) throws Exception { - final Trade charge = new Trade(this.getName(), ess); + final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); - run(server, user, commandLabel, args); + run(user, commandLabel, args); charge.charge(user); } - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - run(server, (CommandSender)user.getBase(), commandLabel, args); + run((CommandSender)user.getBase(), commandLabel, args); } @Override - public final void run(final Server server, final CommandSender sender, final String commandLabel, final Command cmd, final String[] args) throws Exception + public final void run(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) throws Exception { - run(server, sender, commandLabel, args); + run(sender, commandLabel, args); } - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - throw new Exception(_("onlyPlayers", commandLabel)); + throw new Exception(_("onlyPlayers", commandName)); } public static String getFinalArg(final String[] args, final int start) @@ -126,4 +123,10 @@ public abstract class EssentialsCommand implements IEssentialsCommand } return bldr.toString(); } + + @Override + public String getPermission() + { + return permission; + } } |