Skip to content

Commit ce04da1

Browse files
committed
[+] Fixed Method Invoking Error
1 parent fd4efe9 commit ce04da1

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Project exclude paths
2+
/target/

src/main/java/xyz/damt/command/command/Command.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Command {
2323
private final String[] aliases;
2424
private final boolean async;
2525
private final Method method;
26+
private final Object object;
2627

2728
private final CommandExecutor commandExecutor;
2829
private final List<Command> subCommands = new LinkedList<>();
@@ -40,7 +41,9 @@ public class Command {
4041
* @param async if the command should be ran async or not
4142
*/
4243

43-
public Command(String name, String[] aliases, Method method, String description, String usage, boolean async) {
44+
public Command(Object object, String name, String[] aliases, Method method, String description, String usage, boolean async) {
45+
this.object = object;
46+
4447
this.name = name;
4548
this.aliases = aliases;
4649
this.method = method;
@@ -79,9 +82,9 @@ public void execute(CommandSender commandSender, String[] args) {
7982

8083
if (player) {
8184
Player player = (Player) commandSender;
82-
method.invoke(this, player, args);
85+
method.invoke(object, player, args);
8386
} else {
84-
method.invoke(this, commandSender, args);
87+
method.invoke(object, commandSender, args);
8588
}
8689
}
8790

src/main/java/xyz/damt/command/command/CommandFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private final void init() {
9292

9393
if (commandAnnotation != null) {
9494
Permission permissionAnnotation = method.getAnnotation(Permission.class);
95-
Command command = new Command(commandAnnotation.value(), commandAnnotation.aliases(), method, commandAnnotation.description(), commandAnnotation.usage(), commandAnnotation.async());
95+
Command command = new Command(object, commandAnnotation.value(), commandAnnotation.aliases(), method, commandAnnotation.description(), commandAnnotation.usage(), commandAnnotation.async());
9696

9797
if (permissionAnnotation != null) {
9898
command.setPermission(permissionAnnotation.permission());

src/test/java/xyz/damt/example/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.Getter;
44
import org.bukkit.plugin.java.JavaPlugin;
55
import xyz.damt.command.CommandHandler;
6+
import xyz.damt.example.command.FlyCommand;
67

78
@Getter
89
public class Main extends JavaPlugin {
@@ -20,6 +21,7 @@ public void onLoad() {
2021
@Override
2122
public void onEnable() {
2223
this.commandHandler = new CommandHandler(this);
24+
commandHandler.register(new FlyCommand());
2325
}
2426

2527
}

0 commit comments

Comments
 (0)