Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
efekos committed May 29, 2024
1 parent 0cf4e94 commit a9d13d4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/efekos/arn/Arn.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static void run(Class<?> mainClass) {

/**
* Scans {@link Container}s annotated with {@link CustomArgumentType} and creates a resolver for them.
*
* @param reflections Main reflections.
*/
private void scanCustomArguments(Reflections reflections) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dev/efekos/arn/argument/CustomArgumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,33 @@
/**
* An interface used to create custom argument types. When scanned by {@link dev.efekos.arn.Arn}, {@link T} becomes a
* usable argument type that is handled by the implementation of this interface.
*
* @param <T> Type of the custom argument.
* @since 0.3.1
* @author efekos
* @since 0.3.1
*/
public interface CustomArgumentType<T> {

/**
* Returns class instance of the custom argument.
*
* @return A {@link Class} instance.
*/
Class<T> getType();

/**
* Suggests a list of strings to the given command sender.
*
* @param sender Any command sender.
* @return A list of suggestions.
*/
List<String> suggest(CommandSender sender);

/**
* Parses the given argument.
*
* @param sender Sender who sent this argument.
* @param arg The argument value.
* @param arg The argument value.
* @return Parsed object.
* @throws CommandSyntaxException If {@code arg} is invalid.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/efekos/arn/exception/ArnException.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ArnException extends Exception {
*/
public ArnException() {
List<StackTraceElement> list = new ArrayList<>(Arrays.asList(this.getStackTrace()));
for (int i = 0; i < 3; i++) list.remove(list.size()-1);
for (int i = 0; i < 3; i++) list.remove(list.size() - 1);
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
}

Expand All @@ -54,7 +54,7 @@ public ArnException() {
public ArnException(String message) {
super(message);
List<StackTraceElement> list = new ArrayList<>(Arrays.asList(this.getStackTrace()));
for (int i = 0; i < 3; i++) list.remove(list.size()-1);
for (int i = 0; i < 3; i++) list.remove(list.size() - 1);
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
}

Expand All @@ -67,7 +67,7 @@ public ArnException(String message) {
public ArnException(String message, Throwable cause) {
super(message, cause);
List<StackTraceElement> list = new ArrayList<>(Arrays.asList(this.getStackTrace()));
for (int i = 0; i < 3; i++) list.remove(list.size()-1);
for (int i = 0; i < 3; i++) list.remove(list.size() - 1);
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
}

Expand All @@ -79,7 +79,7 @@ public ArnException(String message, Throwable cause) {
public ArnException(Throwable cause) {
super(cause);
List<StackTraceElement> list = new ArrayList<>(Arrays.asList(this.getStackTrace()));
for (int i = 0; i < 3; i++) list.remove(list.size()-1);
for (int i = 0; i < 3; i++) list.remove(list.size() - 1);
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
}

Expand All @@ -94,7 +94,7 @@ public ArnException(Throwable cause) {
public ArnException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
List<StackTraceElement> list = new ArrayList<>(Arrays.asList(this.getStackTrace()));
for (int i = 0; i < 3; i++) list.remove(list.size()-1);
for (int i = 0; i < 3; i++) list.remove(list.size() - 1);
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class CmdCustomArg implements CommandArgumentResolver {

/**
* Creates a new resolver.
*
* @param customArgumentType An instance of the {@link CustomArgumentType} this resolver resolves.
*/
public CmdCustomArg(CustomArgumentType<?> customArgumentType) {
Expand All @@ -62,11 +63,13 @@ public boolean isApplicable(Parameter parameter) {
return parameter.isAnnotationPresent(CommandArgument.class) && parameter.getType().equals(customArgumentType.getType());
}

/**{@inheritDoc}*/
/**
* {@inheritDoc}
*/
@Override
public ArgumentBuilder apply(Parameter parameter) {
String s = parameter.getAnnotation(CommandArgument.class).value();
return CommandDispatcher.a(s.isEmpty()?parameter.getName():s,StringArgumentType.string()).suggests((commandContext, suggestionsBuilder) -> {
return CommandDispatcher.a(s.isEmpty() ? parameter.getName() : s, StringArgumentType.string()).suggests((commandContext, suggestionsBuilder) -> {
for (String ss : customArgumentType.suggest(commandContext.getSource().getBukkitSender())) {
suggestionsBuilder.suggest(ss);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,36 @@ public final class HndCustomArg implements CommandHandlerMethodArgumentResolver

/**
* Creates a new resolver.
*
* @param customArgumentType An instance of the {@link CustomArgumentType} this resolver resolves.
*/
public HndCustomArg(CustomArgumentType<?> customArgumentType) {
this.customArgumentType = customArgumentType;
}

/**{@inheritDoc}*/
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(Parameter parameter) {
return parameter.isAnnotationPresent(CommandArgument.class) && parameter.getType().equals(customArgumentType.getType());
}

/**{@inheritDoc}*/
/**
* {@inheritDoc}
*/
@Override
public boolean requireCommandArgument() {
return true;
}

/**{@inheritDoc}*/
/**
* {@inheritDoc}
*/
@Override
public Object resolve(Parameter parameter, CommandHandlerMethod method, CommandContext<CommandListenerWrapper> context) throws CommandSyntaxException {
String s = parameter.getAnnotation(CommandArgument.class).value();
String string = StringArgumentType.getString(context, s.isEmpty() ? parameter.getName() : s);
return customArgumentType.parse(context.getSource().getBukkitSender(),string);
return customArgumentType.parse(context.getSource().getBukkitSender(), string);
}
}

0 comments on commit a9d13d4

Please sign in to comment.