Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3f8274

Browse files
committed
Simplify CommandAPIPaperConfig and fix example projects
Some additional cleanup
1 parent dbd67af commit c3f8274

File tree

51 files changed

+141
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+141
-657
lines changed

commandapi-kotlin/commandapi-kotlin-paper/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<repositories>
6363
<repository>
6464
<id>papermc</id>
65-
<url>https://papermc.io/repo/repository/maven-public/</url>
65+
<url>https://repo.papermc.io/repository/maven-public/</url>
6666
</repository>
6767
<repository>
6868
<id>sonatype</id>

commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public BundledNMS<Source> getNMS() {
9494
public void onLoad() {
9595
super.onLoad();
9696
checkPaperDependencies();
97-
PaperCommandRegistration registration = (PaperCommandRegistration) CommandAPIBukkit.get().getCommandRegistrationStrategy();
97+
PaperCommandRegistration<Source> registration = (PaperCommandRegistration<Source>) getCommandRegistrationStrategy();
9898
registration.registerLifecycleEvent();
9999
}
100100

@@ -139,7 +139,7 @@ public void onServerReloadResources(ServerResourcesReloadedEvent event) {
139139
CommandAPI.logNormal("Did not hook into Paper ServerResourcesReloadedEvent while using commandapi-paper. Are you actually using Paper?");
140140
}
141141

142-
PaperCommandRegistration registration = (PaperCommandRegistration) super.getCommandRegistrationStrategy();
142+
PaperCommandRegistration<Source> registration = (PaperCommandRegistration<Source>) getCommandRegistrationStrategy();
143143
registration.registerLifecycleEvent();
144144
}
145145

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package dev.jorel.commandapi;
22

3+
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
34
import io.papermc.paper.plugin.configuration.PluginMeta;
45
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
6+
import org.bukkit.plugin.java.JavaPlugin;
57

