diff --git a/.editorconfig b/.editorconfig index 03a8209fa1..4b2065012d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,9 @@ indent_style = space [commandapi-documentation-velocity-code/**{.java,.kt}] indent_style = space + +[commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/**{.java,.kt}] +indent_style = space + +[commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/**{.java,.kt}] +indent_style = space diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 724013bf9b..9a17faa442 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,6 +54,9 @@ jobs: ### Compilation ### + - name: Setup Paper NMS for all applicable versions + run: ./setupPaperNMS.sh + - name: Build the CommandAPI (Bukkit+Velocity) using maven run: mvn clean install --batch-mode -P Platform.Bukkit,Platform.Velocity @@ -146,15 +149,25 @@ jobs: ### Upload .jar artifacts ### - - name: Upload CommandAPI (Bukkit) plugin artifact + - name: Upload CommandAPI (Spigot) plugin artifact if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS uses: actions/upload-artifact@v3 with: - name: CommandAPI (Bukkit plugin) + name: CommandAPI (Spigot plugin) path: | - commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/CommandAPI*.jar - !commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/*sources.jar - !commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/*javadoc.jar + commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/CommandAPI*.jar + !commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/*sources.jar + !commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/*javadoc.jar + + - name: Upload CommandAPI (Paper) plugin artifact + if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS + uses: actions/upload-artifact@v3 + with: + name: CommandAPI (Paper plugin) + path: | + commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/CommandAPI*.jar + !commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/*sources.jar + !commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/*javadoc.jar - name: Upload CommandAPI (Velocity) plugin artifact if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS diff --git a/.gitignore b/.gitignore index c681da171e..2ae3cf246c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ docssrc/src/.markdownlint-cli2.yaml .gradle *.versionsBackup dependency-reduced-pom.xml +.paper-nms diff --git a/README.md b/README.md index 986d4ab45f..acb465dbbf 100644 --- a/README.md +++ b/README.md @@ -412,6 +412,31 @@ This is the current roadmap for the CommandAPI (as of 30th April 2024): + 10.0.0 + ??? + + + + + 9.7.0 December 2024 diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index 1017f2b5e6..c5a3e4bd8c 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -35,6 +35,7 @@ dev.jorel commandapi-bukkit-core ${project.version} + provided com.google.auto.service @@ -49,25 +50,5 @@ provided - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - testCompile - - - - dev.jorel.commandapi.annotations.Annotations - - - - - - - \ No newline at end of file diff --git a/commandapi-codecov/pom.xml b/commandapi-codecov/pom.xml index c7bd6938e3..8ddbca2cff 100644 --- a/commandapi-codecov/pom.xml +++ b/commandapi-codecov/pom.xml @@ -51,7 +51,7 @@ ${project.version} - + - - + ${project.version}--> + + diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java index 08ce1a7342..d357ce99a6 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java @@ -926,21 +926,6 @@ public Optional> lookupPreviewable(List path) { } } - /** - * - * @param path a list of Strings representing the path (names of command nodes) - * to (and including) the previewable argument - * @return Whether a previewable is legacy (non-Adventure) or not - */ - public boolean lookupPreviewableLegacyStatus(List path) { - final Previewable previewable = previewableArguments.get(path); - if (previewable != null && previewable.getPreview().isPresent()) { - return previewable.isLegacy(); - } else { - return true; - } - } - ///////////////////////// // SECTION: Reflection // ///////////////////////// diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java index f215e37cec..3ff63b67c6 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java @@ -32,18 +32,18 @@ public interface CommandAPIPlatform config); + void onLoad(CommandAPIConfig config); /** * Platform-specific stuff that should happen when the CommandAPI is enabled, * such as registering event listeners. */ - public abstract void onEnable(); + void onEnable(); /** * Platform-specific stuff that should happen when the CommandAPI is disabled. */ - public abstract void onDisable(); + void onDisable(); // Converting between CommandSender, AbstractCommandSender, and Brigadier Sources @@ -54,7 +54,7 @@ public interface CommandAPIPlatform getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + AbstractCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); /** * Converts the class used by Brigadier when running commands into an AbstractCommandSender wrapping the platform's CommandSender @@ -62,7 +62,7 @@ public interface CommandAPIPlatform getCommandSenderFromCommandSource(Source source); + AbstractCommandSender getCommandSenderFromCommandSource(Source source); /** * Converts a CommandSender wrapped in an AbstractCommandSender to an object Brigadier can use when running its commands @@ -70,7 +70,7 @@ public interface CommandAPIPlatform sender); + Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); /** * Wraps a CommandSender in an AbstractCommandSender class, the inverse operation to {@link AbstractCommandSender#getSource()} @@ -78,14 +78,14 @@ public interface CommandAPIPlatform wrapCommandSender(CommandSender sender); + AbstractCommandSender wrapCommandSender(CommandSender sender); // Registers a permission. Bukkit's permission system requires permissions to be "registered" // before they can be used. - public abstract void registerPermission(String string); + void registerPermission(String string); // Some commands have existing suggestion providers - public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); + SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); /** * Stuff to run before a command is generated. For Bukkit, this involves checking @@ -93,7 +93,7 @@ public interface CommandAPIPlatform resultantNode, List> aliasNodes); + void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode resultantNode, List> aliasNodes); /** * Registers a Brigadier command node and returns the built node. */ - public abstract LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace); + LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace); /** @@ -118,12 +118,12 @@ public interface CommandAPIPlatform getBrigadierDispatcher(); + CommandDispatcher getBrigadierDispatcher(); /** * Creates a JSON file that describes the hierarchical structure of the commands @@ -133,13 +133,13 @@ public interface CommandAPIPlatform dispatcher) throws IOException; + void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException; /** * @return A new default Logger meant for the CommandAPI to use. This logger will be used by the CommandAPI * if one is not set using {@link CommandAPI#setLogger(CommandAPILogger)}. */ - public default CommandAPILogger getLogger() { + default CommandAPILogger getLogger() { return new CommandAPILogger() { private static final String PREFIX = "[CommandAPI] "; private static final String YELLOW = "\u001B[33m"; @@ -172,19 +172,19 @@ public void severe(String message, Throwable throwable) { /** * Reloads the server's data packs to include CommandAPI commands */ - public abstract void reloadDataPacks(); + void reloadDataPacks(); /** * Updates the requirements required for a given player to execute a command. * * @param player the player to update */ - public abstract void updateRequirements(AbstractPlayer player); + void updateRequirements(AbstractPlayer player); // Create the concrete instances of objects implemented by the platform - public abstract AbstractCommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta); + AbstractCommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta); - public abstract Argument newConcreteMultiLiteralArgument(String nodeName, String[] literals); + Argument newConcreteMultiLiteralArgument(String nodeName, String[] literals); - public abstract Argument newConcreteLiteralArgument(String nodeName, String literal); + Argument newConcreteLiteralArgument(String nodeName, String literal); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index a28b569b12..d876a6ec55 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -3,7 +3,7 @@ /** * This file handles loading the correct platform implementation. The CommandAPIVersionHandler * file within the commandapi-core module is NOT used at run time. Instead, the platform modules - * replace this class with their own version that handles loads the correct class for their version. + * replace this class with their own version that loads the correct class. */ public abstract class CommandAPIVersionHandler { diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java index d145a0b956..a69e19e88d 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/Previewable.java @@ -43,9 +43,4 @@ public interface Previewable dev.jorel - commandapi-bukkit-core + commandapi-paper-core ${project.version} dev.jorel - commandapi-bukkit-kotlin + commandapi-spigot-core + ${project.version} + + + dev.jorel + commandapi-kotlin-bukkit ${project.version} diff --git a/commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java index dd5cb39347..2405886d2a 100644 --- a/commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java +++ b/commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java @@ -31,32 +31,106 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.tree.LiteralCommandNode; import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.*; -import dev.jorel.commandapi.arguments.*; +import dev.jorel.commandapi.Brigadier; +import dev.jorel.commandapi.BukkitTooltip; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.CommandTree; +import dev.jorel.commandapi.Converter; +import dev.jorel.commandapi.IStringTooltip; +import dev.jorel.commandapi.StringTooltip; +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.CustomArgument; import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.ListArgumentBuilder; +import dev.jorel.commandapi.arguments.LiteralArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MapArgumentBuilder; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.SafeSuggestions; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.SuggestionsBranch; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.WorldArgument; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; import dev.jorel.commandapi.executors.ExecutorType; +import dev.jorel.commandapi.wrappers.CommandResult; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.*; -import net.kyori.adventure.inventory.Book; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Sound; +import org.bukkit.World; import org.bukkit.advancement.Advancement; import org.bukkit.advancement.AdvancementProgress; -import org.bukkit.block.*; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.block.Container; +import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; import org.bukkit.command.ProxiedCommandSender; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.*; import org.bukkit.help.HelpTopic; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.inventory.ComplexRecipe; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -79,8 +153,17 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; import java.util.function.Predicate; @@ -238,96 +321,6 @@ void argument_blockState() { /* ANCHOR_END: argumentBlockState1 */ } -void argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -new CommandAPICommand("namecolor") - .withArguments(new AdventureChatColorArgument("chatcolor")) - .executesPlayer((player, args) -> { - NamedTextColor color = (NamedTextColor) args.get("chatcolor"); - player.displayName(Component.text().color(color).append(Component.text(player.getName())).build()); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -new CommandAPICommand("showbook") - .withArguments(new PlayerArgument("target")) - .withArguments(new TextArgument("title")) - .withArguments(new StringArgument("author")) - .withArguments(new AdventureChatComponentArgument("contents")) - .executes((sender, args) -> { - Player target = (Player) args.get("target"); - String title = (String) args.get("title"); - String author = (String) args.get("author"); - Component content = (Component) args.get("contents"); - - // Create a book and show it to the user (Requires Paper) - Book mybook = Book.book(Component.text(title), Component.text(author), content); - target.openBook(mybook); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -new CommandAPICommand("pbroadcast") - .withArguments(new AdventureChatArgument("message")) - .executes((sender, args) -> { - Component message = (Component) args.get("message"); - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS); - Bukkit.getServer().broadcast(message); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure3 */ -} - -void argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -new CommandAPICommand("namecolor") - .withArguments(new ChatColorArgument("chatcolor")) - .executesPlayer((player, args) -> { - ChatColor color = (ChatColor) args.get("chatcolor"); - player.setDisplayName(color + player.getName()); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -new CommandAPICommand("makebook") - .withArguments(new PlayerArgument("player")) - .withArguments(new ChatComponentArgument("contents")) - .executes((sender, args) -> { - Player player = (Player) args.get("player"); - BaseComponent[] arr = (BaseComponent[]) args.get("contents"); - - // Create book - ItemStack is = new ItemStack(Material.WRITTEN_BOOK); - BookMeta meta = (BookMeta) is.getItemMeta(); - meta.setTitle("Custom Book"); - meta.setAuthor(player.getName()); - meta.spigot().setPages(arr); - is.setItemMeta(meta); - - // Give player the book - player.getInventory().addItem(is); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -new CommandAPICommand("pbroadcast") - .withArguments(new ChatArgument("message")) - .executes((sender, args) -> { - BaseComponent[] message = (BaseComponent[]) args.get("message"); - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(message); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot3 */ -} - void argument_command() { /* ANCHOR: argumentCommand1 */ new CommandAPICommand("sudo") @@ -744,29 +737,18 @@ void argument_multiLiteral() { /* ANCHOR_END: argumentMultiLiteral1 */ } -class argument_nbt extends JavaPlugin { -/* ANCHOR: argumentNBT1 */ -@Override -public void onLoad() { - CommandAPI.onLoad(new CommandAPIBukkitConfig(this) - .initializeNBTAPI(NBTContainer.class, NBTContainer::new) - ); -} -/* ANCHOR_END: argumentNBT1 */ - void argument_nbt2() { /* ANCHOR: argumentNBT2 */ new CommandAPICommand("award") .withArguments(new NBTCompoundArgument("nbt")) .executes((sender, args) -> { NBTContainer nbt = (NBTContainer) args.get("nbt"); - + // Do something with "nbt" here... }) .register(); /* ANCHOR_END: argumentNBT2 */ } -} void argument_objectives() { /* ANCHOR: argumentObjectives1 */ @@ -1297,74 +1279,6 @@ void brigadierSuggestions() { /* ANCHOR_END: brigadierSuggestions3 */ } -void chatPreview() { -/* ANCHOR: chatPreview1 */ -new CommandAPICommand("broadcast") - .withArguments(new ChatArgument("message").withPreview(info -> { - // Convert parsed BaseComponent[] to plain text - String plainText = BaseComponent.toPlainText(info.parsedInput()); - - // Translate the & in plain text and generate a new BaseComponent[] - return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); - })) - .executesPlayer((player, args) -> { - // The user still entered legacy text. We need to properly convert this - // to a BaseComponent[] by converting to plain text then to BaseComponent[] - String plainText = BaseComponent.toPlainText((BaseComponent[]) args.get("message")); - Bukkit.spigot().broadcast(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText))); - }) - .register(); -/* ANCHOR_END: chatPreview1 */ - -/* ANCHOR: chatPreview2 */ -new CommandAPICommand("broadcast") - .withArguments(new AdventureChatArgument("message").withPreview(info -> { - // Convert parsed Component to plain text - String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); - - // Translate the & in plain text and generate a new Component - return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); - })) - .executesPlayer((player, args) -> { - // The user still entered legacy text. We need to properly convert this - // to a Component by converting to plain text then to Component - String plainText = PlainTextComponentSerializer.plainText().serialize((Component) args.get("broadcast")); - Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)); - }) - .register(); -/* ANCHOR_END: chatPreview2 */ - -/* ANCHOR: chatPreview3 */ -new CommandAPICommand("broadcast") - .withArguments(new ChatArgument("message").usePreview(true).withPreview(info -> { - // Convert parsed BaseComponent[] to plain text - String plainText = BaseComponent.toPlainText(info.parsedInput()); - - // Translate the & in plain text and generate a new BaseComponent[] - return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); - })) - .executesPlayer((player, args) -> { - Bukkit.spigot().broadcast((BaseComponent[]) args.get("message")); - }) - .register(); -/* ANCHOR_END: chatPreview3 */ - -/* ANCHOR: chatPreview4 */ -new CommandAPICommand("broadcast") - .withArguments(new AdventureChatArgument("message").usePreview(true).withPreview(info -> { - // Convert parsed Component to plain text - String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); - - // Translate the & in plain text and generate a new Component - return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); - })) - .executesPlayer((player, args) -> { - Bukkit.broadcast((Component) args.get("message")); - }) - .register(); -/* ANCHOR_END: chatPreview4 */ -} - void commandArguments() { /* ANCHOR: commandArguments1 */ new CommandAPICommand("mycommand") @@ -2328,45 +2242,6 @@ void safeArgumentSuggestions() { /* ANCHOR_END: safeArgumentSuggestions7 */ } -class setupShading { -JavaPlugin plugin = new JavaPlugin() {}; - -{ -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(new CommandAPIBukkitConfig(plugin).silentLogs(true)); -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin extends JavaPlugin { - - @Override - public void onLoad() { - CommandAPI.onLoad(new CommandAPIBukkitConfig(this).verboseOutput(true)); // Load with verbose output - - new CommandAPICommand("ping") - .executes((sender, args) -> { - sender.sendMessage("pong!"); - }) - .register(); - } - - @Override - public void onEnable() { - CommandAPI.onEnable(); - - // Register commands, listeners etc. - } - - @Override - public void onDisable() { - CommandAPI.onDisable(); - } - -} -/* ANCHOR_END: setupShading2 */ -} - class stringArgumentSuggestions { { Map warps = new HashMap<>(); diff --git a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt index b95e4c92f5..7c1c5baa21 100644 --- a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt +++ b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -14,16 +14,10 @@ import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException import dev.jorel.commandapi.executors.* -import dev.jorel.commandapi.kotlindsl.commandAPICommand import dev.jorel.commandapi.kotlindsl.getValue -import dev.jorel.commandapi.kotlindsl.playerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor -import dev.jorel.commandapi.kotlindsl.stringArgument import dev.jorel.commandapi.wrappers.* import dev.jorel.commandapi.wrappers.Rotation -import net.kyori.adventure.inventory.Book import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import net.md_5.bungee.api.chat.BaseComponent @@ -57,8 +51,6 @@ import org.bukkit.util.EulerAngle import java.util.* import java.util.concurrent.CompletableFuture import java.util.function.Predicate -import java.util.function.Supplier -import kotlin.collections.LinkedHashMap import kotlin.random.Random class Examples : JavaPlugin() { @@ -188,96 +180,6 @@ CommandAPICommand("set") /* ANCHOR_END: argumentBlockState1 */ } -fun argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -CommandAPICommand("namecolor") - .withArguments(AdventureChatColorArgument("chatcolor")) - .executesPlayer(PlayerCommandExecutor { player, args -> - val color = args["chatcolor"] as NamedTextColor - player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) - }) - .register() -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -CommandAPICommand("showbook") - .withArguments(PlayerArgument("target")) - .withArguments(TextArgument("title")) - .withArguments(StringArgument("author")) - .withArguments(AdventureChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> - val target = args["target"] as Player - val title = args["title"] as String - val author = args["author"] as String - val content = args["contents"] as Component - - // Create a book and show it to the user (Requires Paper) - val mybook = Book.book(Component.text(title), Component.text(author), content) - target.openBook(mybook) - }) - .register() -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -CommandAPICommand("pbroadcast") - .withArguments(AdventureChatArgument("message")) - .executes(CommandExecutor { _, args -> - val message = args["message"] as Component - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) - }) - .register() -/* ANCHOR_END: argumentChatAdventure3 */ -} - -fun argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -CommandAPICommand("namecolor") - .withArguments(ChatColorArgument("chatColor")) - .executesPlayer(PlayerCommandExecutor { player, args -> - val color = args["chatColor"] as ChatColor - player.setDisplayName("$color${player.name}") - }) - .register() -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -CommandAPICommand("makebook") - .withArguments(PlayerArgument("player")) - .withArguments(ChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> - val player = args["player"] as Player - val arr = args["contents"] as Array - - // Create book - val item = ItemStack(Material.WRITTEN_BOOK) - val meta = item.itemMeta as BookMeta - meta.title = "Custom Book" - meta.author = player.name - meta.spigot().setPages(arr) - item.itemMeta = meta - - // Give player the book - player.inventory.addItem(item) - }) - .register() -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -CommandAPICommand("pbroadcast") - .withArguments(ChatArgument("message")) - .executes(CommandExecutor { _, args -> - val message = args["message"] as Array - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(*message) - }) - .register() -/* ANCHOR_END: argumentChatSpigot3 */ -} - fun argument_command() { /* ANCHOR: argumentCommand1 */ CommandAPICommand("sudo") @@ -674,16 +576,6 @@ CommandAPICommand("gamemode") /* ANCHOR_END: argumentMultiLiteral1 */ } -class argument_nbt : JavaPlugin() { - -/* ANCHOR: argumentNBT1 */ -override fun onLoad() { - CommandAPI.onLoad(CommandAPIBukkitConfig(this) - .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) - ) -} -/* ANCHOR_END: argumentNBT1 */ - fun argument_nbt2() { /* ANCHOR: argumentNBT2 */ CommandAPICommand("award") @@ -697,8 +589,6 @@ CommandAPICommand("award") /* ANCHOR_END: argumentNBT2 */ } -} - fun argument_objectives() { /* ANCHOR: argumentObjectives1 */ CommandAPICommand("sidebar") @@ -1213,75 +1103,6 @@ CommandAPICommand("commandargument") /* ANCHOR_END: brigadierSuggestions3 */ } -fun chatPreview() { -/* ANCHOR: chatPreview1 */ -CommandAPICommand("broadcast") - .withArguments(ChatArgument("message").withPreview { info -> - // Convert parsed BaseComponent[] to plain text - val plainText: String = BaseComponent.toPlainText(*info.parsedInput() as Array) - - // Translate the & in plain text and generate a new BaseComponent[] - TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - // The user still entered legacy text. We need to properly convert this - // to a BaseComponent[] by converting to plain text then to BaseComponent[] - val plainText: String = BaseComponent.toPlainText(*args["message"] as Array) - val baseComponents: Array = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - Bukkit.spigot().broadcast(*baseComponents) - }) - .register() -/* ANCHOR_END: chatPreview1 */ - -/* ANCHOR: chatPreview2 */ -CommandAPICommand("broadcast") - .withArguments(AdventureChatArgument("message").withPreview { info -> - // Convert parsed Component to plain text - val plainText: String = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) - - // Translate the & in plain text and generate a new Component - LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - // The user still entered legacy text. We need to properly convert this - // to a Component by converting to plain text then to Component - val plainText: String = PlainTextComponentSerializer.plainText().serialize(args["message"] as Component) - Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)) - }) - .register() -/* ANCHOR_END: chatPreview2 */ - -/* ANCHOR: chatPreview3 */ -CommandAPICommand("broadcast") - .withArguments(ChatArgument("message").usePreview(true).withPreview { info -> - // Convert parsed BaseComponent[] to plain text - val plainText = BaseComponent.toPlainText(*info.parsedInput() as Array) - - // Translate the & in plain text and generate a new BaseComponent[] - TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - Bukkit.spigot().broadcast(*args["message"] as Array) - }) - .register() -/* ANCHOR_END: chatPreview3 */ - -/* ANCHOR: chatPreview4 */ -CommandAPICommand("broadcast") - .withArguments(AdventureChatArgument("message").usePreview(true).withPreview { info -> - // Convert parsed Component to plain text - val plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) - - // Translate the & in plain text and generate a new Component - LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) - } ) - .executesPlayer(PlayerCommandExecutor { _, args -> - Bukkit.broadcast(args["message"] as Component) - }) - .register() -/* ANCHOR_END: chatPreview4 */ -} - fun commandArguments() { /* ANCHOR: commandArguments1 */ CommandAPICommand("mycommand") @@ -2220,42 +2041,6 @@ CommandAPICommand("removeeffect") /* ANCHOR_END: safeArgumentSuggestions7 */ } -class setupShading { -val plugin: JavaPlugin = object: JavaPlugin() {} - -fun setupShading1() { -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(CommandAPIBukkitConfig(plugin).silentLogs(true)) -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin : JavaPlugin() { - - override fun onLoad() { - CommandAPI.onLoad(CommandAPIBukkitConfig(this).verboseOutput(true)) // Load with verbose output - - CommandAPICommand("ping") - .executes(CommandExecutor { sender, _ -> - sender.sendMessage("pong!") - }) - .register() - } - - override fun onEnable() { - CommandAPI.onEnable() - - // Register commands, listeners etc. - } - - override fun onDisable() { - CommandAPI.onDisable() - } - -} -/* ANCHOR_END: setupShading2 */ -} - class stringArgumentSuggestions { fun stringArgumentSuggestions1() { val warps = mutableMapOf() diff --git a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt index 39e6dd5d7d..a34c20ce19 100644 --- a/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt +++ b/commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt @@ -154,96 +154,6 @@ commandAPICommand("set") { /* ANCHOR_END: argumentBlockState1 */ } -fun argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -commandAPICommand("namecolor") { - chatColorArgument("chatcolor") - playerExecutor { player, args -> - val color = args["chatcolor"] as NamedTextColor - player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) - } -} -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -commandAPICommand("showbook") { - playerArgument("target") - textArgument("title") - stringArgument("author") - adventureChatComponentArgument("contents") - anyExecutor { _, args -> - val target = args["target"] as Player - val title = args["title"] as String - val author = args["author"] as String - val content = args["contents"] as Component - - // Create a book and show it to the user (Requires Paper) - val mybook = Book.book(Component.text(title), Component.text(author), content) - target.openBook(mybook) - } -} -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -commandAPICommand("pbroadcast") { - adventureChatArgument("message") - anyExecutor { _, args -> - val message = args["message"] as Component - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) - } -} -/* ANCHOR_END: argumentChatAdventure3 */ -} - -fun argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -commandAPICommand("namecolor") { - chatColorArgument("chatcolor") - playerExecutor { player, args -> - val color = args["chatcolor"] as ChatColor - player.setDisplayName("$color${player.name}") - } -} -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -commandAPICommand("makebook") { - playerArgument("player") - chatComponentArgument("contents") - anyExecutor { _, args -> - val player = args["player"] as Player - val array = args["contents"] as Array - - // Create book - val item = ItemStack(Material.WRITTEN_BOOK) - val meta = item.itemMeta as BookMeta - meta.title = "Custom Book" - meta.author = player.name - meta.spigot().setPages(array) - item.itemMeta = meta - - // Give player the book - player.inventory.addItem(item) - } -} -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -commandAPICommand("pbroadcast") { - chatArgument("message") - anyExecutor { _, args -> - val message = args["message"] as Array - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(*message) - } -} -/* ANCHOR_END: argumentChatSpigot3 */ -} - fun argument_command() { /* ANCHOR: argumentCommand1 */ commandAPICommand("sudo") { diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml similarity index 96% rename from commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml index e37813d66f..d403a7feec 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml @@ -10,7 +10,7 @@ 9.7.1-SNAPSHOT - commandapi-bukkit-kotlin + commandapi-kotlin-bukkit src/main/kotlin @@ -91,7 +91,7 @@ dev.jorel - commandapi-core-kotlin + commandapi-kotlin-core ${project.version} diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt similarity index 92% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt index 773ac92063..ede6d7e8ed 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt @@ -52,14 +52,6 @@ inline fun CommandAPICommand.location2DArgument(nodeName: String, locationType: inline fun CommandAPICommand.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun CommandAPICommand.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt similarity index 91% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt index 0c466dc6d5..e93bf114e9 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt @@ -59,14 +59,6 @@ inline fun CommandTree.location2DArgument(nodeName: String, locationType: Locati inline fun CommandTree.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun CommandTree.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) @@ -177,14 +169,6 @@ inline fun Argument<*>.location2DArgument(nodeName: String, locationType: Locati inline fun Argument<*>.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun Argument<*>.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt diff --git a/commandapi-kotlin/commandapi-core-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-core/pom.xml similarity index 97% rename from commandapi-kotlin/commandapi-core-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-core/pom.xml index 93104f99b3..103b852434 100644 --- a/commandapi-kotlin/commandapi-core-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-core/pom.xml @@ -10,7 +10,7 @@ 9.7.1-SNAPSHOT - commandapi-core-kotlin + commandapi-kotlin-core src/main/kotlin diff --git a/commandapi-kotlin/commandapi-core-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt b/commandapi-kotlin/commandapi-kotlin-core/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-core-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt rename to commandapi-kotlin/commandapi-kotlin-core/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt diff --git a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml new file mode 100644 index 0000000000..0052eddba0 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + + dev.jorel + commandapi-kotlin + 9.7.1-SNAPSHOT + + + commandapi-kotlin-paper + + + src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 16 + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + provided + + + dev.jorel + commandapi-paper-core + ${project.version} + provided + + + dev.jorel + commandapi-kotlin-bukkit + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt new file mode 100644 index 0000000000..c61704ce88 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt @@ -0,0 +1,11 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.Argument +import dev.jorel.commandapi.arguments.ChatArgument +import dev.jorel.commandapi.arguments.ChatColorArgument +import dev.jorel.commandapi.arguments.ChatComponentArgument + +inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt new file mode 100644 index 0000000000..49ebff0364 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt @@ -0,0 +1,12 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.* +import dev.jorel.commandapi.arguments.* + +inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) + +inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt new file mode 100644 index 0000000000..6ebb82efd0 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt @@ -0,0 +1,31 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.BukkitExecutable +import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.executors.ExecutionInfo +import dev.jorel.commandapi.executors.FeedbackForwardingCommandExecutor +import dev.jorel.commandapi.executors.FeedbackForwardingExecutionInfo +import dev.jorel.commandapi.executors.FeedbackForwardingResultingCommandExecutor +import dev.jorel.commandapi.executors.FeedbackForwardingResultingExecutionInfo +import org.bukkit.command.CommandSender + +// Executors for CommandAPICommand, CommandTree and ArgumentTree +inline fun BukkitExecutable<*>.feedbackForwardingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingCommandExecutor { sender, args -> + executor(sender, args) +}) + +// Resulting executors +inline fun BukkitExecutable<*>.feedbackForwardingResultingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor { sender, args -> + executor(sender, args) +}) + +// ExecutionInfo normal executors +inline fun BukkitExecutable<*>.feedbackForwardingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Unit): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingExecutionInfo { info -> + executor(info) +}) + +// ExecutionInfo resulting executors +inline fun BukkitExecutable<*>.feedbackForwardingResultingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Int): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo { info -> + executor(info) +}) \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml new file mode 100644 index 0000000000..f21d96104a --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + + dev.jorel + commandapi-kotlin + 9.7.1-SNAPSHOT + + + commandapi-kotlin-spigot + + + src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 16 + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + provided + + + dev.jorel + commandapi-spigot-core + ${project.version} + provided + + + dev.jorel + commandapi-kotlin-bukkit + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt new file mode 100644 index 0000000000..c61704ce88 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt @@ -0,0 +1,11 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.Argument +import dev.jorel.commandapi.arguments.ChatArgument +import dev.jorel.commandapi.arguments.ChatColorArgument +import dev.jorel.commandapi.arguments.ChatComponentArgument + +inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt new file mode 100644 index 0000000000..49ebff0364 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt @@ -0,0 +1,12 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.* +import dev.jorel.commandapi.arguments.* + +inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) + +inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml similarity index 95% rename from commandapi-kotlin/commandapi-velocity-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-velocity/pom.xml index 5a333d9c68..f5682511d7 100644 --- a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml @@ -10,7 +10,7 @@ 9.7.1-SNAPSHOT - commandapi-velocity-kotlin + commandapi-kotlin-velocity src/main/kotlin @@ -67,7 +67,7 @@ dev.jorel - commandapi-core-kotlin + commandapi-kotlin-core ${project.version} diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java index 08d26ffa64..13c93ab0b8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java @@ -1,6 +1,7 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.exceptions.PlatformException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.*; import org.bukkit.command.CommandSender; @@ -462,6 +463,9 @@ default Impl executesRemoteConsole(RemoteConsoleResultingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor executor) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addNormalExecutor(executor); return instance(); } @@ -473,6 +477,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor execut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addNormalExecutor(info); return instance(); } @@ -484,6 +491,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor executor) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingResultingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addResultingExecutor(executor); return instance(); } @@ -495,6 +505,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo info) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingResultingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addResultingExecutor(info); return instance(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java new file mode 100644 index 0000000000..d174c52d78 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java @@ -0,0 +1,22 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; + +public interface BukkitPlatform extends CommandAPIPlatform, CommandSender, Source> { + + @Override + void onLoad(CommandAPIConfig config); + + CommandMap getCommandMap(); + + @Override + BukkitCommandSender wrapCommandSender(CommandSender sender); + + Platform activePlatform(); + + CommandRegistrationStrategy createCommandRegistrationStrategy(); + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java index 7b5500746d..52dff1d549 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java @@ -179,7 +179,7 @@ public static Tooltip ofAdventureComponent(S object, Component tooltip) { * @return native minecraft message object which can be used natively by brigadier. */ public static Message messageFromBaseComponents(BaseComponent... components) { - return CommandAPIBukkit.get().generateMessageFromJson(ComponentSerializer.toString(components)); + return CommandAPIBukkit.get().getNMS().generateMessageFromJson(ComponentSerializer.toString(components)); } /** @@ -192,7 +192,7 @@ public static Message messageFromBaseComponents(BaseComponent... components) { * @return native minecraft message object which can be used natively by brigadier. */ public static Message messageFromAdventureComponent(Component component) { - return CommandAPIBukkit.get().generateMessageFromJson(GsonComponentSerializer.gson().serialize(component)); + return CommandAPIBukkit.get().getNMS().generateMessageFromJson(GsonComponentSerializer.gson().serialize(component)); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index e18a59a98a..4c58fbc6b3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -1,9 +1,32 @@ package dev.jorel.commandapi; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CSS; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_MINECRAFT_SERVER; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.arguments.AbstractArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.LiteralArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.AbstractPlayer; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.nms.NMS; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Keyed; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.permissions.Permission; import java.io.File; import java.io.IOException; @@ -20,110 +43,78 @@ import java.util.logging.Level; import java.util.logging.Logger; -import net.kyori.adventure.text.ComponentLike; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Keyed; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.ProxiedCommandSender; -import org.bukkit.command.RemoteConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.server.ServerLoadEvent; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; -import org.bukkit.permissions.Permission; -import org.bukkit.plugin.java.JavaPlugin; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.tree.LiteralCommandNode; - -import dev.jorel.commandapi.arguments.AbstractArgument; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.MultiLiteralArgument; -import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.AbstractPlayer; -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.nms.NMS; -import dev.jorel.commandapi.preprocessor.Unimplemented; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; -import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.chat.BaseComponent; - -// CommandAPIBukkit is an CommandAPIPlatform, but also needs all of the methods from -// NMS, so it implements NMS. Our implementation of CommandAPIBukkit is now derived +// TODO: This comment seems incorrect since it no longer implements NMS +// CommandAPIBukkit needs all of the methods fromNMS, so it implements NMS. +// Our implementation of CommandAPIBukkit is now derived // using the version handler (and thus, deferred to our NMS-specific implementations) -public abstract class CommandAPIBukkit implements CommandAPIPlatform, CommandSender, Source>, NMS { +public abstract class CommandAPIBukkit implements BukkitPlatform { // References to utility classes - private static CommandAPIBukkit instance; - private static InternalBukkitConfig config; - private PaperImplementations paper; + // TODO: This seems odd, CommandAPIBukkit is instanceof BukkitPlatform, and these objects do always end + // up being set to the same value. It seems like only the CommandAPIBukkit variable is necessary? + private static BukkitPlatform instance; + private static CommandAPIBukkit bukkit; + protected static InternalBukkitConfig config; + + protected NMS nms; private CommandRegistrationStrategy commandRegistrationStrategy; protected CommandAPIBukkit() { - CommandAPIBukkit.instance = this; + CommandAPIBukkit.bukkit = this; + } + + protected > void setInstance(T instance) { + CommandAPIBukkit.instance = instance; } @SuppressWarnings("unchecked") public static CommandAPIBukkit get() { - if(CommandAPIBukkit.instance != null) { - return (CommandAPIBukkit) instance; - } else { - throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + if (CommandAPIBukkit.bukkit != null) { + return (CommandAPIBukkit) bukkit; } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } - public PaperImplementations getPaper() { - return paper; + @SuppressWarnings("unchecked") + public static > T platform() { + if (CommandAPIBukkit.instance != null) { + return (T) instance; + } + throw new IllegalStateException("Tried to access the Bukkit platform, but it was null! Are you using CommandAPI features before calling CommandPAI#onLoad?"); + } + + public NMS getNMS() { + if (nms != null) { + return nms; + } + throw new IllegalStateException("Tried to access NMS instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } public static InternalBukkitConfig getConfiguration() { - if(config != null) { + if (config != null) { return config; - } else { - throw new IllegalStateException("Tried to access InternalBukkitConfig, but it was null! Did you load the CommandAPI properly with CommandAPI#onLoad?"); } + throw new IllegalStateException("Tried to access InternalBukkitConfig, but it was null! Did you load the CommandAPI properly with CommandAPI#onLoad?"); } public CommandRegistrationStrategy getCommandRegistrationStrategy() { return commandRegistrationStrategy; } - @Override - public void onLoad(CommandAPIConfig config) { - if(config instanceof CommandAPIBukkitConfig bukkitConfig) { - CommandAPIBukkit.setInternalConfig(new InternalBukkitConfig(bukkitConfig)); - } else { - CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); - CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); - } - + public void onLoad() { checkDependencies(); } - - private static void setInternalConfig(InternalBukkitConfig internalBukkitConfig) { - CommandAPIBukkit.config = internalBukkitConfig; + + protected void stopCommandRegistrations() { + // Prevent command registration after server has loaded + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + // We want the lowest priority so that we always get to this first, in case a dependent plugin is using + // CommandAPI features in their own ServerLoadEvent listener for some reason + @EventHandler(priority = EventPriority.LOWEST) + public void onServerLoad(ServerLoadEvent event) { + CommandAPI.stopCommandRegistration(); + } + }, getConfiguration().getPlugin()); } private void checkDependencies() { @@ -143,74 +134,9 @@ private void checkDependencies() { } } - try { - Class.forName("net.kyori.adventure.text.Component"); - CommandAPI.logNormal("Hooked into Adventure for AdventureChat/AdventureChatComponents"); - } catch (ClassNotFoundException e) { - if (CommandAPI.getConfiguration().hasVerboseOutput()) { - CommandAPI.logWarning("Could not hook into Adventure for AdventureChat/AdventureChatComponents"); - } - } - - boolean isPaperPresent = false; - - try { - Class.forName("io.papermc.paper.event.server.ServerResourcesReloadedEvent"); - isPaperPresent = true; - CommandAPI.logNormal("Hooked into Paper for paper-specific API implementations"); - } catch (ClassNotFoundException e) { - isPaperPresent = false; - if (CommandAPI.getConfiguration().hasVerboseOutput()) { - CommandAPI.logWarning("Could not hook into Paper for /minecraft:reload. Consider upgrading to Paper: https://papermc.io/"); - } - } - - boolean isFoliaPresent = false; - - try { - Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); - isFoliaPresent = true; - CommandAPI.logNormal("Hooked into Folia for folia-specific API implementations"); - CommandAPI.logNormal("Folia support is still in development. Please report any issues to the CommandAPI developers!"); - } catch (ClassNotFoundException e) { - isFoliaPresent = false; - } - - paper = new PaperImplementations(isPaperPresent, isFoliaPresent, this); - commandRegistrationStrategy = createCommandRegistrationStrategy(); } - @Override - public void onEnable() { - JavaPlugin plugin = config.getPlugin(); - - new Schedulers(paper).scheduleSyncDelayed(plugin, () -> { - commandRegistrationStrategy.runTasksAfterServerStart(); - - if (paper.isFoliaPresent()) { - CommandAPI.logNormal("Skipping initial datapack reloading because Folia was detected"); - } else { - if (!getConfiguration().skipReloadDatapacks()) { - reloadDataPacks(); - } - } - updateHelpForCommands(CommandAPI.getRegisteredCommands()); - }, 0L); - - // Prevent command registration after server has loaded - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - // We want the lowest priority so that we always get to this first, in case a dependent plugin is using - // CommandAPI features in their own ServerLoadEvent listener for some reason - @EventHandler(priority = EventPriority.LOWEST) - public void onServerLoad(ServerLoadEvent event) { - CommandAPI.stopCommandRegistration(); - } - }, getConfiguration().getPlugin()); - - paper.registerReloadHandler(plugin); - } - /* * Generate and register help topics */ @@ -275,7 +201,7 @@ private String[] getUsageList(RegisteredCommand currentCommand) { return usages; } - void updateHelpForCommands(List commands) { + protected void updateHelpForCommands(List commands) { Map helpTopicsToAdd = new HashMap<>(); Set namespacedCommandNames = new HashSet<>(); @@ -325,7 +251,7 @@ void updateHelpForCommands(List commands) { sb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE).append(String.join(", ", command.aliases())); } - helpTopic = generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission); + helpTopic = nms.generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission); } helpTopicsToAdd.put(commandPrefix, helpTopic); @@ -346,7 +272,7 @@ void updateHelpForCommands(List commands) { // Don't override the plugin help topic commandPrefix = generateCommandHelpPrefix(alias); - helpTopic = generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission); + helpTopic = nms.generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission); // Namespaced commands shouldn't have a help topic, we should save the namespaced alias name namespacedCommandNames.add(generateCommandHelpPrefix(alias, command.namespace())); @@ -356,11 +282,11 @@ void updateHelpForCommands(List commands) { } // We have to use helpTopics.put (instead of .addTopic) because we're overwriting an existing help topic, not adding a new help topic - getHelpMap().putAll(helpTopicsToAdd); + nms.getHelpMap().putAll(helpTopicsToAdd); // We also have to remove help topics for namespaced command names for (String namespacedCommandName : namespacedCommandNames) { - getHelpMap().remove(namespacedCommandName); + nms.getHelpMap().remove(namespacedCommandName); } } @@ -369,57 +295,6 @@ public void onDisable() { // Nothing to do } - @Override - @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); - - @Override - @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getCommandSenderFromCommandSource(Source cs); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT) - public abstract Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - - public BukkitCommandSender wrapCommandSender(CommandSender sender) { - if (sender instanceof BlockCommandSender block) { - return new BukkitBlockCommandSender(block); - } - if (sender instanceof ConsoleCommandSender console) { - return new BukkitConsoleCommandSender(console); - } - if (sender instanceof Player player) { - return new BukkitPlayer(player); - } - if (sender instanceof org.bukkit.entity.Entity entity) { - return new BukkitEntity(entity); - } - if (sender instanceof NativeProxyCommandSender nativeProxy) { - return new BukkitNativeProxyCommandSender(nativeProxy); - } - if (sender instanceof ProxiedCommandSender proxy) { - return new BukkitProxiedCommandSender(proxy); - } - if (sender instanceof RemoteConsoleCommandSender remote) { - return new BukkitRemoteConsoleCommandSender(remote); - } - if (paper.isPaperPresent()) { - final Class FeedbackForwardingSender = paper.getFeedbackForwardingCommandSender(); - if (FeedbackForwardingSender.isInstance(sender)) { - // We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance - return new BukkitFeedbackForwardingCommandSender(FeedbackForwardingSender.cast(sender)); - } - - final Class NullCommandSender = paper.getNullCommandSender(); - if (NullCommandSender != null && NullCommandSender.isInstance(sender)) { - // Since this should only be during a function load, this is just a placeholder to evade the exception. - return null; - } - - } - throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); - } - @Override public void registerPermission(String string) { try { @@ -429,10 +304,6 @@ public void registerPermission(String string) { } } - @Override - @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) - public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); - @Override public void preCommandRegistration(String commandName) { // Warn if the command we're registering already exists in this plugin's @@ -504,7 +375,7 @@ private void unregisterInternal(String commandName, boolean unregisterNamespaces if (!CommandAPI.canRegister()) { // Help topics (from Bukkit and CommandAPI) are only setup after plugins enable, so we only need to worry // about removing them once the server is loaded. - getHelpMap().remove("/" + commandName); + nms.getHelpMap().remove("/" + commandName); // Notify players for (Player p : Bukkit.getOnlinePlayers()) { @@ -518,14 +389,6 @@ public final CommandDispatcher getBrigadierDispatcher() { return commandRegistrationStrategy.getBrigadierDispatcher(); } - @Override - @Unimplemented(because = {REQUIRES_MINECRAFT_SERVER, VERSION_SPECIFIC_IMPLEMENTATION}) - public abstract void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; - - @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) // What are the odds? - public abstract T getMinecraftServer(); - - @Override public CommandAPILogger getLogger() { return new DefaultLogger(); } @@ -543,10 +406,6 @@ public void severe(String message, Throwable exception) { } } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) - public abstract void reloadDataPacks(); - @Override public void updateRequirements(AbstractPlayer player) { ((Player) player.getSource()).updateCommands(); @@ -566,39 +425,6 @@ public Argument newConcreteLiteralArgument(String nodeName, String liter public CommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta) { return new CommandAPICommand(meta); } - - /** - * Forces a command to return a success value of 0 - * - * @param message Description of the error message, formatted as an array of base components - * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's - * {@link CommandSyntaxException} - */ - public static WrapperCommandSyntaxException failWithBaseComponents(BaseComponent... message) { - return CommandAPI.failWithMessage(BukkitTooltip.messageFromBaseComponents(message)); - } - - /** - * Forces a command to return a success value of 0 - * - * @param message Description of the error message, formatted as an adventure chat component - * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's - * {@link CommandSyntaxException} - */ - public static WrapperCommandSyntaxException failWithAdventureComponent(Component message) { - return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message)); - } - - /** - * Forces a command to return a success value of 0 - * - * @param message Description of the error message, formatted as an adventure chat component - * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's - * {@link CommandSyntaxException} - */ - public static WrapperCommandSyntaxException failWithAdventureComponent(ComponentLike message) { - return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message.asComponent())); - } /** * Initializes the CommandAPI's implementation of an NBT API. If you are shading @@ -619,8 +445,8 @@ public static WrapperCommandSyntaxException failWithAdventureComponent(Component public static void initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor) { getConfiguration().lateInitializeNBT(nbtContainerClass, nbtContainerConstructor); } - - protected void registerBukkitRecipesSafely(Iterator recipes) { + + public void registerBukkitRecipesSafely(Iterator recipes) { Recipe recipe; while (recipes.hasNext()) { recipe = recipes.next(); @@ -655,4 +481,38 @@ boolean isInvalidNamespace(String commandName, String namespace) { } return false; } + + /* + * Implement several methods from CommandAPIPlatform that just need to delegate to NMS + */ + + @Override + public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { + return nms.getSenderForCommand(cmdCtx, forceNative); + } + + @Override + public Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { + return nms.getBrigadierSourceFromCommandSender(sender); + } + + @Override + public SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider) { + return nms.getSuggestionProvider(suggestionProvider); + } + + @Override + public BukkitCommandSender getCommandSenderFromCommandSource(Source css) { + return nms.getCommandSenderFromCommandSource(css); + } + + @Override + public void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException { + nms.createDispatcherFile(file, dispatcher); + } + + @Override + public void reloadDataPacks() { + nms.reloadDataPacks(); + } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java index 5944f50ebb..0050dc39a8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java @@ -1,17 +1,15 @@ package dev.jorel.commandapi; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; import org.bukkit.plugin.java.JavaPlugin; /** * A class that contains information needed to configure the CommandAPI on Bukkit-based servers. */ -public class CommandAPIBukkitConfig extends CommandAPIConfig { +public abstract class CommandAPIBukkitConfig> extends CommandAPIConfig { JavaPlugin plugin; // Default configuration - boolean shouldHookPaperReload = true; boolean skipReloadDatapacks = false; /** @@ -25,31 +23,6 @@ public CommandAPIBukkitConfig(JavaPlugin plugin) { this.plugin = plugin; super.setNamespace("minecraft"); } - - /** - * Sets the CommandAPI to hook into Paper's {@link ServerResourcesReloadedEvent} when available - * if true. This helps CommandAPI commands to work in datapacks after {@code /minecraft:reload} - * is run. - * - * @param hooked whether the CommandAPI should hook into Paper's {@link ServerResourcesReloadedEvent} - * @return this CommandAPIBukkitConfig - */ - public CommandAPIBukkitConfig shouldHookPaperReload(boolean hooked) { - this.shouldHookPaperReload = hooked; - return this; - } - - /** - * Sets whether the CommandAPI should skip its datapack reload step after the server - * has finished loading. This does not skip reloading of datapacks when invoked manually - * when {@link #shouldHookPaperReload(boolean)} is set. - * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading - * @return this CommandAPIBukkitConfig - */ - public CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) { - this.skipReloadDatapacks = skip; - return this; - } /** * Sets whether the CommandAPI should use Mojang mappings as opposed to Spigot's mappings @@ -60,43 +33,44 @@ public CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) { * @deprecated Use the `commandapi-bukkit-shade-mojang-mapped` depdendency instead of `commandapi-bukkit-shade` if you want to use mojang mappings. */ @Deprecated(since = "9.4.1", forRemoval = true) - public CommandAPIBukkitConfig useMojangMappings(boolean useMojangMappings) { + public T useMojangMappings(boolean useMojangMappings) { // A little unconventional, but we really don't need to implement mojang mapping flags // all over the place, we want it to have as minimal interaction as possible so it can // be used by the test framework as a global static flag. Also, we want to set this // as early as possible in the CommandAPI's loading sequence, including before loading // an NMS class, which setup reflection based on `USING_MOJANG_MAPPINGS`. SafeVarHandle.USING_MOJANG_MAPPINGS = useMojangMappings; - return this; + return instance(); } /** * @return this CommandAPIBukkitConfig */ - public CommandAPIBukkitConfig usePluginNamespace() { + public T usePluginNamespace() { super.setNamespace(plugin.getName().toLowerCase()); super.usePluginNamespace = true; - return this; + return instance(); } @Override - public CommandAPIBukkitConfig setNamespace(String namespace) { + public T setNamespace(String namespace) { if (namespace == null) { throw new NullPointerException("Default namespace can't be null!"); } if (namespace.isEmpty()) { CommandAPI.logNormal("Did not set namespace to an empty value! Namespace '" + super.namespace + "' is used as the default namespace!"); - return this; + return instance(); } if (!CommandAPIHandler.NAMESPACE_PATTERN.matcher(namespace).matches()) { CommandAPI.logNormal("Did not set namespace to the provided '" + namespace + "' namespace because only 0-9, a-z, underscores, periods and hyphens are allowed!"); - return this; + return instance(); } return super.setNamespace(namespace); } - @Override - public CommandAPIBukkitConfig instance() { - return this; + public T skipReloadDatapacks(boolean skip) { + this.skipReloadDatapacks = skip; + return instance(); } + } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java index 58dedd464f..84b8a35002 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java @@ -196,7 +196,7 @@ private static void convertPluginCommand(JavaPlugin plugin, String commandName, org.bukkit.command.Command command = plugin.getCommand(commandName); if (command == null) { - command = CommandAPIBukkit.get().getSimpleCommandMap() + command = CommandAPIBukkit.get().getNMS().getSimpleCommandMap() .getCommand(commandName); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java index 371f24fe46..2ea3acdf31 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java @@ -1,6 +1,5 @@ package dev.jorel.commandapi; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; import org.bukkit.plugin.java.JavaPlugin; /** @@ -8,13 +7,10 @@ * only ever read from, nothing is ever written to it. That's why there's only * getter methods. */ -public class InternalBukkitConfig extends InternalConfig { +public abstract class InternalBukkitConfig extends InternalConfig { // The plugin that is loading the CommandAPI private final JavaPlugin plugin; - // Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run - private final boolean shouldHookPaperReload; - private final boolean skipReloadDatapacks; /** @@ -22,10 +18,9 @@ public class InternalBukkitConfig extends InternalConfig { * * @param config The configuration to use to set up this internal configuration */ - public InternalBukkitConfig(CommandAPIBukkitConfig config) { + public InternalBukkitConfig(CommandAPIBukkitConfig> config) { super(config); this.plugin = config.plugin; - this.shouldHookPaperReload = config.shouldHookPaperReload; this.skipReloadDatapacks = config.skipReloadDatapacks; } @@ -36,21 +31,11 @@ public JavaPlugin getPlugin() { return plugin; } - /** - * @return Whether the CommandAPI should hook into Paper's {@link ServerResourcesReloadedEvent} - * when available to perform the CommandAPI's custom datapack reload when {@code /minecraft:reload} - * is run. - */ - public boolean shouldHookPaperReload() { - return shouldHookPaperReload; - } - - - /** * @return Whether the CommandAPI should skip reloading datapacks when the server has finished loading */ public boolean skipReloadDatapacks() { return skipReloadDatapacks; } + } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java deleted file mode 100644 index c9f04d1b31..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java +++ /dev/null @@ -1,155 +0,0 @@ -package dev.jorel.commandapi; - -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.nms.NMS; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; - -public class PaperImplementations { - - private final boolean isPaperPresent; - private final boolean isFoliaPresent; - private final NMS nmsInstance; - private final Class feedbackForwardingCommandSender; - private final Class nullCommandSender; - - /** - * Constructs a PaperImplementations object - * - * @param isPaperPresent Whether this is a Paper server or not - * @param isFoliaPresent Whether this is a Folia server or not - * @param nmsInstance The instance of NMS - */ - @SuppressWarnings("unchecked") - public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS nmsInstance) { - this.isPaperPresent = isPaperPresent; - this.isFoliaPresent = isFoliaPresent; - this.nmsInstance = nmsInstance; - - Class tempFeedbackForwardingCommandSender = null; - try { - tempFeedbackForwardingCommandSender = (Class) Class.forName("io.papermc.paper.commands.FeedbackForwardingSender"); - } catch (ClassNotFoundException e) { - // uhh... - } - - this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender; - - Class tempNullCommandSender = null; - try { - tempNullCommandSender = (Class) Class.forName("io.papermc.paper.brigadier.NullCommandSender"); - } catch (ClassNotFoundException e) { - // uhh... - } - - this.nullCommandSender = tempNullCommandSender; - } - - /** - * Hooks into Paper's {@link ServerResourcesReloadedEvent} to detect if - * {@code /minecraft:reload} is called, and registers a reload handler that - * automatically calls the CommandAPI's internal datapack reloading function - * - * @param plugin the plugin that the CommandAPI is being used from - */ - public void registerReloadHandler(Plugin plugin) { - if (isPaperPresent) { - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - @EventHandler - public void onServerReloadResources(ServerResourcesReloadedEvent event) { - // This event is called after Paper is done with everything command related - // which means we can put commands back - CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); - - // Normally, the reloadDataPacks() method is responsible for updating commands for - // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload - // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to - // paper-1.20.6-65 - if (!CommandAPIBukkit.getConfiguration().shouldHookPaperReload()) { - for (Player player : Bukkit.getOnlinePlayers()) { - player.updateCommands(); - } - return; - } - CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); - nmsInstance.reloadDataPacks(); - } - - }, plugin); - CommandAPI.logNormal("Hooked into Paper ServerResourcesReloadedEvent"); - } else { - CommandAPI.logNormal("Did not hook into Paper ServerResourcesReloadedEvent"); - } - } - - /** - * @return Bukkit's {@link CommandMap} - */ - public CommandMap getCommandMap() { - if (isPaperPresent) { - return Bukkit.getServer().getCommandMap(); - } else { - return nmsInstance.getSimpleCommandMap(); - } - } - - /** - * @return whether we're using paper or not - */ - public boolean isPaperPresent() { - return this.isPaperPresent; - } - - /** - * @return whether we're using folia or not - */ - public boolean isFoliaPresent() { - return this.isFoliaPresent; - } - - /** - * @return a class reference pointing to {@code io.papermc.paper.commands.FeedbackForwardingSender} - */ - public Class getFeedbackForwardingCommandSender() { - return this.feedbackForwardingCommandSender; - } - - /** - * @return a class reference pointing to {@code io.papermc.paper.brigadier.NullCommandSender} - */ - public Class getNullCommandSender() { - return this.nullCommandSender; - } - - /** - * Builds a {@link WrapperCommandSyntaxException} from a message with colour codes like {@link ChatColor} or using the § symbol. - * - * @param message the error message to be displayed - * @return A {@link WrapperCommandSyntaxException} with the given message as error message - */ - public WrapperCommandSyntaxException getExceptionFromString(String message) { - if (isPaperPresent) { - // I don't know why, but if you set this to an Object first, then cast it to a Component, - // running this code is totally fine on a Spigot server. If you don't do this (e.g. set - // it to a Component or inline this), for some reason Java throws a stronk at runtime. - // For your sanity and the sanity of whoever has to maintain this in the future, please - // DO NOT try to simplify this statement: - final Object adventureComponent = LegacyComponentSerializer.legacySection().deserialize(message); - return new WrapperCommandSyntaxException(new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent((Component) adventureComponent)).create()); - } else { - return new WrapperCommandSyntaxException(new SimpleCommandExceptionType(BukkitTooltip.messageFromBaseComponents(TextComponent.fromLegacyText(message))).create()); - } - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java new file mode 100644 index 0000000000..e4cad3d7a3 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java @@ -0,0 +1,16 @@ +package dev.jorel.commandapi; + +/** + * The Bukkit platform that is used at runtime + */ +public enum Platform { + /** + * Represents the Spigot platform, uses module commandapi-spigot + */ + SPIGOT, + + /** + * Represents the Paper platform, uses module commandapi-paper + */ + PAPER +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java index 11d724fd16..ae08f1f21c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java @@ -40,7 +40,7 @@ public class AdvancementArgument extends SafeOverrideableArgument Advancement parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdvancement(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAdvancement(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java index 52b5e6066b..e3826aff49 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java @@ -44,7 +44,7 @@ public class AngleArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for argument */ public AngleArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentAngle(), String::valueOf); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentAngle(), String::valueOf); } @Override @@ -60,6 +60,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Float parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAngle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAngle(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java index 2cdc750b7b..1fa5297711 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java @@ -45,7 +45,7 @@ public class AxisArgument extends SafeOverrideableArgument e.stream().map(Axis::name).map(String::toLowerCase).reduce(String::concat).get()); } @@ -63,6 +63,6 @@ public CommandAPIArgumentType getArgumentType() { public EnumSet parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAxis(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAxis(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java index 942153960f..e4af93ed2f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java @@ -43,7 +43,7 @@ public class BiomeArgument extends SafeOverrideableArgument implem * @param nodeName the name of the node for argument */ public BiomeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentSyntheticBiome(), + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentSyntheticBiome(), ((Function) Biome::name).andThen(String::toLowerCase)); } @@ -65,7 +65,7 @@ public SuggestionProviders getSuggestionProvider() { @Override public Biome parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Biome) CommandAPIBukkit.get().getBiome(cmdCtx, key, ArgumentSubType.BIOME_BIOME); + return (Biome) CommandAPIBukkit.get().getNMS().getBiome(cmdCtx, key, ArgumentSubType.BIOME_BIOME); } /** @@ -82,7 +82,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getBiome(cmdCtx, key, ArgumentSubType.BIOME_NAMESPACEDKEY); + return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getNMS().getBiome(cmdCtx, key, ArgumentSubType.BIOME_NAMESPACEDKEY); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java index 7ede3fc9ed..97179aade8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java @@ -45,7 +45,7 @@ public class BlockPredicateArgument extends Argument { * @param nodeName the name of the node for argument */ public BlockPredicateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentBlockPredicate()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentBlockPredicate()); } @Override @@ -61,6 +61,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Predicate parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getBlockPredicate(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getBlockPredicate(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java index 20f514abbf..b113865e6b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java @@ -42,7 +42,7 @@ public class BlockStateArgument extends Argument { * @param nodeName the name of the node for argument */ public BlockStateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentBlockState()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentBlockState()); } @Override @@ -58,6 +58,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public BlockData parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getBlockState(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getBlockState(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java index faf0543255..965f6a261b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java @@ -46,7 +46,7 @@ private void applySuggestions() { super.replaceSuggestions((info, builder) -> { // Extract information CommandSender sender = info.sender(); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); String command = info.currentArg(); // Setup context for errors @@ -194,7 +194,7 @@ public CommandAPIArgumentType getArgumentType() { public CommandResult parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { // Extract information String command = cmdCtx.getArgument(key, String.class); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); CommandSender sender = CommandAPIBukkit.get().getSenderForCommand(cmdCtx, false).getSource(); StringReader context = new StringReader(command); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java index 83ef7848fb..a32220d9f0 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java @@ -40,7 +40,7 @@ public class EnchantmentArgument extends SafeOverrideableArgument Enchantment parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getEnchantment(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getEnchantment(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java index 3e01bc0064..9584c1f61a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java @@ -54,7 +54,7 @@ public static class OneEntity extends Argument { * @param nodeName the name of the node for this argument */ public OneEntity(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY)); } @Override @@ -69,7 +69,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Entity parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Entity) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY, true); + return (Entity) CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY, true); } @Override @@ -91,7 +91,7 @@ public static class OnePlayer extends Argument { * @param nodeName the name of the node for this argument */ public OnePlayer(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER)); } @Override @@ -106,7 +106,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Player parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Player) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER, true); + return (Player) CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER, true); } @Override @@ -140,7 +140,7 @@ public ManyEntities(String nodeName) { * @param allowEmpty whether this entity selector should allow no entities found, or should throw an error instead */ public ManyEntities(String nodeName, boolean allowEmpty) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES)); this.allowEmpty = allowEmpty; } @@ -157,7 +157,7 @@ public CommandAPIArgumentType getArgumentType() { @SuppressWarnings("unchecked") @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Collection) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES, this.allowEmpty); + return (Collection) CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES, this.allowEmpty); } @SuppressWarnings("unchecked") @@ -196,7 +196,7 @@ public ManyPlayers(String nodeName) { * * @param allowEmpty whether this entity selector should allow no entities found, or should throw an error instead */ public ManyPlayers(String nodeName, boolean allowEmpty) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS)); this.allowEmpty = allowEmpty; } @@ -213,7 +213,7 @@ public CommandAPIArgumentType getArgumentType() { @SuppressWarnings("unchecked") @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Collection) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS, allowEmpty); + return (Collection) CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS, allowEmpty); } @SuppressWarnings("unchecked") diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java index 8ebd9b04bd..e912803611 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java @@ -38,7 +38,7 @@ public class EntityTypeArgument extends SafeOverrideableArgument EntityType parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getEntityType(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getEntityType(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java index fd3bb278fa..98b065e2fb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java @@ -38,7 +38,7 @@ public class FloatRangeArgument extends SafeOverrideableArgument FloatRange parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getFloatRange(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getFloatRange(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java index 9bf736c111..b2dd155b7e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java @@ -41,7 +41,7 @@ public class FunctionArgument extends SafeOverrideableArgument n)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentTag(), fromKey(n -> n)); } @Override @@ -61,6 +61,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public FunctionWrapper[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getFunction(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getFunction(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java index 85bfc8f28e..289c5ebe6e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java @@ -38,7 +38,7 @@ public class IntegerRangeArgument extends SafeOverrideableArgument IntegerRange parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getIntRange(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getIntRange(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java index edfa6369c8..b68aca41b4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java @@ -38,7 +38,7 @@ public class ItemStackArgument extends SafeOverrideableArgument ItemStack parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getItemStack(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getItemStack(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java index 1b6183d9c2..8b952a28c8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java @@ -41,7 +41,7 @@ public class ItemStackPredicateArgument extends Argument { * @param nodeName the name of the node for this argument */ public ItemStackPredicateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentItemPredicate()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentItemPredicate()); } @Override @@ -56,6 +56,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Predicate parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getItemStackPredicate(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getItemStackPredicate(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java index 3e6f2de758..e7f65d9e37 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java @@ -59,8 +59,8 @@ public Location2DArgument(String nodeName, LocationType type) { * @param centerPosition whether LocationType.PRECISE_POSITION should center the position of the location within a block */ public Location2DArgument(String nodeName, LocationType type, boolean centerPosition) { - super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get()._ArgumentPosition2D() - : CommandAPIBukkit.get()._ArgumentVec2(centerPosition), + super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get().getNMS()._ArgumentPosition2D() + : CommandAPIBukkit.get().getNMS()._ArgumentVec2(centerPosition), type == LocationType.BLOCK_POSITION ? (Location2D l) -> l.getBlockX() + " " + l.getBlockZ() : (Location2D l) -> l.getX() + " " + l.getZ()); isPrecise = type == LocationType.PRECISE_POSITION; @@ -89,7 +89,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Location2D parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { return isPrecise ? - CommandAPIBukkit.get().getLocation2DPrecise(cmdCtx, key) : - CommandAPIBukkit.get().getLocation2DBlock(cmdCtx, key); + CommandAPIBukkit.get().getNMS().getLocation2DPrecise(cmdCtx, key) : + CommandAPIBukkit.get().getNMS().getLocation2DBlock(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java index fe477594f9..a85806c78e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java @@ -58,8 +58,8 @@ public LocationArgument(String nodeName, LocationType type) { * @param centerPosition whether LocationType.PRECISE_POSITION should center the position of the location within a block */ public LocationArgument(String nodeName, LocationType type, boolean centerPosition) { - super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get()._ArgumentPosition() - : CommandAPIBukkit.get()._ArgumentVec3(centerPosition), + super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get().getNMS()._ArgumentPosition() + : CommandAPIBukkit.get().getNMS()._ArgumentVec3(centerPosition), type == LocationType.BLOCK_POSITION ? (Location l) -> l.getBlockX() + " " + l.getBlockY() + " " + l.getBlockZ() : (Location l) -> l.getX() + " " + l.getY() + " " + l.getZ()); @@ -89,7 +89,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Location parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { return isPrecise ? - CommandAPIBukkit.get().getLocationPrecise(cmdCtx, key) : - CommandAPIBukkit.get().getLocationBlock(cmdCtx, key); + CommandAPIBukkit.get().getNMS().getLocationPrecise(cmdCtx, key) : + CommandAPIBukkit.get().getNMS().getLocationBlock(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java index ae14acb56c..8d32327669 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java @@ -39,7 +39,7 @@ public class LootTableArgument extends SafeOverrideableArgument LootTable parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getLootTable(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getLootTable(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java index 1df682386f..d5dfb712ab 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java @@ -38,7 +38,7 @@ public class MathOperationArgument extends SafeOverrideableArgument MathOperation parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getMathOperation(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getMathOperation(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java index efefb6b326..df6ca60240 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java @@ -40,7 +40,7 @@ public class NBTCompoundArgument extends SafeOverrideableArgument< * @param nodeName the name of the node for this argument */ public NBTCompoundArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentNBTCompound(), NBTContainer::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentNBTCompound(), NBTContainer::toString); if (CommandAPI.getConfiguration().getNBTContainerClass() == null || CommandAPI.getConfiguration().getNBTContainerConstructor() == null) { throw new NullPointerException( "The NBTCompoundArgument hasn't been initialized properly! Use CommandAPIConfig.initializeNBTAPI() in your onLoad() method"); @@ -62,6 +62,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public NBTContainer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (NBTContainer) CommandAPIBukkit.get().getNBTCompound(cmdCtx, key, CommandAPI.getConfiguration().getNBTContainerConstructor()); + return (NBTContainer) CommandAPIBukkit.get().getNMS().getNBTCompound(cmdCtx, key, CommandAPI.getConfiguration().getNBTContainerConstructor()); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java index 0f09352c65..3e7fc81636 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java @@ -43,7 +43,7 @@ public class NamespacedKeyArgument extends SafeOverrideableArgument NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getMinecraftKey(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getMinecraftKey(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java index 6192e830bf..ee270e10d0 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java @@ -38,7 +38,7 @@ public class ObjectiveArgument extends SafeOverrideableArgument Objective parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getObjective(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getObjective(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java index 9c5e8ad0c2..06e3cf8bb8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java @@ -37,7 +37,7 @@ public class ObjectiveCriteriaArgument extends Argument { * @param nodeName the name of the node for this argument */ public ObjectiveCriteriaArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreboardCriteria()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreboardCriteria()); } @Override @@ -52,6 +52,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public String parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getObjectiveCriteria(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getObjectiveCriteria(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java index 34321f2976..4f1c3abe88 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java @@ -40,7 +40,7 @@ public class OfflinePlayerArgument extends SafeOverrideableArgument OfflinePlayer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getOfflinePlayer(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getOfflinePlayer(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java index aa6f1a74a4..36186b73b8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java @@ -39,7 +39,7 @@ public class ParticleArgument extends SafeOverrideableArgument ParticleData parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getParticle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getParticle(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java index 220bc56f3f..c3e9238e0e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java @@ -43,7 +43,7 @@ public class PlayerArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public PlayerArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentProfile(), Player::getName); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentProfile(), Player::getName); } @Override @@ -58,6 +58,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Player parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getPlayer(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getPlayer(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java index 45985192e6..3e97970c15 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java @@ -39,7 +39,7 @@ public class PotionEffectArgument extends SafeOverrideableArgument PotionEffectType parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (PotionEffectType) CommandAPIBukkit.get().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_POTION_EFFECT); + return (PotionEffectType) CommandAPIBukkit.get().getNMS().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_POTION_EFFECT); } /** @@ -70,7 +70,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_NAMESPACEDKEY); + return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getNMS().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_NAMESPACEDKEY); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java index 405f97986b..c706694773 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java @@ -39,7 +39,7 @@ public class RecipeArgument extends SafeOverrideableArgument imp * @param nodeName the name of the node for this argument */ public RecipeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentRecipe(), fromKey((Recipe r) -> ((Keyed) r).getKey())); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentRecipe(), fromKey((Recipe r) -> ((Keyed) r).getKey())); } @Override @@ -59,7 +59,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Recipe parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getRecipe(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getRecipe(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java index 52cc6a477a..890a49b1d8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java @@ -38,7 +38,7 @@ public class RotationArgument extends SafeOverrideableArgument Rotation parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getRotation(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getRotation(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java index 763726cef8..472d6e9049 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java @@ -50,7 +50,7 @@ public static class Single extends Argument { * @param nodeName the name of the node for this argument */ public Single(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_SINGLE)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_SINGLE)); } @Override @@ -65,7 +65,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public String parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreHolderSingle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreHolderSingle(cmdCtx, key); } } @@ -83,7 +83,7 @@ public static class Multiple extends Argument { * @param nodeName the name of the node for this argument */ public Multiple(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_MULTIPLE)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_MULTIPLE)); } @Override @@ -98,7 +98,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreHolderMultiple(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreHolderMultiple(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java index e4838d9f88..921499bacb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java @@ -38,7 +38,7 @@ public class ScoreboardSlotArgument extends SafeOverrideableArgument ScoreboardSlot parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreboardSlot(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreboardSlot(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java index 47f84e2f97..3b0c54622c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java @@ -40,7 +40,7 @@ public class SoundArgument extends SafeOverrideableArgument implem * @param nodeName the name of the node for this argument */ public SoundArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentMinecraftKeyRegistered(), CommandAPIBukkit.get()::convert); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentMinecraftKeyRegistered(), CommandAPIBukkit.get().getNMS()::convert); } @Override @@ -60,7 +60,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Sound parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Sound) CommandAPIBukkit.get().getSound(cmdCtx, key, ArgumentSubType.SOUND_SOUND); + return (Sound) CommandAPIBukkit.get().getNMS().getSound(cmdCtx, key, ArgumentSubType.SOUND_SOUND); } /** @@ -77,7 +77,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getSound(cmdCtx, key, ArgumentSubType.SOUND_NAMESPACEDKEY); + return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getNMS().getSound(cmdCtx, key, ArgumentSubType.SOUND_NAMESPACEDKEY); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java index 99fc31fbd3..fa2e28c605 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java @@ -38,7 +38,7 @@ public class TeamArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public TeamArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreboardTeam(), Team::getName); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreboardTeam(), Team::getName); } @Override @@ -53,6 +53,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Team parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getTeam(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getTeam(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java index a246d8b39a..2f969df5e7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java @@ -38,7 +38,7 @@ public class TimeArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public TimeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentTime(), Time::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentTime(), Time::toString); } @Override @@ -53,6 +53,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Integer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getTime(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getTime(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java index 9b74d706d1..f6f396a28d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java @@ -39,7 +39,7 @@ public class UUIDArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public UUIDArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentUUID(), UUID::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentUUID(), UUID::toString); } @Override @@ -54,6 +54,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public UUID parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getUUID(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getUUID(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java index 62263ea0a0..6460ba2c49 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java @@ -43,7 +43,7 @@ public class WorldArgument extends SafeOverrideableArgument { public WorldArgument(String nodeName) { // Dev note: DO NOT use a method reference for the World class! See // https://github.com/JorelAli/CommandAPI/issues/397 for more info - super(nodeName, CommandAPIBukkit.get()._ArgumentDimension(), world -> world.getName().toLowerCase()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentDimension(), world -> world.getName().toLowerCase()); } @Override @@ -62,6 +62,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public World parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getDimension(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getDimension(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java new file mode 100644 index 0000000000..8c1bf8b5ff --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java @@ -0,0 +1,8 @@ +package dev.jorel.commandapi.exceptions; + +public class PlatformException extends RuntimeException { + + public PlatformException(String message) { + super(message); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index ecc85b5f5a..8f52119c8a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -20,6 +20,8 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; +import java.io.File; +import java.io.IOException; import java.util.Collection; import java.util.EnumSet; import java.util.Map; @@ -28,7 +30,11 @@ import java.util.function.Function; import java.util.function.Predicate; +import com.mojang.brigadier.CommandDispatcher; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.preprocessor.Unimplemented; import org.bukkit.Axis; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -39,6 +45,7 @@ import org.bukkit.advancement.Advancement; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; @@ -72,57 +79,62 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.md_5.bungee.api.chat.BaseComponent; -public interface NMS { +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CSS; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_MINECRAFT_SERVER; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; + +public abstract class NMS { /** * @return Advancement argument (api:advancement) */ - ArgumentType _ArgumentAdvancement(); + public abstract ArgumentType _ArgumentAdvancement(); /** * @return Angle argument (minecraft:angle) */ - ArgumentType _ArgumentAngle(); + public abstract ArgumentType _ArgumentAngle(); /** * @return Axis argument (minecraft:swizzle) */ - ArgumentType _ArgumentAxis(); + public abstract ArgumentType _ArgumentAxis(); /** * @return Block predicate argument (minecraft:block_predicate) */ - ArgumentType _ArgumentBlockPredicate(); + public abstract ArgumentType _ArgumentBlockPredicate(); /** * @return Block state argument (minecraft:block_state) */ - ArgumentType _ArgumentBlockState(); + public abstract ArgumentType _ArgumentBlockState(); /** * @return Chat argument (minecraft:message) */ - ArgumentType _ArgumentChat(); + public abstract ArgumentType _ArgumentChat(); /** * @return Chat component argument (minecraft:component) */ - ArgumentType _ArgumentChatComponent(); + public abstract ArgumentType _ArgumentChatComponent(); /** * @return Chat color argument (minecraft:color) */ - ArgumentType _ArgumentChatFormat(); + public abstract ArgumentType _ArgumentChatFormat(); /** * @return Dimension argument (minecraft:dimension) */ - ArgumentType _ArgumentDimension(); + public abstract ArgumentType _ArgumentDimension(); /** * @return Enchantment argument (minecraft:item_enchantment) */ - ArgumentType _ArgumentEnchantment(); + public abstract ArgumentType _ArgumentEnchantment(); /** * @param subType one of {@link ArgumentSubType#ENTITYSELECTOR_MANY_ENTITIES}, @@ -131,134 +143,134 @@ public interface NMS { * {@link ArgumentSubType#ENTITYSELECTOR_ONE_PLAYER} * @return Entity selector argument (minecraft:entity) */ - ArgumentType _ArgumentEntity(ArgumentSubType subType); + public abstract ArgumentType _ArgumentEntity(ArgumentSubType subType); /** * @return Entity type argument (minecraft:entity_summon) */ - ArgumentType _ArgumentEntitySummon(); + public abstract ArgumentType _ArgumentEntitySummon(); /** * @return Float range argument (minecraft:float_range) */ - ArgumentType _ArgumentFloatRange(); + public abstract ArgumentType _ArgumentFloatRange(); /** * @return Int range argument (minecraft:int_range) */ - ArgumentType _ArgumentIntRange(); + public abstract ArgumentType _ArgumentIntRange(); /** * @return Item predicate argument (minecraft:item_predicate) */ - ArgumentType _ArgumentItemPredicate(); + public abstract ArgumentType _ArgumentItemPredicate(); /** * @return Itemstack argument (minecraft:item_stack) */ - ArgumentType _ArgumentItemStack(); + public abstract ArgumentType _ArgumentItemStack(); /** * @return Math operation argument (minecraft:operation) */ - ArgumentType _ArgumentMathOperation(); + public abstract ArgumentType _ArgumentMathOperation(); /** * @return Minecraft key argument (minecraft:resource_location) */ - ArgumentType _ArgumentMinecraftKeyRegistered(); + public abstract ArgumentType _ArgumentMinecraftKeyRegistered(); /** * @return Potion effect argument (minecraft:mob_effect) */ - ArgumentType _ArgumentMobEffect(); + public abstract ArgumentType _ArgumentMobEffect(); /** * @return NBT compound tag argument (minecraft:nbt_compound_tag) */ - ArgumentType _ArgumentNBTCompound(); + public abstract ArgumentType _ArgumentNBTCompound(); /** * @return Particle argument (minecraft:particle) */ - ArgumentType _ArgumentParticle(); + public abstract ArgumentType _ArgumentParticle(); /** * @return Position argument (minecraft:block_pos) */ - ArgumentType _ArgumentPosition(); + public abstract ArgumentType _ArgumentPosition(); /** * @return 2D position (column) argument (minecraft:column_pos) */ - ArgumentType _ArgumentPosition2D(); + public abstract ArgumentType _ArgumentPosition2D(); /** * @return Player argument (minecraft:game_profile) */ - ArgumentType _ArgumentProfile(); + public abstract ArgumentType _ArgumentProfile(); /** * @return Recipe argument (api:recipe) */ - ArgumentType _ArgumentRecipe(); + public abstract ArgumentType _ArgumentRecipe(); /** * @return Rotation argument (minecraft:rotation) */ - ArgumentType _ArgumentRotation(); + public abstract ArgumentType _ArgumentRotation(); /** * @return Scoreboard objective criteria argument (minecraft:objective_criteria) */ - ArgumentType _ArgumentScoreboardCriteria(); + public abstract ArgumentType _ArgumentScoreboardCriteria(); /** * @return Scoreboard objective argument (minecraft:objective) */ - ArgumentType _ArgumentScoreboardObjective(); + public abstract ArgumentType _ArgumentScoreboardObjective(); /** * @return Scoreboard slot argument (minecraft:scoreboard_slot) */ - ArgumentType _ArgumentScoreboardSlot(); + public abstract ArgumentType _ArgumentScoreboardSlot(); /** * @return Scoreboard team argument (minecraft:team) */ - ArgumentType _ArgumentScoreboardTeam(); + public abstract ArgumentType _ArgumentScoreboardTeam(); /** * @param subType one of {@link ArgumentSubType#SCOREHOLDER_MULTIPLE} or * {@link ArgumentSubType#SCOREHOLDER_SINGLE} * @return Scoreholder argument (minecraft:score_holder) */ - ArgumentType _ArgumentScoreholder(ArgumentSubType subType); + public abstract ArgumentType _ArgumentScoreholder(ArgumentSubType subType); /** * @return Function argument (minecraft:function) */ - ArgumentType _ArgumentTag(); + public abstract ArgumentType _ArgumentTag(); /** * @return Time argument (minecraft:time) */ - ArgumentType _ArgumentTime(); + public abstract ArgumentType _ArgumentTime(); /** * @return UUID argument (minecraft:uuid) */ - ArgumentType _ArgumentUUID(); + public abstract ArgumentType _ArgumentUUID(); /** * @return Location 2D argument (precise position) (minecraft:vec2) */ - ArgumentType _ArgumentVec2(boolean centerPosition); + public abstract ArgumentType _ArgumentVec2(boolean centerPosition); /** * @return Location argument (precise position) (minecraft:vec3) */ - ArgumentType _ArgumentVec3(boolean centerPosition); + public abstract ArgumentType _ArgumentVec3(boolean centerPosition); /* * Synthetic arguments - arguments that don't actually exist, but have @@ -268,7 +280,7 @@ public interface NMS { * to it as an _ArgumentSyntheticBiome */ - ArgumentType _ArgumentSyntheticBiome(); + public abstract ArgumentType _ArgumentSyntheticBiome(); /** * A String array of Minecraft versions that this NMS implementation is @@ -278,130 +290,118 @@ public interface NMS { * * @return A String array of compatible Minecraft versions */ - String[] compatibleVersions(); - - String convert(ItemStack is); - - String convert(ParticleData particle); + public abstract String[] compatibleVersions(); - String convert(PotionEffectType potion); + public abstract String convert(ItemStack is); - String convert(Sound sound); + public abstract String convert(ParticleData particle); - Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract String convert(PotionEffectType potion); - Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract String convert(Sound sound); - NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); + public abstract Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Component getAdventureChatComponent(CommandContext cmdCtx, String key); + public abstract float getAngle(CommandContext cmdCtx, String key); - float getAngle(CommandContext cmdCtx, String key); + public abstract EnumSet getAxis(CommandContext cmdCtx, String key); - EnumSet getAxis(CommandContext cmdCtx, String key); + public abstract Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; - Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; - - Predicate getBlockPredicate(CommandContext cmdCtx, String key) + public abstract Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException; - BlockData getBlockState(CommandContext cmdCtx, String key); - - BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - ChatColor getChatColor(CommandContext cmdCtx, String key); + public abstract BlockData getBlockState(CommandContext cmdCtx, String key); - BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); + public abstract World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; - World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 - Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 - - Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) + public abstract Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException; - EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; - FloatRange getFloatRange(CommandContext cmdCtx, String key); + public abstract FloatRange getFloatRange(CommandContext cmdCtx, String key); - FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) + public abstract FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException; - SimpleFunctionWrapper getFunction(NamespacedKey key); + public abstract SimpleFunctionWrapper getFunction(NamespacedKey key); - Set getFunctions(); + public abstract Set getFunctions(); - IntegerRange getIntRange(CommandContext cmdCtx, String key); + public abstract IntegerRange getIntRange(CommandContext cmdCtx, String key); - ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Predicate getItemStackPredicate(CommandContext cmdCtx, String key) + public abstract Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Location2D getLocation2DBlock(CommandContext cmdCtx, String key) + public abstract Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) + public abstract Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; + public abstract Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; - Location getLocationPrecise(CommandContext cmdCtx, String str) + public abstract Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException; - LootTable getLootTable(CommandContext cmdCtx, String key); + public abstract LootTable getLootTable(CommandContext cmdCtx, String key); - MathOperation getMathOperation(CommandContext cmdCtx, String key) + public abstract MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException; - NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key); + public abstract NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key); - Object getNBTCompound(CommandContext cmdCtx, String key, + public abstract Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor); - Objective getObjective(CommandContext cmdCtx, String key) + public abstract Objective getObjective(CommandContext cmdCtx, String key) throws IllegalArgumentException, CommandSyntaxException; - String getObjectiveCriteria(CommandContext cmdCtx, String key); + public abstract String getObjectiveCriteria(CommandContext cmdCtx, String key); - ParticleData getParticle(CommandContext cmdCtx, String key); + public abstract ParticleData getParticle(CommandContext cmdCtx, String key); - Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; - OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) + public abstract OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) + public abstract Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; - Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Rotation getRotation(CommandContext cmdCtx, String key); + public abstract Rotation getRotation(CommandContext cmdCtx, String key); - ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); + public abstract ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); - Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) + public abstract Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException; - String getScoreHolderSingle(CommandContext cmdCtx, String key) + public abstract String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException; + public abstract Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException; - int getTime(CommandContext cmdCtx, String key); + public abstract int getTime(CommandContext cmdCtx, String key); - UUID getUUID(CommandContext cmdCtx, String key); + public abstract UUID getUUID(CommandContext cmdCtx, String key); - World getWorldForCSS(CommandListenerWrapper clw); + public abstract World getWorldForCSS(CommandListenerWrapper clw); /** * Returns the Server's internal (OBC) CommandMap * * @return A SimpleCommandMap from the OBC server */ - SimpleCommandMap getSimpleCommandMap(); + public abstract SimpleCommandMap getSimpleCommandMap(); - Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); + public abstract Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); /** * Retrieve a specific NMS implemented SuggestionProvider @@ -409,22 +409,36 @@ String getScoreHolderSingle(CommandContext cmdCtx, Strin * @param provider The SuggestionProvider type to retrieve * @return A SuggestionProvider that matches the SuggestionProviders input */ - SuggestionProvider getSuggestionProvider(SuggestionProviders provider); + public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders provider); - SimpleFunctionWrapper[] getTag(NamespacedKey key); + public abstract SimpleFunctionWrapper[] getTag(NamespacedKey key); - Set getTags(); + public abstract Set getTags(); /** * Reloads the datapacks by using the updated the commandDispatcher tree */ - void reloadDataPacks(); + public abstract void reloadDataPacks(); + + public abstract HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission); + + public abstract Map getHelpMap(); + + public abstract Message generateMessageFromJson(String json); + + @Unimplemented(because = REQUIRES_CSS) + public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + + @Unimplemented(because = REQUIRES_CSS) + public abstract BukkitCommandSender getCommandSenderFromCommandSource(CommandListenerWrapper css); - HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission); + @Unimplemented(because = REQUIRES_CRAFTBUKKIT) + public abstract CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - Map getHelpMap(); + @Unimplemented(because = {REQUIRES_MINECRAFT_SERVER, VERSION_SPECIFIC_IMPLEMENTATION}) + public abstract void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; - Message generateMessageFromJson(String json); + @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) // What are the odds? + public abstract T getMinecraftServer(); - CommandRegistrationStrategy createCommandRegistrationStrategy(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java index 1d3398e934..9541d9162a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java @@ -63,7 +63,7 @@ public SimpleFunctionWrapper(NamespacedKey minecraftKey, @SuppressWarnings("rawt * @return a SimpleFunctionWrapper[], which is an array of all of the functions that this tag contains */ public static SimpleFunctionWrapper[] getTag(NamespacedKey key) { - return CommandAPIBukkit.get().getTag(key); + return CommandAPIBukkit.get().getNMS().getTag(key); } /** @@ -72,7 +72,7 @@ public static SimpleFunctionWrapper[] getTag(NamespacedKey key) { * @return a SimpleFunctionWrapper representation of the Minecraft function for the provided NamespacedKey */ public static SimpleFunctionWrapper getFunction(NamespacedKey key) { - return CommandAPIBukkit.get().getFunction(key); + return CommandAPIBukkit.get().getNMS().getFunction(key); } /** @@ -80,7 +80,7 @@ public static SimpleFunctionWrapper getFunction(NamespacedKey key) { * @return a set of all functions that the server has registered */ public static Set getFunctions() { - return CommandAPIBukkit.get().getFunctions(); + return CommandAPIBukkit.get().getNMS().getFunctions(); } /** @@ -88,7 +88,7 @@ public static Set getFunctions() { * @return a set of all tags that the server has registered */ public static Set getTags() { - return CommandAPIBukkit.get().getTags(); + return CommandAPIBukkit.get().getNMS().getTags(); } /** diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml deleted file mode 100644 index a60f0cf1a4..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - commandapi-bukkit - dev.jorel - 9.7.1-SNAPSHOT - - 4.0.0 - - commandapi-bukkit-mojang-mapped - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java index 8c5ae506e5..fe3fb4989b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.16.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_16_R3.java @@ -205,7 +205,7 @@ @RequireField(in = ParticleParamItem.class, name = "c", ofType = ItemStack.class) @RequireField(in = ParticleParamRedstone.class, name = "g", ofType = float.class) @RequireField(in = ArgumentPredicateItemStack.class, name = "c", ofType = NBTTagCompound.class) -public class NMS_1_16_R3 extends CommandAPIBukkit { +public class NMS_1_16_R3 extends NMS { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorCheckPermissions; @@ -426,33 +426,6 @@ public org.bukkit.advancement.Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(ChatSerializer.a(ArgumentChat.a(cmdCtx, key))); - } - - @Override - public final NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ArgumentChatFormat.a(cmdCtx, key).e(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(ChatSerializer.a(ArgumentChatComponent.a(cmdCtx, key))); - } - - /* - * ADVENTURE END - */ - @Override public float getAngle(CommandContext cmdCtx, String key) { return ArgumentAngle.a(cmdCtx, key); } @@ -499,21 +472,6 @@ public BlockData getBlockState(CommandContext cmdCtx, St return CraftBlockData.fromData(ArgumentTile.a(cmdCtx, key).a()); } - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(ChatSerializer.a(ArgumentChat.a(cmdCtx, key))); - } - - @Override - public ChatColor getChatColor(CommandContext cmdCtx, String key) { - return CraftChatMessage.getColor(ArgumentChatFormat.a(cmdCtx, key)); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { - return ComponentSerializer.parse(ChatSerializer.a(ArgumentChatComponent.a(cmdCtx, key))); - } - @Override public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { return VanillaCommandWrapper.getListener(senderWrapper.getSource()); @@ -522,7 +480,7 @@ public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractComman @Override public BukkitCommandSender getCommandSenderFromCommandSource(CommandListenerWrapper clw) { try { - return wrapCommandSender(clw.getBukkitSender()); + return CommandAPIBukkit.get().wrapCommandSender(clw.getBukkitSender()); } catch (UnsupportedOperationException e) { return null; } @@ -849,7 +807,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -945,7 +903,8 @@ public void reloadDataPacks() { // Update the CustomFunctionManager for the datapackResources which now has the new commandDispatcher try { - customFunctionManagerBrigadierDispatcher.set(datapackResources.a(), getBrigadierDispatcher()); + customFunctionManagerBrigadierDispatcher.set(datapackResources.a(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -969,7 +928,7 @@ public void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -998,15 +957,4 @@ public T getMinecraftServer() { } } - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.a(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommandDispatcher().a(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java index 7e4c688686..71bc5ef0a7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_Common.java @@ -270,17 +270,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); - } - - @Override - public Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { return switch(subType) { @@ -616,7 +605,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -716,16 +705,4 @@ public T getMinecraftServer() { return null; } } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_R1.java index 0c033fe701..da80ac6a50 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_17_R1.java @@ -28,8 +28,10 @@ import java.util.concurrent.ExecutionException; import com.mojang.brigadier.CommandDispatcher; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.CommandSourceStack; import org.bukkit.Bukkit; import org.bukkit.inventory.Recipe; @@ -75,7 +77,8 @@ public void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -98,7 +101,7 @@ public void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (InterruptedException e) { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17/src/main/java/dev/jorel/commandapi/nms/NMS_1_17.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17/src/main/java/dev/jorel/commandapi/nms/NMS_1_17.java index ef94f4e176..74e479c5bd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17/src/main/java/dev/jorel/commandapi/nms/NMS_1_17.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.17/src/main/java/dev/jorel/commandapi/nms/NMS_1_17.java @@ -28,8 +28,10 @@ import java.util.concurrent.ExecutionException; import com.mojang.brigadier.CommandDispatcher; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.CommandSourceStack; import org.bukkit.Bukkit; import org.bukkit.inventory.Recipe; @@ -75,7 +77,8 @@ public void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -98,7 +101,7 @@ public void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (InterruptedException e) { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java index 5ec15656cb..d1230b70d1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R2.java @@ -292,17 +292,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Differs(from = "1.18", by = "Implement biome argument which contains either a biome or a tag (instead of just a biome)") @Override public Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { @@ -666,7 +655,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -757,7 +746,8 @@ public void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -848,7 +838,7 @@ public void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -876,16 +866,4 @@ public T getMinecraftServer() { return null; } } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java index edc2c0b9cb..30e9b99ea5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.18/src/main/java/dev/jorel/commandapi/nms/NMS_1_18_R1.java @@ -278,17 +278,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); - } - - @Override - public Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { return switch(subType) { @@ -616,7 +605,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -705,7 +694,8 @@ public void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -728,7 +718,7 @@ public void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -756,17 +746,4 @@ public T getMinecraftServer() { return null; } } - - @Override - @Differs(from = "1.17", by = "MinecraftServer#getCommands -> MinecraftServer#aA") - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java index a44a8503fc..d0c33acc7c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common.java @@ -196,63 +196,6 @@ public abstract class NMS_1_19_Common extends NMS_CommonWithFunctions { arg -> net.minecraft.network.chat.Component.translatable("commands.locatebiome.invalid", arg)); } - @Override - public void onEnable() { - super.onEnable(); - - JavaPlugin plugin = getConfiguration().getPlugin(); - // Enable chat preview if the server allows it - if (Bukkit.shouldSendChatPreviews()) { - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - hookChatPreview(plugin, e.getPlayer()); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent e) { - unhookChatPreview(e.getPlayer()); - } - - }, plugin); - CommandAPI.logNormal("Chat preview enabled"); - } else { - CommandAPI.logNormal("Chat preview is not available"); - } - } - - /** - * Hooks into the chat previewing system - * - * @param plugin the plugin (for async calls) - * @param player the player to hook - */ - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) - protected abstract void hookChatPreview(Plugin plugin, Player player); - - /** - * Unhooks a player from the chat previewing system. This should be - * called when the player quits and when the plugin is disabled - * - * @param player the player to unhook - */ - private void unhookChatPreview(Player player) { - final Channel channel = ((CraftPlayer) player).getHandle().connection.connection.channel; - if (channel.pipeline().get("CommandAPI_" + player.getName()) != null) { - channel.eventLoop().submit(() -> channel.pipeline().remove("CommandAPI_" + player.getName())); - } - } - - @Override - public void onDisable() { - super.onDisable(); - - for (Player player : Bukkit.getOnlinePlayers()) { - unhookChatPreview(player); - } - } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } @@ -362,17 +305,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Differs(from = "1.18.2", by = "Biomes now go via the registry. Also have to manually implement ERROR_BIOME_INVALID") @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { @@ -712,7 +644,7 @@ public BukkitCommandSender getSenderForCommand(CommandC if (isNative || (proxy != null && !sender.equals(proxy))) { return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -802,7 +734,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -893,7 +826,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -921,17 +854,4 @@ public T getMinecraftServer() { return null; } } - - @Override - @Differs(from = "1.18", by = "MinecraftServer#aA -> MinecraftServer#aC") - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1.java index d38d68274a..bc8feeb69b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1.java @@ -50,13 +50,4 @@ public String[] compatibleVersions() { return new String[] { "1.19.1", "1.19.2" }; } - @Differs(from = "1.19", by = "Use of 1.19.1 chat preview handler") - @Override - public void hookChatPreview(Plugin plugin, Player player) { - final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; - if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { - playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new NMS_1_19_1_R1_ChatPreviewHandler(this, plugin, player)); - } - } - } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java index 1bdee5aa3e..120686139a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_3_R2.java @@ -272,17 +272,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Differs(from = "1.19.2", by = "Now uses ResourceArgument instead of ResourceOrTagLocationArgument") @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { @@ -600,7 +589,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -696,7 +685,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -787,7 +777,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -825,17 +815,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - @Differs(from = "1.19, 1.19.1, 1.19.2", by = "MinecraftServer#aC -> MinecraftServer#aB") - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java index 288a5d7f6d..66f68c3a22 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_4_R3.java @@ -271,17 +271,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); @@ -595,7 +584,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -686,7 +675,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -777,7 +767,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -815,16 +805,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1.java index b44e796812..01bea2535e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1.java @@ -49,12 +49,4 @@ public String[] compatibleVersions() { return new String[] { "1.19" }; } - @Override - public void hookChatPreview(Plugin plugin, Player player) { - final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; - if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { - playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new NMS_1_19_R1_ChatPreviewHandler(this, plugin, player)); - } - } - } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java index ab5c435600..b7a6cf4611 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java @@ -293,17 +293,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).toBukkit(); } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); @@ -615,7 +604,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -707,7 +696,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -798,7 +788,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -836,16 +826,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java index ba9df06193..2ae73feaa7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java @@ -308,7 +308,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher(), css); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher(), css); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -331,7 +332,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher(), null); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher(), null); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -364,18 +366,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).toBukkit(); } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { @@ -746,7 +736,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -841,7 +831,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -940,7 +930,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -978,16 +968,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java index 9be7ede63f..47620b8bfc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java @@ -63,7 +63,6 @@ import org.bukkit.craftbukkit.v1_20_R4.CraftServer; import org.bukkit.craftbukkit.v1_20_R4.CraftSound; import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R4.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEntity; import org.bukkit.craftbukkit.v1_20_R4.help.CustomHelpTopic; @@ -107,11 +106,6 @@ import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -119,11 +113,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -206,37 +198,23 @@ public class NMS_1_20_R4 extends NMS_Common { private static final Field entitySelectorUsesSelector; // private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; - private static final boolean vanillaCommandDispatcherFieldExists; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final CommandBuildContext commandBuildContext; + + public NMS_1_20_R4(CommandBuildContext commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); - - boolean fieldExists; - try { - MinecraftServer.class.getDeclaredField("vanillaCommandDispatcher"); - fieldExists = true; - } catch (NoSuchFieldException | SecurityException e) { - // Expected on Paper-1.20.6-65 or later due to https://github.com/PaperMC/Paper/pull/8235 - fieldExists = false; - } - vanillaCommandDispatcherFieldExists = fieldExists; } private static NamespacedKey fromResourceLocation(ResourceLocation key) { @@ -245,23 +223,23 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { @Override public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); + return BlockPredicateArgument.blockPredicate(commandBuildContext); } @Override public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); + return BlockStateArgument.block(commandBuildContext); } @Differs(from = "1.20.4", by = "Now needs a command build context") @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT); } @Override @@ -277,22 +255,22 @@ public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { @Override public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); + return ItemPredicateArgument.itemPredicate(commandBuildContext); } @Override public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); + return ItemArgument.item(commandBuildContext); } @Override public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); + return ParticleArgument.particle(commandBuildContext); } @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext, Registries.BIOME); } @Override @@ -305,9 +283,9 @@ public String[] compatibleVersions() { return new String[] { "1.20.5", "1.20.6" }; }; - private static String serializeNMSItemStack(ItemStack is) { + private String serializeNMSItemStack(ItemStack is) { final DataComponentMap patchedMap = PatchedDataComponentMap.fromPatch(PatchedDataComponentMap.EMPTY, is.getComponentsPatch()); - return new ItemInput(is.getItemHolder(), patchedMap).serialize(COMMAND_BUILD_CONTEXT); + return new ItemInput(is.getItemHolder(), patchedMap).serialize(commandBuildContext); } @Differs(from = "1.20.4", by = "Everything") @@ -350,7 +328,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -373,7 +352,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -405,25 +385,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceLocationArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Differs(from = "1.20.4", by = "Serializer.toJson now needs a Provider") - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - // TODO: Figure out if an empty provider is suitable for this context - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) @@ -464,12 +425,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Differs(from = "1.20.4", by = "Serializer.toJson now needs a Provider") - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -818,7 +773,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -909,7 +864,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1007,7 +962,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1024,7 +979,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext); } @SuppressWarnings("unchecked") @@ -1039,39 +994,11 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } + return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java index 4b30a7136b..45ca62b566 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java @@ -153,7 +153,8 @@ public class NMS_1_20_R1 extends NMS_CommonWithFunctions { private static final Field serverFunctionLibraryDispatcher; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + // TODO: Not final so the tests can override the value, is there a better way to do this? + private static CommandBuildContext COMMAND_BUILD_CONTEXT; // Compute all var handles all in one go so we don't do this during main server // runtime @@ -270,17 +271,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); @@ -595,7 +585,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -686,7 +676,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -777,7 +768,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -815,16 +806,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java index 193d7e54a6..b8a6bc0fb2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java @@ -39,6 +39,7 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.CommandAPIBukkit; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -62,7 +63,6 @@ import org.bukkit.craftbukkit.v1_21_R2.CraftServer; import org.bukkit.craftbukkit.v1_21_R2.CraftSound; import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R2.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_21_R2.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_21_R2.help.CustomHelpTopic; @@ -91,10 +91,7 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; @@ -112,11 +109,6 @@ import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -124,11 +116,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -372,7 +362,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -395,7 +386,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -428,23 +420,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) @@ -485,11 +460,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -838,7 +808,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -933,7 +903,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1044,7 +1014,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1083,32 +1053,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java index 39083e3fa5..fe44e7fbf3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java @@ -39,6 +39,7 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.CommandAPIBukkit; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -63,7 +64,6 @@ import org.bukkit.craftbukkit.v1_21_R3.CraftServer; import org.bukkit.craftbukkit.v1_21_R3.CraftSound; import org.bukkit.craftbukkit.v1_21_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R3.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_21_R3.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_21_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_21_R3.help.CustomHelpTopic; @@ -92,10 +92,7 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; @@ -113,11 +110,6 @@ import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -125,11 +117,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -374,7 +364,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -397,7 +388,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -430,23 +422,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) @@ -487,11 +462,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -851,7 +821,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -946,7 +916,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1057,7 +1027,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1096,32 +1066,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java index 40382f44ca..81ad102438 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java @@ -39,6 +39,7 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.CommandAPIBukkit; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -62,7 +63,6 @@ import org.bukkit.craftbukkit.v1_21_R1.CraftServer; import org.bukkit.craftbukkit.v1_21_R1.CraftSound; import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R1.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_21_R1.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_21_R1.help.CustomHelpTopic; @@ -91,10 +91,7 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; @@ -112,11 +109,6 @@ import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -124,11 +116,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -212,18 +202,15 @@ public class NMS_1_21_R1 extends NMS_Common { private static final boolean vanillaCommandDispatcherFieldExists; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final CommandBuildContext commandBuildContext; + + public NMS_1_21_R1(CommandBuildContext commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); @@ -248,22 +235,22 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { @Override public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); + return BlockPredicateArgument.blockPredicate(commandBuildContext); } @Override public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); + return BlockStateArgument.block(commandBuildContext); } @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT); } @Override @@ -279,22 +266,22 @@ public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { @Override public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); + return ItemPredicateArgument.itemPredicate(commandBuildContext); } @Override public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); + return ItemArgument.item(commandBuildContext); } @Override public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); + return ParticleArgument.particle(commandBuildContext); } @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext, Registries.BIOME); } @Override @@ -308,8 +295,8 @@ public String[] compatibleVersions() { }; @Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map") - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext); } @Override @@ -350,7 +337,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -373,7 +361,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -405,24 +394,6 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceLocationArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - // TODO: Figure out if an empty provider is suitable for this context - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) @@ -463,11 +434,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -815,7 +781,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender(sender, proxy, location, world)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -906,8 +872,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1005,7 +970,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1022,7 +987,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext); } @SuppressWarnings("unchecked") @@ -1037,39 +1002,12 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); + return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE); } - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java index 9eec893100..90dda4ffde 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java @@ -88,7 +88,7 @@ * Any of these that do not work should be removed or implemented otherwise * (introducing another NMS_Common module perhaps? */ -public abstract class NMS_Common extends CommandAPIBukkit { +public abstract class NMS_Common extends NMS { private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } @@ -314,18 +314,7 @@ public abstract HelpTopic generateHelpTopic(String commandName, String shortDesc @Override @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.20.2") - public abstract org.bukkit.advancement.Advancement getAdvancement(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - @Override - @Overridden(in = "1.20.5", because = "Serializer.toJson now needs a Provider") - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, from = "ofExact", to = "namedColor", in = "NamedTextColor", introducedIn = "Adventure 4.10.0", info = "1.18 uses Adventure 4.9.3. 1.18.2 uses Adventure 4.11.0") - public abstract NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); + public abstract org.bukkit.advancement.Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; @Override public final float getAngle(CommandContext cmdCtx, String key) { @@ -355,29 +344,13 @@ public abstract Predicate getBlockPredicate(CommandContext cmdCtx, String key); - @Override - @Overridden(in = "1.20.5", because = "Serializer.toJson now needs a Provider") - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public final ChatColor getChatColor(CommandContext cmdCtx, String key) { - return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); - } - - @Override - public final BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public abstract CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender); @Override public final BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { try { - return wrapCommandSender(css.getBukkitSender()); + return CommandAPIBukkit.get().wrapCommandSender(css.getBukkitSender()); } catch (UnsupportedOperationException e) { return null; } @@ -589,10 +562,4 @@ public final UUID getUUID(CommandContext cmdCtx, String key) @Override @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) public abstract void reloadDataPacks(); - - @Override - @Unimplemented(because = NAME_CHANGED, info = "MinecraftServer#getCommands() obfuscated differently across multiple versions") - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "VanillaCommandWrapper") - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "BukkitCommandWrapper") - public abstract CommandRegistrationStrategy createCommandRegistrationStrategy(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java index 75bab19238..a8c1065bb1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java @@ -109,11 +109,6 @@ public ConfigurationAdapter createNew() { return new BukkitConfigurationAdapter(new YamlConfiguration(), configFile); } - @Override - public DefaultBukkitConfig createDefaultConfig() { - return DefaultBukkitConfig.createDefault(); - } - @Override public ConfigurationAdapter loadFromFile() { YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java index fb4a8e4011..7a84a9326a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +@SuppressWarnings("DuplicatedCode") public class DefaultBukkitConfig extends DefaultConfig { public static final CommentedConfigOption USE_LATEST_NMS_VERSION = new CommentedConfigOption<>( @@ -74,7 +75,7 @@ public class DefaultBukkitConfig extends DefaultConfig { private DefaultBukkitConfig() { } - public static DefaultBukkitConfig createDefault() { + public static DefaultBukkitConfig createDefaultPaperConfig() { Map> options = new LinkedHashMap<>(); options.put("verbose-outputs", VERBOSE_OUTPUTS); options.put("silent-logs", SILENT_LOGS); @@ -94,6 +95,25 @@ public static DefaultBukkitConfig createDefault() { return DefaultBukkitConfig.create(options, sections); } + public static DefaultBukkitConfig createDefaultSpigotConfig() { + Map> options = new LinkedHashMap<>(); + options.put("verbose-outputs", VERBOSE_OUTPUTS); + options.put("silent-logs", SILENT_LOGS); + options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION); + options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); + options.put("use-latest-nms-version", USE_LATEST_NMS_VERSION); + options.put("be-lenient-for-minor-versions", BE_LENIENT_FOR_MINOR_VERSIONS); + options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); + options.put("plugins-to-convert", PLUGINS_TO_CONVERT); + options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); + options.put("skip-sender-proxy", SKIP_SENDER_PROXY); + + Map sections = new LinkedHashMap<>(); + sections.put("messages", SECTION_MESSAGE); + + return DefaultBukkitConfig.create(options, sections); + } + public static DefaultBukkitConfig create(Map> options, Map sections) { DefaultBukkitConfig config = new DefaultBukkitConfig(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md deleted file mode 100644 index 9e78f8c114..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-plugin-mojang-mapped diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore deleted file mode 100644 index a87f02033f..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ - -/dependency-reduced-pom.xml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md deleted file mode 100644 index 42aba932e8..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-plugin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore deleted file mode 100644 index a87f02033f..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ - -/dependency-reduced-pom.xml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md deleted file mode 100644 index 0cabf7a945..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-shade diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index 91f202e246..7f35d23681 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -44,7 +44,7 @@ dev.jorel - commandapi-bukkit-core + commandapi-paper-core ${project.version} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java index 0c8e08b948..342a2a86e6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java @@ -9,6 +9,7 @@ import dev.jorel.commandapi.arguments.*; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.nms.NMS; import dev.jorel.commandapi.spying.CommandAPIHandlerSpy; import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.*; @@ -21,6 +22,7 @@ import org.bukkit.advancement.Advancement; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; @@ -45,7 +47,7 @@ * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. */ -public class MockCommandAPIBukkit extends CommandAPIBukkit { +public class MockCommandAPIBukkit extends CommandAPIBukkit implements MockNMS { // Static instance private static MockCommandAPIBukkit instance; @@ -101,6 +103,11 @@ public void onLoad(CommandAPIConfig config) { super.onLoad(config); } + @Override + public void onEnable() { + + } + /** * @return The {@link CommandAPIHandlerSpy} object intercepting calls to {@link CommandAPIHandler} methods. */ @@ -108,6 +115,16 @@ public CommandAPIHandlerSpy getCommandAPIHandlerSpy() { return commandAPIHandlerSpy; } + @Override + public CommandMap getCommandMap() { + return Bukkit.getCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.PAPER; + } + @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { return commandRegistrationStrategy; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java index 1b29fcd14a..d8b99494bb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -15,7 +15,7 @@ public class MockCommandAPIPlugin extends JavaPlugin { // Allow loading with settings, // Default to none if `MockBukkit.load(MockCommandAPIPlugin.class)` is used directly - private static Consumer configureSettings = null; + private static Consumer configureSettings = null; /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. @@ -29,18 +29,18 @@ public static MockCommandAPIPlugin load() { /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. * - * @param configureSettings A {@link Consumer} that can configure the settings of the {@link CommandAPIBukkitConfig} + * @param configureSettings A {@link Consumer} that can configure the settings of the {@link dev.jorel.commandapi.CommandAPIPaperConfig} * before it is used to load the CommandAPI plugin. * @return The {@link MockCommandAPIPlugin} instance that was loaded. */ - public static MockCommandAPIPlugin load(Consumer configureSettings) { + public static MockCommandAPIPlugin load(Consumer configureSettings) { MockCommandAPIPlugin.configureSettings = configureSettings; return MockBukkit.load(MockCommandAPIPlugin.class); } @Override public void onLoad() { - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(this); + CommandAPIPaperConfig config = new CommandAPIPaperConfig(this); if (configureSettings != null) { configureSettings.accept(config); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java new file mode 100644 index 0000000000..a0db0b9f78 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java @@ -0,0 +1,422 @@ +package dev.jorel.commandapi; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import dev.jorel.commandapi.arguments.ArgumentSubType; +import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Axis; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.function.Function; +import java.util.function.Predicate; + +public interface MockNMS { + + /** + * @return Advancement argument (api:advancement) + */ + ArgumentType _ArgumentAdvancement(); + + /** + * @return Angle argument (minecraft:angle) + */ + ArgumentType _ArgumentAngle(); + + /** + * @return Axis argument (minecraft:swizzle) + */ + ArgumentType _ArgumentAxis(); + + /** + * @return Block predicate argument (minecraft:block_predicate) + */ + ArgumentType _ArgumentBlockPredicate(); + + /** + * @return Block state argument (minecraft:block_state) + */ + ArgumentType _ArgumentBlockState(); + + /** + * @return Chat argument (minecraft:message) + */ + ArgumentType _ArgumentChat(); + + /** + * @return Chat component argument (minecraft:component) + */ + ArgumentType _ArgumentChatComponent(); + + /** + * @return Chat color argument (minecraft:color) + */ + ArgumentType _ArgumentChatFormat(); + + /** + * @return Dimension argument (minecraft:dimension) + */ + ArgumentType _ArgumentDimension(); + + /** + * @return Enchantment argument (minecraft:item_enchantment) + */ + ArgumentType _ArgumentEnchantment(); + + /** + * @param subType one of {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_ENTITIES}, + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_PLAYERS}, + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_ENTITY} or + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_PLAYER} + * @return Entity selector argument (minecraft:entity) + */ + ArgumentType _ArgumentEntity(ArgumentSubType subType); + + /** + * @return Entity type argument (minecraft:entity_summon) + */ + ArgumentType _ArgumentEntitySummon(); + + /** + * @return Float range argument (minecraft:float_range) + */ + ArgumentType _ArgumentFloatRange(); + + /** + * @return Int range argument (minecraft:int_range) + */ + ArgumentType _ArgumentIntRange(); + + /** + * @return Item predicate argument (minecraft:item_predicate) + */ + ArgumentType _ArgumentItemPredicate(); + + /** + * @return Itemstack argument (minecraft:item_stack) + */ + ArgumentType _ArgumentItemStack(); + + /** + * @return Math operation argument (minecraft:operation) + */ + ArgumentType _ArgumentMathOperation(); + + /** + * @return Minecraft key argument (minecraft:resource_location) + */ + ArgumentType _ArgumentMinecraftKeyRegistered(); + + /** + * @return Potion effect argument (minecraft:mob_effect) + */ + ArgumentType _ArgumentMobEffect(); + + /** + * @return NBT compound tag argument (minecraft:nbt_compound_tag) + */ + ArgumentType _ArgumentNBTCompound(); + + /** + * @return Particle argument (minecraft:particle) + */ + ArgumentType _ArgumentParticle(); + + /** + * @return Position argument (minecraft:block_pos) + */ + ArgumentType _ArgumentPosition(); + + /** + * @return 2D position (column) argument (minecraft:column_pos) + */ + ArgumentType _ArgumentPosition2D(); + + /** + * @return Player argument (minecraft:game_profile) + */ + ArgumentType _ArgumentProfile(); + + /** + * @return Recipe argument (api:recipe) + */ + ArgumentType _ArgumentRecipe(); + + /** + * @return Rotation argument (minecraft:rotation) + */ + ArgumentType _ArgumentRotation(); + + /** + * @return Scoreboard objective criteria argument (minecraft:objective_criteria) + */ + ArgumentType _ArgumentScoreboardCriteria(); + + /** + * @return Scoreboard objective argument (minecraft:objective) + */ + ArgumentType _ArgumentScoreboardObjective(); + + /** + * @return Scoreboard slot argument (minecraft:scoreboard_slot) + */ + ArgumentType _ArgumentScoreboardSlot(); + + /** + * @return Scoreboard team argument (minecraft:team) + */ + ArgumentType _ArgumentScoreboardTeam(); + + /** + * @param subType one of {@link ArgumentSubType#SCOREHOLDER_MULTIPLE} or + * {@link ArgumentSubType#SCOREHOLDER_SINGLE} + * @return Scoreholder argument (minecraft:score_holder) + */ + ArgumentType _ArgumentScoreholder(ArgumentSubType subType); + + /** + * @return Function argument (minecraft:function) + */ + ArgumentType _ArgumentTag(); + + /** + * @return Time argument (minecraft:time) + */ + ArgumentType _ArgumentTime(); + + /** + * @return UUID argument (minecraft:uuid) + */ + ArgumentType _ArgumentUUID(); + + /** + * @return Location 2D argument (precise position) (minecraft:vec2) + */ + ArgumentType _ArgumentVec2(boolean centerPosition); + + /** + * @return Location argument (precise position) (minecraft:vec3) + */ + ArgumentType _ArgumentVec3(boolean centerPosition); + + /* + * Synthetic arguments - arguments that don't actually exist, but have + * version-specific implementations, so we can switch their implementation as + * needed. For example, the BiomeArgument is both a + * _ArgumentMinecraftKeyRegistered and a _ArgumentResourceOrTag, but we'll refer + * to it as an _ArgumentSyntheticBiome + */ + + ArgumentType _ArgumentSyntheticBiome(); + + /** + * A String array of Minecraft versions that this NMS implementation is + * compatible with. For example, ["1.14", "1.14.1", "1.14.2", "1.14.3"]. This + * can be found by opening a Minecraft jar file, viewing the version.json file + * and reading the object "name". + * + * @return A String array of compatible Minecraft versions + */ + String[] compatibleVersions(); + + String convert(ItemStack is); + + String convert(ParticleData particle); + + String convert(PotionEffectType potion); + + String convert(Sound sound); + + Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); + + Component getAdventureChatComponent(CommandContext cmdCtx, String key); + + float getAngle(CommandContext cmdCtx, String key); + + EnumSet getAxis(CommandContext cmdCtx, String key); + + Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; + + Predicate getBlockPredicate(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + BlockData getBlockState(CommandContext cmdCtx, String key); + + BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + ChatColor getChatColor(CommandContext cmdCtx, String key); + + BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); + + World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 + + Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) + throws CommandSyntaxException; + + EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + FloatRange getFloatRange(CommandContext cmdCtx, String key); + + FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + SimpleFunctionWrapper getFunction(NamespacedKey key); + + Set getFunctions(); + + IntegerRange getIntRange(CommandContext cmdCtx, String key); + + ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Predicate getItemStackPredicate(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location2D getLocation2DBlock(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; + + Location getLocationPrecise(CommandContext cmdCtx, String str) + throws CommandSyntaxException; + + LootTable getLootTable(CommandContext cmdCtx, String key); + + MathOperation getMathOperation(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key); + + Object getNBTCompound(CommandContext cmdCtx, String key, + Function nbtContainerConstructor); + + Objective getObjective(CommandContext cmdCtx, String key) + throws IllegalArgumentException, CommandSyntaxException; + + String getObjectiveCriteria(CommandContext cmdCtx, String key); + + ParticleData getParticle(CommandContext cmdCtx, String key); + + Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) + throws CommandSyntaxException; + + Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Rotation getRotation(CommandContext cmdCtx, String key); + + ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); + + Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + String getScoreHolderSingle(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + int getTime(CommandContext cmdCtx, String key); + + UUID getUUID(CommandContext cmdCtx, String key); + + World getWorldForCSS(CommandSource clw); + + /** + * Returns the Server's internal (OBC) CommandMap + * + * @return A SimpleCommandMap from the OBC server + */ + SimpleCommandMap getSimpleCommandMap(); + + Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); + + /** + * Retrieve a specific NMS implemented SuggestionProvider + * + * @param provider The SuggestionProvider type to retrieve + * @return A SuggestionProvider that matches the SuggestionProviders input + */ + SuggestionProvider getSuggestionProvider(SuggestionProviders provider); + + SimpleFunctionWrapper[] getTag(NamespacedKey key); + + Set getTags(); + + /** + * Reloads the datapacks by using the updated the commandDispatcher tree + */ + void reloadDataPacks(); + + HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission); + + Map getHelpMap(); + + Message generateMessageFromJson(String json); + + BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + + BukkitCommandSender getCommandSenderFromCommandSource(CommandSource css); + + CommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender); + + void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; + + T getMinecraftServer(); + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/pom.xml index 96dfe6f1bc..e22a3b9a83 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/pom.xml @@ -93,11 +93,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/pom.xml index 1a11114dff..44cee7596f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/pom.xml @@ -94,11 +94,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/pom.xml index 1d36ef1fd5..5b56f39bc9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/pom.xml @@ -95,11 +95,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/pom.xml index 172e4a8014..7bea7c08b9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/pom.xml @@ -94,11 +94,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/pom.xml index f817dc3e9f..8d07555d74 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/pom.xml @@ -95,11 +95,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml index 9f42109eef..aac88ac5b4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml @@ -95,11 +95,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 0ccfd6003d..8d1e6d2b3e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -306,7 +306,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); } @@ -603,7 +603,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml index 3931f82d0c..e21d6a97ab 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml @@ -95,11 +95,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 3d77a346ad..ec48be01b3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -315,7 +315,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getScoreboardName()).thenReturn(name); // ScoreHolderArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); @@ -616,7 +616,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml index 6980675b46..6151c1b063 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml @@ -95,11 +95,6 @@ commandapi-bukkit-test-impl ${project.version} - - dev.jorel - commandapi-bukkit-shade - ${project.version} - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 266ce4a17f..bf7cc46af5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -334,7 +334,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getScoreboardName()).thenReturn(name); // ScoreHolderArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); @@ -420,7 +420,7 @@ public String getNMSParticleNameFromBukkit(Particle particle) { // return BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.bukkitToMinecraft(particle)).toString(); // return particle.getKey().toString(); - Map particleMap = Map.ofEntries( + Map particleMap = Map.ofEntries( Map.entry(Particle.valueOf("EXPLOSION_NORMAL"), "poof"), Map.entry(Particle.valueOf("EXPLOSION_LARGE"), "explosion"), Map.entry(Particle.valueOf("EXPLOSION_HUGE"), "explosion_emitter"), @@ -745,7 +745,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml index 72e6fa6caa..003ec90f05 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml @@ -95,13 +95,15 @@ commandapi-bukkit-test-impl ${project.version} + + dev.jorel - commandapi-bukkit-shade + commandapi-bukkit-1.20 ${project.version} + mojang-mapped + provided - - org.spigotmc spigot @@ -119,6 +121,18 @@ paper-api ${paper.version} --> + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + mojang-mapped + provided + diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/ArgumentNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/ArgumentNMS.java deleted file mode 100644 index c4a080131c..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/ArgumentNMS.java +++ /dev/null @@ -1,598 +0,0 @@ -package dev.jorel.commandapi.test; - -import static org.mockito.ArgumentMatchers.any; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.function.Function; -import java.util.function.Predicate; - -import org.bukkit.Axis; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; -import org.mockito.Mockito; - -import com.mojang.brigadier.Message; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; - -import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.arguments.ArgumentSubType; -import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.wrappers.FloatRange; -import dev.jorel.commandapi.wrappers.FunctionWrapper; -import dev.jorel.commandapi.wrappers.IntegerRange; -import dev.jorel.commandapi.wrappers.Location2D; -import dev.jorel.commandapi.wrappers.MathOperation; -import dev.jorel.commandapi.wrappers.ParticleData; -import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.ScoreboardSlot; -import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ParticleArgument; -import net.minecraft.commands.arguments.ResourceArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderLookup; -import net.minecraft.core.HolderOwner; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; - -/** - * Argument related method implementations - */ -@SuppressWarnings({ "unchecked", "rawtypes" }) -public abstract class ArgumentNMS extends MockPlatform { - - CommandAPIBukkit baseNMS; - - protected ArgumentNMS(CommandAPIBukkit baseNMS) { - this.baseNMS = (CommandAPIBukkit) baseNMS; - } - - @Override - public ArgumentType _ArgumentAdvancement() { - return baseNMS._ArgumentAdvancement(); - } - - @Override - public ArgumentType _ArgumentAngle() { - return baseNMS._ArgumentAngle(); - } - - @Override - public ArgumentType _ArgumentAxis() { - return baseNMS._ArgumentAxis(); - } - - @Override - public final ArgumentType _ArgumentBlockPredicate() { - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.BLOCK.asLookup()); // Registry.BLOCK - return BlockPredicateArgument.blockPredicate(buildContextMock); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.BLOCK.asLookup()); // Registry.BLOCK - return BlockStateArgument.block(buildContextMock); - } - - @Override - public ArgumentType _ArgumentChat() { - return baseNMS._ArgumentChat(); - } - - @Override - public ArgumentType _ArgumentChatComponent() { - return baseNMS._ArgumentChatComponent(); - } - - @Override - public ArgumentType _ArgumentChatFormat() { - return baseNMS._ArgumentChatFormat(); - } - - @Override - public ArgumentType _ArgumentDimension() { - return baseNMS._ArgumentDimension(); - } - - @Override - public ArgumentType _ArgumentEnchantment() { - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.ENCHANTMENT.asLookup()); // Registry.ENCHANTMENT - return ResourceArgument.resource(buildContextMock, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return baseNMS._ArgumentEntity(subType); - } - - @Override - public ArgumentType _ArgumentEntitySummon() { - // We can't use BASE_NMS for this, because that requires a - // COMMAND_BUILD_CONTEXT. The COMMAND_BUILD_CONTEXT is only defined for - // CraftServer instances, otherwise it'll return null. - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.ENTITY_TYPE.asLookup()); // Registry.ENTITY_TYPE - return ResourceArgument.resource(buildContextMock, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType _ArgumentFloatRange() { - return baseNMS._ArgumentFloatRange(); - } - - @Override - public ArgumentType _ArgumentIntRange() { - return baseNMS._ArgumentIntRange(); - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.ITEM.asLookup()); // Registry.ITEM - return ItemPredicateArgument.itemPredicate(buildContextMock); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - // We can't use BASE_NMS for this, because that requires a - // COMMAND_BUILD_CONTEXT. - // The COMMAND_BUILD_CONTEXT is only defined for CraftServer instances, - // otherwise - // it'll return null. - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.ITEM.asLookup()); // Registry.ITEM - return ItemArgument.item(buildContextMock); - } - - @Override - public ArgumentType _ArgumentMathOperation() { - return baseNMS._ArgumentMathOperation(); - } - - @Override - public ArgumentType _ArgumentMinecraftKeyRegistered() { - return baseNMS._ArgumentMinecraftKeyRegistered(); - } - - @Override - public ArgumentType _ArgumentMobEffect() { - // We can't use BASE_NMS for this, because that requires a - // COMMAND_BUILD_CONTEXT. The COMMAND_BUILD_CONTEXT is only defined for - // CraftServer instances, otherwise it'll return null. - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.MOB_EFFECT.asLookup()); // Registry.MOB_EFFECT - return ResourceArgument.resource(buildContextMock, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType _ArgumentNBTCompound() { - return baseNMS._ArgumentNBTCompound(); - } - - @Override - public ArgumentType _ArgumentParticle() { - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenReturn(BuiltInRegistries.PARTICLE_TYPE.asLookup()); // Registry.PARTICLE_TYPE - return ParticleArgument.particle(buildContextMock); - } - - @Override - public ArgumentType _ArgumentPosition() { - return baseNMS._ArgumentPosition(); - } - - @Override - public ArgumentType _ArgumentPosition2D() { - return baseNMS._ArgumentPosition2D(); - } - - @Override - public ArgumentType _ArgumentProfile() { - return baseNMS._ArgumentProfile(); - } - - @Override - public ArgumentType _ArgumentRecipe() { - return baseNMS._ArgumentRecipe(); - } - - @Override - public ArgumentType _ArgumentRotation() { - return baseNMS._ArgumentRotation(); - } - - @Override - public ArgumentType _ArgumentScoreboardCriteria() { - return baseNMS._ArgumentScoreboardCriteria(); - } - - @Override - public ArgumentType _ArgumentScoreboardObjective() { - return baseNMS._ArgumentScoreboardObjective(); - } - - @Override - public ArgumentType _ArgumentScoreboardSlot() { - return baseNMS._ArgumentScoreboardSlot(); - } - - @Override - public ArgumentType _ArgumentScoreboardTeam() { - return baseNMS._ArgumentScoreboardTeam(); - } - - @Override - public ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { - return baseNMS._ArgumentScoreholder(subType); - } - - @Override - public final ArgumentType _ArgumentSyntheticBiome() { - // Unpack Biomes.class -// Set> biomes = new HashSet<>(); -// for(Field f : Biomes.class.getDeclaredFields()) { -// try { -// biomes.add((ResourceKey) f.get(null)); -// } catch (IllegalArgumentException | IllegalAccessException e) { -// e.printStackTrace(); -// } -// } - - CommandBuildContext buildContextMock = Mockito.mock(CommandBuildContext.class); - Mockito - .when(buildContextMock.holderLookup(any(ResourceKey.class))) - .thenAnswer(invocation -> { - HolderLookup hl = Mockito.mock(HolderLookup.class); - Mockito.when(hl.get((ResourceKey)any())).thenAnswer(i -> { - ResourceKey rk = i.getArgument(0, ResourceKey.class); -// if(biomes.contains(rk)) { -// return Optional.of(Holder.Reference.createStandAlone(new HolderOwner() { }, rk)); -// } else { -// return Optional.empty(); -// } - // We'll return the thing anyway. Bukkit will handle if the thing exists or not... - return Optional.of(Holder.Reference.createStandAlone(new HolderOwner() { }, rk)); - }); - return hl; - }); - return ResourceArgument.resource(buildContextMock, Registries.BIOME); - } - - @Override - public ArgumentType _ArgumentTag() { - return baseNMS._ArgumentTag(); - } - - @Override - public ArgumentType _ArgumentTime() { - return baseNMS._ArgumentTime(); - } - - @Override - public ArgumentType _ArgumentUUID() { - return baseNMS._ArgumentUUID(); - } - - @Override - public ArgumentType _ArgumentVec2(boolean centerPosition) { - return baseNMS._ArgumentVec2(centerPosition); - } - - @Override - public ArgumentType _ArgumentVec3(boolean centerPosition) { - return baseNMS._ArgumentVec3(centerPosition); - } - - @Override - public Message generateMessageFromJson(final String json) { - return baseNMS.generateMessageFromJson(json); - } - - @Override - public org.bukkit.advancement.Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getAdvancement(cmdCtx, key); - } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getAdventureChat(cmdCtx, key); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - return baseNMS.getAdventureChatColor(cmdCtx, key); - } - - @Override - public Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return baseNMS.getAdventureChatComponent(cmdCtx, key); - } - - @Override - public float getAngle(CommandContext cmdCtx, String key) { - return baseNMS.getAngle(cmdCtx, key); - } - - @Override - public EnumSet getAxis(CommandContext cmdCtx, String key) { - return baseNMS.getAxis(cmdCtx, key); - } - - @Override - public Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return baseNMS.getBiome(cmdCtx, key, subType); - } - - @Override - public Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getBlockPredicate(cmdCtx, key); - } - - @Override - public BlockData getBlockState(CommandContext cmdCtx, String key) { - return baseNMS.getBlockState(cmdCtx, key); - } - - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getChat(cmdCtx, key); - } - - @Override - public ChatColor getChatColor(CommandContext cmdCtx, String key) { - return baseNMS.getChatColor(cmdCtx, key); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { - return baseNMS.getChatComponent(cmdCtx, key); - } - - @Override - public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getDimension(cmdCtx, key); - } - - @Override - public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getEnchantment(cmdCtx, key); - } - - @Override - public Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { - return baseNMS.getEntitySelector(cmdCtx, key, subType, allowEmpty); - } - - @Override - public EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getEntityType(cmdCtx, key); - } - - @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { - return baseNMS.getFloatRange(cmdCtx, key); - } - - @Override - public FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getFunction(cmdCtx, key); - } - - @Override - public SimpleFunctionWrapper getFunction(NamespacedKey key) { - return baseNMS.getFunction(key); - } - - @Override - public Set getFunctions() { - return baseNMS.getFunctions(); - } - - @Override - public IntegerRange getIntRange(CommandContext cmdCtx, String key) { - return baseNMS.getIntRange(cmdCtx, key); - } - - @Override - public ItemStack getItemStack(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getItemStack(cmdCtx, key); - } - - @Override - public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return baseNMS.getItemStackPredicate(cmdCtx, key); - } - - @Override - public Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getLocation2DBlock(cmdCtx, key); - } - - @Override - public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getLocation2DPrecise(cmdCtx, key); - } - - @Override - public Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException { - return baseNMS.getLocationBlock(cmdCtx, str); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException { - return baseNMS.getLocationPrecise(cmdCtx, str); - } - - @Override - public LootTable getLootTable(CommandContext cmdCtx, String key) { - return baseNMS.getLootTable(cmdCtx, key); - } - - @Override - public MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getMathOperation(cmdCtx, key); - } - - @Override - public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { - return baseNMS.getMinecraftKey(cmdCtx, key); - } - - @Override - public Object getNBTCompound(CommandContext cmdCtx, String key, - Function nbtContainerConstructor) { - return baseNMS.getNBTCompound((CommandContext) cmdCtx, key, nbtContainerConstructor); - } - - @Override - public Objective getObjective(CommandContext cmdCtx, String key) - throws IllegalArgumentException, CommandSyntaxException { - return baseNMS.getObjective(cmdCtx, key); - } - - @Override - public String getObjectiveCriteria(CommandContext cmdCtx, String key) { - return baseNMS.getObjectiveCriteria(cmdCtx, key); - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getOfflinePlayer(cmdCtx, key); - } - - @Override - public ParticleData getParticle(CommandContext cmdCtx, String key) { - return baseNMS.getParticle(cmdCtx, key); - } - - @Override - public Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getPlayer(cmdCtx, key); - } - - @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - return baseNMS.getPotionEffect(cmdCtx, key, subType); - } - - @Override - public Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getRecipe(cmdCtx, key); - } - - @Override - public Rotation getRotation(CommandContext cmdCtx, String key) { - return baseNMS.getRotation(cmdCtx, key); - } - - @Override - public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { - return baseNMS.getScoreboardSlot(cmdCtx, key); - } - - @Override - public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getScoreHolderMultiple(cmdCtx, key); - } - - @Override - public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getScoreHolderSingle(cmdCtx, key); - } - - @Override - public Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { - return baseNMS.getSound(cmdCtx, key, subType); - } - - @Override - public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { - if(provider == SuggestionProviders.BIOMES) { - return _ArgumentSyntheticBiome()::listSuggestions; - } else { - return baseNMS.getSuggestionProvider(provider); - } - } - - @Override - public SimpleFunctionWrapper[] getTag(NamespacedKey key) { - return baseNMS.getTag(key); - } - - @Override - public Set getTags() { - return baseNMS.getTags(); - } - - @Override - public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return baseNMS.getTeam(cmdCtx, key); - } - - @Override - public int getTime(CommandContext cmdCtx, String key) { - return baseNMS.getTime(cmdCtx, key); - } - - @Override - public UUID getUUID(CommandContext cmdCtx, String key) { - return baseNMS.getUUID(cmdCtx, key); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums_1_20.java similarity index 88% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums_1_20.java index 353835341a..ba3f196119 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/Enums_1_20.java @@ -4,18 +4,12 @@ import org.bukkit.block.Biome; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; +import org.bukkit.loot.LootTables; import org.bukkit.potion.PotionEffectType; -import dev.jorel.commandapi.CommandAPIBukkit; - -public abstract class Enums extends ArgumentNMS { - - protected Enums(CommandAPIBukkit baseNMS) { - super(baseNMS); - } - +public interface Enums_1_20 extends Enums { @Override - public final Enchantment[] getEnchantments() { + default Enchantment[] getEnchantments() { return new Enchantment[] { Enchantment.PROTECTION_ENVIRONMENTAL, Enchantment.PROTECTION_FIRE, @@ -60,7 +54,7 @@ public final Enchantment[] getEnchantments() { } @Override - public final EntityType[] getEntityTypes() { + default EntityType[] getEntityTypes() { return new EntityType[] { EntityType.DROPPED_ITEM, EntityType.EXPERIENCE_ORB, @@ -191,174 +185,174 @@ public final EntityType[] getEntityTypes() { } @Override - public final org.bukkit.loot.LootTables[] getLootTables() { - return new org.bukkit.loot.LootTables[] { - // org.bukkit.loot.LootTables.EMPTY, - org.bukkit.loot.LootTables.ABANDONED_MINESHAFT, - org.bukkit.loot.LootTables.BURIED_TREASURE, - org.bukkit.loot.LootTables.DESERT_PYRAMID, - org.bukkit.loot.LootTables.END_CITY_TREASURE, - org.bukkit.loot.LootTables.IGLOO_CHEST, - org.bukkit.loot.LootTables.JUNGLE_TEMPLE, - org.bukkit.loot.LootTables.JUNGLE_TEMPLE_DISPENSER, - org.bukkit.loot.LootTables.NETHER_BRIDGE, - org.bukkit.loot.LootTables.PILLAGER_OUTPOST, - org.bukkit.loot.LootTables.BASTION_TREASURE, - org.bukkit.loot.LootTables.BASTION_OTHER, - org.bukkit.loot.LootTables.BASTION_BRIDGE, - org.bukkit.loot.LootTables.BASTION_HOGLIN_STABLE, - org.bukkit.loot.LootTables.ANCIENT_CITY, - org.bukkit.loot.LootTables.ANCIENT_CITY_ICE_BOX, - org.bukkit.loot.LootTables.RUINED_PORTAL, - org.bukkit.loot.LootTables.SHIPWRECK_MAP, - org.bukkit.loot.LootTables.SHIPWRECK_SUPPLY, - org.bukkit.loot.LootTables.SHIPWRECK_TREASURE, - org.bukkit.loot.LootTables.SIMPLE_DUNGEON, - org.bukkit.loot.LootTables.SPAWN_BONUS_CHEST, - org.bukkit.loot.LootTables.STRONGHOLD_CORRIDOR, - org.bukkit.loot.LootTables.STRONGHOLD_CROSSING, - org.bukkit.loot.LootTables.STRONGHOLD_LIBRARY, - org.bukkit.loot.LootTables.UNDERWATER_RUIN_BIG, - org.bukkit.loot.LootTables.UNDERWATER_RUIN_SMALL, - org.bukkit.loot.LootTables.VILLAGE_ARMORER, - org.bukkit.loot.LootTables.VILLAGE_BUTCHER, - org.bukkit.loot.LootTables.VILLAGE_CARTOGRAPHER, - org.bukkit.loot.LootTables.VILLAGE_DESERT_HOUSE, - org.bukkit.loot.LootTables.VILLAGE_FISHER, - org.bukkit.loot.LootTables.VILLAGE_FLETCHER, - org.bukkit.loot.LootTables.VILLAGE_MASON, - org.bukkit.loot.LootTables.VILLAGE_PLAINS_HOUSE, - org.bukkit.loot.LootTables.VILLAGE_SAVANNA_HOUSE, - org.bukkit.loot.LootTables.VILLAGE_SHEPHERD, - org.bukkit.loot.LootTables.VILLAGE_SNOWY_HOUSE, - org.bukkit.loot.LootTables.VILLAGE_TAIGA_HOUSE, - org.bukkit.loot.LootTables.VILLAGE_TANNERY, - org.bukkit.loot.LootTables.VILLAGE_TEMPLE, - org.bukkit.loot.LootTables.VILLAGE_TOOLSMITH, - org.bukkit.loot.LootTables.VILLAGE_WEAPONSMITH, - org.bukkit.loot.LootTables.WOODLAND_MANSION, - org.bukkit.loot.LootTables.ARMOR_STAND, - org.bukkit.loot.LootTables.AXOLOTL, - org.bukkit.loot.LootTables.BAT, - org.bukkit.loot.LootTables.BEE, - org.bukkit.loot.LootTables.BLAZE, - org.bukkit.loot.LootTables.CAT, - org.bukkit.loot.LootTables.CAVE_SPIDER, - org.bukkit.loot.LootTables.CHICKEN, - org.bukkit.loot.LootTables.COD, - org.bukkit.loot.LootTables.COW, - org.bukkit.loot.LootTables.CREEPER, - org.bukkit.loot.LootTables.DOLPHIN, - org.bukkit.loot.LootTables.DONKEY, - org.bukkit.loot.LootTables.DROWNED, - org.bukkit.loot.LootTables.ELDER_GUARDIAN, - org.bukkit.loot.LootTables.ENDER_DRAGON, - org.bukkit.loot.LootTables.ENDERMAN, - org.bukkit.loot.LootTables.ENDERMITE, - org.bukkit.loot.LootTables.EVOKER, - org.bukkit.loot.LootTables.FOX, - org.bukkit.loot.LootTables.GHAST, - org.bukkit.loot.LootTables.GIANT, - org.bukkit.loot.LootTables.GLOW_SQUID, - org.bukkit.loot.LootTables.GOAT, - org.bukkit.loot.LootTables.GUARDIAN, - org.bukkit.loot.LootTables.HOGLIN, - org.bukkit.loot.LootTables.HORSE, - org.bukkit.loot.LootTables.HUSK, - org.bukkit.loot.LootTables.ILLUSIONER, - org.bukkit.loot.LootTables.IRON_GOLEM, - org.bukkit.loot.LootTables.LLAMA, - org.bukkit.loot.LootTables.MAGMA_CUBE, - org.bukkit.loot.LootTables.MOOSHROOM, - org.bukkit.loot.LootTables.MULE, - org.bukkit.loot.LootTables.OCELOT, - org.bukkit.loot.LootTables.PANDA, - org.bukkit.loot.LootTables.PARROT, - org.bukkit.loot.LootTables.PHANTOM, - org.bukkit.loot.LootTables.PIG, - org.bukkit.loot.LootTables.PIGLIN, - org.bukkit.loot.LootTables.PIGLIN_BRUTE, - org.bukkit.loot.LootTables.PILLAGER, - org.bukkit.loot.LootTables.PLAYER, - org.bukkit.loot.LootTables.POLAR_BEAR, - org.bukkit.loot.LootTables.PUFFERFISH, - org.bukkit.loot.LootTables.RABBIT, - org.bukkit.loot.LootTables.RAVAGER, - org.bukkit.loot.LootTables.SALMON, - org.bukkit.loot.LootTables.SHULKER, - org.bukkit.loot.LootTables.SILVERFISH, - org.bukkit.loot.LootTables.SKELETON, - org.bukkit.loot.LootTables.SKELETON_HORSE, - org.bukkit.loot.LootTables.SLIME, - org.bukkit.loot.LootTables.SNOW_GOLEM, - org.bukkit.loot.LootTables.SPIDER, - org.bukkit.loot.LootTables.SQUID, - org.bukkit.loot.LootTables.STRAY, - org.bukkit.loot.LootTables.STRIDER, - org.bukkit.loot.LootTables.TRADER_LLAMA, - org.bukkit.loot.LootTables.TROPICAL_FISH, - org.bukkit.loot.LootTables.TURTLE, - org.bukkit.loot.LootTables.VEX, - org.bukkit.loot.LootTables.VILLAGER, - org.bukkit.loot.LootTables.VINDICATOR, - org.bukkit.loot.LootTables.WANDERING_TRADER, - org.bukkit.loot.LootTables.WITCH, - org.bukkit.loot.LootTables.WITHER, - org.bukkit.loot.LootTables.WITHER_SKELETON, - org.bukkit.loot.LootTables.WOLF, - org.bukkit.loot.LootTables.ZOGLIN, - org.bukkit.loot.LootTables.ZOMBIE, - org.bukkit.loot.LootTables.ZOMBIE_HORSE, - org.bukkit.loot.LootTables.ZOMBIE_VILLAGER, - org.bukkit.loot.LootTables.ZOMBIFIED_PIGLIN, - org.bukkit.loot.LootTables.ARMORER_GIFT, - org.bukkit.loot.LootTables.BUTCHER_GIFT, - org.bukkit.loot.LootTables.CARTOGRAPHER_GIFT, - org.bukkit.loot.LootTables.CAT_MORNING_GIFT, - org.bukkit.loot.LootTables.CLERIC_GIFT, - org.bukkit.loot.LootTables.FARMER_GIFT, - org.bukkit.loot.LootTables.FISHERMAN_GIFT, - org.bukkit.loot.LootTables.FISHING, - org.bukkit.loot.LootTables.FISHING_FISH, - org.bukkit.loot.LootTables.FISHING_JUNK, - org.bukkit.loot.LootTables.FISHING_TREASURE, - org.bukkit.loot.LootTables.FLETCHER_GIFT, - org.bukkit.loot.LootTables.LEATHERWORKER_GIFT, - org.bukkit.loot.LootTables.LIBRARIAN_GIFT, - org.bukkit.loot.LootTables.MASON_GIFT, - org.bukkit.loot.LootTables.SHEPHERD_GIFT, - org.bukkit.loot.LootTables.TOOLSMITH_GIFT, - org.bukkit.loot.LootTables.WEAPONSMITH_GIFT, - org.bukkit.loot.LootTables.SNIFFER_DIGGING, - org.bukkit.loot.LootTables.PIGLIN_BARTERING, - org.bukkit.loot.LootTables.DESERT_WELL_ARCHAEOLOGY, - org.bukkit.loot.LootTables.DESERT_PYRAMID_ARCHAEOLOGY, - org.bukkit.loot.LootTables.TRAIL_RUINS_ARCHAEOLOGY_COMMON, - org.bukkit.loot.LootTables.TRAIL_RUINS_ARCHAEOLOGY_RARE, - org.bukkit.loot.LootTables.OCEAN_RUIN_WARM_ARCHAEOLOGY, - org.bukkit.loot.LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY, - org.bukkit.loot.LootTables.SHEEP, - org.bukkit.loot.LootTables.SHEEP_BLACK, - org.bukkit.loot.LootTables.SHEEP_BLUE, - org.bukkit.loot.LootTables.SHEEP_BROWN, - org.bukkit.loot.LootTables.SHEEP_CYAN, - org.bukkit.loot.LootTables.SHEEP_GRAY, - org.bukkit.loot.LootTables.SHEEP_GREEN, - org.bukkit.loot.LootTables.SHEEP_LIGHT_BLUE, - org.bukkit.loot.LootTables.SHEEP_LIGHT_GRAY, - org.bukkit.loot.LootTables.SHEEP_LIME, - org.bukkit.loot.LootTables.SHEEP_MAGENTA, - org.bukkit.loot.LootTables.SHEEP_ORANGE, - org.bukkit.loot.LootTables.SHEEP_PINK, - org.bukkit.loot.LootTables.SHEEP_PURPLE, - org.bukkit.loot.LootTables.SHEEP_RED, - org.bukkit.loot.LootTables.SHEEP_WHITE, - org.bukkit.loot.LootTables.SHEEP_YELLOW, + default LootTables[] getLootTables() { + return new LootTables[] { + // LootTables.EMPTY, + LootTables.ABANDONED_MINESHAFT, + LootTables.BURIED_TREASURE, + LootTables.DESERT_PYRAMID, + LootTables.END_CITY_TREASURE, + LootTables.IGLOO_CHEST, + LootTables.JUNGLE_TEMPLE, + LootTables.JUNGLE_TEMPLE_DISPENSER, + LootTables.NETHER_BRIDGE, + LootTables.PILLAGER_OUTPOST, + LootTables.BASTION_TREASURE, + LootTables.BASTION_OTHER, + LootTables.BASTION_BRIDGE, + LootTables.BASTION_HOGLIN_STABLE, + LootTables.ANCIENT_CITY, + LootTables.ANCIENT_CITY_ICE_BOX, + LootTables.RUINED_PORTAL, + LootTables.SHIPWRECK_MAP, + LootTables.SHIPWRECK_SUPPLY, + LootTables.SHIPWRECK_TREASURE, + LootTables.SIMPLE_DUNGEON, + LootTables.SPAWN_BONUS_CHEST, + LootTables.STRONGHOLD_CORRIDOR, + LootTables.STRONGHOLD_CROSSING, + LootTables.STRONGHOLD_LIBRARY, + LootTables.UNDERWATER_RUIN_BIG, + LootTables.UNDERWATER_RUIN_SMALL, + LootTables.VILLAGE_ARMORER, + LootTables.VILLAGE_BUTCHER, + LootTables.VILLAGE_CARTOGRAPHER, + LootTables.VILLAGE_DESERT_HOUSE, + LootTables.VILLAGE_FISHER, + LootTables.VILLAGE_FLETCHER, + LootTables.VILLAGE_MASON, + LootTables.VILLAGE_PLAINS_HOUSE, + LootTables.VILLAGE_SAVANNA_HOUSE, + LootTables.VILLAGE_SHEPHERD, + LootTables.VILLAGE_SNOWY_HOUSE, + LootTables.VILLAGE_TAIGA_HOUSE, + LootTables.VILLAGE_TANNERY, + LootTables.VILLAGE_TEMPLE, + LootTables.VILLAGE_TOOLSMITH, + LootTables.VILLAGE_WEAPONSMITH, + LootTables.WOODLAND_MANSION, + LootTables.ARMOR_STAND, + LootTables.AXOLOTL, + LootTables.BAT, + LootTables.BEE, + LootTables.BLAZE, + LootTables.CAT, + LootTables.CAVE_SPIDER, + LootTables.CHICKEN, + LootTables.COD, + LootTables.COW, + LootTables.CREEPER, + LootTables.DOLPHIN, + LootTables.DONKEY, + LootTables.DROWNED, + LootTables.ELDER_GUARDIAN, + LootTables.ENDER_DRAGON, + LootTables.ENDERMAN, + LootTables.ENDERMITE, + LootTables.EVOKER, + LootTables.FOX, + LootTables.GHAST, + LootTables.GIANT, + LootTables.GLOW_SQUID, + LootTables.GOAT, + LootTables.GUARDIAN, + LootTables.HOGLIN, + LootTables.HORSE, + LootTables.HUSK, + LootTables.ILLUSIONER, + LootTables.IRON_GOLEM, + LootTables.LLAMA, + LootTables.MAGMA_CUBE, + LootTables.MOOSHROOM, + LootTables.MULE, + LootTables.OCELOT, + LootTables.PANDA, + LootTables.PARROT, + LootTables.PHANTOM, + LootTables.PIG, + LootTables.PIGLIN, + LootTables.PIGLIN_BRUTE, + LootTables.PILLAGER, + LootTables.PLAYER, + LootTables.POLAR_BEAR, + LootTables.PUFFERFISH, + LootTables.RABBIT, + LootTables.RAVAGER, + LootTables.SALMON, + LootTables.SHULKER, + LootTables.SILVERFISH, + LootTables.SKELETON, + LootTables.SKELETON_HORSE, + LootTables.SLIME, + LootTables.SNOW_GOLEM, + LootTables.SPIDER, + LootTables.SQUID, + LootTables.STRAY, + LootTables.STRIDER, + LootTables.TRADER_LLAMA, + LootTables.TROPICAL_FISH, + LootTables.TURTLE, + LootTables.VEX, + LootTables.VILLAGER, + LootTables.VINDICATOR, + LootTables.WANDERING_TRADER, + LootTables.WITCH, + LootTables.WITHER, + LootTables.WITHER_SKELETON, + LootTables.WOLF, + LootTables.ZOGLIN, + LootTables.ZOMBIE, + LootTables.ZOMBIE_HORSE, + LootTables.ZOMBIE_VILLAGER, + LootTables.ZOMBIFIED_PIGLIN, + LootTables.ARMORER_GIFT, + LootTables.BUTCHER_GIFT, + LootTables.CARTOGRAPHER_GIFT, + LootTables.CAT_MORNING_GIFT, + LootTables.CLERIC_GIFT, + LootTables.FARMER_GIFT, + LootTables.FISHERMAN_GIFT, + LootTables.FISHING, + LootTables.FISHING_FISH, + LootTables.FISHING_JUNK, + LootTables.FISHING_TREASURE, + LootTables.FLETCHER_GIFT, + LootTables.LEATHERWORKER_GIFT, + LootTables.LIBRARIAN_GIFT, + LootTables.MASON_GIFT, + LootTables.SHEPHERD_GIFT, + LootTables.TOOLSMITH_GIFT, + LootTables.WEAPONSMITH_GIFT, + LootTables.SNIFFER_DIGGING, + LootTables.PIGLIN_BARTERING, + LootTables.DESERT_WELL_ARCHAEOLOGY, + LootTables.DESERT_PYRAMID_ARCHAEOLOGY, + LootTables.TRAIL_RUINS_ARCHAEOLOGY_COMMON, + LootTables.TRAIL_RUINS_ARCHAEOLOGY_RARE, + LootTables.OCEAN_RUIN_WARM_ARCHAEOLOGY, + LootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY, + LootTables.SHEEP, + LootTables.SHEEP_BLACK, + LootTables.SHEEP_BLUE, + LootTables.SHEEP_BROWN, + LootTables.SHEEP_CYAN, + LootTables.SHEEP_GRAY, + LootTables.SHEEP_GREEN, + LootTables.SHEEP_LIGHT_BLUE, + LootTables.SHEEP_LIGHT_GRAY, + LootTables.SHEEP_LIME, + LootTables.SHEEP_MAGENTA, + LootTables.SHEEP_ORANGE, + LootTables.SHEEP_PINK, + LootTables.SHEEP_PURPLE, + LootTables.SHEEP_RED, + LootTables.SHEEP_WHITE, + LootTables.SHEEP_YELLOW, }; } @Override - public final PotionEffectType[] getPotionEffects() { + default PotionEffectType[] getPotionEffects() { return new PotionEffectType[] { PotionEffectType.SPEED, PotionEffectType.SLOW, @@ -397,7 +391,7 @@ public final PotionEffectType[] getPotionEffects() { } @Override - public Sound[] getSounds() { + default Sound[] getSounds() { return new Sound[] { Sound.AMBIENT_BASALT_DELTAS_ADDITIONS, Sound.AMBIENT_BASALT_DELTAS_LOOP, @@ -1877,7 +1871,7 @@ public Sound[] getSounds() { } @Override - public Biome[] getBiomes() { + default Biome[] getBiomes() { return new Biome[] { Biome.OCEAN, Biome.PLAINS, diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockCommandBuildContext.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockCommandBuildContext.java new file mode 100644 index 0000000000..a0e07fb5e3 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockCommandBuildContext.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.test; + +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.HolderOwner; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import org.mockito.Mockito; + +import java.util.Map; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; + +// TODO: Can this logic be shared with other test implementation versions? +public class MockCommandBuildContext implements CommandBuildContext { + // TODO: There might be an easier way to create the CommandBuildContext we need, + // but I don't think it is important enough to figure out right now. I just + // copied this logic from ArgumentNMS without really knowing what is going on. + private static final HolderLookup biomeLookup = Mockito.mock(HolderLookup.class); + + private static final Map, HolderLookup> registryLookup = Map.of( + Registries.BLOCK, BuiltInRegistries.BLOCK.asLookup(), + Registries.ENCHANTMENT, BuiltInRegistries.ENCHANTMENT.asLookup(), + Registries.ENTITY_TYPE, BuiltInRegistries.ENTITY_TYPE.asLookup(), + Registries.ITEM, BuiltInRegistries.ITEM.asLookup(), + Registries.MOB_EFFECT, BuiltInRegistries.MOB_EFFECT.asLookup(), + Registries.PARTICLE_TYPE, BuiltInRegistries.PARTICLE_TYPE.asLookup(), + Registries.BIOME, biomeLookup + ); + + static { + Mockito.when(biomeLookup.get((ResourceKey)any())).thenAnswer(i -> { + ResourceKey rk = i.getArgument(0, ResourceKey.class); +// if(biomes.contains(rk)) { +// return Optional.of(Holder.Reference.createStandAlone(new HolderOwner() { }, rk)); +// } else { +// return Optional.empty(); +// } + // We'll return the thing anyway. Bukkit will handle if the thing exists or not... + return Optional.of(Holder.Reference.createStandAlone(new HolderOwner() { }, rk)); + }); + } + + @Override + @SuppressWarnings("unchecked") + public HolderLookup holderLookup(ResourceKey> resourceKey) { + return (HolderLookup) registryLookup.get(resourceKey); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockPlatform_1_20.java similarity index 63% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockPlatform_1_20.java index 36fe844713..b2834a1d79 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockPlatform_1_20.java @@ -7,17 +7,19 @@ import com.google.common.collect.Streams; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import dev.jorel.commandapi.*; +import dev.jorel.commandapi.Brigadier; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SafeVarHandle; +import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.nms.NMS_1_20_R1; import net.minecraft.SharedConstants; -import net.minecraft.advancements.Advancement; import net.minecraft.commands.CommandFunction; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor; +import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; @@ -41,12 +43,13 @@ import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.criteria.ObjectiveCriteria; -import net.minecraft.world.scores.criteria.ObjectiveCriteria.RenderType; import org.bukkit.*; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.craftbukkit.v1_20_R1.CraftParticle; import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R1.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemFactory; import org.bukkit.enchantments.Enchantment; @@ -61,53 +64,28 @@ import org.jetbrains.annotations.Nullable; import org.mockito.Mockito; -import java.io.File; -import java.io.IOException; -import java.security.CodeSource; import java.util.*; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import static org.mockito.ArgumentMatchers.*; -public class MockNMS extends Enums { +public class MockPlatform_1_20 extends MockPlatform implements Enums_1_20 { private static final SafeVarHandle> helpMapTopics = SafeVarHandle.ofOrNull(HelpMapMock.class, "topics", "topics", Map.class); - static { - CodeSource src = PotionEffectType.class.getProtectionDomain().getCodeSource(); - if (src != null) { - System.err.println("Loading PotionEffectType sources from " + src.getLocation()); - } - } - static ServerAdvancementManager advancementDataWorld = new ServerAdvancementManager(null); + private static final ServerAdvancementManager advancementDataWorld = new ServerAdvancementManager(null); - MinecraftServer minecraftServerMock = null; - List players = new ArrayList<>(); - PlayerList playerListMock; + private MinecraftServer minecraftServerMock = null; + private List players = new ArrayList<>(); + private PlayerList playerListMock; final RecipeManager recipeManager; Map functions = new HashMap<>(); Map> tags = new HashMap<>(); - public MockNMS(CommandAPIBukkit baseNMS) { - super(baseNMS); - - CommandAPIBukkit nms = Mockito.spy(super.baseNMS); - // Stub in our getMinecraftServer implementation - Mockito.when(nms.getMinecraftServer()).thenAnswer(i -> getMinecraftServer()); - // Stub in our getSimpleCommandMap implementation - // Note that calling `nms.getSimpleCommandMap()` throws a - // class cast exception (`CraftServer` vs `CommandAPIServerMock`), - // so we have to mock with `doAnswer` instead of `when` - Mockito.doAnswer(i -> getSimpleCommandMap()).when(nms).getSimpleCommandMap(); - super.baseNMS = nms; - - // Initialize baseNMS's paper field (with paper specific implementations disabled) - MockPlatform.setField(CommandAPIBukkit.class, "paper", - super.baseNMS, new PaperImplementations(false, false, super.baseNMS)); - -// initializeArgumentsInArgumentTypeInfos(); + protected MockPlatform_1_20() { + super(); // Initialize WorldVersion (game version) SharedConstants.tryDetectVersion(); @@ -142,6 +120,183 @@ public MockNMS(CommandAPIBukkit baseNMS) { } return null; }); + + // Create NMS spy now that registries are set up + createNMSSpy(new NMS_1_20_R1()); + } + + @Override + protected void setupNMSSpy(NMS spy) { + // Create CommandBuildContext - private static field + // Some ArgumentTypes need this when constructed + setField(NMS_1_20_R1.class, "COMMAND_BUILD_CONTEXT", null, new MockCommandBuildContext()); + } + + @SuppressWarnings("unchecked") + @Override + public T getMinecraftServer() { + if (minecraftServerMock != null) { + return (T) minecraftServerMock; + } + minecraftServerMock = Mockito.mock(MinecraftServer.class); + + // LootTableArgument + Mockito.when(minecraftServerMock.getLootData()).thenAnswer(invocation -> { + //.getKeys(LootDataType.TABLE) + LootDataManager lootDataManager = Mockito.mock(LootDataManager.class); + + Mockito.when(lootDataManager.getLootTable(any(ResourceLocation.class))).thenAnswer(i -> { + if (BuiltInLootTables.all().contains(i.getArgument(0))) { + return net.minecraft.world.level.storage.loot.LootTable.EMPTY; + } else { + return null; + } + }); + + Mockito.when(lootDataManager.getKeys(any())).thenAnswer(i -> { + return Streams + .concat( + Arrays.stream(getEntityTypes()) + .filter(e -> !e.equals(EntityType.UNKNOWN)) + // TODO? These entity types don't have corresponding + // loot table entries! Did Spigot miss them out? + .filter(e -> !e.equals(EntityType.ALLAY)) + .filter(e -> !e.equals(EntityType.FROG)) + .filter(e -> !e.equals(EntityType.TADPOLE)) + .filter(e -> !e.equals(EntityType.WARDEN)) + .filter(e -> e.isAlive()) + .map(EntityType::getKey) + .map(k -> new ResourceLocation("minecraft", "entities/" + k.getKey())), + BuiltInLootTables.all().stream()) + .collect(Collectors.toSet()); + }); + return lootDataManager; + }); + + // AdvancementArgument + Mockito.when(minecraftServerMock.getAdvancements()).thenAnswer(i -> advancementDataWorld); + + // TeamArgument + ServerScoreboard scoreboardServerMock = Mockito.mock(ServerScoreboard.class); + Mockito.when(scoreboardServerMock.getPlayerTeam(anyString())).thenAnswer(invocation -> { // Scoreboard#getPlayerTeam + String teamName = invocation.getArgument(0); + Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + if (team == null) { + return null; + } else { + return new PlayerTeam(scoreboardServerMock, teamName); + } + }); + Mockito.when(scoreboardServerMock.getObjective(anyString())).thenAnswer(invocation -> { // Scoreboard#getObjective + String objectiveName = invocation.getArgument(0); + org.bukkit.scoreboard.Objective bukkitObjective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + if (bukkitObjective == null) { + return null; + } else { + return new Objective(scoreboardServerMock, objectiveName, ObjectiveCriteria.byName(bukkitObjective.getCriteria()).get(), Component.literal(bukkitObjective.getDisplayName()), switch(bukkitObjective.getRenderType()) { + case HEARTS: + yield ObjectiveCriteria.RenderType.HEARTS; + case INTEGER: + yield ObjectiveCriteria.RenderType.INTEGER; + }); + } + }); + Mockito.when(minecraftServerMock.getScoreboard()).thenReturn(scoreboardServerMock); // MinecraftServer#getScoreboard + + // WorldArgument (Dimension) + Mockito.when(minecraftServerMock.getLevel(any(ResourceKey.class))).thenAnswer(invocation -> { + // Get the ResourceKey and extract the world name from it + ResourceKey resourceKey = invocation.getArgument(0); + String worldName = resourceKey.location().getPath(); + + // Get the world via Bukkit (returns a WorldMock) and create a + // CraftWorld clone of it for WorldServer.getWorld() + World world = Bukkit.getServer().getWorld(worldName); + if (world == null) { + return null; + } else { + CraftWorld craftWorldMock = Mockito.mock(CraftWorld.class); + Mockito.when(craftWorldMock.getName()).thenReturn(world.getName()); + Mockito.when(craftWorldMock.getUID()).thenReturn(world.getUID()); + + // Create our return WorldServer object + ServerLevel bukkitWorldServerMock = Mockito.mock(ServerLevel.class); + Mockito.when(bukkitWorldServerMock.getWorld()).thenReturn(craftWorldMock); + return bukkitWorldServerMock; + } + }); + + // Player lists + Mockito.when(minecraftServerMock.getPlayerList()).thenAnswer(i -> playerListMock); + Mockito.when(minecraftServerMock.getPlayerList().getPlayers()).thenAnswer(i -> players); + + // PlayerArgument + GameProfileCache userCacheMock = Mockito.mock(GameProfileCache.class); + Mockito.when(userCacheMock.get(anyString())).thenAnswer(invocation -> { + String playerName = invocation.getArgument(0); + for (ServerPlayer onlinePlayer : players) { + if (onlinePlayer.getBukkitEntity().getName().equals(playerName)) { + return Optional.of(new GameProfile(onlinePlayer.getBukkitEntity().getUniqueId(), playerName)); + } + } + return Optional.empty(); + }); + Mockito.when(minecraftServerMock.getProfileCache()).thenReturn(userCacheMock); + + // RecipeArgument + Mockito.when(minecraftServerMock.getRecipeManager()).thenAnswer(i -> this.recipeManager); + + // FunctionArgument + // We're using 2 as the function compilation level. + Mockito.when(minecraftServerMock.getFunctionCompilationLevel()).thenReturn(2); + Mockito.when(minecraftServerMock.getFunctions()).thenAnswer(i -> { + ServerFunctionLibrary serverFunctionLibrary = Mockito.mock(ServerFunctionLibrary.class); + + // Functions + Mockito.when(serverFunctionLibrary.getFunction(any())).thenAnswer(invocation -> Optional.ofNullable(functions.get(invocation.getArgument(0)))); + Mockito.when(serverFunctionLibrary.getFunctions()).thenAnswer(invocation -> functions); + + // Tags + Mockito.when(serverFunctionLibrary.getTag(any())).thenAnswer(invocation -> tags.getOrDefault(invocation.getArgument(0), List.of())); + Mockito.when(serverFunctionLibrary.getAvailableTags()).thenAnswer(invocation -> tags.keySet()); + + return new ServerFunctionManager(minecraftServerMock, serverFunctionLibrary) { + + // Make sure we don't use ServerFunctionManager#getDispatcher! + // That method accesses MinecraftServer.vanillaCommandDispatcher + // directly (boo) and that causes all sorts of nonsense. + @Override + public CommandDispatcher getDispatcher() { + return Brigadier.getCommandDispatcher(); + } + }; + }); + + Mockito.when(minecraftServerMock.getGameRules()).thenAnswer(i -> new GameRules()); + Mockito.when(minecraftServerMock.getProfiler()).thenAnswer(i -> InactiveMetricsRecorder.INSTANCE.getProfiler()); + + // Brigadier and resources dispatcher, used in `NMS#createCommandRegistrationStrategy` + Commands brigadierCommands = new Commands(); + MockPlatform.setField(brigadierCommands.getClass(), "g", "dispatcher", + brigadierCommands, getMockBrigadierDispatcher()); + minecraftServerMock.vanillaCommandDispatcher = brigadierCommands; + + Commands resourcesCommands = new Commands(); + MockPlatform.setField(resourcesCommands.getClass(), "g", "dispatcher", + resourcesCommands, getMockResourcesDispatcher()); + Mockito.when(minecraftServerMock.getCommands()).thenReturn(resourcesCommands); + + return (T) minecraftServerMock; + } + + @Override + public SimpleCommandMap getSimpleCommandMap() { + return ((ServerMock) Bukkit.getServer()).getCommandMap(); + } + + @Override + public Map getHelpMap() { + return helpMapTopics.get((HelpMapMock) Bukkit.getHelpMap()); } /************************* @@ -248,16 +403,6 @@ public List getAllItemNames() { .toList(); } - @Override - public String[] compatibleVersions() { - return baseNMS.compatibleVersions(); - } - - @Override - public SimpleCommandMap getSimpleCommandMap() { - return ((ServerMock) Bukkit.getServer()).getCommandMap(); - } - @SuppressWarnings({ "deprecation", "unchecked" }) @Override public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender senderWrapper) { @@ -289,7 +434,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen // return bs; // }); Mockito.when(css.getLevel().isInWorldBounds(any(BlockPos.class))).thenReturn(true); - Mockito.when(css.getAnchor()).thenReturn(Anchor.EYES); + Mockito.when(css.getAnchor()).thenReturn(EntityAnchorArgument.Anchor.EYES); // Get mocked MinecraftServer Mockito.when(css.getServer()).thenAnswer(s -> getMinecraftServer()); @@ -306,7 +451,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); } @@ -343,7 +488,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen // Suggestions Mockito.when(css.enabledFeatures()).thenAnswer(invocation -> FeatureFlags.DEFAULT_FLAGS); - + // FunctionArgument // We don't really need to do anything funky here, we'll just return the same CSS Mockito.when(css.withSuppressedOutput()).thenReturn(css); @@ -357,18 +502,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return css; } - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void createDispatcherFile(File file, CommandDispatcher dispatcher) - throws IOException { - baseNMS.createDispatcherFile(file, dispatcher); - } - - @Override - public World getWorldForCSS(CommandSourceStack clw) { - return baseNMS.getWorldForCSS(clw); - } - @Override public String getBukkitPotionEffectTypeName(PotionEffectType potionEffectType) { // NamespacedKey#asString is PAPER ONLY, whereas NamespacedKey#toString @@ -392,163 +525,6 @@ public List getAllRecipes() { return recipeManager.getRecipeIds().map(k -> new NamespacedKey(k.getNamespace(), k.getPath())).toList(); } - @SuppressWarnings("unchecked") - @Override - public T getMinecraftServer() { - if (minecraftServerMock != null) { - return (T) minecraftServerMock; - } - minecraftServerMock = Mockito.mock(MinecraftServer.class); - - // LootTableArgument - Mockito.when(minecraftServerMock.getLootData()).thenAnswer(invocation -> { - //.getKeys(LootDataType.TABLE) - LootDataManager lootDataManager = Mockito.mock(LootDataManager.class); - - Mockito.when(lootDataManager.getLootTable(any(ResourceLocation.class))).thenAnswer(i -> { - if (BuiltInLootTables.all().contains(i.getArgument(0))) { - return net.minecraft.world.level.storage.loot.LootTable.EMPTY; - } else { - return null; - } - }); - - Mockito.when(lootDataManager.getKeys(any())).thenAnswer(i -> { - return Streams - .concat( - Arrays.stream(getEntityTypes()) - .filter(e -> !e.equals(EntityType.UNKNOWN)) - // TODO? These entity types don't have corresponding - // loot table entries! Did Spigot miss them out? - .filter(e -> !e.equals(EntityType.ALLAY)) - .filter(e -> !e.equals(EntityType.FROG)) - .filter(e -> !e.equals(EntityType.TADPOLE)) - .filter(e -> !e.equals(EntityType.WARDEN)) - .filter(e -> e.isAlive()) - .map(EntityType::getKey) - .map(k -> new ResourceLocation("minecraft", "entities/" + k.getKey())), - BuiltInLootTables.all().stream()) - .collect(Collectors.toSet()); - }); - return lootDataManager; - }); - - // AdvancementArgument - Mockito.when(minecraftServerMock.getAdvancements()).thenAnswer(i -> advancementDataWorld); - - // TeamArgument - ServerScoreboard scoreboardServerMock = Mockito.mock(ServerScoreboard.class); - Mockito.when(scoreboardServerMock.getPlayerTeam(anyString())).thenAnswer(invocation -> { // Scoreboard#getPlayerTeam - String teamName = invocation.getArgument(0); - Team team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); - if (team == null) { - return null; - } else { - return new PlayerTeam(scoreboardServerMock, teamName); - } - }); - Mockito.when(scoreboardServerMock.getObjective(anyString())).thenAnswer(invocation -> { // Scoreboard#getObjective - String objectiveName = invocation.getArgument(0); - org.bukkit.scoreboard.Objective bukkitObjective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); - if (bukkitObjective == null) { - return null; - } else { - return new Objective(scoreboardServerMock, objectiveName, ObjectiveCriteria.byName(bukkitObjective.getCriteria()).get(), Component.literal(bukkitObjective.getDisplayName()), switch(bukkitObjective.getRenderType()) { - case HEARTS: - yield RenderType.HEARTS; - case INTEGER: - yield RenderType.INTEGER; - }); - } - }); - Mockito.when(minecraftServerMock.getScoreboard()).thenReturn(scoreboardServerMock); // MinecraftServer#getScoreboard - - // WorldArgument (Dimension) - Mockito.when(minecraftServerMock.getLevel(any(ResourceKey.class))).thenAnswer(invocation -> { - // Get the ResourceKey and extract the world name from it - ResourceKey resourceKey = invocation.getArgument(0); - String worldName = resourceKey.location().getPath(); - - // Get the world via Bukkit (returns a WorldMock) and create a - // CraftWorld clone of it for WorldServer.getWorld() - World world = Bukkit.getServer().getWorld(worldName); - if (world == null) { - return null; - } else { - CraftWorld craftWorldMock = Mockito.mock(CraftWorld.class); - Mockito.when(craftWorldMock.getName()).thenReturn(world.getName()); - Mockito.when(craftWorldMock.getUID()).thenReturn(world.getUID()); - - // Create our return WorldServer object - ServerLevel bukkitWorldServerMock = Mockito.mock(ServerLevel.class); - Mockito.when(bukkitWorldServerMock.getWorld()).thenReturn(craftWorldMock); - return bukkitWorldServerMock; - } - }); - - // Player lists - Mockito.when(minecraftServerMock.getPlayerList()).thenAnswer(i -> playerListMock); - Mockito.when(minecraftServerMock.getPlayerList().getPlayers()).thenAnswer(i -> players); - - // PlayerArgument - GameProfileCache userCacheMock = Mockito.mock(GameProfileCache.class); - Mockito.when(userCacheMock.get(anyString())).thenAnswer(invocation -> { - String playerName = invocation.getArgument(0); - for (ServerPlayer onlinePlayer : players) { - if (onlinePlayer.getBukkitEntity().getName().equals(playerName)) { - return Optional.of(new GameProfile(onlinePlayer.getBukkitEntity().getUniqueId(), playerName)); - } - } - return Optional.empty(); - }); - Mockito.when(minecraftServerMock.getProfileCache()).thenReturn(userCacheMock); - - // RecipeArgument - Mockito.when(minecraftServerMock.getRecipeManager()).thenAnswer(i -> this.recipeManager); - - // FunctionArgument - // We're using 2 as the function compilation level. - Mockito.when(minecraftServerMock.getFunctionCompilationLevel()).thenReturn(2); - Mockito.when(minecraftServerMock.getFunctions()).thenAnswer(i -> { - ServerFunctionLibrary serverFunctionLibrary = Mockito.mock(ServerFunctionLibrary.class); - - // Functions - Mockito.when(serverFunctionLibrary.getFunction(any())).thenAnswer(invocation -> Optional.ofNullable(functions.get(invocation.getArgument(0)))); - Mockito.when(serverFunctionLibrary.getFunctions()).thenAnswer(invocation -> functions); - - // Tags - Mockito.when(serverFunctionLibrary.getTag(any())).thenAnswer(invocation -> tags.getOrDefault(invocation.getArgument(0), List.of())); - Mockito.when(serverFunctionLibrary.getAvailableTags()).thenAnswer(invocation -> tags.keySet()); - - return new ServerFunctionManager(minecraftServerMock, serverFunctionLibrary) { - - // Make sure we don't use ServerFunctionManager#getDispatcher! - // That method accesses MinecraftServer.vanillaCommandDispatcher - // directly (boo) and that causes all sorts of nonsense. - @Override - public CommandDispatcher getDispatcher() { - return Brigadier.getCommandDispatcher(); - } - }; - }); - - Mockito.when(minecraftServerMock.getGameRules()).thenAnswer(i -> new GameRules()); - Mockito.when(minecraftServerMock.getProfiler()).thenAnswer(i -> InactiveMetricsRecorder.INSTANCE.getProfiler()); - - // Brigadier and resources dispatcher, used in `NMS#createCommandRegistrationStrategy` - Commands brigadierCommands = new Commands(); - MockPlatform.setField(brigadierCommands.getClass(), "g", "dispatcher", - brigadierCommands, getMockBrigadierDispatcher()); - minecraftServerMock.vanillaCommandDispatcher = brigadierCommands; - - Commands resourcesCommands = new Commands(); - MockPlatform.setField(resourcesCommands.getClass(), "g", "dispatcher", - resourcesCommands, getMockResourcesDispatcher()); - Mockito.when(minecraftServerMock.getCommands()).thenReturn(resourcesCommands); - - return (T) minecraftServerMock; - } - @SuppressWarnings("unchecked") @Override public void addFunction(NamespacedKey key, List commands) { @@ -604,7 +580,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); @@ -614,7 +590,7 @@ public Player setupMockedCraftPlayer(String name) { @Override public org.bukkit.advancement.Advancement addAdvancement(NamespacedKey key) { advancementDataWorld.advancements.advancements.put(new ResourceLocation(key.toString()), - new Advancement(new ResourceLocation(key.toString()), null, null, null, new HashMap<>(), null, false)); + new net.minecraft.advancements.Advancement(new ResourceLocation(key.toString()), null, null, null, new HashMap<>(), null, false)); return new org.bukkit.advancement.Advancement() { @Override @@ -654,215 +630,17 @@ public Collection getCriteria() { }; } - @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return baseNMS.getSenderForCommand(cmdCtx, forceNative); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack clw) { - try { - return wrapCommandSender(clw.getBukkitSender()); - } catch (UnsupportedOperationException e) { - return null; - } - } - -// @Override -// public void createDispatcherFile(File file, CommandDispatcher dispatcher) -// throws IOException { -// Files -// .asCharSink(file, StandardCharsets.UTF_8) -// .write(new GsonBuilder() -// .setPrettyPrinting() -// .create() -// .toJson(DispatcherUtil.toJSON(dispatcher, dispatcher.getRoot()))); -// } -// -// @SuppressWarnings("rawtypes") -// private void initializeArgumentsInArgumentTypeInfos() { -// @SuppressWarnings("unchecked") -// Map, ArgumentTypeInfo> map = getFieldAs(ArgumentTypeInfos.class, "a", null, Map.class); -// map.put(BoolArgumentType.class, SingletonArgumentInfo.contextFree(BoolArgumentType::bool)); -// map.put(FloatArgumentType.class, new FloatArgumentInfo()); -// map.put(DoubleArgumentType.class, new DoubleArgumentInfo()); -// map.put(IntegerArgumentType.class, new IntegerArgumentInfo()); -// map.put(LongArgumentType.class, new LongArgumentInfo()); -// map.put(StringArgumentType.class, new StringArgumentSerializer()); -// map.put(EntityArgument.class, new EntityArgument.Info()); -// map.put(GameProfileArgument.class, SingletonArgumentInfo.contextFree(GameProfileArgument::gameProfile)); -// map.put(BlockPosArgument.class, SingletonArgumentInfo.contextFree(BlockPosArgument::blockPos)); -// map.put(ColumnPosArgument.class, SingletonArgumentInfo.contextFree(ColumnPosArgument::columnPos)); -// map.put(Vec3Argument.class, SingletonArgumentInfo.contextFree(Vec3Argument::vec3)); -// map.put(Vec2Argument.class, SingletonArgumentInfo.contextFree(Vec2Argument::vec2)); -// map.put(BlockStateArgument.class, SingletonArgumentInfo.contextAware(BlockStateArgument::block)); -// map.put(BlockPredicateArgument.class, SingletonArgumentInfo.contextAware(BlockPredicateArgument::blockPredicate)); -// map.put(ItemArgument.class, SingletonArgumentInfo.contextAware(ItemArgument::item)); -// map.put(ItemPredicateArgument.class, SingletonArgumentInfo.contextAware(ItemPredicateArgument::itemPredicate)); -// map.put(ColorArgument.class, SingletonArgumentInfo.contextFree(ColorArgument::color)); -// map.put(ComponentArgument.class, SingletonArgumentInfo.contextFree(ComponentArgument::textComponent)); -// map.put(MessageArgument.class, SingletonArgumentInfo.contextFree(MessageArgument::message)); -// map.put(CompoundTagArgument.class, SingletonArgumentInfo.contextFree(CompoundTagArgument::compoundTag)); -// map.put(NbtTagArgument.class, SingletonArgumentInfo.contextFree(NbtTagArgument::nbtTag)); -// map.put(NbtPathArgument.class, SingletonArgumentInfo.contextFree(NbtPathArgument::nbtPath)); -// map.put(ObjectiveArgument.class, SingletonArgumentInfo.contextFree(ObjectiveArgument::objective)); -// map.put(ObjectiveCriteriaArgument.class, SingletonArgumentInfo.contextFree(ObjectiveCriteriaArgument::criteria)); -// map.put(OperationArgument.class, SingletonArgumentInfo.contextFree(OperationArgument::operation)); -// map.put(ParticleArgument.class, SingletonArgumentInfo.contextFree(ParticleArgument::particle)); -// map.put(AngleArgument.class, SingletonArgumentInfo.contextFree(AngleArgument::angle)); -// map.put(RotationArgument.class, SingletonArgumentInfo.contextFree(RotationArgument::rotation)); -// map.put(ScoreboardSlotArgument.class, SingletonArgumentInfo.contextFree(ScoreboardSlotArgument::displaySlot)); -// map.put(ScoreHolderArgument.class, new ScoreHolderArgument.Info()); -// map.put(SwizzleArgument.class, SingletonArgumentInfo.contextFree(SwizzleArgument::swizzle)); -// map.put(TeamArgument.class, SingletonArgumentInfo.contextFree(TeamArgument::team)); -// map.put(SlotArgument.class, SingletonArgumentInfo.contextFree(SlotArgument::slot)); -// map.put(ResourceLocationArgument.class, SingletonArgumentInfo.contextFree(ResourceLocationArgument::id)); -// map.put(MobEffectArgument.class, SingletonArgumentInfo.contextFree(MobEffectArgument::effect)); -// map.put(FunctionArgument.class, SingletonArgumentInfo.contextFree(FunctionArgument::functions)); -// map.put(EntityAnchorArgument.class, SingletonArgumentInfo.contextFree(EntityAnchorArgument::anchor)); -// map.put(RangeArgument.Ints.class, SingletonArgumentInfo.contextFree(RangeArgument::intRange)); -// map.put(RangeArgument.Floats.class, SingletonArgumentInfo.contextFree(RangeArgument::floatRange)); -// map.put(ItemEnchantmentArgument.class, SingletonArgumentInfo.contextFree(ItemEnchantmentArgument::enchantment)); -// map.put(EntitySummonArgument.class, SingletonArgumentInfo.contextFree(EntitySummonArgument::id)); -// map.put(DimensionArgument.class, SingletonArgumentInfo.contextFree(DimensionArgument::dimension)); -// map.put(TimeArgument.class, SingletonArgumentInfo.contextFree(TimeArgument::time)); -// map.put(ResourceOrTagLocationArgument.class, new ResourceOrTagLocationArgument.Info()); -// map.put(ResourceKeyArgument.class, new ResourceKeyArgument.Info()); -// map.put(TemplateMirrorArgument.class, SingletonArgumentInfo.contextFree(TemplateMirrorArgument::templateMirror)); -// map.put(TemplateRotationArgument.class, SingletonArgumentInfo.contextFree(TemplateRotationArgument::templateRotation)); -// map.put(UuidArgument.class, SingletonArgumentInfo.contextFree(UuidArgument::uuid)); -// } -// -// /** -// * An implementation of {@link ArgumentUtils} which produces JSON from a command -// * dispatcher and its root node. We have to avoid accessing IRegistry because it -// * isn't mock-able and cannot be instantiated through normal means -// */ -// private static class DispatcherUtil { -// -// static Map, String> argumentParsers = new HashMap<>(); -// -// static { -// argumentParsers.put(BoolArgumentType.class, "brigadier:bool"); -// argumentParsers.put(FloatArgumentType.class, "brigadier:float"); -// argumentParsers.put(DoubleArgumentType.class, "brigadier:double"); -// argumentParsers.put(IntegerArgumentType.class, "brigadier:integer"); -// argumentParsers.put(LongArgumentType.class, "brigadier:long"); -// argumentParsers.put(StringArgumentType.class, "brigadier:string"); -// argumentParsers.put(EntityArgument.class, "entity"); -// argumentParsers.put(GameProfileArgument.class, "game_profile"); -// argumentParsers.put(BlockPosArgument.class, "block_pos"); -// argumentParsers.put(ColumnPosArgument.class, "column_pos"); -// argumentParsers.put(Vec3Argument.class, "vec3"); -// argumentParsers.put(Vec2Argument.class, "vec2"); -// argumentParsers.put(BlockStateArgument.class, "block_state"); -// argumentParsers.put(BlockPredicateArgument.class, "block_predicate"); -// argumentParsers.put(ItemArgument.class, "item_stack"); -// argumentParsers.put(ItemPredicateArgument.class, "item_predicate"); -// argumentParsers.put(ColorArgument.class, "color"); -// argumentParsers.put(ComponentArgument.class, "component"); -// argumentParsers.put(MessageArgument.class, "message"); -// argumentParsers.put(CompoundTagArgument.class, "nbt_compound_tag"); -// argumentParsers.put(NbtTagArgument.class, "nbt_tag"); -// argumentParsers.put(NbtPathArgument.class, "nbt_path"); -// argumentParsers.put(ObjectiveArgument.class, "objective"); -// argumentParsers.put(ObjectiveCriteriaArgument.class, "objective_criteria"); -// argumentParsers.put(OperationArgument.class, "operation"); -// argumentParsers.put(ParticleArgument.class, "particle"); -// argumentParsers.put(AngleArgument.class, "angle"); -// argumentParsers.put(RotationArgument.class, "rotation"); -// argumentParsers.put(ScoreboardSlotArgument.class, "scoreboard_slot"); -// argumentParsers.put(ScoreHolderArgument.class, "score_holder"); -// argumentParsers.put(SwizzleArgument.class, "swizzle"); -// argumentParsers.put(TeamArgument.class, "team"); -// argumentParsers.put(SlotArgument.class, "item_slot"); -// argumentParsers.put(ResourceLocationArgument.class, "resource_location"); -// argumentParsers.put(MobEffectArgument.class, "mob_effect"); -// argumentParsers.put(FunctionArgument.class, "function"); -// argumentParsers.put(EntityAnchorArgument.class, "entity_anchor"); -// argumentParsers.put(RangeArgument.Ints.class, "int_range"); -// argumentParsers.put(RangeArgument.Floats.class, "float_range"); -// argumentParsers.put(ItemEnchantmentArgument.class, "item_enchantment"); -// argumentParsers.put(EntitySummonArgument.class, "entity_summon"); -// argumentParsers.put(DimensionArgument.class, "dimension"); -// argumentParsers.put(TimeArgument.class, "time"); -// argumentParsers.put(ResourceOrTagLocationArgument.class, "resource_or_tag"); -// argumentParsers.put(ResourceKeyArgument.class, "resource"); -// argumentParsers.put(TemplateMirrorArgument.class, "template_mirror"); -// argumentParsers.put(TemplateRotationArgument.class, "template_rotation"); -// argumentParsers.put(UuidArgument.class, "uuid"); -// } -// -// public static JsonObject toJSON(CommandDispatcher dispatcher, CommandNode node) { -// JsonObject jsonObject = new JsonObject(); -// -// // Unpack nodes -// if (node instanceof RootCommandNode) { -// jsonObject.addProperty("type", "root"); -// } else if (node instanceof LiteralCommandNode) { -// jsonObject.addProperty("type", "literal"); -// } else if (node instanceof ArgumentCommandNode) { -// ArgumentCommandNode argumentCommandNode = (ArgumentCommandNode) node; -// argToJSON(jsonObject, argumentCommandNode.getType()); -// } else { -// jsonObject.addProperty("type", "unknown"); -// } -// -// // Write children -// JsonObject children = new JsonObject(); -// for (CommandNode child : node.getChildren()) { -// children.add(child.getName(), (JsonElement) toJSON(dispatcher, child)); -// } -// if (children.size() > 0) { -// jsonObject.add("children", (JsonElement) children); -// } -// -// // Write whether the command is executable -// if (node.getCommand() != null) { -// jsonObject.addProperty("executable", Boolean.valueOf(true)); -// } -// if (node.getRedirect() != null) { -// Collection redirectPaths = dispatcher.getPath(node.getRedirect()); -// if (!redirectPaths.isEmpty()) { -// JsonArray redirects = new JsonArray(); -// for (String redirectPath : redirectPaths) { -// redirects.add(redirectPath); -// } -// jsonObject.add("redirect", (JsonElement) redirects); -// } -// } -// return jsonObject; -// } -// -// @SuppressWarnings("unchecked") -// private static > void argToJSON(JsonObject jsonObject, T argument) { -// ArgumentTypeInfo.Template argumentInfo = ArgumentTypeInfos.unpack(argument); -// jsonObject.addProperty("type", "argument"); -// jsonObject.addProperty("parser", argumentParsers.get(argument.getClass())); -// -// // Properties -// JsonObject properties = new JsonObject(); -// @SuppressWarnings("rawtypes") -// ArgumentTypeInfo argumentTypeInfo = argumentInfo.type(); -// argumentTypeInfo.serializeToJson(argumentInfo, properties); -// if (properties.size() > 0) { -// jsonObject.add("properties", (JsonElement) properties); -// } -// } -// } - - @Override - public HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { - return baseNMS.generateHelpTopic(commandName, shortDescription, fullDescription, permission); - } - - @Override - public Map getHelpMap() { - return helpMapTopics.get((HelpMapMock) Bukkit.getHelpMap()); - } - @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return baseNMS.createCommandRegistrationStrategy(); + // TODO: This method is not Paper/Spigot specific pre 1.20.6, so it should probably be defined in NMS_1_20_R1, + // in which case this definition can be removed to simply pass it through to the baseNMS. + return new SpigotCommandRegistration<>( + nms.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> nms.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(nms.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java new file mode 100644 index 0000000000..0cab1eee09 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.test; + +/** + * This file loads the test implementation for 1.20. This overrides the TestVersionHandler file + * within the commandapi-bukkit-test-impl module. + */ +public abstract class TestVersionHandler { + + /** + * @return An implementation of {@link MockPlatform} that works for the current test version. + */ + public static MockPlatform getMockPlatform() { + return new MockPlatform_1_20(); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml index 131128f4f1..b49008359c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml @@ -57,17 +57,25 @@ + - com.mojang - brigadier - 1.0.17 - provided + dev.jorel + commandapi-bukkit-core + ${project.version} dev.jorel - commandapi-bukkit-shade + commandapi-bukkit-plugin-common ${project.version} + + + + com.mojang + brigadier + 1.0.17 + provided + io.papermc.paper paper-api @@ -80,5 +88,19 @@ ${spigot.version} provided + + + + org.mockito + mockito-core + 5.11.0 + + + + + com.github.zafarkhaja + java-semver + 0.9.0 + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java similarity index 50% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 75d18300b3..adaeb10092 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -1,26 +1,11 @@ package dev.jorel.commandapi; -import dev.jorel.commandapi.nms.NMS_1_16_R3; -import dev.jorel.commandapi.nms.NMS_1_17; -import dev.jorel.commandapi.nms.NMS_1_18_R1; -import dev.jorel.commandapi.nms.NMS_1_19_1_R1; -import dev.jorel.commandapi.nms.NMS_1_19_4_R3; -import dev.jorel.commandapi.nms.NMS_1_20_R1; -import dev.jorel.commandapi.nms.NMS_1_20_R2; -import dev.jorel.commandapi.nms.NMS_1_20_R3; -import dev.jorel.commandapi.nms.NMS_1_20_R4; -import dev.jorel.commandapi.test.MockNMS; +import dev.jorel.commandapi.test.TestVersionHandler; -/** - * This file handles loading the correct platform implementation. The CommandAPIVersionHandler - * file within the commandapi-core module is NOT used at run time. Instead, the platform modules - * replace this class with their own version that handles loads the correct class for their version - */ public abstract class CommandAPIVersionHandler { - public static final String profileId = getProfileId(); public static final boolean IS_MOJANG_MAPPED = isMojangMapped(); - + private static String getProfileId() { String profileIdProperty = System.getProperty("profileId"); if(profileIdProperty != null) { @@ -33,7 +18,7 @@ private static String getProfileId() { return null; } } - + private static boolean isMojangMapped() { String profileIdProperty = System.getProperty("profileId"); if(profileIdProperty != null) { @@ -42,27 +27,7 @@ private static boolean isMojangMapped() { return false; } } - - static LoadContext getPlatform() { - if(profileId == null) { - System.out.println("Using default version 1.19.4"); - return new LoadContext(new MockNMS(new NMS_1_19_4_R3())); - } else { - return new LoadContext(new MockNMS(switch(profileId) { - case "Minecraft_1_20_5" -> new NMS_1_20_R4(); - case "Minecraft_1_20_3" -> new NMS_1_20_R3(); - case "Minecraft_1_20_2" -> new NMS_1_20_R2(); - case "Minecraft_1_20" -> new NMS_1_20_R1(); - case "Minecraft_1_19_4" -> new NMS_1_19_4_R3(); - case "Minecraft_1_19_2" -> new NMS_1_19_1_R1(); - case "Minecraft_1_18" -> new NMS_1_18_R1(); - case "Minecraft_1_17" -> new NMS_1_17(); - case "Minecraft_1_16_5" -> new NMS_1_16_R3(); - default -> throw new IllegalArgumentException("Unexpected value: " + System.getProperty("profileId")); - })); - } - } - + public static MCVersion getVersion() { if(profileId == null) { System.out.println("Using default version 1.19.4"); @@ -82,4 +47,8 @@ public static MCVersion getVersion() { }; } } + + static LoadContext getPlatform() { + return new LoadContext(TestVersionHandler.getMockPlatform()); + } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/MCVersion.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/MCVersion.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/MCVersion.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/MCVersion.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/Enums.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/Enums.java new file mode 100644 index 0000000000..26e08268e3 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/Enums.java @@ -0,0 +1,27 @@ +package dev.jorel.commandapi.test; + +import org.bukkit.Sound; +import org.bukkit.block.Biome; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.loot.LootTables; +import org.bukkit.potion.PotionEffectType; + +/** + * Bukkit "enum" lists. These change for each version, so the methods are abstract. + * This is in a separate class because we have to manually define a bunch of long lists, + * so it's easier to read stuff when they are moved elsewhere. + */ +public interface Enums { + Enchantment[] getEnchantments(); + + EntityType[] getEntityTypes(); + + LootTables[] getLootTables(); + + PotionEffectType[] getPotionEffects(); + + Sound[] getSounds(); + + Biome[] getBiomes(); +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockCommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockCommandAPIBukkitConfig.java new file mode 100644 index 0000000000..fb0d6ba501 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockCommandAPIBukkitConfig.java @@ -0,0 +1,19 @@ +package dev.jorel.commandapi.test; + +import dev.jorel.commandapi.CommandAPIBukkitConfig; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * An implementation of {@link CommandAPIBukkitConfig} for the test environment. + * Not made specifically for Spigot or Paper. + */ +public class MockCommandAPIBukkitConfig extends CommandAPIBukkitConfig { + public MockCommandAPIBukkitConfig(JavaPlugin plugin) { + super(plugin); + } + + @Override + public MockCommandAPIBukkitConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockInternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockInternalBukkitConfig.java new file mode 100644 index 0000000000..19def56485 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockInternalBukkitConfig.java @@ -0,0 +1,13 @@ +package dev.jorel.commandapi.test; + +import dev.jorel.commandapi.InternalBukkitConfig; + +/** + * An implementation of {@link InternalBukkitConfig} for the test environment. + * Not made specifically for Spigot or Paper. + */ +public class MockInternalBukkitConfig extends InternalBukkitConfig { + public MockInternalBukkitConfig(MockCommandAPIBukkitConfig config) { + super(config); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java index 98931d39e8..e2e888e8ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java @@ -1,42 +1,49 @@ package dev.jorel.commandapi.test; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.ParsedArgument; +import dev.jorel.commandapi.*; +import dev.jorel.commandapi.commandsenders.*; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import org.bukkit.*; +import org.bukkit.command.*; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.ItemFactory; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.mockito.Mockito; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.security.CodeSource; +import java.util.*; import java.util.jar.JarFile; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.bukkit.Keyed; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Registry; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFactory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.context.ParsedArgument; - -import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.wrappers.ParticleData; +/** + * An implementation of {@link CommandAPIBukkit} for the test environment. + * Not made specifically for Spigot or Paper. + */ +public abstract class MockPlatform extends CommandAPIBukkit implements Enums { + // TODO: Does this work here, or is it actually version-specific? + static { + CodeSource src = PotionEffectType.class.getProtectionDomain().getCodeSource(); + if (src != null) { + System.err.println("Loading PotionEffectType sources from " + src.getLocation()); + } + } -public abstract class MockPlatform extends CommandAPIBukkit { /***************** * Instantiation * *****************/ @@ -53,13 +60,54 @@ protected MockPlatform() { MockPlatform.instance = this; } else { // wtf why was this called twice? + throw new IllegalStateException("MockPlatform loaded twice? I don't think this should happen!"); } + + setInstance(this); } public static void unload() { MockPlatform.instance = null; } + /*********** + * NMS Spy * + ***********/ + + protected void createNMSSpy(NMS baseNMS) { + // Set up a Mockito spy + // We want to forward most methods to the original implementation so we + // can test that code, but we need to override some methods to help them + // play nice with MockBukkit. + NMS spy = Mockito.spy(baseNMS); + + // Version-specific setup + setupNMSSpy(spy); + + // General setup + // Ignore, nothing to do here + Mockito.doNothing().when(spy).reloadDataPacks(); + + // Stub in our getMinecraftServer implementation + Mockito.doAnswer(i -> getMinecraftServer()).when(spy).getMinecraftServer(); + // Stub in our getSimpleCommandMap implementation + // nms throws a class cast exception (`CraftServer` vs `CommandAPIServerMock`) + Mockito.doAnswer(i -> getSimpleCommandMap()).when(spy).getSimpleCommandMap(); + // Stub in our getHelpMap implementation + // nms throws a class cast exception (`SimpleHelpMap` vs `HelpMapMock`) + Mockito.doAnswer(i -> getHelpMap()).when(spy).getHelpMap(); + + this.nms = spy; + } + + protected abstract void setupNMSSpy(NMS spy); + + public abstract T getMinecraftServer(); + + public abstract SimpleCommandMap getSimpleCommandMap(); + + public abstract Map getHelpMap(); + /************************************ * CommandAPIBukkit implementations * ************************************/ @@ -75,29 +123,72 @@ public CommandDispatcher getMockResourcesDispatcher() { return resourcesDispatcher; } + private static void setInternalConfig(InternalBukkitConfig config) { + CommandAPIBukkit.config = config; + } + @Override - public final String convert(ItemStack is) { - throw new UnimplementedError(); + public void onLoad(CommandAPIConfig config) { + if (config instanceof MockCommandAPIBukkitConfig mockConfig) { + setInternalConfig(new MockInternalBukkitConfig(mockConfig)); + } else { + CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); + CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + } + super.onLoad(); } + // Below is copied from Spigot @Override - public final String convert(ParticleData particle) { - throw new UnimplementedError(); + public void onEnable() { + JavaPlugin plugin = getConfiguration().getPlugin(); + + Bukkit.getScheduler().runTaskLater(plugin, () -> { + // Sort out permissions after the server has finished registering them all + getCommandRegistrationStrategy().runTasksAfterServerStart(); + if (!getConfiguration().skipReloadDatapacks()) { + reloadDataPacks(); + } + updateHelpForCommands(CommandAPI.getRegisteredCommands()); + }, 0L); + + super.stopCommandRegistrations(); } @Override - public final String convert(PotionEffectType potion) { - throw new UnimplementedError(); + public CommandMap getCommandMap() { + return getSimpleCommandMap(); } @Override - public final String convert(Sound sound) { - throw new UnimplementedError(); + public Platform activePlatform() { + return Platform.SPIGOT; } @Override - public final void reloadDataPacks() { - assert true; // Nothing to do here + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); } /****************** @@ -114,7 +205,7 @@ public static Object getField(Class className, String fieldName, String mojan field.setAccessible(true); return field.get(instance); } catch (ReflectiveOperationException e) { - return null; + throw new IllegalStateException("Reflection failed :(", e); } } @@ -128,7 +219,7 @@ public static void setField(Class className, String fieldName, String mojangM field.setAccessible(true); field.set(instance, value); } catch (ReflectiveOperationException e) { - e.printStackTrace(); + throw new IllegalStateException("Reflection failed :(", e); } } @@ -142,7 +233,7 @@ public static T getFieldAs(Class className, String fieldName, String moja field.setAccessible(true); return asType.cast(field.get(instance)); } catch (ReflectiveOperationException e) { - return null; + throw new IllegalStateException("Reflection failed :(", e); } } @@ -159,7 +250,7 @@ public static T forceGetArgument(CommandContext cmdCtx, String key) { public abstract ItemFactory getItemFactory(); public abstract org.bukkit.advancement.Advancement addAdvancement(NamespacedKey key); - + public abstract void addFunction(NamespacedKey key, List commands); public abstract void addTag(NamespacedKey key, List> commands); @@ -168,12 +259,12 @@ public static T forceGetArgument(CommandContext cmdCtx, String key) { /** * Converts 1.16.5 and below potion effect names to NamespacedKey names. For * example, converts "effect.minecraft.speed" into "minecraft:speed" - * + * * @param potionEffectType the potion effect to get the namespaced key for * @return a Minecraft namespaced key name for a potion effect */ public abstract String getBukkitPotionEffectTypeName(PotionEffectType potionEffectType); - + public abstract String getNMSParticleNameFromBukkit(Particle particle); // Overrideable @@ -228,29 +319,6 @@ public final List> getRecipes(Class minecraftServerC return list; } - - @SuppressWarnings("serial") - private static class UnimplementedError extends Error { - public UnimplementedError() { - super("Unimplemented"); - } - } - - /*********************** - * Bukkit "enum" lists * - ***********************/ - - public abstract org.bukkit.enchantments.Enchantment[] getEnchantments(); - - public abstract org.bukkit.entity.EntityType[] getEntityTypes(); - - public abstract org.bukkit.loot.LootTables[] getLootTables(); - - public abstract org.bukkit.potion.PotionEffectType[] getPotionEffects(); - - public abstract org.bukkit.Sound[] getSounds(); - - public abstract org.bukkit.block.Biome[] getBiomes(); /** * @return A list of all item names, sorted in alphabetical order. Each item @@ -299,5 +367,4 @@ public Iterator iterator() { } }; } - } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java new file mode 100644 index 0000000000..f84036c325 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/TestVersionHandler.java @@ -0,0 +1,17 @@ +package dev.jorel.commandapi.test; + +/** + * This file handles loading the correct test implementation. The TestVersionHandler file + * within the commandapi-bukkit-test-impl module is NOT used at run time. Instead, the + * test-impl modules replace this class with their own version that loads the correct class. + */ +public abstract class TestVersionHandler { + + /** + * @return An implementation of {@link MockPlatform} that works for the current test version. + */ + public static MockPlatform getMockPlatform() { + throw new IllegalStateException("Wrong version of TestVersionHandler loaded! " + + "Make sure you are using commandapi-bukkit-test-impl-[version] instead of commandapi-bukkit-test-impl"); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml index 6f4accb8b6..78f9cc28a4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml @@ -76,21 +76,6 @@ 1.2.9 provided - - org.mockito - mockito-core - 5.11.0 - - - dev.jorel - commandapi-bukkit-test-impl - ${project.version} - - - dev.jorel - commandapi-bukkit-plugin-common - ${project.version} - @@ -107,13 +92,6 @@ 1.4.4 provided - - - - com.github.zafarkhaja - java-semver - 0.9.0 - @@ -170,6 +148,7 @@ + dev.jorel - commandapi-bukkit-test-impl-1.20 + commandapi-bukkit-1.20 + ${project.version} + test + + + dev.jorel + commandapi-bukkit-nms-common ${project.version} test @@ -480,18 +450,21 @@ dev.jorel - commandapi-bukkit-nms-dependency-mojang-mapped + commandapi-bukkit-test-impl-1.20 ${project.version} - pom + mojang-mapped + test dev.jorel - commandapi-bukkit-shade + commandapi-bukkit-1.20 ${project.version} + mojang-mapped + test dev.jorel - commandapi-bukkit-test-impl-1.20 + commandapi-bukkit-nms-common ${project.version} mojang-mapped test @@ -535,11 +508,6 @@ 2.19.0 provided - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.19.4 @@ -589,11 +557,6 @@ ${project.version} pom - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.19.4 @@ -631,11 +594,6 @@ Minecraft_1_19_2 - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.19.2 @@ -674,11 +632,6 @@ Minecraft_1_18 - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.18 @@ -716,11 +669,6 @@ Minecraft_1_17 - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.17 @@ -757,11 +705,6 @@ Minecraft_1_16_5 - - dev.jorel - commandapi-bukkit-shade - ${project.version} - dev.jorel commandapi-bukkit-test-impl-1.16.5 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/Main.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/Main.java index 5b4aaf4461..a936f1c563 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/Main.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/Main.java @@ -20,11 +20,11 @@ public class Main extends JavaPlugin { public void onLoad() { getDataFolder().mkdirs(); CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); - - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(this) - .useLatestNMSVersion(true) // Doesn't matter because we implement CommandAPIVersionHandler here - .silentLogs(true) - .dispatcherFile(new File(getDataFolder(), "command_registration.json")); + + MockCommandAPIBukkitConfig config = new MockCommandAPIBukkitConfig(this) + .useLatestNMSVersion(true) // Doesn't matter because we implement CommandAPIVersionHandler here + .silentLogs(true) + .dispatcherFile(new File(getDataFolder(), "command_registration.json")); if (nbtContainerClass != null && nbtContainerConstructor != null) { config = config.initializeNBTAPI(nbtContainerClass, nbtContainerConstructor); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java index 7bb3280ea1..06e189cd40 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/TestBase.java @@ -40,7 +40,6 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIVersionHandler; import dev.jorel.commandapi.MCVersion; -import dev.jorel.commandapi.PaperImplementations; import dev.jorel.commandapi.SafeVarHandle; import dev.jorel.commandapi.executors.PlayerCommandExecutor; @@ -90,7 +89,6 @@ public void tearDown() { public void enableServer() { // Run the CommandAPI's enable tasks assertTrue(CommandAPI.canRegister(), "Server was already enabled! Cannot enable twice!"); - disablePaperImplementations(); Bukkit.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP)); assertDoesNotThrow(() -> server.getScheduler().performOneTick()); assertFalse(CommandAPI.canRegister()); @@ -183,10 +181,6 @@ public void compareLists(Collection list1, Collection list2) { System.out.println("List 2 has the following extra items: " + s2_2); } - public static void disablePaperImplementations() { - MockPlatform.setField(PaperImplementations.class, "isPaperPresent", MockPlatform.get().getPaper(), false); - } - /*************** * Suggestions * ***************/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdventureChatColorTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdventureChatColorTests.java deleted file mode 100644 index ae61e52355..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdventureChatColorTests.java +++ /dev/null @@ -1,92 +0,0 @@ -package dev.jorel.commandapi.test.arguments; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.AdventureChatColorArgument; -import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.test.Mut; -import dev.jorel.commandapi.test.TestBase; -import net.kyori.adventure.text.format.NamedTextColor; - -/** - * Tests for the {@link AdventureChatColorArgument} - */ -class ArgumentAdventureChatColorTests extends TestBase { - - /********* - * Setup * - *********/ - - @BeforeEach - public void setUp() { - super.setUp(); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - /********* - * Tests * - *********/ - - @SuppressWarnings("unused") - @Test - void executionTestWithChatColorArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new AdventureChatColorArgument("color")) - .executesPlayer((player, args) -> { - results.set((NamedTextColor) args.get(0)); - }) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // The list of 16 chat colors - for (String str : new String[] { - "black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", - "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", - "yellow", "white" - }) { - server.dispatchCommand(player, "test " + str); - assertEquals(NamedTextColor.NAMES.value(str), results.get()); - } - - // /test reset - server.dispatchCommand(player, "test reset"); - assertEquals(NamedTextColor.WHITE, results.get()); - - assertNoMoreResults(results); - } - - /******************** - * Suggestion tests * - ********************/ - - @Test - void suggestionTestWithChatColorArgument() { - new CommandAPICommand("test") - .withArguments(new AdventureChatColorArgument("color")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test d - assertEquals(List.of("dark_aqua", "dark_blue", "dark_gray", "dark_green", "dark_purple", "dark_red"), server.getSuggestions(player, "test d")); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatColorTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatColorTests.java deleted file mode 100644 index 10657d35ba..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatColorTests.java +++ /dev/null @@ -1,116 +0,0 @@ -package dev.jorel.commandapi.test.arguments; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.MCVersion; -import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.test.Mut; -import dev.jorel.commandapi.test.TestBase; - -/** - * Tests for the {@link ChatColorArgument} - */ -class ArgumentChatColorTests extends TestBase { - - /********* - * Setup * - *********/ - - @BeforeEach - public void setUp() { - super.setUp(); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - /********* - * Tests * - *********/ - - @SuppressWarnings("unused") - @Test - void executionTestWithChatColorArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new ChatColorArgument("color")) - .executesPlayer((player, args) -> { - results.set((ChatColor) args.get(0)); - }) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // The list of 16 chat colors - all16ChatColors: { - int numberOfColors = 0; - for(ChatColor color : ChatColor.values()) { - if(color.isColor()) { - server.dispatchCommand(player, "test " + color.name().toLowerCase()); - assertEquals(color, results.get()); - numberOfColors++; - } - } - - assertEquals(16, numberOfColors); - } - - // /test reset - server.dispatchCommand(player, "test reset"); - assertEquals(ChatColor.RESET, results.get()); - - // /test - // Fails because only 'reset' and the 16 chat colors are permitted - for(ChatColor color : ChatColor.values()) { - if(color.isFormat() && !color.equals(ChatColor.RESET)) { - String colorName = color.name().toLowerCase(); - if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) { - final String command = "test " + colorName; - final int errorPosition = command.length(); - final String truncatedCommand; - if (command.length() > 10) { - truncatedCommand = "..." + command.substring(command.length() - 10, command.length()); - } else { - truncatedCommand = command; - } - assertCommandFailsWith(player, command, String.format("Unknown color '%s' at position %d: %s<--[HERE]", colorName, errorPosition, truncatedCommand)); - } else { - assertCommandFailsWith(player, "test " + colorName, "Unknown color '" + colorName + "'"); - } - } - } - - assertNoMoreResults(results); - } - - /******************** - * Suggestion tests * - ********************/ - - @Test - void suggestionTestWithChatColorArgument() { - new CommandAPICommand("test") - .withArguments(new ChatColorArgument("color")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test d - assertEquals(List.of("dark_aqua", "dark_blue", "dark_gray", "dark_green", "dark_purple", "dark_red"), server.getSuggestions(player, "test d")); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatComponentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatComponentTests.java deleted file mode 100644 index dfa4ffceb1..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatComponentTests.java +++ /dev/null @@ -1,190 +0,0 @@ -package dev.jorel.commandapi.test.arguments; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.MCVersion; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; -import dev.jorel.commandapi.test.Mut; -import dev.jorel.commandapi.test.TestBase; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; - -/** - * Tests for the {@link ChatComponentArgument} and {@link AdventureChatComponentArgument} - */ -class ArgumentChatComponentTests extends TestBase { - - /********* - * Setup * - *********/ - - @BeforeEach - public void setUp() { - super.setUp(); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - final String json = "[\"%s\"]".formatted(""" - ["", { - "text": "Once upon a time, there was a guy " - }, { - "text": "Skepter", - "color": "light_purple", - "hoverEvent": { - "action": "show_entity", - "value": "Skepter" - } - }, { - "text": " and he created the " - }, { - "text": "CommandAPI", - "underlined": true, - "clickEvent": { - "action": "open_url", - "value": "https://github.com/JorelAli/CommandAPI" - } - }] - """.stripIndent().replace("\n", "").replace("\r", "").replace("\"", "\\\"")); - - // The above, in normal human-readable JSON gets turned into this for command purposes: - // [\"[\\\"\\\",{\\\"text\\\":\\\"Once upon a time, there was a guy call \\\"},{\\\"text\\\":\\\"Skepter\\\",\\\"color\\\":\\\"light_purple\\\",\\\"hoverEvent\\\":{\\\"action\\\":\\\"show_entity\\\",\\\"value\\\":\\\"Skepter\\\"}},{\\\"text\\\":\\\" and he created the \\\"},{\\\"text\\\":\\\"CommandAPI\\\",\\\"underlined\\\":true,\\\"clickEvent\\\":{\\\"action\\\":\\\"open_url\\\",\\\"value\\\":\\\"https://github.com/JorelAli/CommandAPI\\\"}}]\"] - - /********* - * Tests * - *********/ - - @Test - void executionTestWithSpigotChatComponentArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new ChatComponentArgument("text")) - .executesPlayer((player, args) -> { - results.set((BaseComponent[]) args.get(0)); - }) - .register(); - - PlayerMock player = server.addPlayer("Skepter"); - - // /test [\"[\\\"\\\",{\\\"text ... /CommandAPI\\\"}}]\"] - // Dev note: See comment at top of file - server.dispatchCommand(player, "test " + json); - assertArrayEquals(ComponentSerializer.parse(json), results.get()); - - // /test [] - // Fails due to invalid JSON for a chat component - if (version.lessThan(MCVersion.V1_18)) { - assertCommandFailsWith(player, "test []", "Invalid chat component: empty at position 8: test []<--[HERE]"); - } else if(version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertCommandFailsWith(player, "test []", "Invalid chat component: Not a JSON object: [] at position 8: test []<--[HERE]"); - } else { - assertCommandFailsWith(player, "test []", "Invalid chat component: Invalid chat component: empty at position 8: test []<--[HERE] at position 8: test []<--[HERE]"); - } - - // /test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"] - // Fails due to inner quotes not being escaped with a \ character - if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 11: ...est [\"[\"\",<--[HERE]"); - } else { - assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 5: test <--[HERE]"); - } - - assertNoMoreResults(results); - } - - @Test - void executionTestWithAdventureChatComponentArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new AdventureChatComponentArgument("text")) - .executesPlayer((player, args) -> { - results.set((Component) args.get(0)); - }) - .register(); - - PlayerMock player = server.addPlayer("Skepter"); - - // /test [\"[\\\"\\\",{\\\"text ... /CommandAPI\\\"}}]\"] - // Dev note: See comment at top of file - server.dispatchCommand(player, "test " + json); - assertEquals(GsonComponentSerializer.gson().deserialize(json), results.get()); - - // /test [] - // Fails due to invalid JSON for a chat component - if (version.lessThan(MCVersion.V1_18)) { - assertCommandFailsWith(player, "test []", "Invalid chat component: empty at position 8: test []<--[HERE]"); - } else if(version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertCommandFailsWith(player, "test []", "Invalid chat component: Not a JSON object: [] at position 8: test []<--[HERE]"); - } else { - assertCommandFailsWith(player, "test []", "Invalid chat component: Invalid chat component: empty at position 8: test []<--[HERE] at position 8: test []<--[HERE]"); - } - - // /test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"] - // Fails due to inner quotes not being escaped with a \ character - if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 11: ...est [\"[\"\",<--[HERE]"); - } else { - assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 5: test <--[HERE]"); - } - - assertNoMoreResults(results); - } - - /******************** - * Suggestion tests * - ********************/ - - @Test - void suggestionTestWithSpigotChatComponentArgument() { - new CommandAPICommand("test") - .withArguments(new ChatComponentArgument("text")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // The ChatComponentArgument doesn't have any suggestions - assertEquals(List.of(), server.getSuggestions(player, "test ")); - - // /test [ - // The ChatComponentArgument doesn't have any suggestions - assertEquals(List.of(), server.getSuggestions(player, "test [")); - } - - @Test - void suggestionTestWithAdventureChatComponentArgument() { - new CommandAPICommand("test") - .withArguments(new AdventureChatComponentArgument("text")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // The ChatComponentArgument doesn't have any suggestions - assertEquals(List.of(), server.getSuggestions(player, "test ")); - - // /test [ - // The ChatComponentArgument doesn't have any suggestions - assertEquals(List.of(), server.getSuggestions(player, "test [")); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatTests.java deleted file mode 100644 index 4a4d3c8bb1..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatTests.java +++ /dev/null @@ -1,175 +0,0 @@ -package dev.jorel.commandapi.test.arguments; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import java.util.List; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.MCVersion; -import dev.jorel.commandapi.arguments.AdventureChatArgument; -import dev.jorel.commandapi.arguments.ChatArgument; -import dev.jorel.commandapi.test.Mut; -import dev.jorel.commandapi.test.TestBase; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.chat.ComponentSerializer; - -/** - * Tests for the {@link ChatArgument} and {@link AdventureChatArgument} - */ -class ArgumentChatTests extends TestBase { - - /********* - * Setup * - *********/ - - @BeforeEach - public void setUp() { - super.setUp(); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - /********* - * Tests * - *********/ - - @Test - void executionTestWithSpigotChatArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new ChatArgument("chat")) - .executesPlayer((player, args) -> { - results.set((BaseComponent[]) args.get("chat")); - }) - .register(); - - PlayerMock player = server.addPlayer("APlayer"); - player.setOp(true); - - BaseComponent expected = new TextComponent("Hello, "); - expected.addExtra(new TextComponent("APlayer")); - expected.addExtra(new TextComponent("!")); - - // /test Hello, @p! - server.dispatchCommand(player, "test Hello, @p!"); - assertArrayEquals(new BaseComponent[] { expected }, results.get()); - - assertNoMoreResults(results); - } - - @Test - void executionTestWithAdventureChatArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new AdventureChatArgument("chat")) - .executesPlayer((player, args) -> { - results.set((Component) args.get("chat")); - }) - .register(); - - PlayerMock player = server.addPlayer("APlayer"); - player.setOp(true); - - // /test Hello, @p! - server.dispatchCommand(player, "test Hello, @p!"); - assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, \",\"APlayer\",\"!\"]"), results.get()); - - assertNoMoreResults(results); - } - - @Test - void executionTestWithSpigotChatArgumentNoOp() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new ChatArgument("chat")) - .executesPlayer((player, args) -> { - results.set((BaseComponent[]) args.get("chat")); - }) - .register(); - - PlayerMock player = server.addPlayer("APlayer"); - - // /test Hello, APlayer! - server.dispatchCommand(player, "test Hello, APlayer!"); - assertArrayEquals(ComponentSerializer.parse("[\"Hello, APlayer!\"]"), results.get()); - - // /test Hello, @p! - server.dispatchCommand(player, "test Hello, @p!"); - assertArrayEquals(ComponentSerializer.parse("[\"Hello, @p!\"]"), results.get()); - - assertNoMoreResults(results); - } - - @Test - void executionTestWithAdventureChatArgumentNoOp() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(new AdventureChatArgument("chat")) - .executesPlayer((player, args) -> { - results.set((Component) args.get("chat")); - }) - .register(); - - PlayerMock player = server.addPlayer("APlayer"); - - // /test Hello, APlayer! - server.dispatchCommand(player, "test Hello, APlayer!"); - assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, APlayer!\"]"), results.get()); - - // /test Hello, @p! - server.dispatchCommand(player, "test Hello, @p!"); - assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, @p!\"]"), results.get()); - - assertNoMoreResults(results); - } - - /******************** - * Suggestion tests * - ********************/ - - @Test - void suggestionTestWithSpigotChatArgument() { - new CommandAPICommand("test") - .withArguments(new ChatArgument("chat")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // Should suggest nothing - assertEquals(List.of(), server.getSuggestions(player, "test ")); - } - - @Test - void suggestionTestWithAdventureChatArgument() { - new CommandAPICommand("test") - .withArguments(new AdventureChatArgument("chat")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test - // Should suggest nothing - assertEquals(List.of(), server.getSuggestions(player, "test ")); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCustomTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCustomTests.java deleted file mode 100644 index b74b7e7e11..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCustomTests.java +++ /dev/null @@ -1,191 +0,0 @@ -package dev.jorel.commandapi.test.arguments; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import com.mojang.brigadier.context.CommandContext; - -import be.seeseemelk.mockbukkit.WorldMock; -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder; -import dev.jorel.commandapi.arguments.LiteralArgument; -import dev.jorel.commandapi.arguments.MultiLiteralArgument; -import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.test.Mut; -import dev.jorel.commandapi.test.TestBase; -import net.kyori.adventure.text.Component; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ComponentBuilder; - -/** - * Tests for the {@link CustomArgument} - */ -class ArgumentCustomTests extends TestBase { - - /********* - * Setup * - *********/ - - @BeforeEach - public void setUp() { - super.setUp(); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - // From the documentation - public Argument customWorldArgument(String nodeName) { - return new CustomArgument(new StringArgument(nodeName), info -> { - World world = Bukkit.getWorld(info.input()); - if (world == null) { - throw CustomArgumentException.fromMessageBuilder(new MessageBuilder("Unknown world: ").appendArgInput()); - } else { - return world; - } - }).replaceSuggestions(ArgumentSuggestions.strings(info -> Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new))); - } - - public Argument customArgumentThatThrowsException(String nodeName) { - return new CustomArgument(new StringArgument(nodeName), info -> { - throw new RuntimeException("👻 Spoopy Exception 👻"); - }); - } - - /********* - * Tests * - *********/ - - @Test - void executionTestWithCustomWorldArgument() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(customWorldArgument("world")) - .executesPlayer((player, args) -> { - results.set(args.getUnchecked(0)); - }) - .register(); - - PlayerMock player = server.addPlayer(); - - WorldMock world1 = server.addSimpleWorld("world1"); - server.addSimpleWorld("world2"); - server.addSimpleWorld("world3"); - - // /test unknownworld - assertCommandFailsWith(player, "test unknownworld", "Unknown world: unknownworld"); - - // /test world1 - server.dispatchCommand(player, "test world1"); - assertEquals(world1, results.get()); - - assertNoMoreResults(results); - } - - @Test - void executionTestWithCustomArgumentThatThrowsException() { - Mut results = Mut.of(); - - new CommandAPICommand("test") - .withArguments(customArgumentThatThrowsException("world")) - .executesPlayer((player, args) -> { - results.set(args.getUnchecked(0)); - }) - .register(); - - PlayerMock player = server.addPlayer(); - - // /test world - assertCommandFailsWith(player, "test world", "Error in executing command test world - world<--[HERE]"); - - assertNoMoreResults(results); - } - - /******************** - * Suggestion tests * - ********************/ - - @Test - void suggestionTestWithCustomWorldArgument() { - new CommandAPICommand("test") - .withArguments(customWorldArgument("world")) - .executesPlayer(P_EXEC) - .register(); - - PlayerMock player = server.addPlayer(); - - server.addSimpleWorld("world1"); - server.addSimpleWorld("world2"); - server.addSimpleWorld("world3"); - - // /test - // We expect to see "world" because that's the default world - assertEquals(List.of("world", "world1", "world2", "world3"), server.getSuggestions(player, "test ")); - } - - /*********************** - * Instantiation tests * - ***********************/ - - @Test - void instantiationTestWithLiteralCustomArgument() { - // LiteralArgument - LiteralArgument literalArgument = new LiteralArgument("world"); - - assertThrows(IllegalArgumentException.class, () -> { - new CustomArgument<>(literalArgument, info -> 1); - }); - - // MultiLiteralArgument - MultiLiteralArgument multiLiteralArgument = new MultiLiteralArgument("node", List.of("hello", "world")); - - assertThrows(IllegalArgumentException.class, () -> { - new CustomArgument<>(multiLiteralArgument, info -> 1); - }); - } - - @Test - void instantiationTestWithCustomArgumentException() { - final String result = "result"; - @SuppressWarnings("unchecked") - final CommandContext context = Mockito.mock(CommandContext.class); - Mockito.when(context.getInput()).thenReturn("input"); - - // String - assertDoesNotThrow(() -> CustomArgumentException.fromString("hello").toCommandSyntax(result, context)); - - // BaseComponents - BaseComponent[] baseComponents = new ComponentBuilder("hello").create(); - - assertDoesNotThrow(() -> CustomArgumentException.fromBaseComponents(baseComponents).toCommandSyntax(result, context)); - - // Adventure Components - Component adventureComponent = Component.text("hello"); - - assertDoesNotThrow(() -> CustomArgumentException.fromAdventureComponent(adventureComponent).toCommandSyntax(result, context)); - - // Null values - assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromString(null).toCommandSyntax(result, context)); - assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromBaseComponents(null).toCommandSyntax(result, context)); - assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromAdventureComponent(null).toCommandSyntax(result, context)); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ArgumentSuggestionTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ArgumentSuggestionTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ArgumentSuggestionTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ArgumentSuggestionTests.java index c13b04125c..e8776c0a28 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ArgumentSuggestionTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ArgumentSuggestionTests.java @@ -1,9 +1,10 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.entity.Player; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandArgumentsTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandArgumentsTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandArgumentsTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandArgumentsTests.java index c36ee65638..ee35fdc6b1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandArgumentsTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandArgumentsTests.java @@ -1,8 +1,10 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.*; +import dev.jorel.commandapi.test.Mut; +import dev.jorel.commandapi.test.TestBase; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTests.java similarity index 93% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTests.java index c4d5c144dd..6c33e57af1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTests.java @@ -1,7 +1,8 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import static org.junit.jupiter.api.Assertions.assertEquals; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.plugin.java.JavaPlugin; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTestsPlugin.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTestsPlugin.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTestsPlugin.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTestsPlugin.java index 7d4f94cce9..fc8b620e13 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandConvertedTestsPlugin.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandConvertedTestsPlugin.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandExecutionTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandExecutionTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandExecutionTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandExecutionTests.java index 77026a694b..0f28f0d4e1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandExecutionTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandExecutionTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import java.util.Arrays; import java.util.LinkedHashMap; @@ -8,6 +8,8 @@ import java.util.function.Function; import java.util.function.Supplier; +import dev.jorel.commandapi.test.Mut; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandHelpTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandHelpTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandHelpTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandHelpTests.java index 16be82cfb9..8a8c9999b4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandHelpTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandHelpTests.java @@ -1,8 +1,9 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandNamespaceTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandNamespaceTests.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandNamespaceTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandNamespaceTests.java index 78839318d6..cf3bf67843 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandNamespaceTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandNamespaceTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; @@ -7,6 +7,7 @@ import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.LiteralArgument; import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.test.*; import org.bukkit.ChatColor; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; @@ -928,60 +929,60 @@ public void testPermissionsWithCommandNameConflictButDifferentNamespace(boolean @Test public void testConfigNamespace() { - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()); - InternalBukkitConfig internalConfig = new InternalBukkitConfig(config); + MockCommandAPIBukkitConfig config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()); + InternalBukkitConfig internalConfig = new MockInternalBukkitConfig(config); // The namespace wasn't changed so it should default to minecraft assertEquals("minecraft", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()); - CommandAPIBukkitConfig finalConfig = config; + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()); + MockCommandAPIBukkitConfig finalConfig = config; // The namespace is set to null, this should throw a NPE assertThrows(NullPointerException.class, () -> finalConfig.setNamespace(null)); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .setNamespace(""); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace was set to an empty namespace so this should result in the default minecraft namespace assertEquals("minecraft", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .setNamespace("custom"); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace was set to a non-empty, non-null custom namespace, this should be valid assertEquals("custom", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .usePluginNamespace(); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace was set to use the plugin name as the namespace, this should be valid assertEquals("commandapitest", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .setNamespace("custom") .usePluginNamespace(); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace was first set to a custom one, then was set to use the plugin name. This should be valid and the plugin name should be the namespace assertEquals("commandapitest", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .setNamespace("custom") .usePluginNamespace() .setNamespace("custom"); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace was first set to a custom one, then was set to use the plugin name, then was set to use a custom one // usePluginNamespace() should take priority and the plugin name should be the namespace assertEquals("commandapitest", internalConfig.getNamespace()); - config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) + config = new MockCommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin()) .setNamespace("Custom"); - internalConfig = new InternalBukkitConfig(config); + internalConfig = new MockInternalBukkitConfig(config); // The namespace uses invalid characters so the namespace should default to minecraft assertEquals("minecraft", internalConfig.getNamespace()); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandPermissionTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandPermissionTests.java similarity index 95% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandPermissionTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandPermissionTests.java index 226c43f8f3..d4b7c4b150 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandPermissionTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandPermissionTests.java @@ -1,7 +1,9 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import static org.junit.jupiter.api.Assertions.assertTrue; +import dev.jorel.commandapi.test.Mut; +import dev.jorel.commandapi.test.TestBase; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandRegistrationTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandRegistrationTests.java index 3014cd0de7..d7464ecdf5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandRegistrationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandRegistrationTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandAPIHandler; @@ -10,6 +10,7 @@ import dev.jorel.commandapi.exceptions.GreedyArgumentException; import dev.jorel.commandapi.exceptions.InvalidCommandNameException; import dev.jorel.commandapi.exceptions.MissingCommandExecutorException; +import dev.jorel.commandapi.test.TestBase; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandUnregisterTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandUnregisterTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandUnregisterTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandUnregisterTests.java index 9fe49d7c42..e780892393 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandUnregisterTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/CommandUnregisterTests.java @@ -1,10 +1,12 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.test.Mut; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; @@ -111,7 +113,6 @@ static class BRIG_TREE { @BeforeEach public void setUp() { super.setUp(); - disablePaperImplementations(); player = server.addPlayer(); @@ -131,7 +132,7 @@ public void setUp() { assertStoresResult(player, "minecraft:test word", vanillaResults, "word"); // Set up a Bukkit command - commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); bukkitResults = Mut.of(); bukkitCommand = new Command("test") { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ConfigGenerationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ConfigGenerationTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ConfigGenerationTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ConfigGenerationTests.java index e4b1df1c67..cb832a148b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ConfigGenerationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ConfigGenerationTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import dev.jorel.commandapi.config.BukkitConfigurationAdapter; import dev.jorel.commandapi.config.CommentedConfigOption; @@ -12,7 +12,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/OnEnableTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/OnEnableTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/OnEnableTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/OnEnableTests.java index 587faa4f95..4f65c2125d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/OnEnableTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/OnEnableTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import be.seeseemelk.mockbukkit.entity.PlayerMock; import com.mojang.brigadier.tree.RootCommandNode; @@ -7,6 +7,9 @@ import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.SpigotCommandRegistration; import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.test.MockPlatform; +import dev.jorel.commandapi.test.Mut; +import dev.jorel.commandapi.test.TestBase; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.SimpleCommandMap; @@ -125,7 +128,7 @@ void testOnEnableRegisterAndUnregisterCommand() { }""", getDispatcherString()); // Make sure command and its aliases exist in the Bukkit CommandMap - SimpleCommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + SimpleCommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); SpigotCommandRegistration spigotCommandRegistration = (SpigotCommandRegistration) CommandAPIBukkit.get().getCommandRegistrationStrategy(); Command mainCommand = commandMap.getCommand("command"); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ResultingCommandTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ResultingCommandTests.java similarity index 68% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ResultingCommandTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ResultingCommandTests.java index 09cce431c0..6eb2b779d6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ResultingCommandTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/ResultingCommandTests.java @@ -1,24 +1,15 @@ -package dev.jorel.commandapi.test; +package dev.jorel.commandapi.test.tests; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; - +import dev.jorel.commandapi.test.TestBase; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.arguments.GreedyStringArgument; -import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.exceptions.GreedyArgumentException; -import dev.jorel.commandapi.exceptions.InvalidCommandNameException; -import dev.jorel.commandapi.exceptions.MissingCommandExecutorException; /** * Tests for commands with resulting command executors diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdvancementTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdvancementTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdvancementTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdvancementTests.java index 3ae1d0860c..192108b063 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAdvancementTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdvancementTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdventureChatColorTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdventureChatColorTests.java new file mode 100644 index 0000000000..06b91b1e79 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAdventureChatColorTests.java @@ -0,0 +1,93 @@ +// TODO: Move chat arguments to spigot/paper tests +//package dev.jorel.commandapi.test.tests.arguments; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +// +//import java.util.List; +// +//import org.bukkit.ChatColor; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +// +//import be.seeseemelk.mockbukkit.entity.PlayerMock; +//import dev.jorel.commandapi.CommandAPICommand; +//import dev.jorel.commandapi.arguments.AdventureChatColorArgument; +//import dev.jorel.commandapi.arguments.ChatColorArgument; +//import dev.jorel.commandapi.test.Mut; +//import dev.jorel.commandapi.test.TestBase; +//import net.kyori.adventure.text.format.NamedTextColor; +// +///** +// * Tests for the {@link AdventureChatColorArgument} +// */ +//class ArgumentAdventureChatColorTests extends TestBase { +// +// /********* +// * Setup * +// *********/ +// +// @BeforeEach +// public void setUp() { +// super.setUp(); +// } +// +// @AfterEach +// public void tearDown() { +// super.tearDown(); +// } +// +// /********* +// * Tests * +// *********/ +// +// @SuppressWarnings("unused") +// @Test +// void executionTestWithChatColorArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new AdventureChatColorArgument("color")) +// .executesPlayer((player, args) -> { +// results.set((NamedTextColor) args.get(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // The list of 16 chat colors +// for (String str : new String[] { +// "black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", +// "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", +// "yellow", "white" +// }) { +// server.dispatchCommand(player, "test " + str); +// assertEquals(NamedTextColor.NAMES.value(str), results.get()); +// } +// +// // /test reset +// server.dispatchCommand(player, "test reset"); +// assertEquals(NamedTextColor.WHITE, results.get()); +// +// assertNoMoreResults(results); +// } +// +// /******************** +// * Suggestion tests * +// ********************/ +// +// @Test +// void suggestionTestWithChatColorArgument() { +// new CommandAPICommand("test") +// .withArguments(new AdventureChatColorArgument("color")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test d +// assertEquals(List.of("dark_aqua", "dark_blue", "dark_gray", "dark_green", "dark_purple", "dark_red"), server.getSuggestions(player, "test d")); +// } +// +//} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAngleTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAngleTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAngleTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAngleTests.java index db20dc57fd..ab71a8148f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAngleTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAngleTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAxisTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAxisTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAxisTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAxisTests.java index 36939abd0f..1a2e5a33d4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentAxisTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentAxisTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBiomeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBiomeTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBiomeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBiomeTests.java index 51f1e77b21..72207e1419 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBiomeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBiomeTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockPredicateTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockPredicateTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockPredicateTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockPredicateTests.java index 38f1b3eeea..fb491e69c6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockPredicateTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockPredicateTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockStateTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockStateTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockStateTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockStateTests.java index d88b1b4b5f..42994ce3b7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentBlockStateTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentBlockStateTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatColorTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatColorTests.java new file mode 100644 index 0000000000..e098b2dfb2 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatColorTests.java @@ -0,0 +1,117 @@ +// TODO: Move chat arguments to spigot/paper tests +//package dev.jorel.commandapi.test.tests.arguments; +// +//import static org.junit.jupiter.api.Assertions.assertEquals; +// +//import java.util.List; +// +//import org.bukkit.ChatColor; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +// +//import be.seeseemelk.mockbukkit.entity.PlayerMock; +//import dev.jorel.commandapi.CommandAPICommand; +//import dev.jorel.commandapi.MCVersion; +//import dev.jorel.commandapi.arguments.ChatColorArgument; +//import dev.jorel.commandapi.test.Mut; +//import dev.jorel.commandapi.test.TestBase; +// +///** +// * Tests for the {@link ChatColorArgument} +// */ +//class ArgumentChatColorTests extends TestBase { +// +// /********* +// * Setup * +// *********/ +// +// @BeforeEach +// public void setUp() { +// super.setUp(); +// } +// +// @AfterEach +// public void tearDown() { +// super.tearDown(); +// } +// +// /********* +// * Tests * +// *********/ +// +// @SuppressWarnings("unused") +// @Test +// void executionTestWithChatColorArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new ChatColorArgument("color")) +// .executesPlayer((player, args) -> { +// results.set((ChatColor) args.get(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // The list of 16 chat colors +// all16ChatColors: { +// int numberOfColors = 0; +// for(ChatColor color : ChatColor.values()) { +// if(color.isColor()) { +// server.dispatchCommand(player, "test " + color.name().toLowerCase()); +// assertEquals(color, results.get()); +// numberOfColors++; +// } +// } +// +// assertEquals(16, numberOfColors); +// } +// +// // /test reset +// server.dispatchCommand(player, "test reset"); +// assertEquals(ChatColor.RESET, results.get()); +// +// // /test +// // Fails because only 'reset' and the 16 chat colors are permitted +// for(ChatColor color : ChatColor.values()) { +// if(color.isFormat() && !color.equals(ChatColor.RESET)) { +// String colorName = color.name().toLowerCase(); +// if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) { +// final String command = "test " + colorName; +// final int errorPosition = command.length(); +// final String truncatedCommand; +// if (command.length() > 10) { +// truncatedCommand = "..." + command.substring(command.length() - 10, command.length()); +// } else { +// truncatedCommand = command; +// } +// assertCommandFailsWith(player, command, String.format("Unknown color '%s' at position %d: %s<--[HERE]", colorName, errorPosition, truncatedCommand)); +// } else { +// assertCommandFailsWith(player, "test " + colorName, "Unknown color '" + colorName + "'"); +// } +// } +// } +// +// assertNoMoreResults(results); +// } +// +// /******************** +// * Suggestion tests * +// ********************/ +// +// @Test +// void suggestionTestWithChatColorArgument() { +// new CommandAPICommand("test") +// .withArguments(new ChatColorArgument("color")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test d +// assertEquals(List.of("dark_aqua", "dark_blue", "dark_gray", "dark_green", "dark_purple", "dark_red"), server.getSuggestions(player, "test d")); +// } +// +//} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatComponentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatComponentTests.java new file mode 100644 index 0000000000..9810d6416f --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatComponentTests.java @@ -0,0 +1,191 @@ +// TODO: Move chat arguments to spigot/paper tests +//package dev.jorel.commandapi.test.tests.arguments; +// +//import static org.junit.jupiter.api.Assertions.assertArrayEquals; +//import static org.junit.jupiter.api.Assertions.assertEquals; +// +//import java.util.List; +// +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +// +//import be.seeseemelk.mockbukkit.entity.PlayerMock; +//import dev.jorel.commandapi.CommandAPICommand; +//import dev.jorel.commandapi.MCVersion; +//import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +//import dev.jorel.commandapi.arguments.ChatComponentArgument; +//import dev.jorel.commandapi.test.Mut; +//import dev.jorel.commandapi.test.TestBase; +//import net.kyori.adventure.text.Component; +//import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +//import net.md_5.bungee.api.chat.BaseComponent; +//import net.md_5.bungee.chat.ComponentSerializer; +// +///** +// * Tests for the {@link ChatComponentArgument} and {@link AdventureChatComponentArgument} +// */ +//class ArgumentChatComponentTests extends TestBase { +// +// /********* +// * Setup * +// *********/ +// +// @BeforeEach +// public void setUp() { +// super.setUp(); +// } +// +// @AfterEach +// public void tearDown() { +// super.tearDown(); +// } +// +// final String json = "[\"%s\"]".formatted(""" +// ["", { +// "text": "Once upon a time, there was a guy " +// }, { +// "text": "Skepter", +// "color": "light_purple", +// "hoverEvent": { +// "action": "show_entity", +// "value": "Skepter" +// } +// }, { +// "text": " and he created the " +// }, { +// "text": "CommandAPI", +// "underlined": true, +// "clickEvent": { +// "action": "open_url", +// "value": "https://github.com/JorelAli/CommandAPI" +// } +// }] +// """.stripIndent().replace("\n", "").replace("\r", "").replace("\"", "\\\"")); +// +// // The above, in normal human-readable JSON gets turned into this for command purposes: +// // [\"[\\\"\\\",{\\\"text\\\":\\\"Once upon a time, there was a guy call \\\"},{\\\"text\\\":\\\"Skepter\\\",\\\"color\\\":\\\"light_purple\\\",\\\"hoverEvent\\\":{\\\"action\\\":\\\"show_entity\\\",\\\"value\\\":\\\"Skepter\\\"}},{\\\"text\\\":\\\" and he created the \\\"},{\\\"text\\\":\\\"CommandAPI\\\",\\\"underlined\\\":true,\\\"clickEvent\\\":{\\\"action\\\":\\\"open_url\\\",\\\"value\\\":\\\"https://github.com/JorelAli/CommandAPI\\\"}}]\"] +// +// /********* +// * Tests * +// *********/ +// +// @Test +// void executionTestWithSpigotChatComponentArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new ChatComponentArgument("text")) +// .executesPlayer((player, args) -> { +// results.set((BaseComponent[]) args.get(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("Skepter"); +// +// // /test [\"[\\\"\\\",{\\\"text ... /CommandAPI\\\"}}]\"] +// // Dev note: See comment at top of file +// server.dispatchCommand(player, "test " + json); +// assertArrayEquals(ComponentSerializer.parse(json), results.get()); +// +// // /test [] +// // Fails due to invalid JSON for a chat component +// if (version.lessThan(MCVersion.V1_18)) { +// assertCommandFailsWith(player, "test []", "Invalid chat component: empty at position 8: test []<--[HERE]"); +// } else if(version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { +// assertCommandFailsWith(player, "test []", "Invalid chat component: Not a JSON object: [] at position 8: test []<--[HERE]"); +// } else { +// assertCommandFailsWith(player, "test []", "Invalid chat component: Invalid chat component: empty at position 8: test []<--[HERE] at position 8: test []<--[HERE]"); +// } +// +// // /test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"] +// // Fails due to inner quotes not being escaped with a \ character +// if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { +// assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 11: ...est [\"[\"\",<--[HERE]"); +// } else { +// assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 5: test <--[HERE]"); +// } +// +// assertNoMoreResults(results); +// } +// +// @Test +// void executionTestWithAdventureChatComponentArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new AdventureChatComponentArgument("text")) +// .executesPlayer((player, args) -> { +// results.set((Component) args.get(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("Skepter"); +// +// // /test [\"[\\\"\\\",{\\\"text ... /CommandAPI\\\"}}]\"] +// // Dev note: See comment at top of file +// server.dispatchCommand(player, "test " + json); +// assertEquals(GsonComponentSerializer.gson().deserialize(json), results.get()); +// +// // /test [] +// // Fails due to invalid JSON for a chat component +// if (version.lessThan(MCVersion.V1_18)) { +// assertCommandFailsWith(player, "test []", "Invalid chat component: empty at position 8: test []<--[HERE]"); +// } else if(version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { +// assertCommandFailsWith(player, "test []", "Invalid chat component: Not a JSON object: [] at position 8: test []<--[HERE]"); +// } else { +// assertCommandFailsWith(player, "test []", "Invalid chat component: Invalid chat component: empty at position 8: test []<--[HERE] at position 8: test []<--[HERE]"); +// } +// +// // /test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"] +// // Fails due to inner quotes not being escaped with a \ character +// if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { +// assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 11: ...est [\"[\"\",<--[HERE]"); +// } else { +// assertCommandFailsWith(player, "test [\"[\"\",{\"text\":\"Some text with bad quote escaping\"}\"]", "Invalid chat component: Unterminated array at line 1 column 6 path $[1] at position 5: test <--[HERE]"); +// } +// +// assertNoMoreResults(results); +// } +// +// /******************** +// * Suggestion tests * +// ********************/ +// +// @Test +// void suggestionTestWithSpigotChatComponentArgument() { +// new CommandAPICommand("test") +// .withArguments(new ChatComponentArgument("text")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // The ChatComponentArgument doesn't have any suggestions +// assertEquals(List.of(), server.getSuggestions(player, "test ")); +// +// // /test [ +// // The ChatComponentArgument doesn't have any suggestions +// assertEquals(List.of(), server.getSuggestions(player, "test [")); +// } +// +// @Test +// void suggestionTestWithAdventureChatComponentArgument() { +// new CommandAPICommand("test") +// .withArguments(new AdventureChatComponentArgument("text")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // The ChatComponentArgument doesn't have any suggestions +// assertEquals(List.of(), server.getSuggestions(player, "test ")); +// +// // /test [ +// // The ChatComponentArgument doesn't have any suggestions +// assertEquals(List.of(), server.getSuggestions(player, "test [")); +// } +// +//} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatTests.java new file mode 100644 index 0000000000..9251a62f74 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentChatTests.java @@ -0,0 +1,176 @@ +// TODO: Move chat arguments to spigot/paper tests +//package dev.jorel.commandapi.test.tests.arguments; +// +//import static org.junit.jupiter.api.Assertions.assertArrayEquals; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assumptions.assumeTrue; +// +//import java.util.List; +// +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +// +//import be.seeseemelk.mockbukkit.entity.PlayerMock; +//import dev.jorel.commandapi.CommandAPICommand; +//import dev.jorel.commandapi.MCVersion; +//import dev.jorel.commandapi.arguments.AdventureChatArgument; +//import dev.jorel.commandapi.arguments.ChatArgument; +//import dev.jorel.commandapi.test.Mut; +//import dev.jorel.commandapi.test.TestBase; +//import net.kyori.adventure.text.Component; +//import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +//import net.md_5.bungee.api.chat.BaseComponent; +//import net.md_5.bungee.api.chat.TextComponent; +//import net.md_5.bungee.chat.ComponentSerializer; +// +///** +// * Tests for the {@link ChatArgument} and {@link AdventureChatArgument} +// */ +//class ArgumentChatTests extends TestBase { +// +// /********* +// * Setup * +// *********/ +// +// @BeforeEach +// public void setUp() { +// super.setUp(); +// } +// +// @AfterEach +// public void tearDown() { +// super.tearDown(); +// } +// +// /********* +// * Tests * +// *********/ +// +// @Test +// void executionTestWithSpigotChatArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new ChatArgument("chat")) +// .executesPlayer((player, args) -> { +// results.set((BaseComponent[]) args.get("chat")); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("APlayer"); +// player.setOp(true); +// +// BaseComponent expected = new TextComponent("Hello, "); +// expected.addExtra(new TextComponent("APlayer")); +// expected.addExtra(new TextComponent("!")); +// +// // /test Hello, @p! +// server.dispatchCommand(player, "test Hello, @p!"); +// assertArrayEquals(new BaseComponent[] { expected }, results.get()); +// +// assertNoMoreResults(results); +// } +// +// @Test +// void executionTestWithAdventureChatArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new AdventureChatArgument("chat")) +// .executesPlayer((player, args) -> { +// results.set((Component) args.get("chat")); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("APlayer"); +// player.setOp(true); +// +// // /test Hello, @p! +// server.dispatchCommand(player, "test Hello, @p!"); +// assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, \",\"APlayer\",\"!\"]"), results.get()); +// +// assertNoMoreResults(results); +// } +// +// @Test +// void executionTestWithSpigotChatArgumentNoOp() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new ChatArgument("chat")) +// .executesPlayer((player, args) -> { +// results.set((BaseComponent[]) args.get("chat")); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("APlayer"); +// +// // /test Hello, APlayer! +// server.dispatchCommand(player, "test Hello, APlayer!"); +// assertArrayEquals(ComponentSerializer.parse("[\"Hello, APlayer!\"]"), results.get()); +// +// // /test Hello, @p! +// server.dispatchCommand(player, "test Hello, @p!"); +// assertArrayEquals(ComponentSerializer.parse("[\"Hello, @p!\"]"), results.get()); +// +// assertNoMoreResults(results); +// } +// +// @Test +// void executionTestWithAdventureChatArgumentNoOp() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(new AdventureChatArgument("chat")) +// .executesPlayer((player, args) -> { +// results.set((Component) args.get("chat")); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer("APlayer"); +// +// // /test Hello, APlayer! +// server.dispatchCommand(player, "test Hello, APlayer!"); +// assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, APlayer!\"]"), results.get()); +// +// // /test Hello, @p! +// server.dispatchCommand(player, "test Hello, @p!"); +// assertEquals(GsonComponentSerializer.gson().deserialize("[\"Hello, @p!\"]"), results.get()); +// +// assertNoMoreResults(results); +// } +// +// /******************** +// * Suggestion tests * +// ********************/ +// +// @Test +// void suggestionTestWithSpigotChatArgument() { +// new CommandAPICommand("test") +// .withArguments(new ChatArgument("chat")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // Should suggest nothing +// assertEquals(List.of(), server.getSuggestions(player, "test ")); +// } +// +// @Test +// void suggestionTestWithAdventureChatArgument() { +// new CommandAPICommand("test") +// .withArguments(new AdventureChatArgument("chat")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test +// // Should suggest nothing +// assertEquals(List.of(), server.getSuggestions(player, "test ")); +// } +// +//} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCommandTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCommandTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCommandTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCommandTests.java index 941c8b70d5..6ce8b60b37 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentCommandTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCommandTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -55,7 +55,7 @@ void executionTestWithCommandArgumentBukkitCommand() { results.set((CommandResult) args.get(0)); }).register(); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); PlayerMock player = server.addPlayer("APlayer"); @@ -87,7 +87,7 @@ void executionTestWithCommandArgumentRestrictedCommandReplaceSuggestions() { results.set((CommandResult) args.get(0)); }).register(); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); registerDummyCommands(commandMap, "give", "data", "tp"); PlayerMock player = server.addPlayer("APlayer"); @@ -165,7 +165,7 @@ void executionTestWithCommandArgumentMultipleCommandBranchingSuggestions() { results.set((CommandResult) args.get(0)); }).register(); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); registerDummyCommands(commandMap, "give", "data", "tp"); PlayerMock player = server.addPlayer("APlayer"); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCustomTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCustomTests.java new file mode 100644 index 0000000000..89a1fd7149 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentCustomTests.java @@ -0,0 +1,197 @@ +// TODO: CustomArgument is currently paper/spigot specific. +// This seems a little strange when the only difference between their (very long) implementations is the message +// type of `CustomArgumentException`. Perhaps `CustomArgumentException` should not be an inner class so the rest +// of the implementation can be shared. Perhaps `CustomArgumentException` should become a interface with just the +// method `toCommandSyntax`, and each message type (String, MessageBuilder, Component/BaseComponent[]) should be +// a subclass, which makes it easier to split up the Spigot/Paper implementation. +//package dev.jorel.commandapi.test.tests.arguments; +// +//import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertThrows; +// +//import java.util.List; +// +//import org.bukkit.Bukkit; +//import org.bukkit.World; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +//import org.mockito.Mockito; +// +//import com.mojang.brigadier.context.CommandContext; +// +//import be.seeseemelk.mockbukkit.WorldMock; +//import be.seeseemelk.mockbukkit.entity.PlayerMock; +//import dev.jorel.commandapi.CommandAPICommand; +//import dev.jorel.commandapi.arguments.Argument; +//import dev.jorel.commandapi.arguments.ArgumentSuggestions; +//import dev.jorel.commandapi.arguments.CustomArgument; +//import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; +//import dev.jorel.commandapi.arguments.CustomArgument.MessageBuilder; +//import dev.jorel.commandapi.arguments.LiteralArgument; +//import dev.jorel.commandapi.arguments.MultiLiteralArgument; +//import dev.jorel.commandapi.arguments.StringArgument; +//import dev.jorel.commandapi.test.Mut; +//import dev.jorel.commandapi.test.TestBase; +//import net.kyori.adventure.text.Component; +//import net.md_5.bungee.api.chat.BaseComponent; +//import net.md_5.bungee.api.chat.ComponentBuilder; +// +///** +// * Tests for the {@link CustomArgument} +// */ +//class ArgumentCustomTests extends TestBase { +// +// /********* +// * Setup * +// *********/ +// +// @BeforeEach +// public void setUp() { +// super.setUp(); +// } +// +// @AfterEach +// public void tearDown() { +// super.tearDown(); +// } +// +// // From the documentation +// public Argument customWorldArgument(String nodeName) { +// return new CustomArgument(new StringArgument(nodeName), info -> { +// World world = Bukkit.getWorld(info.input()); +// if (world == null) { +// throw CustomArgumentException.fromMessageBuilder(new MessageBuilder("Unknown world: ").appendArgInput()); +// } else { +// return world; +// } +// }).replaceSuggestions(ArgumentSuggestions.strings(info -> Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new))); +// } +// +// public Argument customArgumentThatThrowsException(String nodeName) { +// return new CustomArgument(new StringArgument(nodeName), info -> { +// throw new RuntimeException("👻 Spoopy Exception 👻"); +// }); +// } +// +// /********* +// * Tests * +// *********/ +// +// @Test +// void executionTestWithCustomWorldArgument() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(customWorldArgument("world")) +// .executesPlayer((player, args) -> { +// results.set(args.getUnchecked(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// WorldMock world1 = server.addSimpleWorld("world1"); +// server.addSimpleWorld("world2"); +// server.addSimpleWorld("world3"); +// +// // /test unknownworld +// assertCommandFailsWith(player, "test unknownworld", "Unknown world: unknownworld"); +// +// // /test world1 +// server.dispatchCommand(player, "test world1"); +// assertEquals(world1, results.get()); +// +// assertNoMoreResults(results); +// } +// +// @Test +// void executionTestWithCustomArgumentThatThrowsException() { +// Mut results = Mut.of(); +// +// new CommandAPICommand("test") +// .withArguments(customArgumentThatThrowsException("world")) +// .executesPlayer((player, args) -> { +// results.set(args.getUnchecked(0)); +// }) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// // /test world +// assertCommandFailsWith(player, "test world", "Error in executing command test world - world<--[HERE]"); +// +// assertNoMoreResults(results); +// } +// +// /******************** +// * Suggestion tests * +// ********************/ +// +// @Test +// void suggestionTestWithCustomWorldArgument() { +// new CommandAPICommand("test") +// .withArguments(customWorldArgument("world")) +// .executesPlayer(P_EXEC) +// .register(); +// +// PlayerMock player = server.addPlayer(); +// +// server.addSimpleWorld("world1"); +// server.addSimpleWorld("world2"); +// server.addSimpleWorld("world3"); +// +// // /test +// // We expect to see "world" because that's the default world +// assertEquals(List.of("world", "world1", "world2", "world3"), server.getSuggestions(player, "test ")); +// } +// +// /*********************** +// * Instantiation tests * +// ***********************/ +// +// @Test +// void instantiationTestWithLiteralCustomArgument() { +// // LiteralArgument +// LiteralArgument literalArgument = new LiteralArgument("world"); +// +// assertThrows(IllegalArgumentException.class, () -> { +// new CustomArgument<>(literalArgument, info -> 1); +// }); +// +// // MultiLiteralArgument +// MultiLiteralArgument multiLiteralArgument = new MultiLiteralArgument("node", List.of("hello", "world")); +// +// assertThrows(IllegalArgumentException.class, () -> { +// new CustomArgument<>(multiLiteralArgument, info -> 1); +// }); +// } +// +// @Test +// void instantiationTestWithCustomArgumentException() { +// final String result = "result"; +// @SuppressWarnings("unchecked") +// final CommandContext context = Mockito.mock(CommandContext.class); +// Mockito.when(context.getInput()).thenReturn("input"); +// +// // String +// assertDoesNotThrow(() -> CustomArgumentException.fromString("hello").toCommandSyntax(result, context)); +// +// // BaseComponents +// BaseComponent[] baseComponents = new ComponentBuilder("hello").create(); +// +// assertDoesNotThrow(() -> CustomArgumentException.fromBaseComponents(baseComponents).toCommandSyntax(result, context)); +// +// // Adventure Components +// Component adventureComponent = Component.text("hello"); +// +// assertDoesNotThrow(() -> CustomArgumentException.fromAdventureComponent(adventureComponent).toCommandSyntax(result, context)); +// +// // Null values +// assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromString(null).toCommandSyntax(result, context)); +// assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromBaseComponents(null).toCommandSyntax(result, context)); +// assertThrows(IllegalStateException.class, () -> CustomArgumentException.fromAdventureComponent(null).toCommandSyntax(result, context)); +// } +// +//} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEnchantmentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEnchantmentTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEnchantmentTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEnchantmentTests.java index 1af07f8438..7a2b3bdd6b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEnchantmentTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEnchantmentTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntitySelectorTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntitySelectorTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntitySelectorTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntitySelectorTests.java index eb90954e85..7ec325e9c0 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntitySelectorTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntitySelectorTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntityTypeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntityTypeTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntityTypeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntityTypeTests.java index 007e0055e5..e7107c7ab1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntityTypeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentEntityTypeTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assumptions.assumeTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentFunctionTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentFunctionTests.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentFunctionTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentFunctionTests.java index 0d78de9e81..e5faf18e4c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentFunctionTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentFunctionTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -17,7 +17,6 @@ import dev.jorel.commandapi.MCVersion; import dev.jorel.commandapi.arguments.FunctionArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; -import dev.jorel.commandapi.test.MockNMS; import dev.jorel.commandapi.test.MockPlatform; import dev.jorel.commandapi.test.Mut; import dev.jorel.commandapi.test.TestBase; @@ -83,7 +82,7 @@ void executionTestWithFunctionArgument() { int functionResult = result[0].run(); if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertEquals(1, MockNMS.getInstance().popFunctionCallbackResult()); + assertEquals(1, MockPlatform.getInstance().popFunctionCallbackResult()); } else { assertEquals(1, functionResult); } @@ -143,8 +142,8 @@ void executionTestWithFunctionArgumentTag() { int functionResult = wrapper.run(); if (version.greaterThanOrEqualTo(MCVersion.V1_20_3)) { - assertEquals(1, MockNMS.getInstance().popFunctionCallbackResult()); - assertEquals(1, MockNMS.getInstance().popFunctionCallbackResult()); + assertEquals(1, MockPlatform.getInstance().popFunctionCallbackResult()); + assertEquals(1, MockPlatform.getInstance().popFunctionCallbackResult()); } else { assertEquals(2, functionResult); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentGreedyStringTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentGreedyStringTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentGreedyStringTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentGreedyStringTests.java index 773a865046..2dc75e1939 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentGreedyStringTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentGreedyStringTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPICommand; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackPredicateTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackPredicateTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackPredicateTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackPredicateTests.java index 8446dfdd53..839ee08d59 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackPredicateTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackPredicateTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackTests.java index 7ab7118c98..dc2af14096 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentItemStackTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentListTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentListTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentListTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentListTests.java index 212e48a16f..f7e667d859 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentListTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentListTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLiteralTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLiteralTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLiteralTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLiteralTests.java index f1d3e272ec..940e74f7ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLiteralTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLiteralTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLocationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLocationTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLocationTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLocationTests.java index fec30de3c5..b02ae77260 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLocationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLocationTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLootTableTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLootTableTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLootTableTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLootTableTests.java index bc0ca034c7..004c18b567 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentLootTableTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentLootTableTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMapTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMapTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMapTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMapTests.java index 17fa86cf36..df5508a819 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMapTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMapTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMathOperationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMathOperationTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMathOperationTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMathOperationTests.java index 05e8df26be..b8aa17bd72 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMathOperationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMathOperationTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMultiLiteralTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMultiLiteralTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMultiLiteralTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMultiLiteralTests.java index 16b6f7e71f..a87861bc3e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentMultiLiteralTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentMultiLiteralTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPICommand; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundNBTAPITests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundNBTAPITests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundNBTAPITests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundNBTAPITests.java index ecd9c59e2e..d0d2f09f85 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundNBTAPITests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundNBTAPITests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundRtagTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundRtagTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundRtagTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundRtagTests.java index 68ac0e806e..75599c6998 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNBTCompoundRtagTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNBTCompoundRtagTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNamespacedKeyTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNamespacedKeyTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNamespacedKeyTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNamespacedKeyTests.java index 38279ce32b..4adc8649d3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentNamespacedKeyTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentNamespacedKeyTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentObjectiveTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentObjectiveTests.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentObjectiveTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentObjectiveTests.java index 1eae3dc943..d8a053b4fd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentObjectiveTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentObjectiveTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPICommand; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticleTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticleTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticleTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticleTests.java index bb31b3c114..ea99639981 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticleTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticleTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_16_5_Tests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_16_5_Tests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_16_5_Tests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_16_5_Tests.java index a3c6ab505c..b45b08ac20 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_16_5_Tests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_16_5_Tests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_18_Tests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_18_Tests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_18_Tests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_18_Tests.java index e3f5cc75c2..b4cf2f61e1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_18_Tests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_18_Tests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_19_2_Tests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_19_2_Tests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_19_2_Tests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_19_2_Tests.java index 687fa108d1..4e1295771f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticle_1_19_2_Tests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentParticle_1_19_2_Tests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPotionTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPotionTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPotionTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPotionTests.java index 32ee0bdf16..bc8a8b31cb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPotionTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPotionTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assumptions.assumeTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPrimitiveTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPrimitiveTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPrimitiveTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPrimitiveTests.java index 26db36eb06..56e863fdc2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentPrimitiveTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentPrimitiveTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRangeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRangeTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRangeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRangeTests.java index b696bba35a..fd3f26a14a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRangeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRangeTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPICommand; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRecipeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRecipeTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRecipeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRecipeTests.java index 5de4b0a6db..e2c1c0e5d3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRecipeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRecipeTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assumptions.assumeTrue; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRotationTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRotationTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRotationTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRotationTests.java index 816fe28ad8..7b31a7a386 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentRotationTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentRotationTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreHolderTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreHolderTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreHolderTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreHolderTests.java index 8437539f83..6c57ce6456 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreHolderTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreHolderTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertIterableEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreboardSlotTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreboardSlotTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreboardSlotTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreboardSlotTests.java index e4f5c43ac0..9bdbbd6c0c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentScoreboardSlotTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentScoreboardSlotTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentSoundTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentSoundTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentSoundTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentSoundTests.java index 1cfe9db034..0f502a3856 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentSoundTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentSoundTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTeamTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTeamTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTeamTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTeamTests.java index 533eee5725..ebc0af83b9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTeamTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTeamTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTests.java index c476b14705..3de40d92dd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTimeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTimeTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTimeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTimeTests.java index 68c7d9e3f9..3b684cdf8b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentTimeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentTimeTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentUUIDTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentUUIDTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentUUIDTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentUUIDTests.java index 1951f19de1..46c2cd7500 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentUUIDTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentUUIDTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentWorldTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentWorldTests.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentWorldTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentWorldTests.java index ffd7ecefcc..38fc1c4dd5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentWorldTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/ArgumentWorldTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/OptionalArgumentTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/OptionalArgumentTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/OptionalArgumentTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/OptionalArgumentTests.java index a418b2502e..01a135ac7a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/OptionalArgumentTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/arguments/OptionalArgumentTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.arguments; +package dev.jorel.commandapi.test.tests.arguments; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/ScoreboardSlotWrapperTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/ScoreboardSlotWrapperTests.java similarity index 99% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/ScoreboardSlotWrapperTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/ScoreboardSlotWrapperTests.java index 7b0157f969..ef1709ef68 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/ScoreboardSlotWrapperTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/ScoreboardSlotWrapperTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.wrappers; +package dev.jorel.commandapi.test.tests.wrappers.wrappers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/SimpleFunctionWrapperTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/SimpleFunctionWrapperTests.java similarity index 97% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/SimpleFunctionWrapperTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/SimpleFunctionWrapperTests.java index 741d665c7e..5944773c00 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/wrappers/SimpleFunctionWrapperTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/tests/wrappers/wrappers/SimpleFunctionWrapperTests.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi.test.wrappers; +package dev.jorel.commandapi.test.tests.wrappers.wrappers; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml index 395e7c4a0c..690130c3b4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml @@ -42,7 +42,8 @@ commandapi-bukkit-test-impl-1.16.5 - commandapi-bukkit-kotlin-test + + commandapi-bukkit-test-tests \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore deleted file mode 100644 index 00d2ab71dd..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml deleted file mode 100644 index bbe1053977..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - commandapi-bukkit - dev.jorel - 9.7.1-SNAPSHOT - - 4.0.0 - - commandapi-bukkit-vh - - - - dev.jorel - commandapi-bukkit-nms-dependency - ${project.version} - pom - - - - - org.spigotmc - spigot - ${paper.version} - remapped-mojang - provided - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java deleted file mode 100644 index 7e6f9cb3cb..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi; - -import dev.jorel.commandapi.exceptions.UnsupportedVersionException; -import dev.jorel.commandapi.nms.NMS_1_16_R3; -import dev.jorel.commandapi.nms.NMS_1_17; -import dev.jorel.commandapi.nms.NMS_1_17_R1; -import dev.jorel.commandapi.nms.NMS_1_18_R1; -import dev.jorel.commandapi.nms.NMS_1_18_R2; -import dev.jorel.commandapi.nms.NMS_1_19_1_R1; -import dev.jorel.commandapi.nms.NMS_1_19_3_R2; -import dev.jorel.commandapi.nms.NMS_1_19_4_R3; -import dev.jorel.commandapi.nms.NMS_1_19_R1; -import dev.jorel.commandapi.nms.NMS_1_20_R1; -import dev.jorel.commandapi.nms.NMS_1_20_R2; -import dev.jorel.commandapi.nms.NMS_1_20_R3; -import dev.jorel.commandapi.nms.NMS_1_20_R4; -import dev.jorel.commandapi.nms.NMS_1_21_R1; -import dev.jorel.commandapi.nms.NMS_1_21_R2; -import dev.jorel.commandapi.nms.NMS_1_21_R3; -import org.bukkit.Bukkit; - -/** - * This file handles the NMS version to be loaded. The CommandAPIVersionHandler - * file within the commandapi-core module is NOT used at compile time. Instead, - * the commandapi-vh module is loaded instead, which doesn't use reflection to - * load NMS instances. - * - * NMS classes implement {@code NMS}. The type - * CommandListenerWrapper isn't visible as in this Maven module (it's not - * included and in some cases, cannot be included because Maven will only select - * one version of a specific project (in this case, it'll only import one copy - * of Spigot, almost always the latest stable version (from 1.16.5)). In - * Eclipse, this can produce an error saying that a class cannot be resolved - * because it is indirectly referenced from required .class files So sidestep - * this, we introduce a second intermediary class NMSWrapper_VERSION which - * depends on CommandListenerWrapper and then our main NMS_VERSION class extends - * that. - */ -public abstract class CommandAPIVersionHandler { - - /** - * Returns an instance of the current running version's implementation of the Bukkit NMS. - * - * @return an instance of NMS which can run on the specified Minecraft version - */ - static LoadContext getPlatform() { - String latestMajorVersion = "21"; // Change this for Minecraft's major update - if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { - return new LoadContext(new NMS_1_21_R3(), () -> { - CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } else { - String version = Bukkit.getBukkitVersion().split("-")[0]; - CommandAPIPlatform platform = switch (version) { - case "1.16.5" -> new NMS_1_16_R3(); - case "1.17" -> new NMS_1_17(); - case "1.17.1" -> new NMS_1_17_R1(); - case "1.18", "1.18.1" -> new NMS_1_18_R1(); - case "1.18.2" -> new NMS_1_18_R2(); - case "1.19" -> new NMS_1_19_R1(); - case "1.19.1", "1.19.2" -> new NMS_1_19_1_R1(); - case "1.19.3" -> new NMS_1_19_3_R2(); - case "1.19.4" -> new NMS_1_19_4_R3(); - case "1.20", "1.20.1" -> new NMS_1_20_R1(); - case "1.20.2" -> new NMS_1_20_R2(); - case "1.20.3", "1.20.4" -> new NMS_1_20_R3(); - case "1.20.5", "1.20.6" -> new NMS_1_20_R4(); - case "1.21", "1.21.1" -> new NMS_1_21_R1(); - case "1.21.2", "1.21.3" -> new NMS_1_21_R2(); - case "1.21.4" -> new NMS_1_21_R3(); - default -> null; - }; - if (platform != null) { - return new LoadContext(platform); - } - if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { - String currentMajorVersion = version.split("\\.")[1]; - if (latestMajorVersion.equals(currentMajorVersion)) { - return new LoadContext(new NMS_1_21_R3(), () -> { - CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } - } - throw new UnsupportedVersionException(version); - } - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/pom.xml b/commandapi-platforms/commandapi-bukkit/pom.xml index 83c5c2efdd..79646b736c 100644 --- a/commandapi-platforms/commandapi-bukkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/pom.xml @@ -20,22 +20,12 @@ commandapi-bukkit-nms - - commandapi-bukkit-vh - commandapi-bukkit-mojang-mapped - commandapi-bukkit-plugin-common - - commandapi-bukkit-plugin - commandapi-bukkit-shade - commandapi-bukkit-plugin-mojang-mapped - commandapi-bukkit-shade-mojang-mapped - - commandapi-bukkit-test-toolkit + - commandapi-bukkit-test \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml new file mode 100644 index 0000000000..fea6fa979a --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-annotations + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + dev.jorel + commandapi-annotations + ${project.version} + compile + + + dev.jorel + commandapi-paper-core + ${project.version} + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + dev.jorel.commandapi.annotations.Annotations + + + + + + + + + \ No newline at end of file diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java similarity index 96% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java index 0880d6497d..4cc7e7edd4 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java @@ -20,34 +20,10 @@ *******************************************************************************/ package dev.jorel.commandapi.annotations; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.annotation.Annotation; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Processor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.ExecutableType; -import javax.tools.Diagnostic.Kind; -import javax.tools.JavaFileObject; - import com.google.auto.service.AutoService; - import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; import dev.jorel.commandapi.annotations.arguments.AAdvancementArgument; -import dev.jorel.commandapi.annotations.arguments.AAdventureChatArgument; -import dev.jorel.commandapi.annotations.arguments.AAdventureChatComponentArgument; import dev.jorel.commandapi.annotations.arguments.AAngleArgument; import dev.jorel.commandapi.annotations.arguments.AAxisArgument; import dev.jorel.commandapi.annotations.arguments.ABiomeArgument; @@ -99,19 +75,43 @@ import dev.jorel.commandapi.arguments.LocationType; import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ExecutableType; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * The main annotation processor for annotation-based arguments */ @AutoService(Processor.class) public class Annotations extends AbstractProcessor { - private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, - AAdventureChatArgument.class, AAdventureChatComponentArgument.class, AAngleArgument.class, - AAxisArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, ABlockStateArgument.class, - ABooleanArgument.class, AChatArgument.class, AChatColorArgument.class, AChatComponentArgument.class, - ADoubleArgument.class, AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, - AEntitySelectorArgument.ManyPlayers.class, AEntitySelectorArgument.OneEntity.class, - AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, + private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, + AAngleArgument.class, AAxisArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, + ABlockStateArgument.class, ABooleanArgument.class, + AChatArgument.class, AChatColorArgument.class, AChatComponentArgument.class, ADoubleArgument.class, + AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, AEntitySelectorArgument.ManyPlayers.class, + AEntitySelectorArgument.OneEntity.class, AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, AFloatArgument.class, AFloatRangeArgument.class, AFunctionArgument.class, AGreedyStringArgument.class, AIntegerArgument.class, AIntegerRangeArgument.class, AItemStackArgument.class, AItemStackPredicateArgument.class, ALiteralArgument.class, ALocation2DArgument.class, @@ -120,7 +120,7 @@ public class Annotations extends AbstractProcessor { AObjectiveCriteriaArgument.class, AOfflinePlayerArgument.class, AParticleArgument.class, APlayerArgument.class, APotionEffectArgument.class, ARecipeArgument.class, ARotationArgument.class, AScoreboardSlotArgument.class, AScoreHolderArgument.Single.class, AScoreHolderArgument.Multiple.class, ASoundArgument.class, AStringArgument.class, ATeamArgument.class, - ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class}; + ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class }; // List of stuff we can deal with @Override diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java similarity index 90% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java index 862994ec4c..5fbb2bc3e3 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java @@ -25,13 +25,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.AdventureChatArgument; +import dev.jorel.commandapi.arguments.ChatArgument; /** - * Annotation equivalent of the {@link AdventureChatArgument} + * Annotation equivalent of the {@link ChatArgument} */ @Primitive("net.kyori.adventure.text.Component") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AAdventureChatArgument { +public @interface AChatArgument { } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java new file mode 100644 index 0000000000..99fe26a250 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.annotations.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.ChatColorArgument} + */ +@Primitive("net.kyori.adventure.text.format.Component") +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface AChatColorArgument { +} diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java similarity index 89% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java index 934ea89e85..5e87c0c8e3 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java @@ -25,13 +25,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; /** - * Annotation equivalent of the {@link AdventureChatComponentArgument} + * Annotation equivalent of the {@link ChatComponentArgument} */ @Primitive("net.kyori.adventure.text.Component") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AAdventureChatComponentArgument { +public @interface AChatComponentArgument { } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml new file mode 100644 index 0000000000..1ec0e292d1 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-core + + + + minecraft-libraries + https://libraries.minecraft.net + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + provided + + + dev.folia + folia-api + 1.19.4-R0.1-SNAPSHOT + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + com.mojang + brigadier + 1.0.18 + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint + + + dev.jorel.commandapi.preprocessor.Preprocessor + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java new file mode 100644 index 0000000000..4d45ae6918 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -0,0 +1,241 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitEntity; +import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.nms.PaperNMS; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import io.papermc.paper.event.server.ServerResourcesReloadedEvent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import org.bukkit.Bukkit; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class CommandAPIPaper extends CommandAPIBukkit implements PaperNMS { + + private static CommandAPIPaper paper; + + private boolean isPaperPresent = true; + private boolean isFoliaPresent = false; + private final Class feedbackForwardingCommandSender; + private final Class nullCommandSender; + + @SuppressWarnings("unchecked") + protected CommandAPIPaper() { + this.nms = (NMS) bukkitNMS(); + CommandAPIPaper.paper = this; + + Class tempFeedbackForwardingCommandSender = null; + Class tempNullCommandSender = null; + try { + tempFeedbackForwardingCommandSender = (Class) Class.forName("io.papermc.paper.commands.FeedbackForwardingSender"); + } catch (ClassNotFoundException e) { + // uhh... + } + try { + tempNullCommandSender = (Class) Class.forName("io.papermc.paper.brigadier.NullCommandSender"); + } catch (ClassNotFoundException e) { + // uhh... + } + + this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender; + this.nullCommandSender = tempNullCommandSender; + + setInstance(this); + } + + @SuppressWarnings("unchecked") + public static CommandAPIPaper getPaper() { + if (paper != null) { + return (CommandAPIPaper) paper; + } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + public static InternalPaperConfig getConfiguration() { + return (InternalPaperConfig) CommandAPIBukkit.getConfiguration(); + } + + private static void setInternalConfig(InternalPaperConfig config) { + CommandAPIBukkit.config = config; + } + + @Override + public void onLoad(CommandAPIConfig config) { + if (config instanceof CommandAPIPaperConfig paperConfig) { + CommandAPIPaper.setInternalConfig(new InternalPaperConfig(paperConfig)); + } else { + CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); + CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + } + super.onLoad(); + checkPaperDependencies(); + } + + @Override + public void onEnable() { + JavaPlugin plugin = getConfiguration().getPlugin(); + + new Schedulers(isFoliaPresent).scheduleSyncDelayed(plugin, () -> { + getCommandRegistrationStrategy().runTasksAfterServerStart(); + if (isFoliaPresent) { + CommandAPI.logNormal("Skipping initial datapack reloading because Folia was detected"); + } else { + if (!getConfiguration().skipReloadDatapacks()) { + reloadDataPacks(); + } + } + updateHelpForCommands(CommandAPI.getRegisteredCommands()); + }, 0L); + + super.stopCommandRegistrations(); + + // Basically just a check to ensure we're actually running Paper + if (isPaperPresent) { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onServerReloadResources(ServerResourcesReloadedEvent event) { + // This event is called after Paper is done with everything command related + // which means we can put commands back + getCommandRegistrationStrategy().preReloadDataPacks(); + + // Normally, the reloadDataPacks() method is responsible for updating commands for + // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload + // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to + // paper-1.20.6-65 + if (!CommandAPIPaper.getConfiguration().shouldHookPaperReload()) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.updateCommands(); + } + return; + } + CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); + reloadDataPacks(); + } + }, plugin); + CommandAPI.logNormal("Hooked into Paper ServerResourcesReloadedEvent"); + } else { + CommandAPI.logNormal("Did not hook into Paper ServerResourcesReloadedEvent while using commandapi-paper. Are you actually using Paper?"); + } + } + + private void checkPaperDependencies() { + try { + Class.forName("net.kyori.adventure.text.Component"); + CommandAPI.logNormal("Hooked into Adventure for AdventureChat/AdventureChatComponents"); + } catch (ClassNotFoundException e) { + if (CommandAPI.getConfiguration().hasVerboseOutput()) { + CommandAPI.logWarning("Could not hook into Adventure for AdventureChat/AdventureChatComponents"); + } + } + + isPaperPresent = false; + + try { + Class.forName("io.papermc.paper.event.server.ServerResourcesReloadedEvent"); + isPaperPresent = true; + CommandAPI.logNormal("Hooked into Paper for paper-specific API implementations"); + } catch (ClassNotFoundException e) { + isPaperPresent = false; + if (CommandAPI.getConfiguration().hasVerboseOutput()) { + CommandAPI.logWarning("Could not hook into Paper for /minecraft:reload. Consider upgrading to Paper: https://papermc.io/"); + } + } + + isFoliaPresent = false; + + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); + isFoliaPresent = true; + CommandAPI.logNormal("Hooked into Folia for folia-specific API implementations"); + CommandAPI.logNormal("Folia support is still in development. Please report any issues to the CommandAPI developers!"); + } catch (ClassNotFoundException e) { + isFoliaPresent = false; + } + } + + public CommandMap getCommandMap() { + return Bukkit.getCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.PAPER; + } + + @Override + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + if (this.feedbackForwardingCommandSender.isInstance(sender)) { + // We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance + return new BukkitFeedbackForwardingCommandSender(this.feedbackForwardingCommandSender.cast(sender)); + } + if (this.nullCommandSender != null && this.nullCommandSender.isInstance(sender)) { + // Since this should only be during a function load, this is just a placeholder to evade the exception. + return null; + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); + } + + /** + * Forces a command to return a success value of 0 + * + * @param message Description of the error message, formatted as an adventure chat component + * @return a {@link dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException} that wraps Brigadier's + * {@link com.mojang.brigadier.exceptions.CommandSyntaxException} + */ + public static WrapperCommandSyntaxException failWithAdventureComponent(Component message) { + return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message)); + } + + /** + * Forces a command to return a success value of 0 + * + * @param message Description of the error message, formatted as an adventure chat component + * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's + * {@link com.mojang.brigadier.exceptions.CommandSyntaxException} + */ + public static WrapperCommandSyntaxException failWithAdventureComponent(ComponentLike message) { + return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message.asComponent())); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java new file mode 100644 index 0000000000..8a6355671d --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -0,0 +1,41 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandAPIPaperConfig extends CommandAPIBukkitConfig { + + boolean shouldHookPaperReload = true; + + public CommandAPIPaperConfig(JavaPlugin plugin) { + super(plugin); + } + + /** + * Sets the CommandAPI to hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} when available + * if true. This helps CommandAPI commands to work in datapacks after {@code /minecraft:reload} + * is run. + * + * @param hooked whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} + * @return this CommandAPIBukkitConfig + */ + public CommandAPIPaperConfig shouldHookPaperReload(boolean hooked) { + this.shouldHookPaperReload = hooked; + return this; + } + + /** + * Sets whether the CommandAPI should skip its datapack reload step after the server + * has finished loading. This does not skip reloading of datapacks when invoked manually + * when {@link #shouldHookPaperReload(boolean)} is set. + * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading + * @return this CommandAPIBukkitConfig + */ + public CommandAPIPaperConfig skipReloadDatapacks(boolean skip) { + return super.skipReloadDatapacks(skip); + } + + @Override + public CommandAPIPaperConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java new file mode 100644 index 0000000000..bd44185582 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java @@ -0,0 +1,22 @@ +package dev.jorel.commandapi; + +public class InternalPaperConfig extends InternalBukkitConfig { + + // Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run + private final boolean shouldHookPaperReload; + + public InternalPaperConfig(CommandAPIPaperConfig config) { + super(config); + this.shouldHookPaperReload = config.shouldHookPaperReload; + } + + /** + * @return Whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} + * when available to perform the CommandAPI's custom datapack reload when {@code /minecraft:reload} + * is run. + */ + public boolean shouldHookPaperReload() { + return shouldHookPaperReload; + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java similarity index 77% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java index 28e00a54da..e324e85947 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java @@ -4,14 +4,14 @@ public class Schedulers { - private final PaperImplementations paperImplementations; + private final boolean isFoliaPresent; - public Schedulers(PaperImplementations paperImplementations) { - this.paperImplementations = paperImplementations; + public Schedulers(boolean isFoliaPresent) { + this.isFoliaPresent = isFoliaPresent; } public int scheduleSyncRepeatingTask(Plugin plugin, Runnable runnable, long delay, long period) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> runnable.run(), delay <= 0 ? 1 : delay, period); return 1; } else { @@ -20,7 +20,7 @@ public int scheduleSyncRepeatingTask(Plugin plugin, Runnable runnable, long dela } public void cancelTask(Plugin plugin, int id) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().cancelTasks(plugin); } else { plugin.getServer().getScheduler().cancelTask(id); @@ -28,7 +28,7 @@ public void cancelTask(Plugin plugin, int id) { } public void scheduleSync(Plugin plugin, Runnable runnable) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().execute(plugin, runnable); } else { plugin.getServer().getScheduler().runTask(plugin, runnable); @@ -36,7 +36,7 @@ public void scheduleSync(Plugin plugin, Runnable runnable) { } public void scheduleSyncDelayed(Plugin plugin, Runnable runnable, long delay) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, task -> runnable.run(), delay <= 0 ? 1 : delay); } else { plugin.getServer().getScheduler().runTaskLater(plugin, runnable, delay); @@ -44,7 +44,7 @@ public void scheduleSyncDelayed(Plugin plugin, Runnable runnable, long delay) { } public void scheduleAsync(Plugin plugin, Runnable runnable) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getAsyncScheduler().runNow(plugin, task -> runnable.run()); } else { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, runnable); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java similarity index 87% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java index bcc136de39..60e66cb0e6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java @@ -24,6 +24,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.commandsenders.BukkitPlayer; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; @@ -42,7 +43,7 @@ * * @apiNote Returns a {@link Component} object */ -public class AdventureChatArgument extends Argument implements GreedyArgument, Previewable { +public class ChatArgument extends Argument implements GreedyArgument, Previewable { private PreviewableFunction preview; private boolean usePreview; @@ -53,8 +54,8 @@ public class AdventureChatArgument extends Argument implements Greedy * * @param nodeName the name of the node for argument */ - public AdventureChatArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChat()); + public ChatArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChat()); try { Class.forName("net.kyori.adventure.text.Component"); @@ -76,7 +77,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Component parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(); - Component component = CommandAPIBukkit.get().getAdventureChat(cmdCtx, key); + Component component = CommandAPIPaper.getPaper().getChat(cmdCtx, key); Optional> previewOptional = getPreview(); if (this.usePreview && previewOptional.isPresent() && sender instanceof Player player) { @@ -94,7 +95,7 @@ public Component parseArgument(CommandContext preview) { + public ChatArgument withPreview(PreviewableFunction preview) { this.preview = preview; return this; } @@ -105,12 +106,7 @@ public Optional> getPreview() { } @Override - public boolean isLegacy() { - return false; - } - - @Override - public AdventureChatArgument usePreview(boolean usePreview) { + public ChatArgument usePreview(boolean usePreview) { this.usePreview = usePreview; return this; } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java similarity index 87% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java index 3a2a6abecc..6111b52644 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java @@ -20,6 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.arguments; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import org.bukkit.ChatColor; @@ -37,7 +38,7 @@ * * @apiNote Returns a {@link ChatColor} object */ -public class AdventureChatColorArgument extends SafeOverrideableArgument { +public class ChatColorArgument extends SafeOverrideableArgument { /** * Constructs a ChatColor argument with a given node name. Represents a color or @@ -45,8 +46,8 @@ public class AdventureChatColorArgument extends SafeOverrideableArgument NamedTextColor parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdventureChatColor(cmdCtx, key); + return CommandAPIPaper.getPaper().getChatColor(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java similarity index 89% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java index 389e41f29b..a94f957ee8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; import net.kyori.adventure.text.Component; @@ -33,15 +34,15 @@ * @since 5.10 * @apiNote Returns a {@link Component} object */ -public class AdventureChatComponentArgument extends Argument { +public class ChatComponentArgument extends Argument { /** * Constructs a ChatComponent argument with a given node name. Represents raw JSON text, used in Book MetaData, Chat and other various areas of Minecraft * @see Raw JSON text * @param nodeName the name of the node for argument */ - public AdventureChatComponentArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChatComponent()); + public ChatComponentArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatComponent()); try { Class.forName("net.kyori.adventure.text.Component"); @@ -62,6 +63,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Component parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdventureChatComponent(cmdCtx, key); + return CommandAPIPaper.getPaper().getChatComponent(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java new file mode 100644 index 0000000000..d61d9937aa --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java @@ -0,0 +1,377 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.arguments; + +import com.mojang.brigadier.LiteralMessage; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import dev.jorel.commandapi.BukkitTooltip; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.executors.CommandArguments; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; + +/** + * An argument that represents any custom object + * + * @param the return type of this custom argument when it is used + * @param the return type of the underlying base argument {@code base}. For + * example, this would be {@code Integer} for an + * {@link IntegerArgument} + * + * @since 2.0 + * @apiNote Returns a {@link T} object + */ +public class CustomArgument extends Argument { + + private final CustomArgumentInfoParser infoParser; + private final Argument base; + + private static final String INPUT = "%input%"; + private static final String FULL_INPUT = "%finput%"; + + /** + * Creates a CustomArgument with a valid parser, with an underlying base + * argument as its parsing implementation. + * + * @param base the base argument to use for this custom argument. This base + * argument will represent the parsing implementation for client + * side and server side parsing. This base argument cannot be a + * {@link LiteralArgument} or {@link MultiLiteralArgument} + * @param parser A {@link CustomArgumentInfo} parser object which includes + * information such as the command sender, previously declared + * arguments and current input. This parser should return an + * object of your choice. + *

+ * {@code } the return type of this custom argument when + * it is used
+ * {@code } the return type of the underlying base + * argument {@code base}. For example, this would be + * {@code Integer} for an {@link IntegerArgument} + *

+ */ + public CustomArgument(Argument base, CustomArgumentInfoParser parser) { + super(base.getNodeName(), base.getRawType()); + if (base instanceof LiteralArgument || base instanceof MultiLiteralArgument) { + throw new IllegalArgumentException(base.getClass().getSimpleName() + " is not a suitable base argument type for a CustomArgument"); + } + this.base = base; + this.infoParser = parser; + } + + @Override + public Class getPrimitiveType() { + return null; + } + + @Override + public CommandAPIArgumentType getArgumentType() { + return CommandAPIArgumentType.CUSTOM; + } + + @Override + public T parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) + throws CommandSyntaxException { + // Get the raw input and parsed input + final String customresult = CommandAPIHandler.getRawArgumentInput(cmdCtx, key); + final B parsedInput = base.parseArgument(cmdCtx, key, previousArgs); + + try { + return infoParser.apply(new CustomArgumentInfo<>(CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(), + previousArgs, customresult, parsedInput)); + } catch (CustomArgumentException e) { + throw e.toCommandSyntax(customresult, cmdCtx); + } catch (Exception e) { + String errorMsg = new MessageBuilder("Error in executing command ").appendFullInput().append(" - ") + .appendArgInput().appendHere().toString().replace(INPUT, customresult) + .replace(FULL_INPUT, cmdCtx.getInput()); + throw new SimpleCommandExceptionType(() -> errorMsg).create(); + } + } + + /** + * MessageBuilder is used to create error messages for invalid argument inputs + */ + public static class MessageBuilder implements Serializable { + + private static final long serialVersionUID = 838497662821791798L; + + StringBuilder builder; + + /** + * Create a blank message + */ + public MessageBuilder() { + builder = new StringBuilder(); + } + + /** + * Create a message with an input string + * + * @param str The string to start the message with + */ + public MessageBuilder(String str) { + builder = new StringBuilder(str); + } + + /** + * Appends the argument input that the CommandSender used in this command.
+ * For example, if /foo bar was executed and an error occurs with + * the CustomArgument bar, then the arg input will append + * bar to the end of the message.
+ *
+ * This input is determined at runtime, and is stored as %input% + * until executed + * + * @return A reference to this object + */ + public MessageBuilder appendArgInput() { + builder.append(INPUT); + return this; + } + + /** + * Appends the whole input that the CommandSender used in this command.
+ * For example, if /foo bar was executed, then foo bar + * will be appended to the end of the message.
+ *
+ * This input is determined at runtime, and is stored as %finput% + * until executed + * + * @return A reference to this object + */ + public MessageBuilder appendFullInput() { + builder.append(FULL_INPUT); + return this; + } + + /** + * Appends <--[HERE] to the end of the message + * + * @return A reference to this object + */ + public MessageBuilder appendHere() { + builder.append("<--[HERE]"); + return this; + } + + /** + * Appends a string to the end of this message + * + * @param str The string to append to the end of this message + * @return A reference to this object + */ + public MessageBuilder append(String str) { + builder.append(str); + return this; + } + + /** + * Appends an object to the end of this message + * + * @param obj The object to append to the end of this message + * @return A reference to this object + */ + public MessageBuilder append(Object obj) { + builder.append(obj); + return this; + } + + /** + * Returns the String content of this MessageBuilder + * + * @return the String content of this MessageBuilder + */ + @Override + public String toString() { + return builder.toString(); + } + } + + /** + * An exception used to create command-related errors for the CustomArgument + */ + @SuppressWarnings("serial") + public static class CustomArgumentException extends Exception { + + private Component errorComponent = null; + private String errorMessage = null; + private MessageBuilder errorMessageBuilder = null; + + /* Prevent instantiation from any other sources */ + private CustomArgumentException() { + + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + * @deprecated Use {@link CustomArgumentException#fromString(String)} instead + */ + @Deprecated(since = "9.0.1", forRemoval = true) + public CustomArgumentException(String errorMessage) { + this.errorMessage = errorMessage; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + * @deprecated Use {@link CustomArgumentException#fromMessageBuilder(MessageBuilder)} instead + */ + @Deprecated(since = "9.0.1", forRemoval = true) + public CustomArgumentException(MessageBuilder errorMessage) { + this.errorMessageBuilder = errorMessage; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromString(String errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorMessage = errorMessage; + return exception; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromAdventureComponent(Component errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorComponent = errorMessage; + return exception; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromMessageBuilder(MessageBuilder errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorMessageBuilder = errorMessage; + return exception; + } + + /** + * Converts this CustomArgumentException into a CommandSyntaxException + * + * @param result the argument that the user entered that caused this exception + * to arise + * @param cmdCtx the command context that executed this command + * @return a Brigadier CommandSyntaxException + */ + public CommandSyntaxException toCommandSyntax(String result, CommandContext cmdCtx) { + if (errorComponent != null) { + // Deal with Adventure Component + Message brigadierMessage = BukkitTooltip.messageFromAdventureComponent(errorComponent); + return new SimpleCommandExceptionType(brigadierMessage).create(); + } + + if (errorMessageBuilder != null) { + // Deal with MessageBuilder + String errorMsg = errorMessageBuilder.toString().replace(INPUT, result).replace(FULL_INPUT, + cmdCtx.getInput()); + return new SimpleCommandExceptionType(new LiteralMessage(errorMsg)).create(); + } + + if (errorMessage != null) { + // Deal with String + Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(errorMessage); + return new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(component)).create(); + } + + throw new IllegalStateException("No error component, error message creator or error message specified"); + } + + } + + /** + * A record which contains information which can be passed to the custom + * argument's parser. + * + * @param sender the sender that types this argument + * @param previousArgs previousArgs - a {@link CommandArguments} object holding previously declared (parsed) + * arguments. This can be used as if it were arguments in a command executor method. + * @param input the current input which the user has typed for this + * argument + * @param currentInput the current input, when parsed with the underlying base + * argument. + */ + public record CustomArgumentInfo( + /** + * sender - the sender that types this argument + */ + CommandSender sender, + + /** + * previousArgs - a {@link CommandArguments} object holding previously declared (parsed) arguments. This can + * be used as if it were arguments in a command executor method. + */ + CommandArguments previousArgs, + + /** + * input - the current input which the user has typed for this argument + */ + String input, + + /** + * currentInput - the current input, when parsed with the underlying base + * argument. + */ + B currentInput) { + } + + /** + * A FunctionalInterface that takes in a {@link CustomArgumentInfo}, returns T + * and can throw a {@link CustomArgumentException} + * + * @param the type that is returned when applying this parser + */ + @FunctionalInterface + public static interface CustomArgumentInfoParser { + + /** + * Applies a CustomArgumentInfo input to this custom argument parser + * + * @param info the custom argument info to apply to this parser + * @return the applied output represented by this FunctionalInterface + * @throws CustomArgumentException if an error occurs during parsing + */ + public T apply(CustomArgumentInfo info) throws CustomArgumentException; + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java new file mode 100644 index 0000000000..f9655a7875 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java @@ -0,0 +1,18 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +public interface PaperNMS { + + Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NamedTextColor getChatColor(CommandContext cmdCtx, String key); + + Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NMS bukkitNMS(); + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml new file mode 100644 index 0000000000..8e3f6b9863 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-documentation-code + + + + minecraft-libraries + https://libraries.minecraft.net + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + + com.mojang + brigadier + 1.0.17 + provided + + + com.mojang + authlib + 3.3.39 + provided + + + + + net.kyori + adventure-platform-bukkit + 4.2.0 + test + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + + + dev.jorel + commandapi-kotlin-paper + ${project.version} + + + + + de.tr7zw + item-nbt-api + 2.11.1 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + test-compile + + test-compile + + + + ${project.basedir}/src/main/kotlin/ + + + + + + 16 + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java new file mode 100644 index 0000000000..63a31fd847 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java @@ -0,0 +1,155 @@ +package dev.jorel.commandapi.examples.java; + +import de.tr7zw.changeme.nbtapi.NBTContainer; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class Examples { + +void argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +new CommandAPICommand("namecolor") + .withArguments(new ChatColorArgument("chatcolor")) + .executesPlayer((player, args) -> { + NamedTextColor color = (NamedTextColor) args.get("chatcolor"); + player.displayName(Component.text().color(color).append(Component.text(player.getName())).build()); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +new CommandAPICommand("showbook") + .withArguments(new PlayerArgument("target")) + .withArguments(new TextArgument("title")) + .withArguments(new StringArgument("author")) + .withArguments(new ChatComponentArgument("contents")) + .executes((sender, args) -> { + Player target = (Player) args.get("target"); + String title = (String) args.get("title"); + String author = (String) args.get("author"); + Component content = (Component) args.get("contents"); + + // Create a book and show it to the user (Requires Paper) + Book mybook = Book.book(Component.text(title), Component.text(author), content); + target.openBook(mybook); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +new CommandAPICommand("pbroadcast") + .withArguments(new ChatArgument("message")) + .executes((sender, args) -> { + Component message = (Component) args.get("message"); + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS); + Bukkit.getServer().broadcast(message); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure3 */ +} + +class argument_nbt extends JavaPlugin { +/* ANCHOR: argumentNBT1 */ +@Override +public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig(this) + .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + ); +} +/* ANCHOR_END: argumentNBT1 */ +} + +void chatPreview() { +/* ANCHOR: chatPreview1 */ +new CommandAPICommand("broadcast") + .withArguments(new ChatArgument("message").withPreview(info -> { + // Convert parsed Component to plain text + String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); + + // Translate the & in plain text and generate a new Component + return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); + })) + .executesPlayer((player, args) -> { + // The user still entered legacy text. We need to properly convert this + // to a Component by converting to plain text then to Component + String plainText = PlainTextComponentSerializer.plainText().serialize((Component) args.get("broadcast")); + Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)); + }) + .register(); +/* ANCHOR_END: chatPreview1 */ + +/* ANCHOR: chatPreview2 */ +new CommandAPICommand("broadcast") + .withArguments(new ChatArgument("message").usePreview(true).withPreview(info -> { + // Convert parsed Component to plain text + String plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput()); + + // Translate the & in plain text and generate a new Component + return LegacyComponentSerializer.legacyAmpersand().deserialize(plainText); + })) + .executesPlayer((player, args) -> { + Bukkit.broadcast((Component) args.get("message")); + }) + .register(); +/* ANCHOR_END: chatPreview2 */ +} + +class setupShading { +JavaPlugin plugin = new JavaPlugin() {}; + +{ +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(new CommandAPIPaperConfig(plugin).silentLogs(true)); +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig(this).verboseOutput(true)); // Load with verbose output + + new CommandAPICommand("ping") + .executes((sender, args) -> { + sender.sendMessage("pong!"); + }) + .register(); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + + // Register commands, listeners etc. + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt new file mode 100644 index 0000000000..e5f8003e59 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -0,0 +1,149 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPIPaperConfig +import dev.jorel.commandapi.arguments.* +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import net.kyori.adventure.inventory.Book +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer +import org.bukkit.Bukkit +import org.bukkit.Server +import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +class Examples { + +fun argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +CommandAPICommand("namecolor") + .withArguments(ChatColorArgument("chatcolor")) + .executesPlayer(PlayerCommandExecutor { player, args -> + val color = args["chatcolor"] as NamedTextColor + player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) + }) + .register() +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +CommandAPICommand("showbook") + .withArguments(PlayerArgument("target")) + .withArguments(TextArgument("title")) + .withArguments(StringArgument("author")) + .withArguments(ChatComponentArgument("contents")) + .executes(CommandExecutor { _, args -> + val target = args["target"] as Player + val title = args["title"] as String + val author = args["author"] as String + val content = args["contents"] as Component + + // Create a book and show it to the user (Requires Paper) + val mybook = Book.book(Component.text(title), Component.text(author), content) + target.openBook(mybook) + }) + .register() +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +CommandAPICommand("pbroadcast") + .withArguments(ChatArgument("message")) + .executes(CommandExecutor { _, args -> + val message = args["message"] as Component + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) + Bukkit.getServer().broadcast(message) + }) + .register() +/* ANCHOR_END: argumentChatAdventure3 */ +} + +class argument_nbt : JavaPlugin() { + +/* ANCHOR: argumentNBT1 */ +override fun onLoad() { + CommandAPI.onLoad(CommandAPIPaperConfig(this) + .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + ) +} +/* ANCHOR_END: argumentNBT1 */ + +} + +fun chatPreview() { +/* ANCHOR: chatPreview1 */ +CommandAPICommand("broadcast") + .withArguments(ChatArgument("message").withPreview { info -> + // Convert parsed Component to plain text + val plainText: String = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) + + // Translate the & in plain text and generate a new Component + LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) + }) + .executesPlayer(PlayerCommandExecutor { _, args -> + // The user still entered legacy text. We need to properly convert this + // to a Component by converting to plain text then to Component + val plainText: String = PlainTextComponentSerializer.plainText().serialize(args["message"] as Component) + Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(plainText)) + }) + .register() +/* ANCHOR_END: chatPreview1 */ + +/* ANCHOR: chatPreview2 */ +CommandAPICommand("broadcast") + .withArguments(ChatArgument("message").usePreview(true).withPreview { info -> + // Convert parsed Component to plain text + val plainText = PlainTextComponentSerializer.plainText().serialize(info.parsedInput() as Component) + + // Translate the & in plain text and generate a new Component + LegacyComponentSerializer.legacyAmpersand().deserialize(plainText) + }) + .executesPlayer(PlayerCommandExecutor { _, args -> + Bukkit.broadcast(args["message"] as Component) + }) + .register() +/* ANCHOR_END: chatPreview2 */ +} + +class setupShading { +val plugin: JavaPlugin = object : JavaPlugin() {} + +fun setupShading1() { +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(CommandAPIPaperConfig(plugin).silentLogs(true)) +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin : JavaPlugin() { + + override fun onLoad() { + CommandAPI.onLoad(CommandAPIPaperConfig(this).verboseOutput(true)) // Load with verbose output + + CommandAPICommand("ping") + .executes(CommandExecutor { sender, _ -> + sender.sendMessage("pong!") + }) + .register() + } + + override fun onEnable() { + CommandAPI.onEnable() + + // Register commands, listeners etc. + } + + override fun onDisable() { + CommandAPI.onDisable() + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt new file mode 100644 index 0000000000..08a72c561d --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt @@ -0,0 +1,80 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.kotlindsl.anyExecutor +import dev.jorel.commandapi.kotlindsl.chatArgument +import dev.jorel.commandapi.kotlindsl.chatColorArgument +import dev.jorel.commandapi.kotlindsl.chatComponentArgument +import dev.jorel.commandapi.kotlindsl.commandAPICommand +import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument +import dev.jorel.commandapi.kotlindsl.playerArgument +import dev.jorel.commandapi.kotlindsl.playerExecutor +import dev.jorel.commandapi.kotlindsl.stringArgument +import dev.jorel.commandapi.kotlindsl.textArgument +import net.kyori.adventure.inventory.Book +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.Bukkit +import org.bukkit.Server +import org.bukkit.entity.Player + +class ExamplesKotlinDSL { + +fun argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +commandAPICommand("namecolor") { + chatColorArgument("chatcolor") + playerExecutor { player, args -> + val color = args["chatcolor"] as NamedTextColor + player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) + } +} +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +commandAPICommand("showbook") { + playerArgument("target") + textArgument("title") + stringArgument("author") + chatComponentArgument("contents") + anyExecutor { _, args -> + val target = args["target"] as Player + val title = args["title"] as String + val author = args["author"] as String + val content = args["contents"] as Component + + // Create a book and show it to the user (Requires Paper) + val mybook = Book.book(Component.text(title), Component.text(author), content) + target.openBook(mybook) + } +} +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +commandAPICommand("pbroadcast") { + chatArgument("message") + anyExecutor { _, args -> + val message = args["message"] as Component + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) + Bukkit.getServer().broadcast(message) + } +} +/* ANCHOR_END: argumentChatAdventure3 */ +} + +fun argument_nbt() { +/* ANCHOR: argumentNBT1 */ +commandAPICommand("award") { + nbtCompoundArgument("nbt") + anyExecutor { _, args -> + val nbt = args["nbt"] as NBTContainer + + // Do something with "nbt" here... + } +} +/* ANCHOR_END: argumentNBT1 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml new file mode 100644 index 0000000000..acf34ab12c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-mojang-mapped + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/pom.xml new file mode 100644 index 0000000000..a8f0588f85 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.16.5 + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + com.destroystokyo.paper + paper-api + 1.16.5-R0.1-SNAPSHOT + provided + + + + + org.spigotmc + spigot + 1.16.5-R0.1-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.16.5 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_16_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_16_R3.java new file mode 100644 index 0000000000..01076d5eb6 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.16.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_16_R3.java @@ -0,0 +1,61 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.server.v1_16_R3.ArgumentChat; +import net.minecraft.server.v1_16_R3.ArgumentChatComponent; +import net.minecraft.server.v1_16_R3.ArgumentChatFormat; +import net.minecraft.server.v1_16_R3.CommandListenerWrapper; +import net.minecraft.server.v1_16_R3.IChatBaseComponent; +import net.minecraft.server.v1_16_R3.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_16_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper; + +public class PaperNMS_1_16_R3 extends CommandAPIPaper { + + private NMS_1_16_R3 bukkitNMS; + + @Override + public final Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(IChatBaseComponent.ChatSerializer.a(ArgumentChat.a(cmdCtx, key))); + } + + @Override + public final NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ArgumentChatFormat.a(cmdCtx, key).e(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(IChatBaseComponent.ChatSerializer.a(ArgumentChatComponent.a(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_16_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.a(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommandDispatcher().a(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/pom.xml new file mode 100644 index 0000000000..b048ffd67f --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.17-common + + + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_Common.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_Common.java new file mode 100644 index 0000000000..a0c64fb6e2 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_Common.java @@ -0,0 +1,43 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_17_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_17_R1.command.VanillaCommandWrapper; + +public abstract class PaperNMS_1_17_Common extends PaperNMS_Common { + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS().getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS().getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS().getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/pom.xml new file mode 100644 index 0000000000..5ee3d9c9e1 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.17.1 + + + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + + + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + dev.jorel + commandapi-bukkit-1.17.1 + ${project.version} + + + dev.jorel + commandapi-paper-1.17-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.17-common + ${project.version} + mojang-mapped + provided + + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + org.spigotmc + spigot + ${spigot.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_R1.java new file mode 100644 index 0000000000..f39a24dd17 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17_R1.java @@ -0,0 +1,17 @@ +package dev.jorel.commandapi.nms; + +import net.minecraft.commands.CommandSourceStack; + +public class PaperNMS_1_17_R1 extends PaperNMS_1_17_Common { + + private NMS_1_17_R1 bukkitNMS; + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_17_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/pom.xml new file mode 100644 index 0000000000..9a41bb4b50 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/pom.xml @@ -0,0 +1,155 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.17 + + + 1.17-R0.1-SNAPSHOT + 1.17-R0.1-SNAPSHOT + 1.17-R0.1-SNAPSHOT + + + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public// + + + + + + dev.jorel + commandapi-bukkit-1.17 + ${project.version} + + + dev.jorel + commandapi-paper-1.17-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.17-common + ${project.version} + mojang-mapped + provided + + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17.java new file mode 100644 index 0000000000..8ddc966567 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.17/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_17.java @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.nms; + +public class PaperNMS_1_17 extends PaperNMS_1_17_Common { + + private NMS_1_17 bukkitNMS; + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + bukkitNMS = new NMS_1_17(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/pom.xml new file mode 100644 index 0000000000..6ab0c55fcb --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.18.2 + + + 1.18.2-R0.1-SNAPSHOT + 1.18.2-R0.1-SNAPSHOT + 1.18.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.18.2 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R2.java new file mode 100644 index 0000000000..48b833adab --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R2.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_18_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_18_R2.command.VanillaCommandWrapper; + +public class PaperNMS_1_18_R2 extends PaperNMS_Common { + + private NMS_1_18_R2 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_18_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/pom.xml new file mode 100644 index 0000000000..15b70c9d67 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.18 + + + 1.18.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.18 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R1.java new file mode 100644 index 0000000000..2ef61895d7 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.18/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_18_R1.java @@ -0,0 +1,55 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_18_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_18_R1.command.VanillaCommandWrapper; + +public class PaperNMS_1_18_R1 extends PaperNMS_Common { + + private NMS_1_18_R1 bukkitNMS; + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.ofExact(color); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_18_R1(); + } + return bukkitNMS; + } + + @Override + @Differs(from = "1.17", by = "MinecraftServer#getCommands -> MinecraftServer#aA") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/pom.xml new file mode 100644 index 0000000000..306d921cd4 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.19-common + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common.java new file mode 100644 index 0000000000..69e8e07adc --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common.java @@ -0,0 +1,116 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import dev.jorel.commandapi.preprocessor.Unimplemented; +import io.netty.channel.Channel; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R1.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; + +public abstract class PaperNMS_1_19_Common extends PaperNMS_Common { + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public void onEnable() { + super.onEnable(); + + JavaPlugin plugin = getConfiguration().getPlugin(); + // Enable chat preview if the server allows it + if (Bukkit.shouldSendChatPreviews()) { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + hookChatPreview(plugin, e.getPlayer()); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + unhookChatPreview(e.getPlayer()); + } + + }, plugin); + CommandAPI.logNormal("Chat preview enabled"); + } else { + CommandAPI.logNormal("Chat preview is not available"); + } + } + + /** + * Hooks into the chat previewing system + * + * @param plugin the plugin (for async calls) + * @param player the player to hook + */ + @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) + protected abstract void hookChatPreview(Plugin plugin, Player player); + + /** + * Unhooks a player from the chat previewing system. This should be + * called when the player quits and when the plugin is disabled + * + * @param player the player to unhook + */ + private void unhookChatPreview(Player player) { + final Channel channel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (channel.pipeline().get("CommandAPI_" + player.getName()) != null) { + channel.eventLoop().submit(() -> channel.pipeline().remove("CommandAPI_" + player.getName())); + } + } + + @Override + public void onDisable() { + super.onDisable(); + + for (Player player : Bukkit.getOnlinePlayers()) { + unhookChatPreview(player); + } + } + + @Override + @Differs(from = "1.18", by = "MinecraftServer#aA -> MinecraftServer#aC") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS().getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS().getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS().getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common_ChatPreviewHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common_ChatPreviewHandler.java new file mode 100644 index 0000000000..08e3f9b211 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_Common_ChatPreviewHandler.java @@ -0,0 +1,132 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.ParseResults; +import com.mojang.brigadier.context.ParsedCommandNode; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.arguments.PreviewInfo; +import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import dev.jorel.commandapi.wrappers.PreviewableFunction; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public abstract class PaperNMS_1_19_Common_ChatPreviewHandler extends ChannelDuplexHandler { + + protected final CommandAPIPaper platform; + protected final Plugin plugin; + protected final Player player; + protected final Connection connection; + + protected PaperNMS_1_19_Common_ChatPreviewHandler(CommandAPIPaper platform, Plugin plugin, Player player) { + this.platform = (CommandAPIPaper) platform; + this.plugin = plugin; + this.player = player; + this.connection = ((CraftPlayer) player).getHandle().connection.connection; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof ServerboundChatPreviewPacket chatPreview) { + // make sure the result is worth consuming here + // Is command + if (!chatPreview.query().isEmpty() && chatPreview.query().charAt(0) == '/') { + // Is previewable argument + if (InitialParse.processChatPreviewQuery(chatPreview.query(), platform, player).preview.isPresent()) { + handleChatPreviewPacket(chatPreview); + return; + } + } + } + + // Normal packet handling + super.channelRead(ctx, msg); + } + + protected abstract void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview); + + public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { + final InitialParse ip = InitialParse.processChatPreviewQuery(chatPreviewQuery, platform, player); + final Optional> preview = ip.preview; + if (preview.isEmpty()) { + return null; + } + + final String fullInput = ip.fullInput; + final ParseResults results = ip.results; + final List path = ip.path; + + // Calculate the (argument) input and generate the component to send + String input = results.getContext().getNodes().get(results.getContext().getNodes().size() - 1).getRange().get(fullInput); + + final String jsonToSend; + + Object component; + try { + @SuppressWarnings("rawtypes") final PreviewInfo previewInfo; + Component parsedInput; + try { + parsedInput = platform.getChat(results.getContext().build(fullInput), path.get(path.size() - 1)); + } catch (CommandSyntaxException e) { + throw new WrapperCommandSyntaxException(e); + } + previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); + + component = preview.get().generatePreview(previewInfo); + } catch (WrapperCommandSyntaxException e) { + component = PlainTextComponentSerializer.plainText().deserialize(e.getMessage() == null ? "" : e.getMessage()); + } + + if (component != null) { + if (component instanceof Component adventureComponent) { + jsonToSend = GsonComponentSerializer.gson().serialize(adventureComponent); + } else { + throw new IllegalArgumentException("Unexpected type returned from chat preview, got: " + component.getClass().getSimpleName()); + } + } else { + throw new NullPointerException("Returned value from chat preview was null"); + } + + return net.minecraft.network.chat.Component.Serializer.fromJson(jsonToSend); + } + + private record InitialParse(String fullInput, ParseResults results, List path, Optional> preview){ + private static InitialParse cachedResult = null; + public static InitialParse processChatPreviewQuery(String chatPreviewQuery, CommandAPIPaper platform, Player player){ + // Substring 1 to get rid of the leading / + final String fullInput = chatPreviewQuery.substring(1); + + if(cachedResult != null && cachedResult.fullInput.equals(fullInput)) return cachedResult; + + ParseResults results = platform.getBrigadierDispatcher() + .parse(fullInput, platform.getBrigadierSourceFromCommandSender(new BukkitPlayer(player))); + + // Generate the path for lookup + List path = new ArrayList<>(); + for (ParsedCommandNode commandNode : results.getContext().getNodes()) { + path.add(commandNode.getNode().getName()); + } + Optional> preview = CommandAPIHandler.getInstance().lookupPreviewable(path); + + cachedResult = new InitialParse(fullInput, results, path, preview); + return cachedResult; + } + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/pom.xml new file mode 100644 index 0000000000..f18802df9e --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/pom.xml @@ -0,0 +1,172 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.19.1 + + + 1.19.2-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + + dev.jorel + commandapi-paper-1.19-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19-common + ${project.version} + mojang-mapped + provided + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19.1 + ${project.version} + compile + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1.java new file mode 100644 index 0000000000..e2882a8620 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1.java @@ -0,0 +1,29 @@ +package dev.jorel.commandapi.nms; + +import io.netty.channel.Channel; +import net.minecraft.commands.CommandSourceStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class PaperNMS_1_19_1_R1 extends PaperNMS_1_19_Common { + + private NMS_1_19_1_R1 bukkitNMS; + + @Override + public void hookChatPreview(Plugin plugin, Player player) { + final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { + playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new PaperNMS_1_19_1_R1_ChatPreviewHandler(this, plugin, player)); + } + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + bukkitNMS = new NMS_1_19_1_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1_ChatPreviewHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1_ChatPreviewHandler.java new file mode 100644 index 0000000000..e3eb6997d1 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.1/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_1_R1_ChatPreviewHandler.java @@ -0,0 +1,68 @@ +package dev.jorel.commandapi.nms; + +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.SafeVarHandle; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.PacketSendListener; +import net.minecraft.network.chat.ChatPreviewCache; +import net.minecraft.network.chat.ChatPreviewThrottler; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundChatPreviewPacket; +import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_19_1_R1_ChatPreviewHandler extends PaperNMS_1_19_Common_ChatPreviewHandler { + + private static final SafeVarHandle packetListenerPreviewThrottler; + private static final SafeVarHandle packetListenerPreviewCache; + + static { + packetListenerPreviewThrottler = SafeVarHandle.ofOrNull(ServerGamePacketListenerImpl.class, "M", "chatPreviewThrottler", ChatPreviewThrottler.class); + packetListenerPreviewCache = SafeVarHandle.ofOrNull(ServerGamePacketListenerImpl.class, "L", "chatPreviewCache", ChatPreviewCache.class); + } + + ChatPreviewThrottler throttler; + + public PaperNMS_1_19_1_R1_ChatPreviewHandler(CommandAPIPaper platform, Plugin plugin, Player player) { + super(platform, plugin, player); + + throttler = packetListenerPreviewThrottler.get(((CraftPlayer) player).getHandle().connection); + } + + @Override + protected void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview) { + // We want to run this synchronously, just in case there's some funky async stuff going on here + throttler.schedule(() -> { + int i = chatPreview.queryId(); + CompletableFuture result = new CompletableFuture<>(); + + // Get preview + Bukkit.getScheduler().runTask(this.plugin, () -> result.complete(parseChatPreviewQuery(chatPreview.query()))); + + // Update player's ChatPreviewCache + result.thenAcceptAsync(component -> { + if(component == null) return; + ChatPreviewCache c = packetListenerPreviewCache.get(((CraftPlayer) player).getHandle().connection); + c.set(chatPreview.query().substring(1), component); + }); + + // Send ChatPreviewPacket using the throttler + return result.thenAccept( + component -> { + if(component == null) return; + connection.send( + new ClientboundChatPreviewPacket(i, component), + PacketSendListener.exceptionallySend(() -> new ClientboundChatPreviewPacket(i, null)) + ); + } + ); + }); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/pom.xml new file mode 100644 index 0000000000..f749df52fc --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/pom.xml @@ -0,0 +1,157 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.19.3 + + + 1.19.3-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19.3 + ${project.version} + compile + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_3_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_3_R2.java new file mode 100644 index 0000000000..829d6545b6 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_3_R2.java @@ -0,0 +1,55 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R2.command.VanillaCommandWrapper; + +public class PaperNMS_1_19_3_R2 extends PaperNMS_Common { + + private NMS_1_19_3_R2 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_3_R2(); + } + return bukkitNMS; + } + + @Override + @Differs(from = "1.19, 1.19.1, 1.19.2", by = "MinecraftServer#aC -> MinecraftServer#aB") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/pom.xml new file mode 100644 index 0000000000..6ad49f5a45 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.19.4 + + + 1.19.4-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19.4 + ${project.version} + compile + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_4_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_4_R3.java new file mode 100644 index 0000000000..eff0d73b59 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_4_R3.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R3.command.VanillaCommandWrapper; + +public class PaperNMS_1_19_4_R3 extends PaperNMS_Common { + + private NMS_1_19_4_R3 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_4_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/pom.xml new file mode 100644 index 0000000000..24cf096523 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/pom.xml @@ -0,0 +1,172 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.19 + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + + dev.jorel + commandapi-paper-1.19-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19-common + ${project.version} + mojang-mapped + provided + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-1.19 + ${project.version} + compile + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1.java new file mode 100644 index 0000000000..a55eb42273 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1.java @@ -0,0 +1,29 @@ +package dev.jorel.commandapi.nms; + +import io.netty.channel.Channel; +import net.minecraft.commands.CommandSourceStack; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class PaperNMS_1_19_R1 extends PaperNMS_1_19_Common { + + private NMS_1_19_R1 bukkitNMS; + + @Override + protected void hookChatPreview(Plugin plugin, Player player) { + final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { + playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new PaperNMS_1_19_R1_ChatPreviewHandler(this, plugin, player)); + } + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + bukkitNMS = new NMS_1_19_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1_ChatPreviewHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1_ChatPreviewHandler.java similarity index 74% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1_ChatPreviewHandler.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1_ChatPreviewHandler.java index 7e886c6d67..8fc42f813f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_R1_ChatPreviewHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.19/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_19_R1_ChatPreviewHandler.java @@ -1,6 +1,6 @@ package dev.jorel.commandapi.nms; -import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.protocol.game.ClientboundChatPreviewPacket; import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; @@ -8,9 +8,9 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -public class NMS_1_19_R1_ChatPreviewHandler extends NMS_1_19_Common_ChatPreviewHandler { +public class PaperNMS_1_19_R1_ChatPreviewHandler extends PaperNMS_1_19_Common_ChatPreviewHandler { - public NMS_1_19_R1_ChatPreviewHandler(CommandAPIBukkit platform, Plugin plugin, Player player) { + public PaperNMS_1_19_R1_ChatPreviewHandler(CommandAPIPaper platform, Plugin plugin, Player player) { super(platform, plugin, player); } @@ -21,4 +21,4 @@ protected void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview) new ClientboundChatPreviewPacket(chatPreview.queryId(), parseChatPreviewQuery(chatPreview.query())) )); } -} \ No newline at end of file +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/pom.xml new file mode 100644 index 0000000000..ba937b56f8 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.20.2 + + + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.2 + ${project.version} + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R2.java new file mode 100644 index 0000000000..8f68375606 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R2.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; + +public class PaperNMS_1_20_R2 extends PaperNMS_Common { + + private NMS_1_20_R2 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/pom.xml new file mode 100644 index 0000000000..54d244e755 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.20.3 + + + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.3 + ${project.version} + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R3.java new file mode 100644 index 0000000000..d49af75f95 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.3/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R3.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R3.command.VanillaCommandWrapper; + +public class PaperNMS_1_20_R3 extends PaperNMS_Common { + + private NMS_1_20_R3 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml new file mode 100644 index 0000000000..36a4f89087 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.20.5 + + + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.20.6-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + mojang-mapped + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.4 + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java new file mode 100644 index 0000000000..949c3f7dee --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java @@ -0,0 +1,105 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import dev.jorel.commandapi.SpigotCommandRegistration; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.command.VanillaCommandWrapper; + +import java.lang.reflect.Field; + +public class PaperNMS_1_20_R4 extends PaperNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private static final boolean vanillaCommandDispatcherFieldExists; + private static final Commands vanillaCommandDispatcher; + + private NMS_1_20_R4 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + + boolean fieldExists; + Commands commandDispatcher; + try { + Field vanillaCommandDispatcherField = MinecraftServer.class.getDeclaredField("vanillaCommandDispatcher"); + commandDispatcher = (Commands) vanillaCommandDispatcherField.get(getPaper().bukkitNMS().getMinecraftServer()); + fieldExists = true; + } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { + // Expected on Paper-1.20.6-65 or later due to https://github.com/PaperMC/Paper/pull/8235 + commandDispatcher = null; + fieldExists = false; + } + vanillaCommandDispatcher = commandDispatcher; + vanillaCommandDispatcherFieldExists = fieldExists; + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R4(COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + if (vanillaCommandDispatcherFieldExists) { + return new SpigotCommandRegistration<>( + vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } else { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/pom.xml new file mode 100644 index 0000000000..04c5ff4f96 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.20 + + + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20 + ${project.version} + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R1.java new file mode 100644 index 0000000000..b185979514 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R1.java @@ -0,0 +1,53 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R1.command.VanillaCommandWrapper; + +public class PaperNMS_1_20_R1 extends PaperNMS_Common { + + private NMS_1_20_R1 bukkitNMS; + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public final Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R1(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml new file mode 100644 index 0000000000..945627bff7 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.21.2 + + + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.21.3-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + mojang-mapped + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.4 + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java new file mode 100644 index 0000000000..71d7d9ad60 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java @@ -0,0 +1,71 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; + +public class PaperNMS_1_21_R2 extends PaperNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R2 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml new file mode 100644 index 0000000000..6a0de86f9a --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.21.4 + + + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.21.4-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.4 + ${project.version} + mojang-mapped + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.5-SNAPSHOT + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java new file mode 100644 index 0000000000..b63b8d75f6 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java @@ -0,0 +1,71 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; + +public class PaperNMS_1_21_R3 extends PaperNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R3 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml new file mode 100644 index 0000000000..74a11e156a --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -0,0 +1,110 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-1.21 + + + 1.21-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.21-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + mojang-mapped + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.4 + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java new file mode 100644 index 0000000000..6be9e8ca0f --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java @@ -0,0 +1,71 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; + +public class PaperNMS_1_21_R1 extends PaperNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R1 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R1(COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common-mojang-mapped/pom.xml new file mode 100644 index 0000000000..cfcbfdcfd6 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common-mojang-mapped/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-nms-common-mojang-mapped + + pom + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-bukkit-nms-common + + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + mojang-mapped + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/pom.xml new file mode 100644 index 0000000000..d3c1d2e5cb --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/pom.xml @@ -0,0 +1,234 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-nms-common + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + + org.spigotmc + spigot + ${spigot.version} + provided + remapped-mojang + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + + + + Spigot_1_20_4_R3 + + + org.spigotmc + spigot + 1.20.4-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_2_R2 + + + org.spigotmc + spigot + 1.20.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_R1 + + + org.spigotmc + spigot + 1.20-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_19_3_R2 + + + org.spigotmc + spigot + 1.19.3-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_19_R1 + + true + + + + org.spigotmc + spigot + 1.19-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_18_2_R2 + + + org.spigotmc + spigot + 1.18.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_18_R1 + + + org.spigotmc + spigot + 1.18-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_17_R1 + + + org.spigotmc + spigot + 1.17-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_Common.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_Common.java new file mode 100644 index 0000000000..cdb7c3eea2 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-common/src/main/java/dev/jorel/commandapi/nms/PaperNMS_Common.java @@ -0,0 +1,31 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.preprocessor.Unimplemented; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.MessageArgument; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; + +public abstract class PaperNMS_Common extends CommandAPIPaper { + + @Override + public Component getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, from = "ofExact", to = "namedColor", in = "NamedTextColor", introducedIn = "Adventure 4.10.0", info = "1.18 uses Adventure 4.9.3. 1.18.2 uses Adventure 4.11.0") + public abstract NamedTextColor getChatColor(CommandContext cmdCtx, String key); + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency-mojang-mapped/pom.xml new file mode 100644 index 0000000000..2fd8d8791b --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency-mojang-mapped/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-nms-dependency-mojang-mapped + pom + + + + + dev.jorel + commandapi-paper-nms-common-mojang-mapped + ${project.version} + pom + + + dev.jorel + commandapi-paper-1.19-common + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.17-common + ${project.version} + mojang-mapped + + + + + dev.jorel + commandapi-bukkit-1.17-common + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-bukkit-1.19-common + ${project.version} + mojang-mapped + + + + + dev.jorel + commandapi-paper-1.21.4 + ${project.version} + + + dev.jorel + commandapi-paper-1.21.2 + ${project.version} + + + dev.jorel + commandapi-paper-1.21 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.5 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.3 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.20.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.20 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.19.4 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.19.3 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.19.1 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.19 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.18.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.18 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.17 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-paper-1.17.1 + ${project.version} + mojang-mapped + + + + + dev.jorel + commandapi-paper-1.16.5 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml new file mode 100644 index 0000000000..2c4dcb6103 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml @@ -0,0 +1,128 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 9.7.1-SNAPSHOT + + + commandapi-paper-nms-dependency + pom + + + + + dev.jorel + commandapi-paper-nms-common + ${project.version} + + + dev.jorel + commandapi-paper-1.19-common + ${project.version} + + + dev.jorel + commandapi-paper-1.17-common + ${project.version} + + + + + dev.jorel + commandapi-bukkit-1.17-common + ${project.version} + + + dev.jorel + commandapi-bukkit-1.19-common + ${project.version} + + + + + dev.jorel + commandapi-paper-1.21.4 + ${project.version} + + + dev.jorel + commandapi-paper-1.21.2 + ${project.version} + + + dev.jorel + commandapi-paper-1.21 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.5 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.3 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.2 + ${project.version} + + + dev.jorel + commandapi-paper-1.20 + ${project.version} + + + dev.jorel + commandapi-paper-1.19.4 + ${project.version} + + + dev.jorel + commandapi-paper-1.19.3 + ${project.version} + + + dev.jorel + commandapi-paper-1.19.1 + ${project.version} + + + dev.jorel + commandapi-paper-1.19 + ${project.version} + + + dev.jorel + commandapi-paper-1.18.2 + ${project.version} + + + dev.jorel + commandapi-paper-1.18 + ${project.version} + + + dev.jorel + commandapi-paper-1.17 + ${project.version} + + + dev.jorel + commandapi-paper-1.17.1 + ${project.version} + + + dev.jorel + commandapi-paper-1.16.5 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml new file mode 100644 index 0000000000..1d2ec9c71c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-nms + pom + + + commandapi-paper-nms-common + commandapi-paper-nms-common-mojang-mapped + + commandapi-paper-1.21.4 + commandapi-paper-1.21.2 + commandapi-paper-1.21 + commandapi-paper-1.20.5 + commandapi-paper-1.20.3 + commandapi-paper-1.20.2 + commandapi-paper-1.20 + commandapi-paper-1.19-common + commandapi-paper-1.19.4 + commandapi-paper-1.19.3 + commandapi-paper-1.19.1 + commandapi-paper-1.19 + commandapi-paper-1.18.2 + commandapi-paper-1.18 + commandapi-paper-1.17-common + commandapi-paper-1.17.1 + commandapi-paper-1.17 + commandapi-paper-1.16.5 + + commandapi-paper-nms-dependency + commandapi-paper-nms-dependency-mojang-mapped + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/pom.xml similarity index 67% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/pom.xml index 3ee82a354b..8de175c4e8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/pom.xml @@ -1,36 +1,15 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel + commandapi-paper 9.7.1-SNAPSHOT - 4.0.0 - - commandapi-bukkit-plugin-mojang-mapped + commandapi-paper-plugin-mojang-mapped @@ -51,45 +30,39 @@ dev.jorel - commandapi-bukkit-core + commandapi-paper-core ${project.version} compile - + dev.jorel - commandapi-bukkit-nms-dependency-mojang-mapped + commandapi-paper-nms-dependency-mojang-mapped ${project.version} pom dev.jorel - commandapi-bukkit-vh + commandapi-paper-vh ${project.version} dev.jorel - commandapi-bukkit-mojang-mapped + commandapi-paper-mojang-mapped ${project.version} - io.papermc.paper - paper-api - ${paper.version} - provided + dev.jorel + commandapi-bukkit-plugin-common + ${project.version} - org.spigotmc - spigot-api + io.papermc.paper + paper-api ${paper.version} provided - - dev.jorel - commandapi-bukkit-plugin-common - ${project.version} - @@ -177,4 +150,5 @@ + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java new file mode 100644 index 0000000000..8e17c74be5 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CommandAPIArgumentType; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.FloatRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.OfflinePlayerArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.exceptions.InvalidNumberException; +import dev.jorel.commandapi.exceptions.UnknownArgumentException; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A command parsing system that converts string arguments into something way + * more useful + */ +class AdvancedConverter { + + /** + * Pattern for arguments, which are of the form {@code [type]} + *
    + *
  • {@code node_name} is a standard node name.
  • + *
  • {@code type} is either a namespaced key representing the argument + * (described in {@code conversionforownerssingleargs.md} in the main + * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or + * {@code n..} where {@code n} is a constant integer or floating point + * number
  • + *
+ */ + private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); + + /** + * Pattern for literal, of the form {@code (node_name)}. It also supports + * multiple node names of the form + * {@code (node_name_1|node_name_2|...|node_name_n)} + */ + private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); + + private final JavaPlugin plugin; + private final String command; + private int argumentIndex = 1; + + public AdvancedConverter(JavaPlugin plugin, String command) { + this.plugin = plugin; + this.command = command; + } + + public AdvancedConverter(String command) { + this.plugin = null; + this.command = command; + } + + public void convert() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(plugin, commandName); + } else { + Converter.convert(plugin, commandName, arguments); + } + + } + + public void convertCommand() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(commandName); + } else { + Converter.convert(commandName, arguments); + } + } + + /** + *
+	 * plugins-to-convert: 
+	 *   - Essentials: 
+	 *     - speed [0..10]
+	 *     - speed [minecraft:game_profile]
+	 *     - speed (walk|fly) [0..10]
+	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
+	 * 
+ */ + private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { + List> arguments = new ArrayList<>(); + String[] parts = command.split(" "); + for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { + arguments.add(parseArgument(parts[argumentIndex])); + } + return arguments; + } + + private boolean isRangeAnInteger(double value) { + return value == (long) value; + } + + private double parseValue(String bound) throws InvalidNumberException { + try { + return Double.parseDouble(bound); + } catch (NumberFormatException e) { + throw new InvalidNumberException(bound, command, argumentIndex); + } + } + + private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { + if (bounds.length == 1) { + // x.. + double value = parseValue(bounds[0]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, (long) value); + } else { + return new DoubleArgument(nodeName, value); + } + } else if (bounds[0].length() == 0) { + // ..x + double value = parseValue(bounds[1]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); + } else { + return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); + } + } else { + // x..x + double value0 = parseValue(bounds[0]); + double value1 = parseValue(bounds[1]); + if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { + return new DoubleArgument(nodeName, value0, value1); + } else { + return new LongArgument(nodeName, (long) value0, (long) value1); + } + } + } + + /* + * CodeFactor will always complain about this method because it's really bulky + * and adding a generator (i.e. Function>) inside the + * CommandAPIArgumentType class would be better, EXCEPT in practice, this is + * worse because then CommandAPIArgumentType would have to depend on every + * argument and every argument depends on CommandAPIArgumentType, so that would + * mean every argument would always have to be packaged in the CommandAPI - jar + * minimisation wouldn't be able to minimise this as best as it could. + * + * Additionally, we only need this for the plugin version of the CommandAPI, not + * the main API. + */ + @SuppressWarnings("rawtypes") + private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { + return switch (CommandAPIArgumentType.fromInternal(argumentType)) { + case ADVANCEMENT -> new AdvancementArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case ANGLE -> new AngleArgument(nodeName); + case AXIS -> new AxisArgument(nodeName); + case BIOME -> new BiomeArgument(nodeName); + case BLOCKSTATE -> new BlockStateArgument(nodeName); + case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); + case CHAT -> new ChatArgument(nodeName); + case CHATCOLOR -> new ChatColorArgument(nodeName); + case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case COMMAND -> new CommandArgument(nodeName); + case ENCHANTMENT -> new EnchantmentArgument(nodeName); + case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); + case ENTITY_TYPE -> new EntityTypeArgument(nodeName); + case FLOAT_RANGE -> new FloatRangeArgument(nodeName); + case FUNCTION -> new FunctionArgument(nodeName); + case INT_RANGE -> new IntegerRangeArgument(nodeName); + case ITEMSTACK -> new ItemStackArgument(nodeName); + case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); + case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); + case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); + case LOOT_TABLE -> new LootTableArgument(nodeName); + case MATH_OPERATION -> new MathOperationArgument(nodeName); + case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); + case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); + case OBJECTIVE -> new ObjectiveArgument(nodeName); + case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); + case OFFLINE_PLAYER -> new OfflinePlayerArgument(nodeName); + case PARTICLE -> new ParticleArgument(nodeName); + case PLAYER -> new PlayerArgument(nodeName); + case POTION_EFFECT -> new PotionEffectArgument(nodeName); + case RECIPE -> new RecipeArgument(nodeName); + case ROTATION -> new RotationArgument(nodeName); + case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); + case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); + case SOUND -> new SoundArgument(nodeName); + case TEAM -> new TeamArgument(nodeName); + case TIME -> new TimeArgument(nodeName); + case UUID -> new UUIDArgument(nodeName); + case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); + case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); + case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); + case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); + case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); + case PRIMITIVE_LONG -> new LongArgument(nodeName); + case PRIMITIVE_STRING -> new StringArgument(nodeName); + case PRIMITIVE_TEXT -> new TextArgument(nodeName); + case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); + default -> throw new UnknownArgumentException(argumentType); + }; + } + + private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { + Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); + Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); + if (literalMatcher.matches()) { + // Parse literals + return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); + } else if (argumentMatcher.matches()) { + // Parse arguments + String nodeName = argumentMatcher.group(1); + String argumentType = argumentMatcher.group(2); + + if (argumentType.contains("..")) { + // Parse ranges + return parseRange(nodeName, argumentType.split("\\.\\.")); + } else { + // We have a few edge cases to handle + return switch (argumentType) { + case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); + case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); + case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); + case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); + case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); + case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); + default -> parseDefinedArgumentType(argumentType, nodeName); + }; + } + } else { + throw new UnknownArgumentException(argument); + } + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 06b984520f..2a8645078b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -21,6 +21,7 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.InvalidPluginException; @@ -45,7 +46,7 @@ public void onLoad() { // Read config file saveDefaultConfig(); FileConfiguration fileConfig = getConfig(); - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(this) + CommandAPIPaperConfig config = new CommandAPIPaperConfig(this) .verboseOutput(fileConfig.getBoolean("verbose-outputs")) .silentLogs(fileConfig.getBoolean("silent-logs")) .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) @@ -145,7 +146,11 @@ public void onEnable() { @Override public void saveDefaultConfig() { File configFile = new File(getDataFolder(), "config.yml"); - BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig(getDataFolder(), getLogger()); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveConfig( + DefaultBukkitConfig.createDefaultPaperConfig(), + getDataFolder(), + getLogger() + ); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/resources/config.yml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/resources/config.yml new file mode 100644 index 0000000000..324801b268 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/resources/config.yml @@ -0,0 +1,83 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Hook into Paper's ServerResourcesReloadedEvent (default: true) +# If "true", and the CommandAPI detects it is running on a Paper server, it will +# hook into Paper's ServerResourcesReloadedEvent to detect when /minecraft:reload is run. +# This allows the CommandAPI to automatically call its custom datapack-reloading +# function which allows CommandAPI commands to be used in datapacks. +# If you set this to false, CommandAPI commands may not work inside datapacks after +# reloading datapacks. +hook-paper-reload: true + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/resources/plugin.yml similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/plugin.yml rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin-mojang-mapped/src/main/resources/plugin.yml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/LICENSE b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/LICENSE similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/LICENSE rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/LICENSE diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml new file mode 100644 index 0000000000..0981aa68fa --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-plugin + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-paper-vh + ${project.version} + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + dev.jorel + commandapi-bukkit-plugin-common + ${project.version} + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + LICENSE + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java index ee37b92115..bf170af4d4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -28,8 +28,8 @@ import org.bukkit.plugin.java.JavaPlugin; import dev.jorel.commandapi.arguments.AdvancementArgument; -import dev.jorel.commandapi.arguments.AdventureChatArgument; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; import dev.jorel.commandapi.arguments.AngleArgument; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.AxisArgument; @@ -37,9 +37,7 @@ import dev.jorel.commandapi.arguments.BlockPredicateArgument; import dev.jorel.commandapi.arguments.BlockStateArgument; import dev.jorel.commandapi.arguments.BooleanArgument; -import dev.jorel.commandapi.arguments.ChatArgument; import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; import dev.jorel.commandapi.arguments.CommandAPIArgumentType; import dev.jorel.commandapi.arguments.CommandArgument; import dev.jorel.commandapi.arguments.DoubleArgument; @@ -231,8 +229,8 @@ private Argument parseRange(String nodeName, String[] bounds) throws InvalidN private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { return switch (CommandAPIArgumentType.fromInternal(argumentType)) { case ADVANCEMENT -> new AdvancementArgument(nodeName); - case ADVENTURE_CHAT -> new AdventureChatArgument(nodeName); - case ADVENTURE_CHAT_COMPONENT -> new AdventureChatComponentArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); case ANGLE -> new AngleArgument(nodeName); case AXIS -> new AxisArgument(nodeName); case BIOME -> new BiomeArgument(nodeName); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java new file mode 100644 index 0000000000..2a8645078b --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Main CommandAPI plugin entrypoint + */ +public class CommandAPIMain extends JavaPlugin { + + private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; + + @Override + public void onLoad() { + // Read config file + saveDefaultConfig(); + FileConfiguration fileConfig = getConfig(); + CommandAPIPaperConfig config = new CommandAPIPaperConfig(this) + .verboseOutput(fileConfig.getBoolean("verbose-outputs")) + .silentLogs(fileConfig.getBoolean("silent-logs")) + .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) + .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) + .shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload")) + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + + for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + config.addSkipSenderProxy(pluginName); + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + } + + // Main CommandAPI loading + CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); + CommandAPI.onLoad(config); + + // Convert all plugins to be converted + if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() + && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { + CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); + } + + convertCommands(fileConfig); + } + + private void convertCommands(FileConfiguration fileConfig) { + // Load all plugins at the same time + Map pluginsToConvert = new HashMap<>(); + for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { + String[] pluginCommands; + if (map.values().size() == 1 && map.values().iterator().next() == null) { + pluginCommands = new String[0]; + } else { + @SuppressWarnings("unchecked") + List commands = (List) map.values().iterator().next(); + pluginCommands = commands.toArray(new String[0]); + } + + // Get the plugin, if it doesn't exist, scream in the console (but + // don't crash, we want to continue!) + final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); + if (plugin != null) { + pluginsToConvert.put(plugin, pluginCommands); + } + } + + // Convert plugin commands + for (Entry pluginToConvert : pluginsToConvert.entrySet()) { + if (pluginToConvert.getValue().length == 0) { + Converter.convert(pluginToConvert.getKey()); + } else { + for (String command : pluginToConvert.getValue()) { + new AdvancedConverter(pluginToConvert.getKey(), command).convert(); + } + } + } + + // Convert all arbitrary commands + for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { + new AdvancedConverter(commandName).convertCommand(); + } + } + + private JavaPlugin getAndValidatePlugin(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + if (plugin instanceof JavaPlugin javaPlugin) { + return javaPlugin; + } else { + new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); + } + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + return null; + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + /** + * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, + * this doesn't fail silently if the config.yml already exists but instead will update the config with + * new values if available. + *

+ * This should fail silently if all values are set already. + */ + @Override + public void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveConfig( + DefaultBukkitConfig.createDefaultPaperConfig(), + getDataFolder(), + getLogger() + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/config.yml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/config.yml new file mode 100644 index 0000000000..324801b268 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/config.yml @@ -0,0 +1,83 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Hook into Paper's ServerResourcesReloadedEvent (default: true) +# If "true", and the CommandAPI detects it is running on a Paper server, it will +# hook into Paper's ServerResourcesReloadedEvent to detect when /minecraft:reload is run. +# This allows the CommandAPI to automatically call its custom datapack-reloading +# function which allows CommandAPI commands to be used in datapacks. +# If you set this to false, CommandAPI commands may not work inside datapacks after +# reloading datapacks. +hook-paper-reload: true + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/plugin.yml similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/plugin.yml rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/plugin.yml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade-mojang-mapped/pom.xml similarity index 54% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml rename to commandapi-platforms/commandapi-paper/commandapi-paper-shade-mojang-mapped/pom.xml index 2bfcbf1cc9..719a9589d5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade-mojang-mapped/pom.xml @@ -1,54 +1,38 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel + commandapi-paper 9.7.1-SNAPSHOT - 4.0.0 - - commandapi-bukkit-shade + commandapi-paper-shade-mojang-mapped dev.jorel - commandapi-bukkit-core + commandapi-paper-core ${project.version} compile dev.jorel - commandapi-bukkit-vh + commandapi-paper-nms-dependency-mojang-mapped + ${project.version} + pom + + + dev.jorel + commandapi-paper-vh ${project.version} dev.jorel - commandapi-bukkit-nms-dependency + commandapi-paper-mojang-mapped ${project.version} - pom @@ -74,9 +58,24 @@ dev.jorel:commandapi-core dev/jorel/commandapi/CommandAPIVersionHandler** + dev/jorel/commandapi/MojangMappedVersionHandler** + + + org.bukkit.craftbukkit.v1_20_R4 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R1 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R2 + org.bukkit.craftbukkit + + @@ -100,4 +99,5 @@ + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/LICENSE b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/LICENSE similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/LICENSE rename to commandapi-platforms/commandapi-paper/commandapi-paper-shade/LICENSE diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md new file mode 100644 index 0000000000..809bd4251b --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md @@ -0,0 +1 @@ +# commandapi-shade \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml new file mode 100644 index 0000000000..5352a5ded5 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-shade + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-paper-vh + ${project.version} + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + normal + package + + shade + + + true + true + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml new file mode 100644 index 0000000000..3a33a85a2e --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 9.7.1-SNAPSHOT + + + commandapi-paper-vh + + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + + + org.spigotmc + spigot + ${paper.version} + remapped-mojang + provided + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 0000000000..0c24c9de15 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,68 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.exceptions.UnsupportedVersionException; +import dev.jorel.commandapi.nms.PaperNMS_1_16_R3; +import dev.jorel.commandapi.nms.PaperNMS_1_17; +import dev.jorel.commandapi.nms.PaperNMS_1_17_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_18_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_18_R2; +import dev.jorel.commandapi.nms.PaperNMS_1_19_1_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_19_3_R2; +import dev.jorel.commandapi.nms.PaperNMS_1_19_4_R3; +import dev.jorel.commandapi.nms.PaperNMS_1_19_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_20_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_20_R2; +import dev.jorel.commandapi.nms.PaperNMS_1_20_R3; +import dev.jorel.commandapi.nms.PaperNMS_1_20_R4; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R2; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R3; +import org.bukkit.Bukkit; + +public abstract class CommandAPIVersionHandler { + + static LoadContext getPlatform() { + String latestMajorVersion = "21"; // Change this for Minecraft's major update + if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + return new LoadContext(new PaperNMS_1_21_R3(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } else { + String version = Bukkit.getBukkitVersion().split("-")[0]; + CommandAPIPlatform platform = switch (version) { + case "1.16.5" -> new PaperNMS_1_16_R3(); + case "1.17" -> new PaperNMS_1_17(); + case "1.17.1" -> new PaperNMS_1_17_R1(); + case "1.18", "1.18.1" -> new PaperNMS_1_18_R1(); + case "1.18.2" -> new PaperNMS_1_18_R2(); + case "1.19" -> new PaperNMS_1_19_R1(); + case "1.19.1", "1.19.2" -> new PaperNMS_1_19_1_R1(); + case "1.19.3" -> new PaperNMS_1_19_3_R2(); + case "1.19.4" -> new PaperNMS_1_19_4_R3(); + case "1.20", "1.20.1" -> new PaperNMS_1_20_R1(); + case "1.20.2" -> new PaperNMS_1_20_R2(); + case "1.20.3", "1.20.4" -> new PaperNMS_1_20_R3(); + case "1.20.5", "1.20.6" -> new PaperNMS_1_20_R4(); + case "1.21", "1.21.1" -> new PaperNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); + case "1.21.4" -> new PaperNMS_1_21_R3(); + default -> null; + }; + if (platform != null) { + return new LoadContext(platform); + } + if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { + String currentMajorVersion = version.split("\\.")[1]; + if (latestMajorVersion.equals(currentMajorVersion)) { + return new LoadContext(new PaperNMS_1_21_R3(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } + } + throw new UnsupportedVersionException(version); + } + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java diff --git a/commandapi-platforms/commandapi-paper/pom.xml b/commandapi-platforms/commandapi-paper/pom.xml new file mode 100644 index 0000000000..626c4bab31 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + dev.jorel + commandapi-platforms + 9.7.1-SNAPSHOT + + + commandapi-paper + pom + + + commandapi-paper-annotations + commandapi-paper-core + commandapi-paper-vh + commandapi-paper-mojang-mapped + commandapi-paper-nms + commandapi-paper-shade + commandapi-paper-plugin + commandapi-paper-plugin-mojang-mapped + commandapi-paper-shade-mojang-mapped + commandapi-paper-documentation-code + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml new file mode 100644 index 0000000000..425e5aac8a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-annotations + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + dev.jorel + commandapi-annotations + ${project.version} + compile + + + dev.jorel + commandapi-spigot-core + ${project.version} + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + dev.jorel.commandapi.annotations.Annotations + + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java new file mode 100644 index 0000000000..344af582dd --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java @@ -0,0 +1,572 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.annotations; + +import com.google.auto.service.AutoService; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.annotations.arguments.AAdvancementArgument; +import dev.jorel.commandapi.annotations.arguments.AAngleArgument; +import dev.jorel.commandapi.annotations.arguments.AAxisArgument; +import dev.jorel.commandapi.annotations.arguments.ABiomeArgument; +import dev.jorel.commandapi.annotations.arguments.ABlockPredicateArgument; +import dev.jorel.commandapi.annotations.arguments.ABlockStateArgument; +import dev.jorel.commandapi.annotations.arguments.ABooleanArgument; +import dev.jorel.commandapi.annotations.arguments.AChatArgument; +import dev.jorel.commandapi.annotations.arguments.AChatColorArgument; +import dev.jorel.commandapi.annotations.arguments.AChatComponentArgument; +import dev.jorel.commandapi.annotations.arguments.ADoubleArgument; +import dev.jorel.commandapi.annotations.arguments.AEnchantmentArgument; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; +import dev.jorel.commandapi.annotations.arguments.AEntityTypeArgument; +import dev.jorel.commandapi.annotations.arguments.AFloatArgument; +import dev.jorel.commandapi.annotations.arguments.AFloatRangeArgument; +import dev.jorel.commandapi.annotations.arguments.AFunctionArgument; +import dev.jorel.commandapi.annotations.arguments.AGreedyStringArgument; +import dev.jorel.commandapi.annotations.arguments.AIntegerArgument; +import dev.jorel.commandapi.annotations.arguments.AIntegerRangeArgument; +import dev.jorel.commandapi.annotations.arguments.AItemStackArgument; +import dev.jorel.commandapi.annotations.arguments.AItemStackPredicateArgument; +import dev.jorel.commandapi.annotations.arguments.ALiteralArgument; +import dev.jorel.commandapi.annotations.arguments.ALocation2DArgument; +import dev.jorel.commandapi.annotations.arguments.ALocationArgument; +import dev.jorel.commandapi.annotations.arguments.ALongArgument; +import dev.jorel.commandapi.annotations.arguments.ALootTableArgument; +import dev.jorel.commandapi.annotations.arguments.AMathOperationArgument; +import dev.jorel.commandapi.annotations.arguments.AMultiLiteralArgument; +import dev.jorel.commandapi.annotations.arguments.ANBTCompoundArgument; +import dev.jorel.commandapi.annotations.arguments.ANamespacedKeyArgument; +import dev.jorel.commandapi.annotations.arguments.AObjectiveArgument; +import dev.jorel.commandapi.annotations.arguments.AObjectiveCriteriaArgument; +import dev.jorel.commandapi.annotations.arguments.AOfflinePlayerArgument; +import dev.jorel.commandapi.annotations.arguments.AParticleArgument; +import dev.jorel.commandapi.annotations.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.arguments.APotionEffectArgument; +import dev.jorel.commandapi.annotations.arguments.ARecipeArgument; +import dev.jorel.commandapi.annotations.arguments.ARotationArgument; +import dev.jorel.commandapi.annotations.arguments.AScoreHolderArgument; +import dev.jorel.commandapi.annotations.arguments.AScoreboardSlotArgument; +import dev.jorel.commandapi.annotations.arguments.ASoundArgument; +import dev.jorel.commandapi.annotations.arguments.AStringArgument; +import dev.jorel.commandapi.annotations.arguments.ATeamArgument; +import dev.jorel.commandapi.annotations.arguments.ATextArgument; +import dev.jorel.commandapi.annotations.arguments.ATimeArgument; +import dev.jorel.commandapi.annotations.arguments.AUUIDArgument; +import dev.jorel.commandapi.annotations.arguments.AWorldArgument; +import dev.jorel.commandapi.annotations.arguments.Primitive; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ExecutableType; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The main annotation processor for annotation-based arguments + */ +@AutoService(Processor.class) +public class Annotations extends AbstractProcessor { + + private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, + AAngleArgument.class, AAxisArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, + ABlockStateArgument.class, ABooleanArgument.class, AChatArgument.class, + AChatColorArgument.class, AChatComponentArgument.class, ADoubleArgument.class, + AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, AEntitySelectorArgument.ManyPlayers.class, + AEntitySelectorArgument.OneEntity.class, AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, + AFloatArgument.class, AFloatRangeArgument.class, AFunctionArgument.class, + AGreedyStringArgument.class, AIntegerArgument.class, AIntegerRangeArgument.class, AItemStackArgument.class, + AItemStackPredicateArgument.class, ALiteralArgument.class, ALocation2DArgument.class, + ALocationArgument.class, ALongArgument.class, ALootTableArgument.class, AMathOperationArgument.class, + AMultiLiteralArgument.class, ANamespacedKeyArgument.class, ANBTCompoundArgument.class, AObjectiveArgument.class, + AObjectiveCriteriaArgument.class, AOfflinePlayerArgument.class, AParticleArgument.class, APlayerArgument.class, + APotionEffectArgument.class, ARecipeArgument.class, ARotationArgument.class, AScoreboardSlotArgument.class, + AScoreHolderArgument.Single.class, AScoreHolderArgument.Multiple.class, ASoundArgument.class, AStringArgument.class, ATeamArgument.class, + ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class }; + + // List of stuff we can deal with + @Override + public Set getSupportedAnnotationTypes() { + return Stream + .concat(Arrays.stream(new Class[] { Alias.class, Command.class, Default.class, NeedsOp.class, + Permission.class, Subcommand.class, Help.class }), Arrays.stream(ARGUMENT_ANNOTATIONS)) + .map(Class::getCanonicalName).collect(Collectors.toSet()); + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + for (Element element : roundEnv.getElementsAnnotatedWith(Command.class)) { + try { + processCommand(element); + } catch (IOException e) { + e.printStackTrace(); + } + } + return true; + } + + // Indentation, because half of this file is actually just making stuff look nice + private String indent(int indent) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < indent; i++) { + builder.append(" "); + } + return builder.toString(); + } + + private String simpleFromQualified(String name) { + if(name == null) { + return null; + } + return name.split("\\.")[name.split("\\.").length - 1]; + } + + private SortedSet calculateImports(Element classElement) { + SortedSet imports = new TreeSet<>(); + + imports.add(CommandAPICommand.class.getCanonicalName()); + if(classElement.getAnnotation(NeedsOp.class) != null) { + imports.add(CommandPermission.class.getCanonicalName()); + } + for (Element methodElement : classElement.getEnclosedElements()) { + if (methodElement.getAnnotation(Subcommand.class) != null) { + imports.add(MultiLiteralArgument.class.getCanonicalName()); + } + if (methodElement.getAnnotation(NeedsOp.class) != null) { + imports.add(CommandPermission.class.getCanonicalName()); + } + + if(methodElement instanceof ExecutableElement method) { + for(VariableElement parameter : method.getParameters()) { + Annotation argument = getArgument(parameter); + if(argument != null) { + + if (argument instanceof ANBTCompoundArgument) { + // Get NBTCompoundArgument type from type mirror + imports.add(parameter.asType().toString()); + } else { + imports.addAll(Arrays.asList(getPrimitive(argument).value())); + } + + if(argument.annotationType().getEnclosingClass() == null) { + // Normal arguments + imports.add("dev.jorel.commandapi.arguments." + argument.annotationType().getSimpleName().substring(1)); + } else { + // Nested arguments, like EntitySelectorArgument + imports.add("dev.jorel.commandapi.arguments." + argument.annotationType().getEnclosingClass().getSimpleName().substring(1)); + } + + if(argument instanceof ALocationArgument || argument instanceof ALocation2DArgument) { + imports.add(LocationType.class.getCanonicalName()); + } + } + + } + } + } + + for(String import_ : new TreeSet<>(imports)) { + if(import_.contains("<")) { + imports.add(import_.substring(0, import_.indexOf("<"))); + imports.add(import_.substring(import_.indexOf("<") + 1, import_.indexOf(">"))); + } + } + + return imports; + } + + private void emitImports(PrintWriter out, Element classElement) { + String previousImport = ""; + for(String import_ : calculateImports(classElement)) { + // Separate different packages + if(previousImport.contains(".") && import_.contains(".") && + !previousImport.substring(0, previousImport.indexOf(".")).equals(import_.substring(0, import_.indexOf(".")))) { + out.println(); + } + // Don't import stuff like "String" + if(!import_.contains(".") || import_.contains("<")) { + continue; + } + + out.print("import "); + out.print(import_); + out.println(";"); + previousImport = import_; + } + out.println(); + } + + // (https://www.baeldung.com/java-annotation-processing-builder) + private void emitPackage(PrintWriter out, TypeElement commandClass) { + int lastDot = commandClass.getQualifiedName().toString().lastIndexOf('.'); + if (lastDot > 0) { + out.print("package "); + out.print(commandClass.getQualifiedName().toString().substring(0, lastDot)); + out.println(";"); + out.println(); + } + } + + private int emitSubcommand(PrintWriter out, Element methodElement, int indent) { + if (methodElement.getAnnotation(Subcommand.class) != null) { + out.println(indent(indent) + ".withArguments("); + indent++; + out.print(indent(indent) + "new MultiLiteralArgument(\"subcommand\", "); + + if(methodElement.getAnnotation(Subcommand.class).value().length == 0) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Invalid @Subcommand on " + methodElement.getSimpleName() + " - no subcommand name was found"); + } + + // @Subcommand (name) + out.print(Arrays.stream(methodElement.getAnnotation(Subcommand.class).value()) + .map(x -> "\"" + x + "\"").collect(Collectors.joining(", "))); + + out.println(")"); + indent++; + out.println(indent(indent) + ".setListed(false)"); + + // @NeedsOp + if (methodElement.getAnnotation(NeedsOp.class) != null) { + out.println(indent(indent) + ".withPermission(CommandPermission.OP)"); + } + + // @Permission + if (methodElement.getAnnotation(Permission.class) != null) { + out.print(indent(indent) + ".withPermission(\""); + out.print(methodElement.getAnnotation(Permission.class).value()); + out.println("\")"); + } + indent--; + indent--; + out.println(indent(indent) + ")"); + } + return indent; + } + + private Map emitArgumentsAndGenerateArgumentMapping(PrintWriter out, Element methodElement, int indent) throws IllegalArgumentException { + Map argumentMapping = new HashMap<>(); + + ExecutableElement executableMethodElement = (ExecutableElement) methodElement; + for(int i = 1; i < executableMethodElement.getParameters().size(); i++) { + VariableElement parameter = executableMethodElement.getParameters().get(i); + T argumentAnnotation = getArgument(parameter); + if (argumentAnnotation == null) { + processingEnv.getMessager().printMessage(Kind.ERROR, + "Parameter " + parameter.getSimpleName() + " in method " + + methodElement.getSimpleName() + + " does not have an argument annotation on it! "); + throw new IllegalArgumentException(); + } + + emitArgument(out, argumentAnnotation, parameter, indent); + + // Handle return types + Primitive primitive = getPrimitive(argumentAnnotation); + if (argumentAnnotation instanceof ANBTCompoundArgument) { + argumentMapping.put(i - 1, parameter.asType().toString()); + } else { + if(primitive.value().length == 1) { + argumentMapping.put(i - 1, primitive.value()[0]); + } + } + } + + return argumentMapping; + } + + private int emitExecutes(PrintWriter out, Map argumentMapping, ExecutableType methodType, TypeElement commandClass, Element methodElement, int indent) { + String[] firstParam = methodType.getParameterTypes().get(0).toString().split("\\."); + out.print(indent(indent)); + switch (firstParam[firstParam.length - 1]) { + case "Player" -> out.print(".executesPlayer"); + case "ConsoleCommandSender" -> out.print(".executesConsole"); + case "BlockCommandSender" -> out.print(".executesCommandBlock"); + case "ProxiedCommandSender" -> out.print(".executesProxy"); + case "NativeProxyCommandSender" -> out.print(".executesNative"); + case "Entity" -> out.print(".executesEntity"); + case "CommandSender" -> out.print(".executes"); + default -> out.print(".executes"); + } + + out.println("((sender, args) -> {"); + indent++; + out.print(indent(indent)); + + // Return int or void? + if (methodType.getReturnType().toString().equals("int")) { + out.print("return "); + } + + out.print(commandClass.getSimpleName()); + out.print("."); + out.print(methodElement.getSimpleName()); + out.print("(sender"); + + for(int i = 0; i < argumentMapping.size(); i++) { + String fromArgumentMap = argumentMapping.get(i); + out.print(", ("); + + if(fromArgumentMap.contains("<")) { + out.print(simpleFromQualified(fromArgumentMap.substring(0, fromArgumentMap.indexOf("<")))); + out.print("<"); + out.print(simpleFromQualified(fromArgumentMap.substring(fromArgumentMap.indexOf("<") + 1, fromArgumentMap.indexOf(">")))); + out.print(">"); + } else { + out.print(simpleFromQualified(fromArgumentMap)); + } + out.print(") args.get("); + out.print(i); + out.print(")"); + } + //populate stuff here + + out.println(");"); + indent--; + out.println(indent(indent) + "})"); + + return indent; + } + + private int emitClassDeclarationStart(PrintWriter out, TypeElement commandClass, int indent) { + out.println("// This class was automatically generated by the CommandAPI"); + out.print("public class "); + out.print(commandClass.getSimpleName() + "$Command"); + out.println(" {"); + out.println(); + indent++; + return indent; + } + + private void emitPermission(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Permission.class) != null) { + out.print(indent(indent) + ".withPermission(\""); + out.print(classElement.getAnnotation(Permission.class).value()); + out.println("\")"); + } + } + + private void emitAlias(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Alias.class) != null) { + out.print(indent(indent) + ".withAliases("); + out.print(Arrays.stream(classElement.getAnnotation(Alias.class).value()) + .map(x -> "\"" + x + "\"").collect(Collectors.joining(", "))); + out.println(")"); + } + } + + private void emitNeedsOp(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(NeedsOp.class) != null) { + out.println(indent(indent) + ".withPermission(CommandPermission.OP)"); + } + } + + private void emitHelp(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Help.class) != null) { + Help helpAnnotation = classElement.getAnnotation(Help.class); + + if(helpAnnotation.shortDescription().isEmpty()) { + out.print(indent(indent) + ".withFullDescription(\""); + out.print(helpAnnotation.value()); + out.println("\")"); + } else { + out.print(indent(indent) + ".withHelp(\""); + out.print(helpAnnotation.shortDescription()); + out.print("\", \""); + out.print(helpAnnotation.value()); + out.println("\")"); + } + } + } + + private void processCommand(Element classElement) throws IOException { + TypeElement commandClass = (TypeElement) classElement; + JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(commandClass.getQualifiedName() + "$Command"); + int indent = 0; + + try (PrintWriter out = new PrintWriter(builderFile.openWriter())) { + emitPackage(out, commandClass); // Package name + emitImports(out, classElement); // Imports + emitClassDeclarationStart(out, commandClass, indent); // Class declaration + + // Main registration method + out.println(indent(indent) + "@SuppressWarnings(\"unchecked\")"); + out.println(indent(indent) + "public static void register() {"); + out.println(); + indent++; + + for (Element methodElement : classElement.getEnclosedElements()) { + if (methodElement.getAnnotation(Default.class) != null + || methodElement.getAnnotation(Subcommand.class) != null) { + + ExecutableType methodType = (ExecutableType) methodElement.asType(); + if(!methodElement.getModifiers().contains(Modifier.STATIC)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Method " + methodElement.getSimpleName() + " must be static to be used as a command"); + } + + out.print(indent(indent) + "new CommandAPICommand(\""); + out.print(commandClass.getAnnotation(Command.class).value()); + out.println("\")"); + indent++; + + indent = emitSubcommand(out, methodElement, indent); // @Subcommand (Also handle @Alias for @Subcommand) + emitNeedsOp(out, classElement, indent); // @NeedsOp + emitPermission(out, classElement, indent); // @Permission + emitAlias(out, classElement, indent); // @Alias + emitHelp(out, classElement, indent); // @Help + + //Maps parameter index to argument's primitive type + Map argumentMapping = null; + try { + argumentMapping = emitArgumentsAndGenerateArgumentMapping(out, methodElement, indent); + } catch (IllegalArgumentException e) { + return; + } + + // .executes + indent = emitExecutes(out, argumentMapping, methodType, commandClass, methodElement, indent); + + // Register command + out.println(indent(indent) + ".register();"); + out.println(); + indent--; + } + } + out.println(indent(indent) + "}"); // register() + indent--; + out.println(); + out.println("}"); // $Command class + } + } + + private void emitArgument(PrintWriter out, T argumentAnnotation, VariableElement parameter, int indent) { + out.print(indent(indent) + ".withArguments(new "); + // We're assuming that the name of the argument MUST be "A" + the same name + if(argumentAnnotation.annotationType().getEnclosingClass() == null) { + // Normal arguments + out.print(argumentAnnotation.annotationType().getSimpleName().substring(1)); + } else { + // Nested arguments, like EntitySelectorArgument + out.print(argumentAnnotation.annotationType().getEnclosingClass().getSimpleName().substring(1)); + out.print("."); + out.print(argumentAnnotation.annotationType().getSimpleName()); + } + + // Node name + out.print("(\""); + out.print(parameter.getSimpleName()); + out.print("\""); + + // Handle parameters + // Number arguments + if(argumentAnnotation instanceof AIntegerArgument argument) { + out.print(", " + argument.min() + ", " + argument.max()); + } else if(argumentAnnotation instanceof ALongArgument argument) { + out.print(", " + argument.min() + "L, " + argument.max() + "L"); + } else if(argumentAnnotation instanceof AFloatArgument argument) { + out.print(", " + argument.min() + "F, " + argument.max() + "F"); + } else if(argumentAnnotation instanceof ADoubleArgument argument) { + out.print(", " + argument.min() + "D, " + argument.max() + "D"); + } + + // Non-number arguments + else if(argumentAnnotation instanceof ALocation2DArgument argument) { + out.print(", " + LocationType.class.getSimpleName() + "." + argument.value().toString()); + } else if(argumentAnnotation instanceof ALocationArgument argument) { + out.print(", " + LocationType.class.getSimpleName() + "." + argument.value().toString()); + } else if(argumentAnnotation instanceof AMultiLiteralArgument argument) { + out.print(", " + Arrays.stream(argument.value()).map(s -> "\"" + s + "\"").collect(Collectors.joining(", "))); + } else if(argumentAnnotation instanceof ALiteralArgument argument) { + out.print(", \""); + out.print(argument.value()); + out.print("\""); + } + + out.print(")"); + + if(argumentAnnotation instanceof ALiteralArgument) { + out.print(".setListed(true)"); + } + + out.println(")"); + } + + // Checks if an annotation mirror is an argument annotation + private boolean isArgument(AnnotationMirror mirror) { + final String mirrorName = mirror.getAnnotationType().toString(); + return Arrays.stream(ARGUMENT_ANNOTATIONS).map(Class::getCanonicalName).anyMatch(mirrorName::equals); + } + + // Get the Primitive annotation from an annotation + private Primitive getPrimitive(T annotation) { + return annotation.annotationType().getDeclaredAnnotation(Primitive.class); + } + + @SuppressWarnings("unchecked") + private T getArgument(VariableElement tMirror) { + for(AnnotationMirror mirror : tMirror.getAnnotationMirrors()) { + if(isArgument(mirror)) { + T argumentAnnotation = null; + String mirrorCanonicalName = mirror.getAnnotationType().toString(); + try { + argumentAnnotation = tMirror.getAnnotationsByType((Class) Class.forName(mirrorCanonicalName))[0]; + } catch (ClassNotFoundException e) { + // We might be in a nested class. Let's try accessing that + try { + // Replace final . with $ + mirrorCanonicalName = mirrorCanonicalName.substring(0, mirrorCanonicalName.lastIndexOf(".")) + "$" + mirrorCanonicalName.substring(mirrorCanonicalName.lastIndexOf(".") + 1); + argumentAnnotation = tMirror.getAnnotationsByType((Class) Class.forName(mirrorCanonicalName))[0]; + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + } + + return argumentAnnotation; + } + } + return null; + } + +} diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml new file mode 100644 index 0000000000..fe5a53a74a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-core + + + + minecraft-libraries + https://libraries.minecraft.net + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + dev.jorel + commandapi-preprocessor + ${project.version} + provided + + + com.mojang + brigadier + 1.0.18 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint + + + dev.jorel.commandapi.preprocessor.Preprocessor + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java new file mode 100644 index 0000000000..c7b3a52cee --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java @@ -0,0 +1,131 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitEntity; +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.nms.SpigotNMS; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class CommandAPISpigot extends CommandAPIBukkit implements SpigotNMS { + + private static CommandAPISpigot spigot; + + @SuppressWarnings("unchecked") + protected CommandAPISpigot() { + this.nms = (NMS) bukkitNMS(); + CommandAPISpigot.spigot = this; + setInstance(this); + } + + @SuppressWarnings("unchecked") + public static CommandAPISpigot getSpigot() { + if (spigot != null) { + return (CommandAPISpigot) spigot; + } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + public static InternalSpigotConfig getConfiguration() { + return (InternalSpigotConfig) CommandAPIBukkit.getConfiguration(); + } + + private static void setInternalConfig(InternalSpigotConfig config) { + CommandAPIBukkit.config = config; + } + + @Override + public void onLoad(CommandAPIConfig config) { + if (config instanceof CommandAPISpigotConfig spigotConfig) { + CommandAPISpigot.setInternalConfig(new InternalSpigotConfig(spigotConfig)); + } else { + CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); + CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + } + super.onLoad(); + } + + @Override + public void onEnable() { + JavaPlugin plugin = getConfiguration().getPlugin(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { + // Sort out permissions after the server has finished registering them all + getCommandRegistrationStrategy().runTasksAfterServerStart(); + if (!getConfiguration().skipReloadDatapacks()) { + reloadDataPacks(); + } + updateHelpForCommands(CommandAPI.getRegisteredCommands()); + }, 0L); + + super.stopCommandRegistrations(); + } + + @Override + public CommandMap getCommandMap() { + return getNMS().getSimpleCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.SPIGOT; + } + + @Override + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); + } + + /** + * Forces a command to return a success value of 0 + * + * @param message Description of the error message, formatted as an array of base components + * @return a {@link dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException} that wraps Brigadier's + * {@link com.mojang.brigadier.exceptions.CommandSyntaxException} + */ + public static WrapperCommandSyntaxException failWithBaseComponents(BaseComponent... message) { + return CommandAPI.failWithMessage(BukkitTooltip.messageFromBaseComponents(message)); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java new file mode 100644 index 0000000000..4134f76755 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java @@ -0,0 +1,25 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandAPISpigotConfig extends CommandAPIBukkitConfig { + + public CommandAPISpigotConfig(JavaPlugin plugin) { + super(plugin); + } + + /** + * Sets whether the CommandAPI should skip its datapack reload step after the server + * has finished loading. + * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading + * @return this CommandAPIBukkitConfig + */ + public CommandAPISpigotConfig skipReloadDatapacks(boolean skip) { + return super.skipReloadDatapacks(skip); + } + + @Override + public CommandAPISpigotConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java new file mode 100644 index 0000000000..8a464291b7 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java @@ -0,0 +1,9 @@ +package dev.jorel.commandapi; + +public class InternalSpigotConfig extends InternalBukkitConfig { + + public InternalSpigotConfig(CommandAPISpigotConfig config) { + super(config); + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java similarity index 95% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java index e028fc7517..fdba67d865 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java @@ -22,6 +22,7 @@ import java.util.Optional; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.executors.CommandArguments; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -56,7 +57,7 @@ public class ChatArgument extends Argument implements GreedyArg * @param nodeName the name of the node for argument */ public ChatArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChat()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChat()); try { Class.forName("org.spigotmc.SpigotConfig"); @@ -78,7 +79,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public BaseComponent[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { final CommandSender sender = CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(); - BaseComponent[] component = CommandAPIBukkit.get().getChat(cmdCtx, key); + BaseComponent[] component = CommandAPISpigot.getSpigot().getChat(cmdCtx, key); Optional> previewOptional = getPreview(); if (this.usePreview && previewOptional.isPresent() && sender instanceof Player player) { @@ -105,11 +106,6 @@ public Optional> getPreview() { return Optional.ofNullable(preview); } - @Override - public boolean isLegacy() { - return true; - } - @Override public ChatArgument usePreview(boolean usePreview) { this.usePreview = usePreview; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java similarity index 89% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java index 9936ed1d2d..216a663157 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.executors.CommandArguments; import org.bukkit.ChatColor; @@ -44,7 +45,7 @@ public class ChatColorArgument extends SafeOverrideableArgument) ChatColor::name).andThen(String::toLowerCase)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatFormat(), ((Function) ChatColor::name).andThen(String::toLowerCase)); } @Override @@ -59,6 +60,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public ChatColor parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getChatColor(cmdCtx, key); + return CommandAPISpigot.getSpigot().getChatColor(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java similarity index 92% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java index 774d4a8ff8..145ac1fa6b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.exceptions.SpigotNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; import net.md_5.bungee.api.chat.BaseComponent; @@ -45,7 +46,7 @@ public class ChatComponentArgument extends Argument { * @param nodeName the name of the node for argument */ public ChatComponentArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChatComponent()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatComponent()); try { Class.forName("org.spigotmc.SpigotConfig"); @@ -67,6 +68,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public BaseComponent[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getChatComponent(cmdCtx, key); + return CommandAPISpigot.getSpigot().getChatComponent(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java similarity index 94% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java index 330d82117d..b01db663c3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java @@ -20,22 +20,20 @@ *******************************************************************************/ package dev.jorel.commandapi.arguments; -import java.io.Serializable; - -import org.bukkit.command.CommandSender; - import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.Message; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; - import dev.jorel.commandapi.BukkitTooltip; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.executors.CommandArguments; -import net.kyori.adventure.text.Component; import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; /** * An argument that represents any custom object @@ -221,7 +219,6 @@ public String toString() { public static class CustomArgumentException extends Exception { private BaseComponent[] errorBaseComponent = null; - private Component errorComponent = null; private String errorMessage = null; private MessageBuilder errorMessageBuilder = null; @@ -232,7 +229,7 @@ private CustomArgumentException() { /** * Constructs a CustomArgumentException with a given error message - * + * * @param errorMessage the error message to display to the user when this * exception is thrown * @deprecated Use {@link CustomArgumentException#fromBaseComponents(BaseComponent...)} instead @@ -268,7 +265,7 @@ public CustomArgumentException(MessageBuilder errorMessage) { /** * Constructs a CustomArgumentException with a given error message - * + * * @param errorMessage the error message to display to the user when this * exception is thrown */ @@ -290,18 +287,6 @@ public static CustomArgumentException fromString(String errorMessage) { return exception; } - /** - * Constructs a CustomArgumentException with a given error message - * - * @param errorMessage the error message to display to the user when this - * exception is thrown - */ - public static CustomArgumentException fromAdventureComponent(Component errorMessage) { - CustomArgumentException exception = new CustomArgumentException(); - exception.errorComponent = errorMessage; - return exception; - } - /** * Constructs a CustomArgumentException with a given error message * @@ -329,12 +314,6 @@ public CommandSyntaxException toCommandSyntax(String result, CommandContext c return new SimpleCommandExceptionType(brigadierMessage).create(); } - if (errorComponent != null) { - // Deal with Adventure Component - Message brigadierMessage = BukkitTooltip.messageFromAdventureComponent(errorComponent); - return new SimpleCommandExceptionType(brigadierMessage).create(); - } - if (errorMessageBuilder != null) { // Deal with MessageBuilder String errorMsg = errorMessageBuilder.toString().replace(INPUT, result).replace(FULL_INPUT, @@ -344,7 +323,8 @@ public CommandSyntaxException toCommandSyntax(String result, CommandContext c if (errorMessage != null) { // Deal with String - return CommandAPIBukkit.get().getPaper().getExceptionFromString(errorMessage).getException(); + BaseComponent[] component = TextComponent.fromLegacyText(errorMessage); + return new SimpleCommandExceptionType(BukkitTooltip.messageFromBaseComponents(component)).create(); } throw new IllegalStateException("No error component, error message creator or error message specified"); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java new file mode 100644 index 0000000000..d021a3e620 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java @@ -0,0 +1,20 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.CommandNode; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; + +public interface SpigotNMS { + + BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + ChatColor getChatColor(CommandContext cmdCtx, String key); + + BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); + + NMS bukkitNMS(); + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml new file mode 100644 index 0000000000..0a3f0d76f6 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-documentation-code + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + + com.mojang + brigadier + 1.0.17 + provided + + + com.mojang + authlib + 3.3.39 + provided + + + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + + + dev.jorel + commandapi-kotlin-spigot + ${project.version} + + + + + de.tr7zw + item-nbt-api + 2.11.1 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + test-compile + + test-compile + + + + ${project.basedir}/src/main/kotlin/ + + + + + + 16 + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java new file mode 100644 index 0000000000..00b67586c4 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java @@ -0,0 +1,156 @@ +package dev.jorel.commandapi.examples.java; + +import de.tr7zw.changeme.nbtapi.NBTContainer; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPISpigotConfig; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.plugin.java.JavaPlugin; + +public class Examples { + +void argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +new CommandAPICommand("namecolor") + .withArguments(new ChatColorArgument("chatcolor")) + .executesPlayer((player, args) -> { + ChatColor color = (ChatColor) args.get("chatcolor"); + player.setDisplayName(color + player.getName()); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +new CommandAPICommand("makebook") + .withArguments(new PlayerArgument("player")) + .withArguments(new ChatComponentArgument("contents")) + .executes((sender, args) -> { + Player player = (Player) args.get("player"); + BaseComponent[] arr = (BaseComponent[]) args.get("contents"); + + // Create book + ItemStack is = new ItemStack(Material.WRITTEN_BOOK); + BookMeta meta = (BookMeta) is.getItemMeta(); + meta.setTitle("Custom Book"); + meta.setAuthor(player.getName()); + meta.spigot().setPages(arr); + is.setItemMeta(meta); + + // Give player the book + player.getInventory().addItem(is); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +new CommandAPICommand("pbroadcast") + .withArguments(new ChatArgument("message")) + .executes((sender, args) -> { + BaseComponent[] message = (BaseComponent[]) args.get("message"); + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(message); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot3 */ +} + +class argument_nbt extends JavaPlugin { +/* ANCHOR: argumentNBT1 */ +@Override +public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + ); +} +/* ANCHOR_END: argumentNBT1 */ +} + +void chatPreview() { +/* ANCHOR: chatPreview1 */ +new CommandAPICommand("broadcast") + .withArguments(new ChatArgument("message").withPreview(info -> { + // Convert parsed BaseComponent[] to plain text + String plainText = BaseComponent.toPlainText(info.parsedInput()); + + // Translate the & in plain text and generate a new BaseComponent[] + return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); + })) + .executesPlayer((player, args) -> { + // The user still entered legacy text. We need to properly convert this + // to a BaseComponent[] by converting to plain text then to BaseComponent[] + String plainText = BaseComponent.toPlainText((BaseComponent[]) args.get("message")); + Bukkit.spigot().broadcast(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText))); + }) + .register(); +/* ANCHOR_END: chatPreview1 */ + +/* ANCHOR: chatPreview2 */ +new CommandAPICommand("broadcast") + .withArguments(new ChatArgument("message").usePreview(true).withPreview(info -> { + // Convert parsed BaseComponent[] to plain text + String plainText = BaseComponent.toPlainText(info.parsedInput()); + + // Translate the & in plain text and generate a new BaseComponent[] + return TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)); + })) + .executesPlayer((player, args) -> { + Bukkit.spigot().broadcast((BaseComponent[]) args.get("message")); + }) + .register(); +/* ANCHOR_END: chatPreview2 */ +} + +class setupShading { +JavaPlugin plugin = new JavaPlugin() { +}; + +{ +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true)); +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this).verboseOutput(true)); // Load with verbose output + + new CommandAPICommand("ping") + .executes((sender, args) -> { + sender.sendMessage("pong!"); + }) + .register(); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + + // Register commands, listeners etc. + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt new file mode 100644 index 0000000000..a6772779b7 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -0,0 +1,153 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPISpigotConfig +import dev.jorel.commandapi.arguments.* +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import net.md_5.bungee.api.chat.BaseComponent +import net.md_5.bungee.api.chat.TextComponent +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.BookMeta +import org.bukkit.plugin.java.JavaPlugin + +class Examples { + +fun argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +CommandAPICommand("namecolor") + .withArguments(ChatColorArgument("chatColor")) + .executesPlayer(PlayerCommandExecutor { player: Player, args: CommandArguments -> + val color = args["chatColor"] as ChatColor + player.setDisplayName("$color${player.name}") + }) + .register() +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +CommandAPICommand("makebook") + .withArguments(PlayerArgument("player")) + .withArguments(ChatComponentArgument("contents")) + .executes(CommandExecutor { _, args -> + val player = args["player"] as Player + val arr = args["contents"] as Array + + // Create book + val item = ItemStack(Material.WRITTEN_BOOK) + val meta = item.itemMeta as BookMeta + meta.title = "Custom Book" + meta.author = player.name + meta.spigot().setPages(arr) + item.itemMeta = meta + + // Give player the book + player.inventory.addItem(item) + }) + .register() +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +CommandAPICommand("pbroadcast") + .withArguments(ChatArgument("message")) + .executes(CommandExecutor { _, args -> + val message = args["message"] as Array + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(*message) + }) + .register() +/* ANCHOR_END: argumentChatSpigot3 */ +} + +class argument_nbt : JavaPlugin() { + +/* ANCHOR: argumentNBT1 */ +override fun onLoad() { + CommandAPI.onLoad(CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + ) +} +/* ANCHOR_END: argumentNBT1 */ +} + +fun chatPreview() { +/* ANCHOR: chatPreview1 */ +CommandAPICommand("broadcast") + .withArguments(ChatArgument("message").withPreview { info -> + // Convert parsed BaseComponent[] to plain text + val plainText: String = BaseComponent.toPlainText(*info.parsedInput() as Array) + + // Translate the & in plain text and generate a new BaseComponent[] + TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) + } ) + .executesPlayer(PlayerCommandExecutor { _, args -> + // The user still entered legacy text. We need to properly convert this + // to a BaseComponent[] by converting to plain text then to BaseComponent[] + val plainText: String = BaseComponent.toPlainText(*args["message"] as Array) + val baseComponents: Array = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) + Bukkit.spigot().broadcast(*baseComponents) + }) + .register() +/* ANCHOR_END: chatPreview1 */ + +/* ANCHOR: chatPreview2 */ +CommandAPICommand("broadcast") + .withArguments(ChatArgument("message").usePreview(true).withPreview { info -> + // Convert parsed BaseComponent[] to plain text + val plainText = BaseComponent.toPlainText(*info.parsedInput() as Array) + + // Translate the & in plain text and generate a new BaseComponent[] + TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', plainText)) + } ) + .executesPlayer(PlayerCommandExecutor { _, args -> + Bukkit.spigot().broadcast(*args["message"] as Array) + }) + .register() +/* ANCHOR_END: chatPreview2 */ +} + +class setupShading { +val plugin: JavaPlugin = object : JavaPlugin() {} + +fun setupShading1() { +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true)) +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin : JavaPlugin() { + + override fun onLoad() { + CommandAPI.onLoad(CommandAPISpigotConfig(this).verboseOutput(true)) // Load with verbose output + + CommandAPICommand("ping") + .executes(CommandExecutor { sender: CommandSender, _ -> + sender.sendMessage("pong!") + }) + .register() + } + + override fun onEnable() { + CommandAPI.onEnable() + + // Register commands, listeners etc. + } + + override fun onDisable() { + CommandAPI.onDisable() + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt new file mode 100644 index 0000000000..22e0715ef2 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt @@ -0,0 +1,62 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.kotlindsl.* +import net.md_5.bungee.api.chat.BaseComponent +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.BookMeta + +class ExamplesKotlinDSL { + +fun argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +commandAPICommand("namecolor") { + chatColorArgument("chatcolor") + playerExecutor { player: Player, args: CommandArguments -> + val color = args["chatcolor"] as ChatColor + player.setDisplayName("$color${player.name}") + } +} +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +commandAPICommand("makebook") { + playerArgument("player") + chatComponentArgument("contents") + anyExecutor { _, args -> + val player = args["player"] as Player + val array = args["contents"] as Array + + // Create book + val item = ItemStack(Material.WRITTEN_BOOK) + val meta = item.itemMeta as BookMeta + meta.title = "Custom Book" + meta.author = player.name + meta.spigot().setPages(array) + item.itemMeta = meta + + // Give player the book + player.inventory.addItem(item) + } +} +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +commandAPICommand("pbroadcast") { + chatArgument("message") + anyExecutor { _, args -> + val message = args["message"] as Array + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(*message) + } +} +/* ANCHOR_END: argumentChatSpigot3 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml new file mode 100644 index 0000000000..077e4382c7 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-mojang-mapped + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java new file mode 100644 index 0000000000..80db4c1b73 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java @@ -0,0 +1,12 @@ +package dev.jorel.commandapi; + +/** + * This file handles loading the correct mappings information. The MojangMappedVersionHandler + * file within the commandapi-core module may not be used at run time. Instead, if a platform module + * wants to be mojang-mapped, they can replace it with this class where {@link #isMojangMapped()} returns {@code true}. + */ +public interface MojangMappedVersionHandler { + static boolean isMojangMapped() { + return true; + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/pom.xml new file mode 100644 index 0000000000..4dd9f9859c --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.16.5 + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + + org.spigotmc + spigot + 1.16.5-R0.1-SNAPSHOT + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.16.5 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_16_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_16_R3.java new file mode 100644 index 0000000000..b53170b642 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.16.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_16_R3.java @@ -0,0 +1,64 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.CommandNode; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.server.v1_16_R3.ArgumentChat; +import net.minecraft.server.v1_16_R3.ArgumentChatComponent; +import net.minecraft.server.v1_16_R3.ArgumentChatFormat; +import net.minecraft.server.v1_16_R3.CommandListenerWrapper; +import net.minecraft.server.v1_16_R3.IChatBaseComponent; +import net.minecraft.server.v1_16_R3.MinecraftServer; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_16_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; + +public class SpigotNMS_1_16_R3 extends CommandAPISpigot { + + private NMS_1_16_R3 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(IChatBaseComponent.ChatSerializer.a(ArgumentChat.a(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return CraftChatMessage.getColor(ArgumentChatFormat.a(cmdCtx, key)); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(IChatBaseComponent.ChatSerializer.a(ArgumentChatComponent.a(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_16_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.a(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommandDispatcher().a(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/pom.xml new file mode 100644 index 0000000000..a68138b9a5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/pom.xml @@ -0,0 +1,154 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.17-common + + + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.17-common + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_Common.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_Common.java new file mode 100644 index 0000000000..d243233e63 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_Common.java @@ -0,0 +1,25 @@ +package dev.jorel.commandapi.nms; + +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_17_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_17_R1.command.VanillaCommandWrapper; + +public abstract class SpigotNMS_1_17_Common extends SpigotNMS_Common { + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS().getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS().getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS().getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/pom.xml new file mode 100644 index 0000000000..520f5fe332 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.17.1 + + + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + 1.17.1-R0.1-SNAPSHOT + + + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + dev.jorel + commandapi-bukkit-1.17.1 + ${project.version} + + + dev.jorel + commandapi-spigot-1.17-common + ${project.version} + mojang-mapped + provided + + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + org.spigotmc + spigot + ${spigot.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_R1.java new file mode 100644 index 0000000000..84f9c0e3fa --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17_R1.java @@ -0,0 +1,34 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; + +public class SpigotNMS_1_17_R1 extends SpigotNMS_1_17_Common { + + private NMS_1_17_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_17_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/pom.xml new file mode 100644 index 0000000000..e68b19af1a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/pom.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.17 + + + 1.17-R0.1-SNAPSHOT + 1.17-R0.1-SNAPSHOT + 1.17-R0.1-SNAPSHOT + + + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + dev.jorel + commandapi-bukkit-1.17 + ${project.version} + + + dev.jorel + commandapi-spigot-1.17-common + ${project.version} + mojang-mapped + provided + + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17.java new file mode 100644 index 0000000000..7623022742 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.17/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_17.java @@ -0,0 +1,34 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; + +public class SpigotNMS_1_17 extends SpigotNMS_1_17_Common { + + private NMS_1_17 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_17(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/pom.xml new file mode 100644 index 0000000000..238f551c81 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.18.2 + + + 1.18.2-R0.1-SNAPSHOT + 1.18.2-R0.1-SNAPSHOT + 1.18.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.18.2 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R2.java new file mode 100644 index 0000000000..007740cd21 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R2.java @@ -0,0 +1,52 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_18_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_18_R2.command.VanillaCommandWrapper; + +public class SpigotNMS_1_18_R2 extends SpigotNMS_Common { + + private NMS_1_18_R2 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_18_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/pom.xml new file mode 100644 index 0000000000..ab6de0d32c --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.18 + + + 1.18.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.18 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R1.java new file mode 100644 index 0000000000..af3076e219 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.18/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_18_R1.java @@ -0,0 +1,54 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_18_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_18_R1.command.VanillaCommandWrapper; + +public class SpigotNMS_1_18_R1 extends SpigotNMS_Common { + + private NMS_1_18_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_18_R1(); + } + return bukkitNMS; + } + + @Override + @Differs(from = "1.17", by = "MinecraftServer#getCommands -> MinecraftServer#aA") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/pom.xml new file mode 100644 index 0000000000..e39ff33b9f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/pom.xml @@ -0,0 +1,133 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.19-common + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.19-common + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common.java new file mode 100644 index 0000000000..099c4092d6 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common.java @@ -0,0 +1,99 @@ +package dev.jorel.commandapi.nms; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import dev.jorel.commandapi.preprocessor.Unimplemented; +import io.netty.channel.Channel; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R1.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; + +public abstract class SpigotNMS_1_19_Common extends SpigotNMS_Common { + + @Override + public void onEnable() { + super.onEnable(); + + JavaPlugin plugin = getConfiguration().getPlugin(); + // Enable chat preview if the server allows it + if (Bukkit.shouldSendChatPreviews()) { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + hookChatPreview(plugin, e.getPlayer()); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + unhookChatPreview(e.getPlayer()); + } + + }, plugin); + CommandAPI.logNormal("Chat preview enabled"); + } else { + CommandAPI.logNormal("Chat preview is not available"); + } + } + + /** + * Hooks into the chat previewing system + * + * @param plugin the plugin (for async calls) + * @param player the player to hook + */ + @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) + protected abstract void hookChatPreview(Plugin plugin, Player player); + + /** + * Unhooks a player from the chat previewing system. This should be + * called when the player quits and when the plugin is disabled + * + * @param player the player to unhook + */ + private void unhookChatPreview(Player player) { + final Channel channel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (channel.pipeline().get("CommandAPI_" + player.getName()) != null) { + channel.eventLoop().submit(() -> channel.pipeline().remove("CommandAPI_" + player.getName())); + } + } + + @Override + public void onDisable() { + super.onDisable(); + + for (Player player : Bukkit.getOnlinePlayers()) { + unhookChatPreview(player); + } + } + + @Override + @Differs(from = "1.18", by = "MinecraftServer#aA -> MinecraftServer#aC") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS().getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS().getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS().getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common_ChatPreviewHandler.java similarity index 70% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common_ChatPreviewHandler.java index ec7402c1af..5f34f29782 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19-common/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_Common_ChatPreviewHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_Common_ChatPreviewHandler.java @@ -3,23 +3,20 @@ import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.context.ParsedCommandNode; import com.mojang.brigadier.exceptions.CommandSyntaxException; - import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.arguments.PreviewInfo; import dev.jorel.commandapi.commandsenders.BukkitPlayer; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.wrappers.PreviewableFunction; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.Connection; -import net.minecraft.network.chat.Component.Serializer; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; @@ -30,14 +27,14 @@ import java.util.List; import java.util.Optional; -public abstract class NMS_1_19_Common_ChatPreviewHandler extends ChannelDuplexHandler { +public abstract class SpigotNMS_1_19_Common_ChatPreviewHandler extends ChannelDuplexHandler { - protected final CommandAPIBukkit platform; + protected final CommandAPISpigot platform; protected final Plugin plugin; protected final Player player; protected final Connection connection; - protected NMS_1_19_Common_ChatPreviewHandler(CommandAPIBukkit platform, Plugin plugin, Player player) { + protected SpigotNMS_1_19_Common_ChatPreviewHandler(CommandAPISpigot platform, Plugin plugin, Player player) { this.platform = platform; this.plugin = plugin; this.player = player; @@ -51,7 +48,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception // Is command if (!chatPreview.query().isEmpty() && chatPreview.query().charAt(0) == '/') { // Is previewable argument - if(InitialParse.processChatPreviewQuery(chatPreview.query(), platform, player).preview.isPresent()){ + if (InitialParse.processChatPreviewQuery(chatPreview.query(), platform, player).preview.isPresent()) { handleChatPreviewPacket(chatPreview); return; } @@ -83,24 +80,13 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { Object component; try { @SuppressWarnings("rawtypes") final PreviewInfo previewInfo; - if (CommandAPIHandler.getInstance().lookupPreviewableLegacyStatus(path)) { - BaseComponent[] parsedInput; - try { - parsedInput = platform.getChat(results.getContext().build(fullInput), path.get(path.size() - 1)); - } catch (CommandSyntaxException e) { - throw new WrapperCommandSyntaxException(e); - } - previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); - } else { - Component parsedInput; - try { - parsedInput = platform.getAdventureChat(results.getContext().build(fullInput), path.get(path.size() - 1)); - } catch (CommandSyntaxException e) { - throw new WrapperCommandSyntaxException(e); - } - previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); + BaseComponent[] parsedInput; + try { + parsedInput = platform.getChat(results.getContext().build(fullInput), path.get(path.size() - 1)); + } catch (CommandSyntaxException e) { + throw new WrapperCommandSyntaxException(e); } - + previewInfo = new PreviewInfo<>(new BukkitPlayer(player), input, chatPreviewQuery, parsedInput); component = preview.get().generatePreview(previewInfo); } catch (WrapperCommandSyntaxException e) { component = TextComponent.fromLegacyText(e.getMessage() == null ? "" : e.getMessage()); @@ -109,12 +95,6 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { if (component != null) { if (component instanceof BaseComponent[] baseComponent) { jsonToSend = ComponentSerializer.toString(baseComponent); - } else if (platform.getPaper().isPaperPresent()) { - if (component instanceof Component adventureComponent) { - jsonToSend = GsonComponentSerializer.gson().serialize(adventureComponent); - } else { - throw new IllegalArgumentException("Unexpected type returned from chat preview, got: " + component.getClass().getSimpleName()); - } } else { throw new IllegalArgumentException("Unexpected type returned from chat preview, got: " + component.getClass().getSimpleName()); } @@ -122,12 +102,12 @@ public MutableComponent parseChatPreviewQuery(String chatPreviewQuery) { throw new NullPointerException("Returned value from chat preview was null"); } - return Serializer.fromJson(jsonToSend); + return Component.Serializer.fromJson(jsonToSend); } private record InitialParse(String fullInput, ParseResults results, List path, Optional> preview){ private static InitialParse cachedResult = null; - public static InitialParse processChatPreviewQuery(String chatPreviewQuery, CommandAPIBukkit platform, Player player){ + public static InitialParse processChatPreviewQuery(String chatPreviewQuery, CommandAPISpigot platform, Player player){ // Substring 1 to get rid of the leading / final String fullInput = chatPreviewQuery.substring(1); @@ -147,4 +127,5 @@ public static InitialParse processChatPreviewQuery(String chatPreviewQuery, Comm return cachedResult; } } -} \ No newline at end of file + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/pom.xml new file mode 100644 index 0000000000..28e7a23611 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/pom.xml @@ -0,0 +1,157 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.19.1 + + + 1.19.2-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT + 1.19.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.19.1 + ${project.version} + + + + dev.jorel + commandapi-spigot-1.19-common + ${project.version} + mojang-mapped + provided + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1.java new file mode 100644 index 0000000000..3f9a8bc8c0 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1.java @@ -0,0 +1,46 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.netty.channel.Channel; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class SpigotNMS_1_19_1_R1 extends SpigotNMS_1_19_Common { + + private NMS_1_19_1_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public void hookChatPreview(Plugin plugin, Player player) { + final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { + playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new SpigotNMS_1_19_1_R1_ChatPreviewHandler(this, plugin, player)); + } + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_1_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1_ChatPreviewHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1_ChatPreviewHandler.java similarity index 87% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1_ChatPreviewHandler.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1_ChatPreviewHandler.java index 56d10098c8..c54aedafbe 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.19.1/src/main/java/dev/jorel/commandapi/nms/NMS_1_19_1_R1_ChatPreviewHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.1/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_1_R1_ChatPreviewHandler.java @@ -1,12 +1,13 @@ package dev.jorel.commandapi.nms; -import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.SafeVarHandle; import dev.jorel.commandapi.preprocessor.RequireField; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.PacketSendListener; import net.minecraft.network.chat.ChatPreviewCache; import net.minecraft.network.chat.ChatPreviewThrottler; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundChatPreviewPacket; import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -19,7 +20,7 @@ @RequireField(in = ServerGamePacketListenerImpl.class, name = "chatPreviewThrottler", ofType = ChatPreviewThrottler.class) @RequireField(in = ServerGamePacketListenerImpl.class, name = "chatPreviewCache", ofType = ChatPreviewCache.class) -public class NMS_1_19_1_R1_ChatPreviewHandler extends NMS_1_19_Common_ChatPreviewHandler { +public class SpigotNMS_1_19_1_R1_ChatPreviewHandler extends SpigotNMS_1_19_Common_ChatPreviewHandler { private static final SafeVarHandle packetListenerPreviewThrottler; private static final SafeVarHandle packetListenerPreviewCache; @@ -31,7 +32,7 @@ public class NMS_1_19_1_R1_ChatPreviewHandler extends NMS_1_19_Common_ChatPrevie ChatPreviewThrottler throttler; - public NMS_1_19_1_R1_ChatPreviewHandler(CommandAPIBukkit platform, Plugin plugin, Player player) { + public SpigotNMS_1_19_1_R1_ChatPreviewHandler(CommandAPISpigot platform, Plugin plugin, Player player) { super(platform, plugin, player); throttler = packetListenerPreviewThrottler.get(((CraftPlayer) player).getHandle().connection); @@ -42,7 +43,7 @@ protected void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview) // We want to run this synchronously, just in case there's some funky async stuff going on here throttler.schedule(() -> { int i = chatPreview.queryId(); - CompletableFuture result = new CompletableFuture<>(); + CompletableFuture result = new CompletableFuture<>(); // Get preview Bukkit.getScheduler().runTask(this.plugin, () -> result.complete(parseChatPreviewQuery(chatPreview.query()))); @@ -66,4 +67,5 @@ protected void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview) ); }); } -} \ No newline at end of file + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/pom.xml new file mode 100644 index 0000000000..e17b56830d --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.19.3 + + + 1.19.3-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT + 1.19.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.19.3 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_3_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_3_R2.java new file mode 100644 index 0000000000..bbe7a85be0 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_3_R2.java @@ -0,0 +1,54 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import dev.jorel.commandapi.preprocessor.Differs; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R2.command.VanillaCommandWrapper; + +public class SpigotNMS_1_19_3_R2 extends SpigotNMS_Common { + + private NMS_1_19_3_R2 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_3_R2(); + } + return bukkitNMS; + } + + @Override + @Differs(from = "1.19, 1.19.1, 1.19.2", by = "MinecraftServer#aC -> MinecraftServer#aB") + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/pom.xml new file mode 100644 index 0000000000..98254df50f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.19.4 + + + 1.19.4-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.19.4 + ${project.version} + compile + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_4_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_4_R3.java new file mode 100644 index 0000000000..1bf601e1c9 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_4_R3.java @@ -0,0 +1,52 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_19_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_19_R3.command.VanillaCommandWrapper; + +public class SpigotNMS_1_19_4_R3 extends SpigotNMS_Common { + + private NMS_1_19_4_R3 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_4_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/pom.xml new file mode 100644 index 0000000000..0c744d34c3 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.19 + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.19 + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + dev.jorel + commandapi-spigot-1.19-common + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1.java new file mode 100644 index 0000000000..cc1ee135d1 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1.java @@ -0,0 +1,46 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.netty.channel.Channel; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class SpigotNMS_1_19_R1 extends SpigotNMS_1_19_Common { + + private NMS_1_19_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + protected void hookChatPreview(Plugin plugin, Player player) { + final Channel playerChannel = ((CraftPlayer) player).getHandle().connection.connection.channel; + if (playerChannel.pipeline().get("CommandAPI_" + player.getName()) == null) { + playerChannel.pipeline().addBefore("packet_handler", "CommandAPI_" + player.getName(), new SpigotNMS_1_19_R1_ChatPreviewHandler(this, plugin, player)); + } + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_19_R1(); + } + return bukkitNMS; + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1_ChatPreviewHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1_ChatPreviewHandler.java new file mode 100644 index 0000000000..3711d74b5d --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.19/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_19_R1_ChatPreviewHandler.java @@ -0,0 +1,24 @@ +package dev.jorel.commandapi.nms; + +import dev.jorel.commandapi.CommandAPISpigot; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.protocol.game.ClientboundChatPreviewPacket; +import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class SpigotNMS_1_19_R1_ChatPreviewHandler extends SpigotNMS_1_19_Common_ChatPreviewHandler { + + public SpigotNMS_1_19_R1_ChatPreviewHandler(CommandAPISpigot platform, Plugin plugin, Player player) { + super(platform, plugin, player); + } + + @Override + protected void handleChatPreviewPacket(ServerboundChatPreviewPacket chatPreview) { + // We want to run this synchronously, just in case there's some funky async stuff going on here + Bukkit.getScheduler().runTask(this.plugin, () -> this.connection.send( + new ClientboundChatPreviewPacket(chatPreview.queryId(), parseChatPreviewQuery(chatPreview.query())) + )); + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml new file mode 100644 index 0000000000..d5219d7136 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.20.2 + + + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.2 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.5 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java new file mode 100644 index 0000000000..2dff0e1760 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java @@ -0,0 +1,52 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; + +public class SpigotNMS_1_20_R2 extends SpigotNMS_Common { + + private NMS_1_20_R2 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml new file mode 100644 index 0000000000..033f18d884 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.20.3 + + + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.3 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.5 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java new file mode 100644 index 0000000000..9ba493ac8f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java @@ -0,0 +1,52 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R3.command.VanillaCommandWrapper; + +public class SpigotNMS_1_20_R3 extends SpigotNMS_Common { + + private NMS_1_20_R3 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml new file mode 100644 index 0000000000..e50c37675e --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.20.5 + + + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java new file mode 100644 index 0000000000..061e2a6c9a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java @@ -0,0 +1,66 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R4.CraftServer; +import org.bukkit.craftbukkit.v1_20_R4.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper; + +public class SpigotNMS_1_20_R4 extends SpigotNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_20_R4 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R4(COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml new file mode 100644 index 0000000000..688ea2181f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.20 + + + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java new file mode 100644 index 0000000000..aadc3f6d08 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java @@ -0,0 +1,52 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R1.command.VanillaCommandWrapper; + +public class SpigotNMS_1_20_R1 extends SpigotNMS_Common { + + private NMS_1_20_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R1(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml new file mode 100644 index 0000000000..6fa708853d --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.21.2 + + + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java new file mode 100644 index 0000000000..a99cc037bb --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java @@ -0,0 +1,66 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R2.CraftServer; +import org.bukkit.craftbukkit.v1_21_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R2.command.VanillaCommandWrapper; + +public class SpigotNMS_1_21_R2 extends SpigotNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R2 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml new file mode 100644 index 0000000000..ebcbb232aa --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.21.4 + + + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java new file mode 100644 index 0000000000..e3a18aa74a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java @@ -0,0 +1,66 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R3.CraftServer; +import org.bukkit.craftbukkit.v1_21_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R3.command.VanillaCommandWrapper; + +public class SpigotNMS_1_21_R3 extends SpigotNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R2 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml new file mode 100644 index 0000000000..ae2a35e351 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-1.21 + + + 1.21.1-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java new file mode 100644 index 0000000000..5514542acf --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java @@ -0,0 +1,66 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R1.CraftServer; +import org.bukkit.craftbukkit.v1_21_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R1.command.VanillaCommandWrapper; + +public class SpigotNMS_1_21_R1 extends SpigotNMS_Common { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R1 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R1(COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/pom.xml new file mode 100644 index 0000000000..c7dc171938 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/pom.xml @@ -0,0 +1,226 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-nms-common + + + 1.19-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + + + org.spigotmc + spigot + ${spigot.version} + provided + remapped-mojang + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + compile + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + + + + Spigot_1_20_4_R3 + + + org.spigotmc + spigot + 1.20.4-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_2_R2 + + + org.spigotmc + spigot + 1.20.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_R1 + + + org.spigotmc + spigot + 1.20-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_19_3_R2 + + + org.spigotmc + spigot + 1.19.3-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_19_R1 + + true + + + + org.spigotmc + spigot + 1.19-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_18_2_R2 + + + org.spigotmc + spigot + 1.18.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_18_R1 + + + org.spigotmc + spigot + 1.18-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_17_R1 + + + org.spigotmc + spigot + 1.17-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_Common.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_Common.java new file mode 100644 index 0000000000..8b353eed2f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-common/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_Common.java @@ -0,0 +1,24 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import org.bukkit.ChatColor; + +public abstract class SpigotNMS_Common extends CommandAPISpigot { + + @Override + public abstract BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + @Override + public final ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public abstract BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml new file mode 100644 index 0000000000..6210d5e5f5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-nms-dependency-mojang-mapped + pom + + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.19-common + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.17-common + ${project.version} + mojang-mapped + + + + + dev.jorel + commandapi-spigot-1.21.4 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.21.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.21 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20.5 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20.3 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.19.4 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.19.3 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.19.1 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.19 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.18.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.18 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.17 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.17.1 + ${project.version} + mojang-mapped + + + + + dev.jorel + commandapi-spigot-1.16.5 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml new file mode 100644 index 0000000000..7c12d8df89 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 9.7.1-SNAPSHOT + + + commandapi-spigot-nms-dependency + pom + + + + + dev.jorel + commandapi-spigot-nms-common + ${project.version} + + + dev.jorel + commandapi-spigot-1.19-common + ${project.version} + + + dev.jorel + commandapi-spigot-1.17-common + ${project.version} + + + + + dev.jorel + commandapi-spigot-1.21.4 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21.2 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.5 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.3 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.2 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20 + ${project.version} + + + dev.jorel + commandapi-spigot-1.19.4 + ${project.version} + + + dev.jorel + commandapi-spigot-1.19.3 + ${project.version} + + + dev.jorel + commandapi-spigot-1.19.1 + ${project.version} + + + dev.jorel + commandapi-spigot-1.19 + ${project.version} + + + dev.jorel + commandapi-spigot-1.18.2 + ${project.version} + + + dev.jorel + commandapi-spigot-1.18 + ${project.version} + + + dev.jorel + commandapi-spigot-1.17 + ${project.version} + + + dev.jorel + commandapi-spigot-1.17.1 + ${project.version} + + + dev.jorel + commandapi-spigot-1.16.5 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml new file mode 100644 index 0000000000..858c1ae874 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-nms + pom + + + commandapi-spigot-nms-common + + commandapi-spigot-1.21.4 + commandapi-spigot-1.21.2 + commandapi-spigot-1.21 + commandapi-spigot-1.20.5 + commandapi-spigot-1.20.3 + commandapi-spigot-1.20.2 + commandapi-spigot-1.20 + commandapi-spigot-1.19-common + commandapi-spigot-1.19.4 + commandapi-spigot-1.19.3 + commandapi-spigot-1.19.1 + commandapi-spigot-1.19 + commandapi-spigot-1.18.2 + commandapi-spigot-1.18 + commandapi-spigot-1.17-common + commandapi-spigot-1.17.1 + commandapi-spigot-1.17 + commandapi-spigot-1.16.5 + + commandapi-spigot-nms-dependency + commandapi-spigot-nms-dependency-mojang-mapped + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml similarity index 59% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml index 08ffc7f977..1900404f97 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml @@ -1,36 +1,15 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel + commandapi-spigot 9.7.1-SNAPSHOT - 4.0.0 - - commandapi-bukkit-plugin + commandapi-spigot-plugin-mojang-mapped @@ -42,35 +21,32 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - papermc - https://repo.papermc.io/repository/maven-public/ - dev.jorel - commandapi-bukkit-core + commandapi-spigot-core ${project.version} compile + dev.jorel - commandapi-bukkit-vh + commandapi-spigot-nms-dependency-mojang-mapped ${project.version} + pom dev.jorel - commandapi-bukkit-nms-dependency + commandapi-spigot-vh ${project.version} - pom - io.papermc.paper - paper-api - ${paper.version} - provided + dev.jorel + commandapi-spigot-mojang-mapped + ${project.version} org.spigotmc @@ -90,7 +66,7 @@ src/main/resources true - + @@ -110,9 +86,24 @@ dev.jorel:commandapi-core dev/jorel/commandapi/CommandAPIVersionHandler** + dev/jorel/commandapi/MojangMappedVersionHandler** + + + org.bukkit.craftbukkit.v1_20_R4 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R1 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R2 + org.bukkit.craftbukkit + + LICENSE @@ -139,6 +130,21 @@ + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.1 + + + + mojang + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java new file mode 100644 index 0000000000..8e17c74be5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CommandAPIArgumentType; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.FloatRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.OfflinePlayerArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.exceptions.InvalidNumberException; +import dev.jorel.commandapi.exceptions.UnknownArgumentException; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A command parsing system that converts string arguments into something way + * more useful + */ +class AdvancedConverter { + + /** + * Pattern for arguments, which are of the form {@code [type]} + *

    + *
  • {@code node_name} is a standard node name.
  • + *
  • {@code type} is either a namespaced key representing the argument + * (described in {@code conversionforownerssingleargs.md} in the main + * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or + * {@code n..} where {@code n} is a constant integer or floating point + * number
  • + *
+ */ + private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); + + /** + * Pattern for literal, of the form {@code (node_name)}. It also supports + * multiple node names of the form + * {@code (node_name_1|node_name_2|...|node_name_n)} + */ + private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); + + private final JavaPlugin plugin; + private final String command; + private int argumentIndex = 1; + + public AdvancedConverter(JavaPlugin plugin, String command) { + this.plugin = plugin; + this.command = command; + } + + public AdvancedConverter(String command) { + this.plugin = null; + this.command = command; + } + + public void convert() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(plugin, commandName); + } else { + Converter.convert(plugin, commandName, arguments); + } + + } + + public void convertCommand() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(commandName); + } else { + Converter.convert(commandName, arguments); + } + } + + /** + *
+	 * plugins-to-convert: 
+	 *   - Essentials: 
+	 *     - speed [0..10]
+	 *     - speed [minecraft:game_profile]
+	 *     - speed (walk|fly) [0..10]
+	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
+	 * 
+ */ + private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { + List> arguments = new ArrayList<>(); + String[] parts = command.split(" "); + for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { + arguments.add(parseArgument(parts[argumentIndex])); + } + return arguments; + } + + private boolean isRangeAnInteger(double value) { + return value == (long) value; + } + + private double parseValue(String bound) throws InvalidNumberException { + try { + return Double.parseDouble(bound); + } catch (NumberFormatException e) { + throw new InvalidNumberException(bound, command, argumentIndex); + } + } + + private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { + if (bounds.length == 1) { + // x.. + double value = parseValue(bounds[0]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, (long) value); + } else { + return new DoubleArgument(nodeName, value); + } + } else if (bounds[0].length() == 0) { + // ..x + double value = parseValue(bounds[1]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); + } else { + return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); + } + } else { + // x..x + double value0 = parseValue(bounds[0]); + double value1 = parseValue(bounds[1]); + if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { + return new DoubleArgument(nodeName, value0, value1); + } else { + return new LongArgument(nodeName, (long) value0, (long) value1); + } + } + } + + /* + * CodeFactor will always complain about this method because it's really bulky + * and adding a generator (i.e. Function>) inside the + * CommandAPIArgumentType class would be better, EXCEPT in practice, this is + * worse because then CommandAPIArgumentType would have to depend on every + * argument and every argument depends on CommandAPIArgumentType, so that would + * mean every argument would always have to be packaged in the CommandAPI - jar + * minimisation wouldn't be able to minimise this as best as it could. + * + * Additionally, we only need this for the plugin version of the CommandAPI, not + * the main API. + */ + @SuppressWarnings("rawtypes") + private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { + return switch (CommandAPIArgumentType.fromInternal(argumentType)) { + case ADVANCEMENT -> new AdvancementArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case ANGLE -> new AngleArgument(nodeName); + case AXIS -> new AxisArgument(nodeName); + case BIOME -> new BiomeArgument(nodeName); + case BLOCKSTATE -> new BlockStateArgument(nodeName); + case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); + case CHAT -> new ChatArgument(nodeName); + case CHATCOLOR -> new ChatColorArgument(nodeName); + case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case COMMAND -> new CommandArgument(nodeName); + case ENCHANTMENT -> new EnchantmentArgument(nodeName); + case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); + case ENTITY_TYPE -> new EntityTypeArgument(nodeName); + case FLOAT_RANGE -> new FloatRangeArgument(nodeName); + case FUNCTION -> new FunctionArgument(nodeName); + case INT_RANGE -> new IntegerRangeArgument(nodeName); + case ITEMSTACK -> new ItemStackArgument(nodeName); + case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); + case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); + case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); + case LOOT_TABLE -> new LootTableArgument(nodeName); + case MATH_OPERATION -> new MathOperationArgument(nodeName); + case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); + case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); + case OBJECTIVE -> new ObjectiveArgument(nodeName); + case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); + case OFFLINE_PLAYER -> new OfflinePlayerArgument(nodeName); + case PARTICLE -> new ParticleArgument(nodeName); + case PLAYER -> new PlayerArgument(nodeName); + case POTION_EFFECT -> new PotionEffectArgument(nodeName); + case RECIPE -> new RecipeArgument(nodeName); + case ROTATION -> new RotationArgument(nodeName); + case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); + case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); + case SOUND -> new SoundArgument(nodeName); + case TEAM -> new TeamArgument(nodeName); + case TIME -> new TimeArgument(nodeName); + case UUID -> new UUIDArgument(nodeName); + case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); + case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); + case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); + case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); + case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); + case PRIMITIVE_LONG -> new LongArgument(nodeName); + case PRIMITIVE_STRING -> new StringArgument(nodeName); + case PRIMITIVE_TEXT -> new TextArgument(nodeName); + case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); + default -> throw new UnknownArgumentException(argumentType); + }; + } + + private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { + Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); + Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); + if (literalMatcher.matches()) { + // Parse literals + return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); + } else if (argumentMatcher.matches()) { + // Parse arguments + String nodeName = argumentMatcher.group(1); + String argumentType = argumentMatcher.group(2); + + if (argumentType.contains("..")) { + // Parse ranges + return parseRange(nodeName, argumentType.split("\\.\\.")); + } else { + // We have a few edge cases to handle + return switch (argumentType) { + case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); + case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); + case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); + case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); + case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); + case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); + default -> parseDefinedArgumentType(argumentType, nodeName); + }; + } + } else { + throw new UnknownArgumentException(argument); + } + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java new file mode 100644 index 0000000000..a6078e4f49 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Main CommandAPI plugin entrypoint + */ +public class CommandAPIMain extends JavaPlugin { + + private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; + + @Override + public void onLoad() { + // Read config file + saveDefaultConfig(); + FileConfiguration fileConfig = getConfig(); + CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) + .verboseOutput(fileConfig.getBoolean("verbose-outputs")) + .silentLogs(fileConfig.getBoolean("silent-logs")) + .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) + .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + + for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + config.addSkipSenderProxy(pluginName); + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + } + + // Main CommandAPI loading + CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); + CommandAPI.onLoad(config); + + // Convert all plugins to be converted + if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() + && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { + CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); + } + + convertCommands(fileConfig); + } + + private void convertCommands(FileConfiguration fileConfig) { + // Load all plugins at the same time + Map pluginsToConvert = new HashMap<>(); + for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { + String[] pluginCommands; + if (map.values().size() == 1 && map.values().iterator().next() == null) { + pluginCommands = new String[0]; + } else { + @SuppressWarnings("unchecked") + List commands = (List) map.values().iterator().next(); + pluginCommands = commands.toArray(new String[0]); + } + + // Get the plugin, if it doesn't exist, scream in the console (but + // don't crash, we want to continue!) + final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); + if (plugin != null) { + pluginsToConvert.put(plugin, pluginCommands); + } + } + + // Convert plugin commands + for (Entry pluginToConvert : pluginsToConvert.entrySet()) { + if (pluginToConvert.getValue().length == 0) { + Converter.convert(pluginToConvert.getKey()); + } else { + for (String command : pluginToConvert.getValue()) { + new AdvancedConverter(pluginToConvert.getKey(), command).convert(); + } + } + } + + // Convert all arbitrary commands + for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { + new AdvancedConverter(commandName).convertCommand(); + } + } + + private JavaPlugin getAndValidatePlugin(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + if (plugin instanceof JavaPlugin javaPlugin) { + return javaPlugin; + } else { + new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); + } + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + return null; + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + /** + * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, + * this doesn't fail silently if the config.yml already exists but instead will update the config with + * new values if available. + *

+ * This should fail silently if all values are set already. + */ + @Override + public void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveConfig( + DefaultBukkitConfig.createDefaultSpigotConfig(), + getDataFolder(), + getLogger() + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml new file mode 100644 index 0000000000..9714bb0dc1 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml @@ -0,0 +1,74 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml new file mode 100644 index 0000000000..c31f8ced83 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml @@ -0,0 +1,13 @@ +name: CommandAPI +main: dev.jorel.commandapi.CommandAPIMain +version: ${project.version} +description: An API to use Minecraft 1.13s new command UI +authors: + - Skepter + - Will Kroboth + - DerEchtePilz +website: https://www.jorel.dev/CommandAPI/ +softdepend: + - NBTAPI +api-version: 1.13 +folia-supported: true diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE new file mode 100644 index 0000000000..29bc4dd177 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2022 Jorel Ali + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml new file mode 100644 index 0000000000..d6afa89cd2 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-plugin + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-spigot-vh + ${project.version} + + + dev.jorel + commandapi-spigot-nms-dependency + ${project.version} + pom + + + dev.jorel + commandapi-bukkit-plugin-common + ${project.version} + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + LICENSE + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java new file mode 100644 index 0000000000..8e17c74be5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CommandAPIArgumentType; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.FloatRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.OfflinePlayerArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.exceptions.InvalidNumberException; +import dev.jorel.commandapi.exceptions.UnknownArgumentException; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A command parsing system that converts string arguments into something way + * more useful + */ +class AdvancedConverter { + + /** + * Pattern for arguments, which are of the form {@code [type]} + *

    + *
  • {@code node_name} is a standard node name.
  • + *
  • {@code type} is either a namespaced key representing the argument + * (described in {@code conversionforownerssingleargs.md} in the main + * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or + * {@code n..} where {@code n} is a constant integer or floating point + * number
  • + *
+ */ + private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); + + /** + * Pattern for literal, of the form {@code (node_name)}. It also supports + * multiple node names of the form + * {@code (node_name_1|node_name_2|...|node_name_n)} + */ + private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); + + private final JavaPlugin plugin; + private final String command; + private int argumentIndex = 1; + + public AdvancedConverter(JavaPlugin plugin, String command) { + this.plugin = plugin; + this.command = command; + } + + public AdvancedConverter(String command) { + this.plugin = null; + this.command = command; + } + + public void convert() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(plugin, commandName); + } else { + Converter.convert(plugin, commandName, arguments); + } + + } + + public void convertCommand() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(commandName); + } else { + Converter.convert(commandName, arguments); + } + } + + /** + *
+	 * plugins-to-convert: 
+	 *   - Essentials: 
+	 *     - speed [0..10]
+	 *     - speed [minecraft:game_profile]
+	 *     - speed (walk|fly) [0..10]
+	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
+	 * 
+ */ + private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { + List> arguments = new ArrayList<>(); + String[] parts = command.split(" "); + for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { + arguments.add(parseArgument(parts[argumentIndex])); + } + return arguments; + } + + private boolean isRangeAnInteger(double value) { + return value == (long) value; + } + + private double parseValue(String bound) throws InvalidNumberException { + try { + return Double.parseDouble(bound); + } catch (NumberFormatException e) { + throw new InvalidNumberException(bound, command, argumentIndex); + } + } + + private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { + if (bounds.length == 1) { + // x.. + double value = parseValue(bounds[0]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, (long) value); + } else { + return new DoubleArgument(nodeName, value); + } + } else if (bounds[0].length() == 0) { + // ..x + double value = parseValue(bounds[1]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); + } else { + return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); + } + } else { + // x..x + double value0 = parseValue(bounds[0]); + double value1 = parseValue(bounds[1]); + if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { + return new DoubleArgument(nodeName, value0, value1); + } else { + return new LongArgument(nodeName, (long) value0, (long) value1); + } + } + } + + /* + * CodeFactor will always complain about this method because it's really bulky + * and adding a generator (i.e. Function>) inside the + * CommandAPIArgumentType class would be better, EXCEPT in practice, this is + * worse because then CommandAPIArgumentType would have to depend on every + * argument and every argument depends on CommandAPIArgumentType, so that would + * mean every argument would always have to be packaged in the CommandAPI - jar + * minimisation wouldn't be able to minimise this as best as it could. + * + * Additionally, we only need this for the plugin version of the CommandAPI, not + * the main API. + */ + @SuppressWarnings("rawtypes") + private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { + return switch (CommandAPIArgumentType.fromInternal(argumentType)) { + case ADVANCEMENT -> new AdvancementArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case ANGLE -> new AngleArgument(nodeName); + case AXIS -> new AxisArgument(nodeName); + case BIOME -> new BiomeArgument(nodeName); + case BLOCKSTATE -> new BlockStateArgument(nodeName); + case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); + case CHAT -> new ChatArgument(nodeName); + case CHATCOLOR -> new ChatColorArgument(nodeName); + case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case COMMAND -> new CommandArgument(nodeName); + case ENCHANTMENT -> new EnchantmentArgument(nodeName); + case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); + case ENTITY_TYPE -> new EntityTypeArgument(nodeName); + case FLOAT_RANGE -> new FloatRangeArgument(nodeName); + case FUNCTION -> new FunctionArgument(nodeName); + case INT_RANGE -> new IntegerRangeArgument(nodeName); + case ITEMSTACK -> new ItemStackArgument(nodeName); + case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); + case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); + case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); + case LOOT_TABLE -> new LootTableArgument(nodeName); + case MATH_OPERATION -> new MathOperationArgument(nodeName); + case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); + case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); + case OBJECTIVE -> new ObjectiveArgument(nodeName); + case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); + case OFFLINE_PLAYER -> new OfflinePlayerArgument(nodeName); + case PARTICLE -> new ParticleArgument(nodeName); + case PLAYER -> new PlayerArgument(nodeName); + case POTION_EFFECT -> new PotionEffectArgument(nodeName); + case RECIPE -> new RecipeArgument(nodeName); + case ROTATION -> new RotationArgument(nodeName); + case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); + case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); + case SOUND -> new SoundArgument(nodeName); + case TEAM -> new TeamArgument(nodeName); + case TIME -> new TimeArgument(nodeName); + case UUID -> new UUIDArgument(nodeName); + case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); + case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); + case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); + case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); + case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); + case PRIMITIVE_LONG -> new LongArgument(nodeName); + case PRIMITIVE_STRING -> new StringArgument(nodeName); + case PRIMITIVE_TEXT -> new TextArgument(nodeName); + case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); + default -> throw new UnknownArgumentException(argumentType); + }; + } + + private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { + Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); + Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); + if (literalMatcher.matches()) { + // Parse literals + return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); + } else if (argumentMatcher.matches()) { + // Parse arguments + String nodeName = argumentMatcher.group(1); + String argumentType = argumentMatcher.group(2); + + if (argumentType.contains("..")) { + // Parse ranges + return parseRange(nodeName, argumentType.split("\\.\\.")); + } else { + // We have a few edge cases to handle + return switch (argumentType) { + case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); + case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); + case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); + case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); + case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); + case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); + default -> parseDefinedArgumentType(argumentType, nodeName); + }; + } + } else { + throw new UnknownArgumentException(argument); + } + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java new file mode 100644 index 0000000000..a6078e4f49 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Main CommandAPI plugin entrypoint + */ +public class CommandAPIMain extends JavaPlugin { + + private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; + + @Override + public void onLoad() { + // Read config file + saveDefaultConfig(); + FileConfiguration fileConfig = getConfig(); + CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) + .verboseOutput(fileConfig.getBoolean("verbose-outputs")) + .silentLogs(fileConfig.getBoolean("silent-logs")) + .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) + .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + + for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + config.addSkipSenderProxy(pluginName); + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + } + + // Main CommandAPI loading + CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); + CommandAPI.onLoad(config); + + // Convert all plugins to be converted + if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() + && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { + CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); + } + + convertCommands(fileConfig); + } + + private void convertCommands(FileConfiguration fileConfig) { + // Load all plugins at the same time + Map pluginsToConvert = new HashMap<>(); + for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { + String[] pluginCommands; + if (map.values().size() == 1 && map.values().iterator().next() == null) { + pluginCommands = new String[0]; + } else { + @SuppressWarnings("unchecked") + List commands = (List) map.values().iterator().next(); + pluginCommands = commands.toArray(new String[0]); + } + + // Get the plugin, if it doesn't exist, scream in the console (but + // don't crash, we want to continue!) + final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); + if (plugin != null) { + pluginsToConvert.put(plugin, pluginCommands); + } + } + + // Convert plugin commands + for (Entry pluginToConvert : pluginsToConvert.entrySet()) { + if (pluginToConvert.getValue().length == 0) { + Converter.convert(pluginToConvert.getKey()); + } else { + for (String command : pluginToConvert.getValue()) { + new AdvancedConverter(pluginToConvert.getKey(), command).convert(); + } + } + } + + // Convert all arbitrary commands + for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { + new AdvancedConverter(commandName).convertCommand(); + } + } + + private JavaPlugin getAndValidatePlugin(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + if (plugin instanceof JavaPlugin javaPlugin) { + return javaPlugin; + } else { + new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); + } + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + return null; + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + /** + * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, + * this doesn't fail silently if the config.yml already exists but instead will update the config with + * new values if available. + *

+ * This should fail silently if all values are set already. + */ + @Override + public void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveConfig( + DefaultBukkitConfig.createDefaultSpigotConfig(), + getDataFolder(), + getLogger() + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml new file mode 100644 index 0000000000..9714bb0dc1 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml @@ -0,0 +1,74 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml new file mode 100644 index 0000000000..c31f8ced83 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml @@ -0,0 +1,13 @@ +name: CommandAPI +main: dev.jorel.commandapi.CommandAPIMain +version: ${project.version} +description: An API to use Minecraft 1.13s new command UI +authors: + - Skepter + - Will Kroboth + - DerEchtePilz +website: https://www.jorel.dev/CommandAPI/ +softdepend: + - NBTAPI +api-version: 1.13 +folia-supported: true diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml similarity index 62% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml index 387841316e..5a3c795d4c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml @@ -1,58 +1,37 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel + commandapi-spigot 9.7.1-SNAPSHOT - 4.0.0 - - commandapi-bukkit-shade-mojang-mapped + commandapi-spigot-shade-mojang-mapped dev.jorel - commandapi-bukkit-core + commandapi-spigot-core ${project.version} compile dev.jorel - commandapi-bukkit-nms-dependency-mojang-mapped + commandapi-spigot-nms-dependency-mojang-mapped ${project.version} pom dev.jorel - commandapi-bukkit-vh + commandapi-spigot-vh ${project.version} dev.jorel - commandapi-bukkit-mojang-mapped + commandapi-spigot-mojang-mapped ${project.version} @@ -124,4 +103,5 @@ + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE new file mode 100644 index 0000000000..29bc4dd177 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2022 Jorel Ali + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md new file mode 100644 index 0000000000..809bd4251b --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md @@ -0,0 +1 @@ +# commandapi-shade \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml new file mode 100644 index 0000000000..023f58d85b --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-shade + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-spigot-vh + ${project.version} + + + dev.jorel + commandapi-spigot-nms-dependency + ${project.version} + pom + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + normal + package + + shade + + + true + true + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml new file mode 100644 index 0000000000..922724bd17 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 9.7.1-SNAPSHOT + + + commandapi-spigot-vh + + + + dev.jorel + commandapi-spigot-nms-dependency + ${project.version} + pom + + + + + org.spigotmc + spigot + ${paper.version} + remapped-mojang + provided + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 0000000000..287a13e325 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,68 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.exceptions.UnsupportedVersionException; +import dev.jorel.commandapi.nms.SpigotNMS_1_16_R3; +import dev.jorel.commandapi.nms.SpigotNMS_1_17; +import dev.jorel.commandapi.nms.SpigotNMS_1_17_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_18_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_18_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_19_1_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_19_3_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_19_4_R3; +import dev.jorel.commandapi.nms.SpigotNMS_1_19_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R3; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R4; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R3; +import org.bukkit.Bukkit; + +public abstract class CommandAPIVersionHandler { + + static LoadContext getPlatform() { + String latestMajorVersion = "21"; // Change this for Minecraft's major update + if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + return new LoadContext(new SpigotNMS_1_21_R3(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } else { + String version = Bukkit.getBukkitVersion().split("-")[0]; + CommandAPIPlatform platform = switch (version) { + case "1.16.5" -> new SpigotNMS_1_16_R3(); + case "1.17" -> new SpigotNMS_1_17(); + case "1.17.1" -> new SpigotNMS_1_17_R1(); + case "1.18", "1.18.1" -> new SpigotNMS_1_18_R1(); + case "1.18.2" -> new SpigotNMS_1_18_R2(); + case "1.19" -> new SpigotNMS_1_19_R1(); + case "1.19.1", "1.19.2" -> new SpigotNMS_1_19_1_R1(); + case "1.19.3" -> new SpigotNMS_1_19_3_R2(); + case "1.19.4" -> new SpigotNMS_1_19_4_R3(); + case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(); + case "1.20.2" -> new SpigotNMS_1_20_R2(); + case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(); + case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(); + case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); + case "1.21.4" -> new SpigotNMS_1_21_R3(); + default -> null; + }; + if (platform != null) { + return new LoadContext(platform); + } + if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { + String currentMajorVersion = version.split("\\.")[1]; + if (latestMajorVersion.equals(currentMajorVersion)) { + return new LoadContext(new SpigotNMS_1_21_R3(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } + } + throw new UnsupportedVersionException(version); + } + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java new file mode 100644 index 0000000000..8cf6fc0d58 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.exceptions; + +/** + * An exception that occurs when this version of Minecraft is unsupported + */ +@SuppressWarnings("serial") +public class UnsupportedVersionException extends RuntimeException { + + /** + * Creates an UnsupportedVersionException + * @param version the version of Minecraft that is unsupported + */ + public UnsupportedVersionException(String version) { + super("This version of Minecraft is unsupported: " + version); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/pom.xml b/commandapi-platforms/commandapi-spigot/pom.xml new file mode 100644 index 0000000000..93a5548406 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + dev.jorel + commandapi-platforms + 9.7.1-SNAPSHOT + + + commandapi-spigot + pom + + + commandapi-spigot-annotations + commandapi-spigot-core + commandapi-spigot-nms + commandapi-spigot-vh + commandapi-spigot-mojang-mapped + commandapi-spigot-plugin + commandapi-spigot-shade + commandapi-spigot-plugin-mojang-mapped + commandapi-spigot-shade-mojang-mapped + commandapi-spigot-documentation-code + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index b1cb25e6a0..3bb523b933 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -8,6 +8,7 @@ import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; +import dev.jorel.commandapi.config.DefaultVelocityConfig; import dev.jorel.commandapi.config.VelocityConfigurationAdapter; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.yaml.NodeStyle; @@ -41,7 +42,8 @@ public CommandAPIMain(ProxyServer server, Logger logger, @DataDirectory Path dat .build(); // Create or update config - VelocityConfigurationAdapter.createMinimalInstance(loader).saveDefaultConfig(configFile.getParent().toFile(), logger); + VelocityConfigurationAdapter.createMinimalInstance(loader) + .saveConfig(DefaultVelocityConfig.createDefault(), configFile.getParent().toFile(), logger); // Load the file as a yaml node ConfigurationNode configYAML; diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java index cab8d6237e..eb2a0646f0 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java @@ -72,17 +72,12 @@ public ConfigurationAdapter complete() { @Override public ConfigurationAdapter createNew() { - return new VelocityConfigurationAdapter(loader, loader.createNode(), createDefaultConfig()); - } - - @Override - public DefaultVelocityConfig createDefaultConfig() { - return DefaultVelocityConfig.createDefault(); + return new VelocityConfigurationAdapter(loader, loader.createNode(), DefaultVelocityConfig.createDefault()); } @Override public ConfigurationAdapter loadFromFile() throws IOException { - return new VelocityConfigurationAdapter(loader, loader.load(), createDefaultConfig()); + return new VelocityConfigurationAdapter(loader, loader.load(), DefaultVelocityConfig.createDefault()); } @Override diff --git a/commandapi-platforms/commandapi-velocity/pom.xml b/commandapi-platforms/commandapi-velocity/pom.xml index 694949624a..5b44ceade8 100644 --- a/commandapi-platforms/commandapi-velocity/pom.xml +++ b/commandapi-platforms/commandapi-velocity/pom.xml @@ -21,5 +21,7 @@ commandapi-velocity-plugin commandapi-velocity-plugin-test commandapi-velocity-shade + + ../../commandapi-documentation-velocity-code \ No newline at end of file diff --git a/commandapi-platforms/pom.xml b/commandapi-platforms/pom.xml index 08c6372b7f..49a035a034 100644 --- a/commandapi-platforms/pom.xml +++ b/commandapi-platforms/pom.xml @@ -19,9 +19,32 @@ Platform.Bukkit commandapi-bukkit - ../commandapi-kotlin/commandapi-core-kotlin - ../commandapi-kotlin/commandapi-bukkit-kotlin - ../commandapi-documentation-code + commandapi-paper + commandapi-spigot + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-paper + ../commandapi-kotlin/commandapi-kotlin-spigot + + + + Platform.Paper + + commandapi-bukkit + commandapi-paper + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-paper + + + + Platform.Spigot + + commandapi-bukkit + commandapi-spigot + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-spigot @@ -34,9 +57,8 @@ Platform.Velocity commandapi-velocity - ../commandapi-kotlin/commandapi-core-kotlin - ../commandapi-kotlin/commandapi-velocity-kotlin - ../commandapi-documentation-velocity-code + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-velocity diff --git a/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java b/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java index 86c9336c0e..09bd9d2ecf 100644 --- a/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java +++ b/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java @@ -27,14 +27,12 @@ public interface ConfigurationAdapter { ConfigurationAdapter createNew(); - DefaultConfig createDefaultConfig(); - ConfigurationAdapter loadFromFile() throws IOException; void saveToFile() throws IOException; - default void saveDefaultConfig(File directory, Logger logger) { - ConfigGenerator generator = ConfigGenerator.createNew(createDefaultConfig()); + default void saveConfig(DefaultConfig config, File directory, Logger logger) { + ConfigGenerator generator = ConfigGenerator.createNew(config); ConfigurationAdapter existingConfig; if (!directory.exists()) { if (!directory.mkdirs()) { diff --git a/docssrc/src/argument_chat_adventure.md b/docssrc/src/argument_chat_adventure.md index 0250b5447e..796217cd8e 100644 --- a/docssrc/src/argument_chat_adventure.md +++ b/docssrc/src/argument_chat_adventure.md @@ -1,12 +1,14 @@ # Adventure chat arguments -> **Developer's Note:** -> -> The two following classes, `AdventureChatComponentArgument` and `AdventureChatArgument` depend on a Paper based server which has the Adventure library. If you use this class on a server without the Adventure library, it will throw a `PaperAdventureNotFoundException` - From Paper 1.16.5 build #473 onwards, Paper now includes [Kyori's Adventure API](https://github.com/KyoriPowered/adventure-platform). This library is a replacement of the BungeeCord chat API and has all of the same functionality as the BungeeCord chat API (and more!). The documentation for this API can be found [here](https://docs.adventure.kyori.net/index.html). Since this functions very similar to the Spigot chat arguments, this page won't reiterate everything about how it works, we'll just outline some examples of how to use these arguments instead. +Additionally, the names used here may be confusing as they are the same names as on the [Spigot chat arguments](./argument_chat_spigot.md) page but have different return types. This is because the classes on this page are only accessible using `commandapi-paper-core` or `commandapi-paper-shade` +while the arguments on the Spigot chat arguments page are only available when using `commandapi-spigot-core` or `commandapi-spigot-shade`. + +> **Developer's Note:** +> +> The three following classes, `ChatColorArgument`, `ChatComponentArgument` and `ChatArgument` depend on a Paper based server which has the Adventure library. If you use this class on a server without the Adventure library, it will throw a `PaperAdventureNotFoundException` ----- @@ -14,7 +16,7 @@ Since this functions very similar to the Spigot chat arguments, this page won't ![Chatcolor argument in-game, displaying a list of Minecraft chat colors](./images/arguments/chatcolor.png) -The `AdventureChatColorArgument` class is used to represent a given chat color (e.g. red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`. +The `ChatColorArgument` class is used to represent a given chat color (e.g. red or green). This argument returns the `NamedTextColor` object. If `reset` is passed to this argument, this will return `NamedTextColor.WHITE`.

@@ -31,15 +33,15 @@ We then use the `ChatColorArgument` to change the player's name color:
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure1}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure1}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure1}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure1}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure1}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure1}} ```
@@ -50,7 +52,7 @@ We then use the `ChatColorArgument` to change the player's name color: ## Adventure chat component argument -The `AdventureChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class. +The `ChatComponentArgument` class accepts raw chat-based JSON as valid input, as declared [here](https://minecraft.wiki/w/Raw_JSON_text_format). This is converted into Adventure's `Component` class.
@@ -67,15 +69,15 @@ We can construct a book using the Adventure API's `Book.book(Component, Componen
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure2}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure2}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure2}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure2}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure2}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure2}} ```
@@ -86,13 +88,13 @@ We can construct a book using the Adventure API's `Book.book(Component, Componen ## Adventure chat argument -The `AdventureChatArgument` class is the equivalent Adventure API class for the `ChatArgument` - it represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `AdventureChatArgument` returns a `Component`, similar to the `AdventureChatComponentArgument`. +The `ChatArgument` represents infinitely long strings similar to the `GreedyStringArgument` and allows entity selectors such as `@e`, `@p` and so on. The `ChatArgument` returns a `Component`, similar to the `ChatComponentArgument`.
### Example - Sending personalized messages to players -We'll take the same example from the `ChatArgument` class, but using the `AdventureChatArgument` instead - We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax: +We want to create a personalized message broadcasted to all users using a chat component that allows entity selectors. For this command, we want the following syntax: ```mccmd /pbroadcast @@ -103,15 +105,15 @@ In order to broadcast an Adventure `Component` to all players on the server, we
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure3}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatAdventure3}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure3}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatAdventure3}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure3}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatAdventure3}} ```
diff --git a/docssrc/src/argument_chat_spigot.md b/docssrc/src/argument_chat_spigot.md index ce7336e39f..381a32a159 100644 --- a/docssrc/src/argument_chat_spigot.md +++ b/docssrc/src/argument_chat_spigot.md @@ -21,15 +21,15 @@ We then use the `ChatColorArgument` to change the player's name color:
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot1}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot1}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot1}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot1}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot1}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot1}} ```
@@ -121,15 +121,15 @@ Now we can create our book command. We use the player as the main target by usin
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot2}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot2}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot2}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot2}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot2}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot2}} ```
@@ -167,15 +167,15 @@ _Bob_ would receive the message "Hello Bob", whereas _Michael_ would receive the
```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot3}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentChatSpigot3}} ``` ```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot3}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentChatSpigot3}} ``` ```kotlin,Kotlin_DSL -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot3}} +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentChatSpigot3}} ```
diff --git a/docssrc/src/argument_nbt.md b/docssrc/src/argument_nbt.md index d43d306194..ce387489e5 100644 --- a/docssrc/src/argument_nbt.md +++ b/docssrc/src/argument_nbt.md @@ -38,12 +38,20 @@ Now, we can configure the CommandAPI using the `CommandAPI.onLoad()` method to u
-```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentNBT1}} +```java,Java_(Paper) +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentNBT1}} ``` -```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentNBT1}} +```java,Java_(Spigot) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentNBT1}} +``` + +```kotlin,Kotlin_(Paper) +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentNBT1}} +``` + +```kotlin,Kotlin_(Spigot) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentNBT1}} ```
diff --git a/docssrc/src/arguments.md b/docssrc/src/arguments.md index 6c75201c99..e2702f8b00 100644 --- a/docssrc/src/arguments.md +++ b/docssrc/src/arguments.md @@ -95,67 +95,65 @@ To access arguments, they have to be casted to the type that the argument repres The type to cast each argument (declared in the `dev.jorel.commandapi.arguments` package) is listed below: -| Argument class | Data type | -|---------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [`AngleArgument`](./argument_angle.md) | `float` | -| [`AdvancementArgument`](./advancementargument.md) | `org.bukkit.advancement.Advancement` | -| [`AdventureChatArgument`](./argument_chat_adventure.md#adventure-chat-argument) | `net.kyori.adventure.text.Component` | -| [`AdventureChatColorArgument`](./argument_chat_adventure.md#adventure-chat-color-argument) | `net.kyori.adventure.text.format.NamedTextColor` | -| [`AdventureChatComponentArgument`](./argument_chat_adventure.md#adventure-chat-component-argument) | `net.kyori.adventure.text.Component` | -| [`AxisArgument`](./argument_axis.md) | `java.util.EnumSet` | -| [`BiomeArgument`](./argument_biome.md) | `org.bukkit.block.Biome` | -| [`BiomeArgument.NamespacedKey`](./argument_biome.md) | `org.bukkit.NamespacedKey` | -| [`BlockPredicateArgument`](./argument_blockpredicate.md) | `java.util.function.Predicate`
 `` | -| [`BlockStateArgument`](./argument_blockstate.md) | `org.bukkit.block.data.BlockData` | -| [`BooleanArgument`](./argument_primitives.md#boolean-arguments) | `boolean` | -| [`ChatArgument`](./argument_chat_spigot.md#chat-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | -| [`ChatColorArgument`](./argument_chats.md#chat-color-argument) | `org.bukkit.ChatColor` | -| [`ChatComponentArgument`](./argument_chat_spigot.md#chat-component-argument) | `net.md_5.bungee.api.chat.BaseComponent[]` | -| [`CommandArgument`](./argument_command.md) | `dev.jorel.commandapi.wrappers.CommandResult` | -| [`CustomArgument`](./argument_custom.md) | `T` | -| [`DoubleArgument`](./argument_primitives.md#numerical-arguments) | `double` | -| [`EnchantmentArgument`](./argument_enchantment.md) | `org.bukkit.enchantments.Enchantment` | -| [`EntitySelectorArgument.ManyEntities`](./argument_entities.md#entity-selector-argument) | `Collection` | -| [`EntitySelectorArgument.ManyPlayers`](./argument_entities.md#entity-selector-argument) | `Collection` | -| [`EntitySelectorArgument.OneEntity`](./argument_entities.md#entity-selector-argument) | `org.bukkit.entity.Entity` | -| [`EntitySelectorArgument.OnePlayer`](./argument_entities.md#entity-selector-argument) | `org.bukkit.entity.Player` | -| [`EntityTypeArgument`](./argument_entities.md#entity-type-argument) | `org.bukkit.entity.EntityType` | -| [`FloatArgument`](./argument_primitives.md#numerical-arguments) | `float` | -| [`FloatRangeArgument`](./argument_range.md#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.FloatRange` | -| [`FunctionArgument`](./functionwrapper.md) | `dev.jorel.commandapi.wrappers.FunctionWrapper[]` | -| [`GreedyStringArgument`](./argument_strings.md#greedy-string-argument) | `String` | -| [`IntegerArgument`](./argument_primitives.md#numerical-arguments) | `int` | -| [`IntegerRangeArgument`](./argument_range.md#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | -| [`ItemStackArgument`](./argument_itemstack.md) | `org.bukkit.inventory.ItemStack` | -| [`ItemStackPredicateArgument`](./argument_itemstackpredicate.md) | `java.util.function.Predicate`
 `` | -| [`ListArgument`](./argument_list.md) | `java.util.Collection` | -| [`LiteralArgument`](./argument_literal.md) | N/A | -| [`Location2DArgument`](./argument_locations.md#location-2d-space) | `dev.jorel.commandapi.wrappers.Location2D` | -| [`LocationArgument`](./argument_locations.md#location-3d-space) | `org.bukkit.Location` | -| [`LongArgument`](./argument_primitives.md#numerical-arguments) | `long` | -| [`LootTableArgument`](./argument_loottable.md) | `org.bukkit.loot.LootTable` | -| [`MapArgument`](./argument_map.md) | `java.util.LinkedHashMap` | -| [`MathOperationArgument`](./argument_mathoperation.md) | `dev.jorel.commandapi.wrappers.MathOperation` | -| [`MultiLiteralArgument`](./argument_multiliteral.md) | `String` | -| [`NamespacedKeyArgument`](./argument_namespacedkey.md) | `org.bukkit.NamespacedKey` | -| [`NBTCompoundArgument`](./argument_nbt.md) | The cast type changes depending on whether you're shading the CommandAPI or using the CommandAPI as a plugin:
  • Shading:
    `T` (implemented yourself)

  • Plugin:
    `dev.jorel.commandapi.nbtapi.NBTContainer`
| -| [`ObjectiveArgument`](./argument_objectives.md#objective-argument) | `org.bukkit.scoreboard.Objective` | -| [`ObjectiveCriteriaArgument`](./argument_objectives.md#objective-criteria-argument) | `String` | -| [`OfflinePlayerArgument`](./argument_entities.md#offlineplayer-argument) | `org.bukkit.OfflinePlayer` | -| [`ParticleArgument`](./argument_particles.md) | `dev.jorel.commandapi.wrappers.ParticleData` | -| [`PlayerArgument`](./argument_entities.md#player-argument) | `org.bukkit.entity.Player` | -| [`PotionEffectArgument`](./argument_potion.md) | `org.bukkit.potion.PotionEffectType` | -| [`PotionEffectArgument.NamespacedKey`](./argument_potion.md) | `org.bukkit.NamespacedKey` | -| [`RecipeArgument`](./argument_recipe.md) | The cast type changes depending on your Minecraft version:
  • Version 1.14.4 and below:
    `org.bukkit.inventory.Recipe`

  • 1.15 and above:
    `org.bukkit.inventory.ComplexRecipe`
| -| [`RotationArgument`](./argument_rotation.md) | `dev.jorel.commandapi.wrappers.Rotation` | -| [`ScoreboardSlotArgument`](./argument_scoreboards.md#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | -| [`ScoreHolderArgument.Single`](./argument_scoreboards.md#score-holder-argument) | `String` | -| [`ScoreHolderArgument.Multiple`](./argument_scoreboards.md#score-holder-argument) | `Collection` | -| [`SoundArgument`](./argument_sound.md) | `org.bukkit.Sound` | -| [`SoundArgument.NamespacedKey`](./argument_sound.md) | `org.bukkit.NamespacedKey` | -| [`StringArgument`](./argument_strings.md#string-argument) | `String` | -| [`TeamArgument`](./argument_team.md) | `org.bukkit.scoreboard.Team` | -| [`TextArgument`](./argument_strings.md#text-argument) | `String` | -| [`TimeArgument`](./argument_time.md) | `int` | -| [`UUIDArgument`](./argument_uuid.md) | `java.util.UUID` | -| [`WorldArgument`](./argument_world.md) | `org.bukkit.World` | +| Argument class | Data type | +|---------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`AngleArgument`](./argument_angle.md) | `float` | +| [`AdvancementArgument`](./advancementargument.md) | `org.bukkit.advancement.Advancement` | +| [`AdventureChatComponentArgument`](./argument_chat_adventure.md#adventure-chat-component-argument) | `net.kyori.adventure.text.Component` | +| [`AxisArgument`](./argument_axis.md) | `java.util.EnumSet` | +| [`BiomeArgument`](./argument_biome.md) | `org.bukkit.block.Biome` | +| [`BiomeArgument.NamespacedKey`](./argument_biome.md) | `org.bukkit.NamespacedKey` | +| [`BlockPredicateArgument`](./argument_blockpredicate.md) | `java.util.function.Predicate`
 `` | +| [`BlockStateArgument`](./argument_blockstate.md) | `org.bukkit.block.data.BlockData` | +| [`BooleanArgument`](./argument_primitives.md#boolean-arguments) | `boolean` | +| [`ChatArgument`](./argument_chat_spigot.md#chat-argument) | The cast type changes depending on the version of the CommandAPI you use:
  • `commandapi-paper-XXX`:
    `net.kyori.adventure.text.Component`

  • `commandapi-spigot-XXX`:
    `net.md_5.bungee.api.chat.BaseComponent[]`
| +| [`ChatColorArgument`](./argument_chats.md#chat-color-argument) | The cast type changes depending on the version of the CommandAPI you use:
  • `commandapi-paper-XXX`:
    `net.kyori.adventure.text.format.NamedTextFormat`

  • `commandapi-spigot-XXX`:
    `org.bukkit.ChatColor`
| +| [`ChatComponentArgument`](./argument_chat_spigot.md#chat-component-argument) | The cast type changes depending on the version of the CommandAPI you use:
  • `commandapi-paper-XXX`:
    `net.kyori.adventure.text.Component`

  • `commandapi-spigot-XXX`:
    `net.md_5.bungee.api.chat.BaseComponent[]`
| +| [`CommandArgument`](./argument_command.md) | `dev.jorel.commandapi.wrappers.CommandResult` | +| [`CustomArgument`](./argument_custom.md) | `T` | +| [`DoubleArgument`](./argument_primitives.md#numerical-arguments) | `double` | +| [`EnchantmentArgument`](./argument_enchantment.md) | `org.bukkit.enchantments.Enchantment` | +| [`EntitySelectorArgument.ManyEntities`](./argument_entities.md#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.ManyPlayers`](./argument_entities.md#entity-selector-argument) | `Collection` | +| [`EntitySelectorArgument.OneEntity`](./argument_entities.md#entity-selector-argument) | `org.bukkit.entity.Entity` | +| [`EntitySelectorArgument.OnePlayer`](./argument_entities.md#entity-selector-argument) | `org.bukkit.entity.Player` | +| [`EntityTypeArgument`](./argument_entities.md#entity-type-argument) | `org.bukkit.entity.EntityType` | +| [`FloatArgument`](./argument_primitives.md#numerical-arguments) | `float` | +| [`FloatRangeArgument`](./argument_range.md#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.FloatRange` | +| [`FunctionArgument`](./functionwrapper.md) | `dev.jorel.commandapi.wrappers.FunctionWrapper[]` | +| [`GreedyStringArgument`](./argument_strings.md#greedy-string-argument) | `String` | +| [`IntegerArgument`](./argument_primitives.md#numerical-arguments) | `int` | +| [`IntegerRangeArgument`](./argument_range.md#the-integerrange--floatrange-class) | `dev.jorel.commandapi.wrappers.IntegerRange` | +| [`ItemStackArgument`](./argument_itemstack.md) | `org.bukkit.inventory.ItemStack` | +| [`ItemStackPredicateArgument`](./argument_itemstackpredicate.md) | `java.util.function.Predicate`
 `` | +| [`ListArgument`](./argument_list.md) | `java.util.Collection` | +| [`LiteralArgument`](./argument_literal.md) | N/A | +| [`Location2DArgument`](./argument_locations.md#location-2d-space) | `dev.jorel.commandapi.wrappers.Location2D` | +| [`LocationArgument`](./argument_locations.md#location-3d-space) | `org.bukkit.Location` | +| [`LongArgument`](./argument_primitives.md#numerical-arguments) | `long` | +| [`LootTableArgument`](./argument_loottable.md) | `org.bukkit.loot.LootTable` | +| [`MapArgument`](./argument_map.md) | `java.util.LinkedHashMap` | +| [`MathOperationArgument`](./argument_mathoperation.md) | `dev.jorel.commandapi.wrappers.MathOperation` | +| [`MultiLiteralArgument`](./argument_multiliteral.md) | `String` | +| [`NamespacedKeyArgument`](./argument_namespacedkey.md) | `org.bukkit.NamespacedKey` | +| [`NBTCompoundArgument`](./argument_nbt.md) | The cast type changes depending on whether you're shading the CommandAPI or using the CommandAPI as a plugin:
  • Shading:
    `T` (implemented yourself)

  • Plugin:
    `dev.jorel.commandapi.nbtapi.NBTContainer`
| +| [`ObjectiveArgument`](./argument_objectives.md#objective-argument) | `org.bukkit.scoreboard.Objective` | +| [`ObjectiveCriteriaArgument`](./argument_objectives.md#objective-criteria-argument) | `String` | +| [`OfflinePlayerArgument`](./argument_entities.md#offlineplayer-argument) | `org.bukkit.OfflinePlayer` | +| [`ParticleArgument`](./argument_particles.md) | `dev.jorel.commandapi.wrappers.ParticleData` | +| [`PlayerArgument`](./argument_entities.md#player-argument) | `org.bukkit.entity.Player` | +| [`PotionEffectArgument`](./argument_potion.md) | `org.bukkit.potion.PotionEffectType` | +| [`PotionEffectArgument.NamespacedKey`](./argument_potion.md) | `org.bukkit.NamespacedKey` | +| [`RecipeArgument`](./argument_recipe.md) | The cast type changes depending on your Minecraft version:
  • Version 1.14.4 and below:
    `org.bukkit.inventory.Recipe`

  • 1.15 and above:
    `org.bukkit.inventory.ComplexRecipe`
| +| [`RotationArgument`](./argument_rotation.md) | `dev.jorel.commandapi.wrappers.Rotation` | +| [`ScoreboardSlotArgument`](./argument_scoreboards.md#scoreboard-slot-argument) | `dev.jorel.commandapi.wrappers.ScoreboardSlot` | +| [`ScoreHolderArgument.Single`](./argument_scoreboards.md#score-holder-argument) | `String` | +| [`ScoreHolderArgument.Multiple`](./argument_scoreboards.md#score-holder-argument) | `Collection` | +| [`SoundArgument`](./argument_sound.md) | `org.bukkit.Sound` | +| [`SoundArgument.NamespacedKey`](./argument_sound.md) | `org.bukkit.NamespacedKey` | +| [`StringArgument`](./argument_strings.md#string-argument) | `String` | +| [`TeamArgument`](./argument_team.md) | `org.bukkit.scoreboard.Team` | +| [`TextArgument`](./argument_strings.md#text-argument) | `String` | +| [`TimeArgument`](./argument_time.md) | `int` | +| [`UUIDArgument`](./argument_uuid.md) | `java.util.UUID` | +| [`WorldArgument`](./argument_world.md) | `org.bukkit.World` | diff --git a/docssrc/src/chatpreview.md b/docssrc/src/chatpreview.md index 87037d1caa..96cebf60ec 100644 --- a/docssrc/src/chatpreview.md +++ b/docssrc/src/chatpreview.md @@ -111,26 +111,26 @@ Say we wanted to make our own `/broadcast` command that allowed the user to use /broadcast ``` -Because the `ChatArgument` and `AdventureChatArgument` can support entity selectors (such as `@p`), it's best to use the `info.parsedInput()` method to handle parsed entity selectors. In our code, we use the `.withPreview()` method and take the parsed input and convert it to plain text. We then convert the plain text with `&` characters into component text to be displayed to the user. +Because the `ChatArgument` can support entity selectors (such as `@p`), it's best to use the `info.parsedInput()` method to handle parsed entity selectors. In our code, we use the `.withPreview()` method and take the parsed input and convert it to plain text. We then convert the plain text with `&` characters into component text to be displayed to the user. For execution, we do the same procedure, because the text that the user enters still has `&` characters that need to be converted into a component.
-```java,Spigot_(Java) -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview1}} -``` - ```java,Paper_(Java) -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview2}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview1}} ``` -```kotlin,Spigot_(Kotlin) -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview1}} +```java,Spigot_(Java) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview1}} ``` ```kotlin,Paper_(Kotlin) -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview2}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview1}} +``` + +```kotlin,Spigot_(Kotlin) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview1}} ```
@@ -151,20 +151,20 @@ By using `.usePreview(true)`, we don't have to re-translate `&` formatting codes
-```java,Spigot_(Java) -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview3}} -``` - ```java,Paper_(Java) -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview4}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview2}} ``` -```kotlin,Spigot_(Kotlin) -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview3}} +```java,Spigot_(Java) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:chatPreview2}} ``` ```kotlin,Paper_(Kotlin) -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview4}} +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview2}} +``` + +```kotlin,Spigot_(Kotlin) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:chatPreview2}} ```
diff --git a/docssrc/src/config.md b/docssrc/src/config.md index d48cb6106b..3e8075a17c 100644 --- a/docssrc/src/config.md +++ b/docssrc/src/config.md @@ -9,7 +9,9 @@ The default `config.yml` is shown below:
config.yml -```yaml +
+ +```yaml,Paper # Verbose outputs (default: false) # If "true", outputs command registration and unregistration logs in the console verbose-outputs: false @@ -79,6 +81,69 @@ other-commands-to-convert: [] skip-sender-proxy: [] ``` +````yaml,Spigot +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: This command has no implementations for %s + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for potentially unsupported Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] +```` + +
+
## Configuration settings diff --git a/docssrc/src/kotlinintro.md b/docssrc/src/kotlinintro.md index dacac19c43..24bc1e252f 100644 --- a/docssrc/src/kotlinintro.md +++ b/docssrc/src/kotlinintro.md @@ -8,20 +8,34 @@ This DSL provides many methods to easily add arguments to your command structure ## Installing the DSL -To install the DSL, you need to add the `commandapi-bukkit-kotlin` dependency into your `pom.xml` or your `build.gradle`, making sure to specify the server flavor you are developing for: +To install the DSL, you need to add the Kotlin DSL dependency into your `pom.xml` or your `build.gradle`, making sure to specify the server flavor you are developing for: ### Adding the dependency with Maven -```xml +
+ +```xml,Paper dev.jorel - commandapi-bukkit-kotlin + commandapi-kotlin-paper 9.7.1-SNAPSHOT ``` +```xml,Spigot + + + dev.jorel + commandapi-kotlin-spigot + 9.6.0-SNAPSHOT + + +``` + +
+ Next, you need to add Kotlin to your project. For this, you first need to add the dependency: ```xml @@ -91,15 +105,27 @@ Next, you need to add the dependency:
-```groovy,build.gradle +```groovy,build.gradle_(Paper) dependencies { - implementation "dev.jorel:commandapi-bukkit-kotlin:9.7.1-SNAPSHOT" + implementation "dev.jorel:commandapi-kotlin-paper:9.7.1-SNAPSHOT" } ``` -```kotlin,build.gradle.kts +```kotlin,build.gradle.kts_(Paper) +dependencies { + implementation("dev.jorel:commandapi-kotlin-paper:9.7.1-SNAPSHOT") +} +``` + +```groovy,build.gradle_(Spigot) +dependencies { + implementation "dev.jorel:commandapi-kotlin-spigot:9.7.1-SNAPSHOT" +} +``` + +```kotlin,build.gradle.kts_(Spigot) dependencies { - implementation("dev.jorel:commandapi-bukkit-kotlin:9.7.1-SNAPSHOT") + implementation("dev.jorel:commandapi-kotlin-spigot:9.7.1-SNAPSHOT") } ``` diff --git a/docssrc/src/setup_dev.md b/docssrc/src/setup_dev.md index 5c60349387..552e0bbf35 100644 --- a/docssrc/src/setup_dev.md +++ b/docssrc/src/setup_dev.md @@ -35,17 +35,32 @@ dependencies: - Add the dependency to your `pom.xml`: - ```xml +
+ + ```xml,Paper dev.jorel - commandapi-bukkit-core + commandapi-paper-core 9.7.1-SNAPSHOT provided ``` + ```xml,Spigot + + + dev.jorel + commandapi-spigot-core + 9.6.0-SNAPSHOT + provided + + + ``` + +
+ ## Using Gradle (recommended) - Add the repositories to your `build.gradle` file (the second repository is required because the CommandAPI depends on the NBT-API): @@ -59,12 +74,22 @@ dependencies: - Add the dependency to your list of dependencies in your `build.gradle` file: - ```gradle +
+ + ```gradle,Paper + dependencies { + compileOnly "dev.jorel:commandapi-paper-core:9.7.1-SNAPSHOT" + } + ``` + + ```gradle,Spigot dependencies { - compileOnly "dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT" + compileOnly "dev.jorel:commandapi-spigot-core:9.6.2-SNAPSHOT" } ``` +
+ ## Manually using the .jar - Download the latest CommandAPI.jar from the download page [here](https://github.com/JorelAli/CommandAPI/releases/latest) diff --git a/docssrc/src/setup_shading.md b/docssrc/src/setup_shading.md index ba55a42b72..718acf3311 100644 --- a/docssrc/src/setup_shading.md +++ b/docssrc/src/setup_shading.md @@ -44,31 +44,54 @@ public class CommandAPIConfig { The `CommandAPIConfig` class follows a typical builder pattern (without you having to run `.build()` at the end), which lets you easily construct configuration instances. -However, the `CommandAPIConfig` class is abstract and cannot be used to configure the CommandAPI directly. Instead, you must use a subclass of `CommandAPIConfig` that corresponds to the platform you are developing for. For example, when developing for Bukkit, you should use the `CommandAPIBukkitConfig` class. +However, the `CommandAPIConfig` class is abstract and cannot be used to configure the CommandAPI directly. Instead, you must use a subclass of `CommandAPIConfig` that corresponds to the platform you are developing for. For example, when developing for a Bukkit-based server, you should use the `CommandAPIPaperConfig` or the `CommandAPISpigotConfig` class. -```java -public class CommandAPIBukkitConfig extends CommandAPIConfig { - CommandAPIBukkitConfig(JavaPlugin plugin); +
+ +```java,Bukkit +public abstract class CommandAPIBukkitConfig extends CommandAPIConfig { + CommandAPIBukkitConfig skipReloadDatapacks(boolean skip); // Whether the CommandAPI should skip its initial datapack reload step +} +``` - CommandAPIBukkitConfig shouldHookPaperReload(boolean hooked); // Whether the CommandAPI should hook into the Paper-exclusive ServerResourcesReloadedEvent - CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) // Whether the CommandAPI should reload datapacks on server load +```java,Paper +public class CommandAPIPaperConfig extends CommandAPIBukkitConfig { + CommandAPIPaperConfig(JavaPlugin plugin); + + CommandAPIPaperConfig shouldHookPaperReload(boolean hooked); // Whether the CommandAPI should hook into the Paper-exclusive ServerResourcesReloadedEvent } ``` -In order to create a `CommandAPIBukkitConfig` object, you must give it a reference to your `JavaPlugin` instance. The CommandAPI always uses this to registers events, so it is required when loading the CommandAPI on Bukkit. There are also Bukkit-specific features, such as the `hook-paper-reload` configuration option, which may be configured using a `CommandAPIBukkitConfig` instance. +```java,Spigot +public class CommandAPISpigotConfig extends CommandAPIBukkitConfig { + CommandAPISpigotConfig(JavaPlugin plugin); +} +``` -For example, to load the CommandAPI on Bukkit with all logging disabled, you can use the following: +
+ +In order to create a `CommandAPIPaperConfig` or a `CommandAPISpigotConfig` object, you must give it a reference to your `JavaPlugin` instance. The CommandAPI always uses this to registers events, so it is required when loading the CommandAPI on Bukkit. There are also platform-specific features, such as the `hook-paper-reload` configuration option on Paper, which may be configured using a `CommandAPIPaperConfig` instance. + +For example, to load the CommandAPI on a Bukkit-based server with all logging disabled, you can use the following:
-```java,Java -{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading1}} +```java,Java_(Paper) +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading1}} +``` + +```java,Java_(Spigot) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading1}} ``` -```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading1}} +```kotlin,Kotlin_(Paper) +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading1}} +``` + +```kotlin,Kotlin_(Spigot) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading1}} ```
@@ -85,12 +108,20 @@ The `onDisable()` method disables the CommandAPI gracefully. This should be plac
-```java,Java -public {{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading2}} +```java,Java_(Paper) +public {{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading2}} ``` -```kotlin,Kotlin -{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading2}} +```java,Java_(Spigot) +public {{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:setupShading2}} +``` + +```kotlin,Kotlin_(Paper) +{{#include ../../commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading2}} +``` + +```kotlin,Kotlin_(Spigot) +{{#include ../../commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:setupShading2}} ```
@@ -111,27 +142,48 @@ By default, the CommandAPI is written in the `dev.jorel.commandapi` package. It ## Shading with Maven -To shade the CommandAPI into a maven project, you'll need to use the `commandapi-bukkit-shade` dependency, which is optimized for shading and doesn't include plugin-specific files _(such as `plugin.yml`)_. Here you have a choice between the Spigot-mapped version and the Mojang-mapped version. **You do not need to use `commandapi-bukkit-core` if you are shading**: +When shading the CommandAPI, you have the option to choose between our version for Paper and our version for Spigot. The respective artifacts are the `commandapi-paper-shade` and the `commandapi-spigot-shade` modules. These are optimized for shading and don't include plugin specific files _(such as `plugin.yml`)_. +You also can choose between a Mojang-mapped and a Spigot-mapped version: Add the CommandAPI shade dependency:
-```xml,Spigot_Mappings +```xml,Paper_(Spigot_Mappings) + + + dev.jorel + commandapi-paper-shade + 9.7.1-SNAPSHOT + + +``` + +```xml,Paper_(Mojang_Mappings) dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade-mojang-mapped 9.7.1-SNAPSHOT ``` -```xml,Mojang_Mappings +```xml,Spigot_(Spigot_Mappings) dev.jorel - commandapi-bukkit-shade-mojang-mapped + commandapi-spigot-shade + 9.7.1-SNAPSHOT + + +``` + +```xml,Spigot_(Mojang_Mappings) + + + dev.jorel + commandapi-spigot-shade-mojang-mapped 9.7.1-SNAPSHOT @@ -226,13 +278,13 @@ Next, we declare our dependencies:
-```groovy,build.gradle_(Spigot_Mappings) +```groovy,build.gradle_(Spigot_Mappings_(Paper)) dependencies { - implementation "dev.jorel:commandapi-bukkit-shade:9.7.1-SNAPSHOT" + implementation "dev.jorel:commandapi-paper-shade:9.7.1-SNAPSHOT" } ``` -```groovy,build.gradle_(Mojang_Mappings) +```groovy,build.gradle_(Spigot_Mappings_(Spigot)) dependencies { implementation "dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.1-SNAPSHOT" } @@ -245,11 +297,47 @@ dependencies { ``` ```kotlin,build.gradle.kts_(Mojang_Mappings) +======= + implementation "dev.jorel:commandapi-spigot-shade:9.7.1-SNAPSHOT" +} +``` + +```groovy,build.gradle_(Mojang_Mappings_(Paper)) dependencies { implementation("dev.jorel:commandapi-bukkit-shade-mojang-mapped:9.7.1-SNAPSHOT") } ``` +```groovy,build.gradle_(Mojang_Mappings_(Spigot)) +dependencies { + implementation("dev.jorel:commandapi-spigot-shade-mojang-mapped:9.7.1-SNAPSHOT") +} +``` + +```kotlin,build.gradle.kts_(Spigot_Mappings_(Paper)) +dependencies { + implementation("dev.jorel:commandapi-paper-shade:9.7.1-SNAPSHOT") +} +``` + +```kotlin,build.gradle.kts_(Spigot_Mappings_(Spigot)) +dependencies { + implementation("dev.jorel:commandapi-spigot-shade:9.7.1-SNAPSHOT") +} +``` + +```kotlin,build.gradle.kts_(Mojang_Mappings_(Paper)) +dependencies { + implementation("dev.jorel:commandapi-paper-shade-mojang-mapped:9.7.1-SNAPSHOT") +} +``` + +```kotlin,build.gradle.kts_(Mojang_Mappings_(Spigot)) +dependencies { + implementation("dev.jorel:commandapi-spigot-shade-mojang-mapped:9.7.1-SNAPSHOT") +} +``` +
Then you just need to relocate the CommandAPI to your desired location in the `shadowJar` task configuration: diff --git a/docssrc/src/upgrading.md b/docssrc/src/upgrading.md index b7ef465e24..076e01ec4c 100644 --- a/docssrc/src/upgrading.md +++ b/docssrc/src/upgrading.md @@ -1,5 +1,39 @@ # Upgrading guide +## From 9.?.? to 10.0.0 + +### CommandAPI restructure + +#### General module changes + +For 10.0.0 the `commandapi-bukkit-xxx` modules have mostly been removed in favour of new platform specific modules that have been made for Paper or Spigot respectively: + +- `commandapi-paper-xxx` +- `commandapi-spigot-xxx` + +In order to update please replace your `commandapi-bukkit-xxx` dependency with either `commandapi-paper-xxx` or `commandapi-spigot-xxx`. + +
+ +**Developer's Note:** + +The fact that Paper is a fork of Spigot does not mean that the Spigot modules work on Paper. Paper has, especially in newer versions, made changes to internal systems the CommandAPI +uses. There are no guarantees that the Spigot modules will work on Paper in any kind or form. + +On the other hand, if you try to use the Paper modules on Spigot you will face registration issues and potential `NoClassDefFoundError`s, depending on the server version you use. +There again is no guarantee for any kind of compatibility. + +
+ +#### Code changes + +The `CommandAPIBukkitConfig` class has been converted into an abstract class and is no longer used to construct a config instance. Instead, use the new `CommandAPIPaperConfig` or +`CommandAPISpigotConfig` classes, depending on the module you use. + +Further changes have been made to arguments that work with components. The classes `AdventureChatArgument`, `AdventureChatComponentArgument` and `AdventureChatColorArgument` have been +removed. Instead, the `ChatArgument`, `ChatComponentArgument` and `ChatColorArgument` have been implemented platform specific and return different types on Paper and Spigot. +On Paper, Adventure components are used while Spigot uses BungeeCord components. + ## From 9.2.0 to 9.3.0 The `BukkitTooltip.generateAdvenureComponents` methods have now been deprecated in favour of the correctly named `BukkitTooltip.generateAdventureComponents` methods: diff --git a/examples/bukkit/commandtrees/pom.xml b/examples/bukkit/commandtrees/pom.xml index 8dcaf1b334..41b9a7b6f7 100644 --- a/examples/bukkit/commandtrees/pom.xml +++ b/examples/bukkit/commandtrees/pom.xml @@ -9,24 +9,24 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ dev.jorel - commandapi-bukkit-core + commandapi-paper-core 9.7.1-SNAPSHOT - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/gradle-groovy/build.gradle b/examples/bukkit/gradle-groovy/build.gradle index 74dd284279..cc6f0613e5 100644 --- a/examples/bukkit/gradle-groovy/build.gradle +++ b/examples/bukkit/gradle-groovy/build.gradle @@ -16,7 +16,7 @@ repositories { mavenCentral() // This adds the Spigot Maven repository to the build maven { - url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' + url 'https://papermc.io/repo/repository/maven-public/' } // CodeMC repository for the NBT API maven { @@ -26,11 +26,11 @@ repositories { dependencies { // This adds the Spigot API artifact to the build - implementation 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT' + implementation 'io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT' // The CommandAPI dependency used for Bukkit and it's forks - implementation 'dev.jorel:commandapi-bukkit-plugin:9.7.1-SNAPSHOT' - + implementation 'dev.jorel:commandapi-paper-plugin:9.7.1-SNAPSHOT' + // NBT API to use NBT-based arguments implementation 'de.tr7zw:item-nbt-api-plugin:2.12.2' } \ No newline at end of file diff --git a/examples/bukkit/gradle-kotlin/build.gradle.kts b/examples/bukkit/gradle-kotlin/build.gradle.kts index 3a06a37228..ca7bc4f143 100644 --- a/examples/bukkit/gradle-kotlin/build.gradle.kts +++ b/examples/bukkit/gradle-kotlin/build.gradle.kts @@ -14,18 +14,18 @@ version = "0.0.1-SNAPSHOT" repositories { // Use Maven Central for resolving dependencies. mavenCentral() - // This adds the Spigot Maven repository to the build - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + // This adds the Paper Maven repository to the build + maven("https://papermc.io/repo/repository/maven-public/") // CodeMC repository for the NBT API maven("https://repo.codemc.org/repository/maven-public/") } dependencies { // This adds the Spigot API artifact to the build - implementation("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT") + implementation("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-plugin:9.7.1-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-plugin:9.7.1-SNAPSHOT") // NBT API to use NBT-based arguments implementation("de.tr7zw:item-nbt-api-plugin:2.12.2") diff --git a/examples/bukkit/kotlindsl-gradle/build.gradle.kts b/examples/bukkit/kotlindsl-gradle/build.gradle.kts index df27487b30..263c0e57d0 100644 --- a/examples/bukkit/kotlindsl-gradle/build.gradle.kts +++ b/examples/bukkit/kotlindsl-gradle/build.gradle.kts @@ -11,18 +11,18 @@ version = "0.0.1-SNAPSHOT" repositories { // Use Maven Central for resolving dependencies. mavenCentral() - // This adds the Spigot Maven repository to the build - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + // This adds the Paper Maven repository to the build + maven("https://papermc.io/repo/repository/maven-public/") } dependencies { implementation(kotlin("stdlib-jdk8")) // This adds the Spigot API artifact to the build - implementation("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT") + implementation("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-core:9.7.1-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-core:9.7.1-SNAPSHOT") // Due to all functions available in the kotlindsl being inlined, we only need this dependency at compile-time - compileOnly("dev.jorel:commandapi-bukkit-kotlin:9.7.1-SNAPSHOT") + compileOnly("dev.jorel:commandapi-kotlin-paper:9.7.1-SNAPSHOT") } \ No newline at end of file diff --git a/examples/bukkit/kotlindsl/pom.xml b/examples/bukkit/kotlindsl/pom.xml index f71393280f..a88445f7e1 100644 --- a/examples/bukkit/kotlindsl/pom.xml +++ b/examples/bukkit/kotlindsl/pom.xml @@ -10,30 +10,30 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ dev.jorel - commandapi-bukkit-core + commandapi-paper-core 9.7.1-SNAPSHOT provided dev.jorel - commandapi-bukkit-kotlin + commandapi-kotlin-paper 9.7.1-SNAPSHOT - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-annotations/pom.xml b/examples/bukkit/maven-annotations/pom.xml index 544c3d255f..aff127a143 100644 --- a/examples/bukkit/maven-annotations/pom.xml +++ b/examples/bukkit/maven-annotations/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,7 +27,7 @@ dev.jorel - commandapi-bukkit-plugin + commandapi-paper-plugin 9.7.1-SNAPSHOT provided @@ -35,15 +35,15 @@ dev.jorel - commandapi-annotations + commandapi-paper-annotations 9.7.1-SNAPSHOT provided - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded-annotations/pom.xml b/examples/bukkit/maven-shaded-annotations/pom.xml index 5b2dc97b39..92a83d47f3 100644 --- a/examples/bukkit/maven-shaded-annotations/pom.xml +++ b/examples/bukkit/maven-shaded-annotations/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,7 +27,7 @@ dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 9.7.1-SNAPSHOT @@ -41,8 +41,8 @@ - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java index e9271c9b84..cf145a0bdb 100644 --- a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java @@ -1,7 +1,7 @@ package io.github.jorelali; import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPIConfig; import dev.jorel.commandapi.CommandAPILogger; import org.bukkit.plugin.java.JavaPlugin; @@ -17,7 +17,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven-shaded-tests/pom.xml b/examples/bukkit/maven-shaded-tests/pom.xml index 472e625618..9725e51f2d 100644 --- a/examples/bukkit/maven-shaded-tests/pom.xml +++ b/examples/bukkit/maven-shaded-tests/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -45,14 +45,14 @@ dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 9.7.1-SNAPSHOT - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.2-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java index f151eac1c1..1f48b9652b 100644 --- a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java +++ b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java @@ -8,7 +8,7 @@ import de.tr7zw.changeme.nbtapi.NBTContainer; import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPILogger; public class MyMain extends JavaPlugin { @@ -20,7 +20,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven-shaded/pom.xml b/examples/bukkit/maven-shaded/pom.xml index 089112386b..698c750722 100644 --- a/examples/bukkit/maven-shaded/pom.xml +++ b/examples/bukkit/maven-shaded/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,14 +27,14 @@ dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 9.7.1-SNAPSHOT - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java index ed3ec4bca1..fdf3a39d92 100644 --- a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java @@ -3,7 +3,7 @@ import java.io.File; import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPILogger; import org.bukkit.plugin.java.JavaPlugin; @@ -19,7 +19,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven/pom.xml b/examples/bukkit/maven/pom.xml index 930e44ccb9..f52acbf4b7 100644 --- a/examples/bukkit/maven/pom.xml +++ b/examples/bukkit/maven/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,15 +27,15 @@ dev.jorel - commandapi-bukkit-plugin + commandapi-paper-plugin 9.7.1-SNAPSHOT provided - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.19.4-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 44aaf777ad..88e3d022bb 100644 --- a/pom.xml +++ b/pom.xml @@ -71,9 +71,12 @@ commandapi-annotations + + commandapi-codecov - + UTF-8 diff --git a/setupPaperNMS.sh b/setupPaperNMS.sh new file mode 100755 index 0000000000..da231d9a0d --- /dev/null +++ b/setupPaperNMS.sh @@ -0,0 +1,13 @@ +echo "Setup Paper NMS for version 1.20.5..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.20.5 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.2..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.2 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.4..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.4 -P Platform.Paper + +echo "Done!" \ No newline at end of file diff --git a/update.sh b/update.sh index 9b3d6145e8..8318f8a375 100755 --- a/update.sh +++ b/update.sh @@ -16,12 +16,15 @@ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" docssrc/src/ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" docssrc/src/test_setup.md # Gradle -sed -i "s/dev\.jorel:commandapi-bukkit-shade:$oldVer/dev\.jorel:commandapi-bukkit-shade:$newVer/" docssrc/src/setup_shading.md -sed -i "s/dev\.jorel:commandapi-bukkit-shade-mojang-mapped:$oldVer/dev\.jorel:commandapi-bukkit-shade-mojang-mapped:$newVer/" docssrc/src/setup_shading.md -sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" docssrc/src/setup_dev.md +sed -i "s/dev\.jorel:commandapi-paper-shade:$oldVer/dev\.jorel:commandapi-paper-shade:$newVer/" docssrc/src/setup_shading.md +sed -i "s/dev\.jorel:commandapi-spigot-shade:$oldVer/dev\.jorel:commandapi-spigot-shade:$newVer/" docssrc/src/setup_shading.md +sed -i "s/dev\.jorel:commandapi-paper-shade-mojang-mapped:$oldVer/dev\.jorel:commandapi-paper-shade-mojang-mapped:$newVer/" docssrc/src/setup_shading.md +sed -i "s/dev\.jorel:commandapi-spigot-shade-mojang-mapped:$oldVer/dev\.jorel:commandapi-spigot-shade-mojang-mapped:$newVer/" docssrc/src/setup_shading.md +sed -i "s/dev\.jorel:commandapi-paper-core:$oldVer/dev\.jorel:commandapi-paper-core:$newVer/" docssrc/src/setup_dev.md +sed -i "s/dev\.jorel:commandapi-spigot-core:$oldVer/dev\.jorel:commandapi-spigot-core:$newVer/" docssrc/src/setup_dev.md sed -i "s/dev\.jorel:commandapi-annotations:$oldVer/dev\.jorel:commandapi-annotations:$newVer/" docssrc/src/setup_annotations.md -sed -i "s/dev\.jorel:commandapi-bukkit-kotlin:$oldVer/dev\.jorel:commandapi-bukkit-kotlin:$newVer/" docssrc/src/kotlinintro.md -sed -i "s/dev\.jorel:commandapi-velocity-kotlin:$oldVer/dev\.jorel:commandapi-velocity-kotlin:$newVer/" docssrc/src/kotlinintro.md +sed -i "s/dev\.jorel:commandapi-kotlin-bukkit:$oldVer/dev\.jorel:commandapi-kotlin-bukkit:$newVer/" docssrc/src/kotlinintro.md +sed -i "s/dev\.jorel:commandapi-kotlin-velocity:$oldVer/dev\.jorel:commandapi-kotlin-velocity:$newVer/" docssrc/src/kotlinintro.md sed -i "s/dev\.jorel:commandapi-bukkit-test-toolkit:$oldVer/dev\.jorel:commandapi-bukkit-test-toolkit:$newVer/" docssrc/src/test_setup.md sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" docssrc/src/test_setup.md @@ -84,20 +87,21 @@ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/vel # Gradle example projects # ########################### -########## -# Bukkit # -########## +######### +# Paper # +######### -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-groovy/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-groovy/build.gradle +# We're using Paper as the example dependency for example projects +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-groovy/README.md +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-groovy/build.gradle -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-kotlin/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-kotlin/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-kotlin/README.md +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-kotlin/build.gradle.kts -sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" examples/bukkit/kotlindsl-gradle/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts -sed -i "s/dev\.jorel:commandapi-bukkit-kotlin:$oldVer/dev\.jorel:commandapi-bukkit-kotlin:$newVer/" examples/bukkit/kotlindsl-gradle/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-kotlin:$oldVer/dev\.jorel:commandapi-bukkit-kotlin:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-paper-core:$oldVer/dev\.jorel:commandapi-paper-core:$newVer/" examples/bukkit/kotlindsl-gradle/README.md +sed -i "s/dev\.jorel:commandapi-paper-core:$oldVer/dev\.jorel:commandapi-paper-core:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-kotlin-paper:$oldVer/dev\.jorel:commandapi-kotlin-paper:$newVer/" examples/bukkit/kotlindsl-gradle/README.md +sed -i "s/dev\.jorel:commandapi-kotlin-paper:$oldVer/dev\.jorel:commandapi-kotlin-paper:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts ############ # Velocity #