use of me.itsmas.network.server.rank.Rank 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.rank.Rank in project Network-depr by Mas281.
the class ChatManager method formatChat.
/**
* Formats a chat message for a {@link User}
*
* @param user The user
* @return The formatted message
*/
private String formatChat(User user) {
Rank rank = user.getRank();
String prefix = rank.getColour().toString();
if (rank != Rank.DEFAULT) {
prefix += "[" + user.getFormattedRank() + "] ";
}
return prefix + "%s: " + C.WHITE + "%s";
}
Aggregations