Corrected all commands of PermCommands

onCommand now supports the change of the permissions prefix
This commit is contained in:
snowleo 2011-06-26 15:47:28 +02:00
parent 3b9a07e560
commit 88ded926f4
24 changed files with 39 additions and 37 deletions

View File

@ -352,22 +352,13 @@ public class Essentials extends JavaPlugin implements IEssentials
return retval; return retval;
} }
@SuppressWarnings("LoggerStringConcat")
public static void previewCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
if (sender instanceof Player)
{
logger.info(ChatColor.BLUE + "[PLAYER_COMMAND] " + ((Player)sender).getName() + ": /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0));
}
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{ {
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command"); return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
} }
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath) public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
{ {
if (("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase())) && sender instanceof Player) if (("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase())) && sender instanceof Player)
{ {
@ -416,8 +407,12 @@ public class Essentials extends JavaPlugin implements IEssentials
try try
{ {
previewCommand(sender, command, commandLabel, args); User user = null;
User user = sender instanceof Player ? getUser(sender) : null; if (sender instanceof Player)
{
user = getUser(sender);
logger.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel , EssentialsCommand.getFinalArg(args, 0)));
}
// New mail notification // New mail notification
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail")) if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
@ -449,7 +444,7 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
// Check authorization // Check authorization
if (user != null && !user.isAuthorized(cmd)) if (user != null && !user.isAuthorized(cmd, permissionPrefix))
{ {
logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName())); logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
user.sendMessage(Util.i18n("noAccessCommand")); user.sendMessage(Util.i18n("noAccessCommand"));

View File

@ -16,7 +16,7 @@ public interface IEssentials
void reload(); void reload();
boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath); boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix);
User getUser(Object base); User getUser(Object base);

View File

@ -22,6 +22,8 @@ public interface IUser
boolean isAuthorized(String node); boolean isAuthorized(String node);
boolean isAuthorized(IEssentialsCommand cmd); boolean isAuthorized(IEssentialsCommand cmd);
boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
void setLastTeleportTimestamp(long time); void setLastTeleportTimestamp(long time);

View File

@ -31,10 +31,15 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
setBase(base); setBase(base);
return this; return this;
} }
public boolean isAuthorized(IEssentialsCommand cmd) public boolean isAuthorized(IEssentialsCommand cmd)
{ {
return isAuthorized("essentials." + (cmd.getName().equals("r") ? "msg" : cmd.getName())); return isAuthorized(cmd, "essentials.");
}
public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix)
{
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
} }
public boolean isAuthorized(String node) public boolean isAuthorized(String node)

View File

@ -21,7 +21,7 @@ public class Commandmangadd extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final String group = args[0]; final String group = args[0];
String command = "/permissions g:" + group + " create"; String command = "permissions g:" + group + " create";
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmangaddi extends EssentialsCommand
} }
final String target = args[0]; final String target = args[0];
final String group = args[1]; final String group = args[1];
String command = "/permissions g:"+target+" parents add "+group; String command = "permissions g:"+target+" parents add "+group;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmangaddp extends EssentialsCommand
} }
final String target = args[0]; final String target = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions g:"+target+" perms add "+perm; String command = "permissions g:"+target+" perms add "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmangcheckp extends EssentialsCommand
} }
final String target = args[0]; final String target = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions g:"+target+" has "+perm; String command = "permissions g:"+target+" has "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -21,7 +21,7 @@ public class Commandmangdel extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final String group = args[0]; final String group = args[0];
String command = "/permissions g:"+group+" delete"; String command = "permissions g:"+group+" delete";
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmangdeli extends EssentialsCommand
} }
final String target = args[0]; final String target = args[0];
final String group = args[1]; final String group = args[1];
String command = "/permissions g:"+target+" parents remove "+group; String command = "permissions g:"+target+" parents remove "+group;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmangdelp extends EssentialsCommand
} }
final String target = args[0]; final String target = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions g:"+target+" perms remove "+perm; String command = "permissions g:"+target+" perms remove "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -21,7 +21,7 @@ public class Commandmanglistp extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final String target = args[0]; final String target = args[0];
String command = "/permissions g:"+target+" perms list"; String command = "permissions g:"+target+" perms list";
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -21,7 +21,7 @@ public class Commandmanload extends EssentialsCommand
{ {
world = args[0]; world = args[0];
} }
String command = "/permissions -reload "+world; String command = "permissions -reload "+world;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -23,7 +23,7 @@ public class Commandmanuadd extends EssentialsCommand
final String player = args[0]; final String player = args[0];
final String group = args[1]; final String group = args[1];
//TODO: Make this command add a player if it doesnt exist /permissions +player+ create //TODO: Make this command add a player if it doesnt exist /permissions +player+ create
String command = "/permissions "+player+" parents add "+group; String command = "permissions "+player+" parents add "+group;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmanuaddp extends EssentialsCommand
} }
final String player = args[0]; final String player = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions "+player+" perms add "+perm; String command = "permissions "+player+" perms add "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmanuaddsub extends EssentialsCommand
} }
final String player = args[0]; final String player = args[0];
final String group = args[1]; final String group = args[1];
String command = "/permissions "+player+" parents add "+group; String command = "permissions "+player+" parents add "+group;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmanucheckp extends EssentialsCommand
} }
final String player = args[0]; final String player = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions "+player+" has "+perm; String command = "permissions "+player+" has "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -21,7 +21,7 @@ public class Commandmanudel extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final String player = args[0]; final String player = args[0];
String command = "/permissions "+player+" delete"; String command = "permissions "+player+" delete";
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmanudelp extends EssentialsCommand
} }
final String player = args[0]; final String player = args[0];
final String perm = args[1]; final String perm = args[1];
String command = "/permissions "+player+" perms remove "+perm; String command = "permissions "+player+" perms remove "+perm;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -22,7 +22,7 @@ public class Commandmanudelsub extends EssentialsCommand
} }
final String player = args[0]; final String player = args[0];
final String group = args[1]; final String group = args[1];
String command = "/permissions "+player+" parents remove "+group; String command = "permissions "+player+" parents remove "+group;
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -21,7 +21,7 @@ public class Commandmanulistp extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final String player = args[0]; final String player = args[0];
String command = "/permissions "+player+" perms list"; String command = "permissions "+player+" perms list";
sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead."); sender.sendMessage(commandLabel + " is deprecated. Use " + command + " instead.");
ess.getServer().dispatchCommand(sender, command); ess.getServer().dispatchCommand(sender, command);
} }

View File

@ -35,7 +35,7 @@ public class EssentialsPermissionsCommands extends JavaPlugin
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args)
{ {
return Essentials.getStatic().onCommandEssentials(sender, command, label, args, EssentialsPermissionsCommands.class.getClassLoader(), "com.earth2me.essentials.permissions.Command"); return Essentials.getStatic().onCommandEssentials(sender, command, label, args, EssentialsPermissionsCommands.class.getClassLoader(), "com.earth2me.essentials.permissions.Command", "groupmanager.");
} }
@Override @Override

View File

@ -38,6 +38,6 @@ public class EssentialsSpawn extends JavaPlugin
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{ {
return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command"); return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.");
} }
} }

View File

@ -65,7 +65,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
{ {
return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command"); return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.");
} }
@Override @Override