Skip to content

Commit

Permalink
Add a injectable value to the FallbackCommandName field
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Aug 26, 2024
1 parent e8df898 commit 0daa3cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nookure.core.command.annotation;

import com.google.inject.BindingAnnotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface FallbackCommandName {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nookure.core.PlayerWrapperBase;
import com.nookure.core.command.Command;
import com.nookure.core.command.CommandManager;
import com.nookure.core.command.annotation.FallbackCommandName;
import com.nookure.core.command.config.CommandConfig;
import com.nookure.core.command.config.CommandPartial;
import com.nookure.core.config.ConfigurationContainer;
Expand All @@ -31,6 +32,9 @@ public class PaperCommandManager<P extends PlayerWrapperBase> extends CommandMan
private Injector injector;
@Inject
private ConfigurationContainer<CommandConfig> commandConfig;
@Inject
@FallbackCommandName
private String fallbackCommandName;

@Override
public void registerCommand(@NotNull Command command) {
Expand Down Expand Up @@ -70,7 +74,7 @@ public void registerCommand(@NotNull Command command) {
if (commandPartial.usage() != null && !commandPartial.usage().isEmpty())
templateCommand.setUsage(commandPartial.usage());

commandMap.register("nkstaff", templateCommand);
commandMap.register(fallbackCommandName == null ? "nookure" : fallbackCommandName, templateCommand);
command.prepare();
}

Expand Down

0 comments on commit 0daa3cd

Please sign in to comment.