diff --git a/core/src/main/java/eu/mhsl/craftattack/core/appliance/Appliance.java b/core/src/main/java/eu/mhsl/craftattack/core/appliance/Appliance.java index f99eb1d..2425741 100644 --- a/core/src/main/java/eu/mhsl/craftattack/core/appliance/Appliance.java +++ b/core/src/main/java/eu/mhsl/craftattack/core/appliance/Appliance.java @@ -9,9 +9,11 @@ import org.bukkit.command.PluginCommand; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -104,16 +106,23 @@ public abstract class Appliance { } private void setCommandExecutor(JavaPlugin plugin, String name, ApplianceCommand executor) { - PluginCommand command = plugin.getCommand(name); - if(command != null && executor != null) { + try { + PluginCommand command = this.createPluginCommand(name, plugin); command.setExecutor(executor); command.setTabCompleter(executor); - } else { - Main.logger().warning("Command " + name + " is not specified in plugin.yml!"); - throw new RuntimeException("All commands must be registered in plugin.yml. Missing command: " + name); + plugin.getServer().getCommandMap().register(plugin.getName(), command); + throw new RuntimeException("Test"); + } catch(Exception e) { + throw new RuntimeException(String.format("Failed to register command '%s'", name), e); } } + private PluginCommand createPluginCommand(String name, JavaPlugin plugin) throws Exception { + Constructor constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); + constructor.setAccessible(true); + return constructor.newInstance(name, plugin); + } + public List getListeners() { return this.listeners; } diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index c2f12b1..1c493b6 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -2,55 +2,4 @@ name: spawn author: olischma, muelleel version: '1.0' main: eu.mhsl.craftattack.core.Main -api-version: '1.21' -commands: - moveWorldMuseumVillager: - description: Moves world museum villager to current player location and persists location to config - usage: /moveWmVillager - permission: admin - report: - description: Reporte einen Spieler - reports: - description: Von dir erstellte Reports - userinfo: - description: Get UUID from any user - projectStart: - description: Starts project countdown - projectStartCancel: - description: Cancels project countdown - projectStartReset: - description: Resets project countdown - moveEventVillager: - appliances: - event: - eventOpenSession: - eventEndSession: - eventAdvertise: - help: - spawn: - teamspeak: - aliases: [ "ts" ] - discord: - aliases: [ "dc" ] - setPlayerLimit: - scheduleRestart: - cancelRestart: - kick: - panicBan: - vogelfrei: - settings: - texturepack: - maintanance: - yearRank: - msg: - r: - playtime: - adminchat: - aliases: [ "sc" ] - acInform: - infobar: - endPrevent: - feedback: - requestFeedback: - setSpawnpoint: - mute: \ No newline at end of file +api-version: '1.21' \ No newline at end of file