68
@SuppressWarnings("UnstableApiUsage")
7-
public class CommandAPIPaperConfig<T extends LifecycleEventOwner> extends CommandAPIBukkitConfig<CommandAPIPaperConfig<T>> {
9+
public class CommandAPIPaperConfig extends CommandAPIBukkitConfig<CommandAPIPaperConfig> {
810

911
PluginMeta pluginMeta;
1012
LifecycleEventOwner lifecycleEventOwner;
@@ -13,24 +15,23 @@ public class CommandAPIPaperConfig<T extends LifecycleEventOwner> extends Comman
1315
/**
1416
* Creates a new {@code CommandAPIPaperConfig} object
1517
*
16-
* @param pluginMeta the {@link io.papermc.paper.plugin.configuration.PluginMeta} of the plugin loading the CommandAPI
17-
* @param lifecycleEventOwner a {@link io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner}.
18-
* Can be a {@link org.bukkit.plugin.java.JavaPlugin} or a {@link io.papermc.paper.plugin.bootstrap.BootstrapContext}
18+
* @param lifecycleEventOwner The {@link LifecycleEventOwner} loading the CommandAPI.
19+
* Can be a {@link JavaPlugin} or a {@link BootstrapContext}.
1920
*/
20-
public CommandAPIPaperConfig(PluginMeta pluginMeta, T lifecycleEventOwner) {
21-
super(pluginMeta.getName());
22-
this.pluginMeta = pluginMeta;
21+
public CommandAPIPaperConfig(LifecycleEventOwner lifecycleEventOwner) {
22+
super(lifecycleEventOwner.getPluginMeta().getName());
23+
this.pluginMeta = lifecycleEventOwner.getPluginMeta();
2324
this.lifecycleEventOwner = lifecycleEventOwner;
2425
fallbackToLatestNMS(true);
2526
}
2627

27-
CommandAPIPaperConfig<T> isCommandAPIPlugin() {
28+
CommandAPIPaperConfig isCommandAPIPlugin() {
2829
this.isCommandAPIPlugin = true;
2930
return this;
3031
}
3132

3233
@Override
33-
public CommandAPIPaperConfig<T> instance() {
34+
public CommandAPIPaperConfig instance() {
3435
return this;
3536
}
3637
}

commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.papermc.paper.plugin.configuration.PluginMeta;
44
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
5-
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
65

76
@SuppressWarnings("UnstableApiUsage")
87
public class InternalPaperConfig extends InternalBukkitConfig {
@@ -11,7 +10,7 @@ public class InternalPaperConfig extends InternalBukkitConfig {
1110
private final LifecycleEventOwner lifecycleEventOwner;
1211
private final boolean isCommandAPIPlugin;
1312

14-
public InternalPaperConfig(CommandAPIPaperConfig<? extends LifecycleEventOwner> config) {
13+
public InternalPaperConfig(CommandAPIPaperConfig config) {
1514
super(config);
1615
this.pluginMeta = config.pluginMeta;
1716
this.lifecycleEventOwner = config.lifecycleEventOwner;

commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
package dev.jorel.commandapi;
22

3-
import com.mojang.brigadier.Command;
43
import com.mojang.brigadier.CommandDispatcher;
54
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
6-
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
7-
import com.mojang.brigadier.suggestion.SuggestionProvider;
8-
import com.mojang.brigadier.tree.ArgumentCommandNode;
95
import com.mojang.brigadier.tree.CommandNode;
106
import com.mojang.brigadier.tree.LiteralCommandNode;
11-
import com.mojang.brigadier.tree.RootCommandNode;
127
import io.papermc.paper.command.brigadier.CommandSourceStack;
13-
import io.papermc.paper.command.brigadier.Commands;
148
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
159
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
16-
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
1710
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
1811
import org.bukkit.Bukkit;
1912
import org.bukkit.help.HelpTopic;
2013
import org.bukkit.plugin.java.JavaPlugin;
2114

22-
import java.util.ArrayList;
2315
import java.util.Arrays;
24-
import java.util.HashSet;
2516
import java.util.List;
26-
import java.util.Set;
2717
import java.util.function.Predicate;
2818
import java.util.function.Supplier;
29-
import java.util.stream.Collectors;
3019

3120
/**
3221
* Handles logic for registering commands after Paper build 65, where <a href="https://github.com/PaperMC/Paper/pull/8235">https://github.com/PaperMC/Paper/pull/8235</a>
3322
* changed a bunch of the behind-the-scenes logic.
3423
*/
24+
@SuppressWarnings("UnstableApiUsage") // We know we are using new Paper Command API stuff
3525
public class PaperCommandRegistration<Source> extends CommandRegistrationStrategy<Source> {
3626
// References to necessary methods
3727
private final Supplier<CommandDispatcher<Source>> getBrigadierDispatcher;
@@ -77,6 +67,7 @@ public void postCommandRegistration(RegisteredCommand registeredCommand, Literal
7767
}
7868

7969
@Override
70+
@SuppressWarnings("ConstantValue") // `getServer` actually is `null` when we are in bootstrap
8071
public LiteralCommandNode<Source> registerCommandNode(LiteralArgumentBuilder<Source> node, String namespace) {
8172
LiteralCommandNode<Source> built = node.build();
8273
if (Bukkit.getServer() == null) {
@@ -105,7 +96,7 @@ public void preReloadDataPacks() {
10596
CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands());
10697
}
10798

108-
@SuppressWarnings("ConstantValue")
99+
@SuppressWarnings("ConstantValue") // `getServer` actually is `null` when we are in bootstrap
109100
void registerLifecycleEvent() {
110101
boolean bootstrap = Bukkit.getServer() == null;
111102
if (bootstrap && !lifecycleEventRegistered[0]) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import dev.jorel.commandapi.config.BukkitConfigurationAdapter;
2424
import dev.jorel.commandapi.config.DefaultBukkitConfig;
25-
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
2625
import org.bukkit.Bukkit;
2726
import org.bukkit.configuration.file.FileConfiguration;
2827
import org.bukkit.plugin.InvalidPluginException;
@@ -47,7 +46,7 @@ public void onLoad() {
4746
// Read config file
4847
saveDefaultConfig();
4948
FileConfiguration fileConfig = getConfig();
50-
CommandAPIPaperConfig<CommandAPIMain> config = new CommandAPIPaperConfig<>(this.getPluginMeta(), this)
49+
CommandAPIPaperConfig config = new CommandAPIPaperConfig(this)
5150
.verboseOutput(fileConfig.getBoolean("verbose-outputs"))
5251
.silentLogs(fileConfig.getBoolean("silent-logs"))
5352
.fallbackToLatestNMS(fileConfig.getBoolean("fallback-to-latest-nms"))

commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@
1010
import dev.jorel.commandapi.nms.PaperNMS_1_21_R4;
1111
import dev.jorel.commandapi.nms.PaperNMS_1_21_R5;
1212
import io.papermc.paper.ServerBuildInfo;
13-
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
14-
15-
import java.util.ArrayList;
16-
import java.util.List;
1713

1814
public abstract class CommandAPIVersionHandler {
19-
2015
static LoadContext getPlatform(CommandAPIConfig<?> config) {
2116
InternalPaperConfig internalPaperConfig;
22-
if (config instanceof CommandAPIPaperConfig<?> paperConfig) {
17+
if (config instanceof CommandAPIPaperConfig paperConfig) {
2318
internalPaperConfig = new InternalPaperConfig(paperConfig);
2419
} else {
2520
throw new IllegalArgumentException("CommandAPIPaper was loaded with non-Paper config!");
@@ -66,5 +61,4 @@ static LoadContext getPlatform(CommandAPIConfig<?> config) {
6661
}
6762
}
6863
}
69-
7064
}

commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import dev.jorel.commandapi.CommandAPI;
44
import dev.jorel.commandapi.CommandAPICommand;
5-
import dev.jorel.commandapi.CommandAPIPaper;
65
import dev.jorel.commandapi.CommandAPIPaperConfig;
76
import dev.jorel.commandapi.arguments.AdvancementArgument;
87
import dev.jorel.commandapi.arguments.AngleArgument;
@@ -50,7 +49,6 @@
5049
import dev.jorel.commandapi.wrappers.ParticleData;
5150
import dev.jorel.commandapi.wrappers.Rotation;
5251
import dev.jorel.commandapi.wrappers.ScoreboardSlot;
53-
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
5452
import net.kyori.adventure.chat.ChatType;
5553
import net.kyori.adventure.chat.SignedMessage;
5654
import net.kyori.adventure.text.Component;
@@ -88,7 +86,7 @@ public class TestPlugin extends JavaPlugin {
8886

8987
@Override
9088
public void onLoad() {
91-
CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this));
89+
CommandAPI.onLoad(new CommandAPIPaperConfig(this));
9290

9391
register(new AdvancementArgument("advancementtype"), Advancement.class, advancement -> advancement.key().asString());
9492
register(new AngleArgument("angletype"), float.class, Object::toString);

examples/build.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ echo "Building Maven examples"
77

88
# Find all pom.xml files
99
for folder in $(find $PWD -name "pom.xml" -print0 | xargs -0 dirname); do
10-
if [[ ! $folder =~ "maven-shaded-tests" ]]; then
11-
# The parentheses are required to only change the directory for the command so the second find $PWD does not break
12-
(cd "$folder" && mvn clean verify)
13-
fi
10+
# The parentheses are required to only change the directory for the command so the second find $PWD does not break
11+
(cd "$folder" && mvn clean verify)
1412
done
1513

1614
echo "Building Gradle examples"

examples/bukkit/automated-tests-shaded/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A simple example showcasing testing CommandAPI commands with [MockBukkit](https:
44

55
Key points:
66

7-
- The MockBukkit and `commandapi-bukkit-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-bukkit-shade` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests.
7+
- The MockBukkit and `commandapi-spigot-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-spigot-shade` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests.
88

99
```xml
1010
<dependencies>
@@ -29,7 +29,6 @@ Key points:
2929
<scope>compile</scope>
3030
</dependency>
3131

32-
<!-- Can also be paper-api -->
3332
<dependency>
3433
<groupId>org.spigotmc</groupId>
3534
<artifactId>spigot-api</artifactId>
@@ -52,7 +51,7 @@ Key points:
5251
public class Main extends JavaPlugin {
5352
@Override
5453
public void onLoad() {
55-
CommandAPI.onLoad(new CommandAPIBukkitConfig(this));
54+
CommandAPI.onLoad(new CommandAPISpigotConfig(this));
5655
}
5756

5857
@Override

0 commit comments

Comments
 (0)