Skip to content

Commit 8b7ad92

Browse files
committed
Implement CommandAPI#552
1 parent 3acccce commit 8b7ad92

File tree

8 files changed

+67
-3
lines changed

8 files changed

+67
-3
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ public void onEnable() {
217217
if (paper.isFoliaPresent()) {
218218
CommandAPI.logNormal("Skipping initial datapack reloading because Folia was detected");
219219
} else {
220-
reloadDataPacks();
220+
if (!getConfiguration().skipReloadDatapacks()) {
221+
reloadDataPacks();
222+
}
221223
}
222224
updateHelpForCommands(CommandAPI.getRegisteredCommands());
223225
}, 0L);

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class CommandAPIBukkitConfig extends CommandAPIConfig<CommandAPIBukkitCon
1212

1313
// Default configuration
1414
boolean shouldHookPaperReload = true;
15+
boolean skipReloadDatapacks = false;
1516

1617
/**
1718
* Creates a new CommandAPIBukkitConfig object. Variables in this
@@ -38,6 +39,18 @@ public CommandAPIBukkitConfig shouldHookPaperReload(boolean hooked) {
3839
return this;
3940
}
4041

42+
/**
43+
* Sets whether the CommandAPI should skip its datapack reload step after the server
44+
* has finished loading. This does not skip reloading of datapacks when invoked manually
45+
* when {@link #shouldHookPaperReload(boolean)} is set.
46+
* @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading
47+
* @return this CommandAPIBukkitConfig
48+
*/
49+
public CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) {
50+
this.skipReloadDatapacks = skip;
51+
return this;
52+
}
53+
4154
/**
4255
* Sets whether the CommandAPI should use Mojang mappings as opposed to Spigot's mappings
4356
* for internal calls. If set to true, the CommandAPI will use Mojang mappings.

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class InternalBukkitConfig extends InternalConfig {
1414

1515
// Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run
1616
private final boolean shouldHookPaperReload;
17+
18+
private final boolean skipReloadDatapacks;
1719

1820
/**
1921
* Creates an {@link InternalBukkitConfig} from a {@link CommandAPIBukkitConfig}
@@ -24,6 +26,7 @@ public InternalBukkitConfig(CommandAPIBukkitConfig config) {
2426
super(config);
2527
this.plugin = config.plugin;
2628
this.shouldHookPaperReload = config.shouldHookPaperReload;
29+
this.skipReloadDatapacks = config.skipReloadDatapacks;
2730
}
2831

2932
/**
@@ -41,4 +44,13 @@ public JavaPlugin getPlugin() {
4144
public boolean shouldHookPaperReload() {
4245
return shouldHookPaperReload;
4346
}
47+
48+
49+
50+
/**
51+
* @return Whether the CommandAPI should skip reloading datapacks when the server has finished loading
52+
*/
53+
public boolean skipReloadDatapacks() {
54+
return skipReloadDatapacks;
55+
}
4456
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void onLoad() {
5050
.useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version"))
5151
.missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation"))
5252
.dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null)
53-
.shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload"));
53+
.shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload"))
54+
.skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload"));
5455

5556
for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) {
5657
if (Bukkit.getPluginManager().getPlugin(pluginName) != null) {

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ use-latest-nms-version: false
5050
# reloading datapacks.
5151
hook-paper-reload: true
5252

53+
# Skips the initial datapack reload when the server loads (default: false)
54+
# If "true", the CommandAPI will not reload datapacks when the server has finished
55+
# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload"
56+
# is set to "true" and /minecraft:reload is run.
57+
skip-initial-datapack-reload: false
58+
5359
################################################################################
5460
# Command conversion #
5561
################################################################################

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void onLoad() {
5050
.useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version"))
5151
.missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation"))
5252
.dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null)
53-
.shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload"));
53+
.shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload"))
54+
.skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload"));
5455

5556
for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) {
5657
if (Bukkit.getPluginManager().getPlugin(pluginName) != null) {

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ use-latest-nms-version: false
5050
# reloading datapacks.
5151
hook-paper-reload: true
5252

53+
# Skips the initial datapack reload when the server loads (default: false)
54+
# If "true", the CommandAPI will not reload datapacks when the server has finished
55+
# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload"
56+
# is set to "true" and /minecraft:reload is run.
57+
skip-initial-datapack-reload: false
58+
5359
################################################################################
5460
# Command conversion #
5561
################################################################################

docssrc/src/config.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,29 @@ hook-paper-reload: false
142142

143143
-----
144144

145+
146+
### `skip-initial-datapack-reload`
147+
148+
Controls whether the CommandAPI should perform its initial datapack reload when the server has finished loading.
149+
150+
The CommandAPI automatically reloads all datapacks in a similar fashion to `/minecraft:reload` in order to propagate CommandAPI commands into datapack functions and tags. This operation may cause a slight delay to server startup and is not necessary if you are not using datapacks or functions that use CommandAPI commands. This operation can be skipped by setting this value to `false`.
151+
152+
Note that datapacks will still be reloaded if performed manually when `hook-paper-reload` is set to `true` and you run `/minecraft:reload`.
153+
154+
**Default value**
155+
156+
```yml
157+
skip-initial-datapack-reload: false
158+
```
159+
160+
**Example value**
161+
162+
```yml
163+
skip-initial-datapack-reload: true
164+
```
165+
166+
-----
167+
145168
### `plugins-to-convert`
146169

147170
Controls the list of plugins to process for command conversion. See [Command conversion](./conversionforowners.md) for more information.

0 commit comments

Comments
 (0)