SteamWar/SpigotCore
Archiviert
13
0

Add SWCommand.inject

Dieser Commit ist enthalten in:
yoyosource 2021-05-14 15:50:49 +02:00
Ursprung e40db3d711
Commit 8985393fe1

Datei anzeigen

@ -22,6 +22,8 @@ package de.steamwar.command;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.annotation.*; import java.lang.annotation.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -169,8 +171,15 @@ public abstract class SWCommand {
} }
private List<Method> methods() { private List<Method> methods() {
List<Method> methods = Arrays.asList(getClass().getDeclaredMethods()); Class<?> current = getClass();
methods.addAll(Arrays.asList(SWCommand.class.getDeclaredMethods())); List<Method> methods = new ArrayList<>();
int count = 0;
while (current != null && count < 4) {
methods.addAll(Arrays.asList(current.getDeclaredMethods()));
current = current.getSuperclass();
count++;
}
System.out.println(methods);
return methods; return methods;
} }
@ -184,6 +193,16 @@ public abstract class SWCommand {
SWCommandUtils.commandMap.register("steamwar", this.command); SWCommandUtils.commandMap.register("steamwar", this.command);
} }
public void inject(Plugin plugin) {
new BukkitRunnable() {
@Override
public void run() {
SWCommand.this.unregister();
SWCommand.this.register();
}
}.runTask(plugin);
}
@Register(help = true) @Register(help = true)
private void internalHelp(CommandSender sender, String... args) { private void internalHelp(CommandSender sender, String... args) {
if (help.isEmpty()) { if (help.isEmpty()) {