updated command registration for usage without static plugin.yml file
This commit is contained in:
		| @@ -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<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); | ||||
|         constructor.setAccessible(true); | ||||
|         return constructor.newInstance(name, plugin); | ||||
|     } | ||||
|  | ||||
|     public List<Listener> getListeners() { | ||||
|         return this.listeners; | ||||
|     } | ||||
|   | ||||
| @@ -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: | ||||
| api-version: '1.21' | ||||
		Reference in New Issue
	
	Block a user