|
11 | 11 | import org.bukkit.ChatColor; |
12 | 12 | import org.bukkit.command.CommandMap; |
13 | 13 | import org.bukkit.command.CommandSender; |
| 14 | +import org.bukkit.entity.Player; |
14 | 15 | import org.bukkit.event.EventHandler; |
15 | 16 | import org.bukkit.event.Listener; |
16 | 17 | import org.bukkit.plugin.Plugin; |
@@ -53,14 +54,24 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS< |
53 | 54 | * @param plugin the plugin that the CommandAPI is being used from |
54 | 55 | */ |
55 | 56 | public void registerReloadHandler(Plugin plugin) { |
56 | | - if (isPaperPresent && CommandAPIBukkit.getConfiguration().shouldHookPaperReload()) { |
| 57 | + if (isPaperPresent) { |
57 | 58 | Bukkit.getServer().getPluginManager().registerEvents(new Listener() { |
58 | | - |
59 | 59 | @EventHandler |
60 | 60 | public void onServerReloadResources(ServerResourcesReloadedEvent event) { |
61 | 61 | // This event is called after Paper is done with everything command related |
62 | 62 | // which means we can put commands back |
63 | 63 | CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); |
| 64 | + |
| 65 | + // Normally, the reloadDataPacks() method is responsible for updating commands for |
| 66 | + // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload |
| 67 | + // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to |
| 68 | + // paper-1.20.6-65 |
| 69 | + if (!CommandAPIBukkit.getConfiguration().shouldHookPaperReload()) { |
| 70 | + for (Player player : Bukkit.getOnlinePlayers()) { |
| 71 | + player.updateCommands(); |
| 72 | + } |
| 73 | + return; |
| 74 | + } |
64 | 75 | CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); |
65 | 76 | nmsInstance.reloadDataPacks(); |
66 | 77 | } |
|
0 commit comments