use of me.itsmas.network.server.command.annotations.RequiredRank in project Network-depr by Mas281.
the class CommandManager method handleMethod.
/**
* Handles the registering of a command via its method
*
* @param object The object containing the method
* @param method The method to handle
*/
private void handleMethod(Object object, Method method) {
if (method.isAnnotationPresent(Command.class)) {
if (method.getParameterCount() < 1) {
// No parameters, invalid command
return;
}
int paramIndex = -1;
int minArgs = 0;
int maxArgs = 0;
boolean optional = false;
for (Parameter parameter : method.getParameters()) {
// There's already been an optional argument
if (optional) {
return;
}
paramIndex++;
Class<?> paramClass = parameter.getType();
if (paramIndex == 0) {
if (paramClass != User.class) {
// First parameter is not a User, invalid command
return;
}
continue;
}
if (!isSupportedParameter(paramClass)) {
// Parameter with no context found or not String
return;
}
if (parameter.isAnnotationPresent(Optional.class)) {
optional = true;
} else {
minArgs++;
}
maxArgs++;
}
if (method.getParameterCount() == 1) {
maxArgs = Integer.MAX_VALUE;
}
String[] aliases = method.getDeclaredAnnotation(Command.class).value().split("\\|");
String usage = getUsage(method);
Rank requiredRank = getRequiredRank(method);
Rank[] specificRanks = getSpecificRanks(method);
CommandData data = new CommandData(object, method, aliases, usage, requiredRank, specificRanks, minArgs, maxArgs);
commands.add(data);
}
}
use of me.itsmas.network.server.command.annotations.RequiredRank in project Network-depr by Mas281.
the class UserCommands method onSetRankCommand.
@Command("setrank")
@Usage("<player> <rank> [prefix]")
@RequiredRank(Rank.ADMIN)
public void onSetRankCommand(User user, User target, Rank rank, @Optional String prefix) {
if (prefix == null) {
prefix = rank.getName();
}
target.setRank(rank, prefix);
String formatted = target.getFormattedRank();
core.getTaskManager().scheduleTask(new UpdateRankTask(target, rank, prefix, user.getName(), user.getUniqueId()));
user.sendMessage("command.rank.executed", target.getName(), formatted);
user.addLog("Updated rank of %s [%s] to %s [%s]", target.getName(), target.getUniqueId(), rank.getName(), prefix);
}
use of me.itsmas.network.server.command.annotations.RequiredRank in project Network-depr by Mas281.
the class UserCommands method onGiveCommand.
@Command("give|item")
@Usage("<player> <item> [amount]")
@RequiredRank(Rank.DEV)
public void onGiveCommand(User user, User target, Material material, @Optional Integer amount) {
if (amount == null || amount < 1) {
amount = 1;
}
ItemStack stack = new ItemStack(material, amount);
target.getPlayer().getInventory().addItem(stack);
user.sendMessage("command.give.executed", amount, material.name(), target.getName());
target.sendMessage("command.give.received", amount, material.name(), user.getName());
}
Aggregations