use of com.bencodez.votingplugin.commands.executers.CommandAliases in project VotingPlugin by Ben12345rocks.
the class CommandLoader method loadAliases.
/**
* Load aliases.
*/
public void loadAliases() {
commands = new HashMap<String, CommandHandler>();
if (!plugin.getConfigFile().isLoadCommandAliases()) {
return;
}
for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
int argLength = cmdHandle.getArgs().length;
String arg0 = "";
if (argLength > 0) {
arg0 = cmdHandle.getArgs()[0];
}
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
try {
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1] + " from /vote" + arg0);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.debug("Failed to set permission for /vote" + arg0);
}
if (argLength > 0) {
String[] args = cmdHandle.getArgs()[0].split("&");
for (String arg : args) {
commands.put("vote" + arg, cmdHandle);
try {
plugin.getCommand("vote" + arg).setExecutor(new CommandAliases(cmdHandle, false));
plugin.getCommand("vote" + arg).setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, false));
String currentPerm = plugin.getCommand("vote" + arg).getPermission();
if (currentPerm == null || currentPerm.length() > perms[0].length()) {
plugin.getCommand("vote" + arg).setPermission(perms[0]);
}
for (String str : plugin.getCommand("vote" + arg).getAliases()) {
commands.put(str, cmdHandle);
}
} catch (Exception ex) {
plugin.devDebug("Failed to load command and tab completer for /vote" + arg);
}
}
}
}
for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
int argLength = cmdHandle.getArgs().length;
String arg0 = "";
if (argLength > 0) {
arg0 = cmdHandle.getArgs()[0];
}
String[] perms = cmdHandle.getPerm().split(Pattern.quote("|"));
try {
if (perms.length > 1) {
// has another perm
plugin.devDebug("Adding child perm " + perms[0] + " to " + perms[1] + " from /adminvote" + arg0);
Permission p = Bukkit.getPluginManager().getPermission(perms[1]);
p.getChildren().put(perms[0], true);
p.recalculatePermissibles();
}
} catch (Exception e) {
plugin.debug("Failed to set permission for /adminvote" + arg0);
}
if (argLength > 0) {
String[] args = cmdHandle.getArgs()[0].split("&");
for (String arg : args) {
commands.put("adminvote" + arg, cmdHandle);
try {
plugin.getCommand("adminvote" + arg).setExecutor(new CommandAliases(cmdHandle, true));
plugin.getCommand("adminvote" + arg).setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, true));
String currentPerm = plugin.getCommand("adminvote" + arg).getPermission();
if (currentPerm == null || currentPerm.length() > perms[0].length()) {
plugin.getCommand("adminvote" + arg).setPermission(perms[0]);
}
for (String str : plugin.getCommand("adminvote" + arg).getAliases()) {
commands.put(str, cmdHandle);
}
} catch (Exception ex) {
plugin.devDebug("Failed to load command and tab completer for /adminvote" + arg + ": " + ex.getMessage());
}
}
}
}
}
Aggregations