From b8436bd1e512909879b11214575be1894e319c60 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:43:33 +0200 Subject: [PATCH 01/13] Clean up NMS_Common to make it compile for all supported versions --- .github/workflows/build.yml | 11 +- .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 50 ++- .../nms/NMS_CommonWithFunctions_1_20_R2.java} | 32 +- .../dev/jorel/commandapi/nms/NMS_1_20_R3.java | 38 ++ .../dev/jorel/commandapi/nms/NMS_1_20_R4.java | 15 + .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 50 ++- .../nms/NMS_CommonWithFunctions_1_20_R1.java | 84 ++++ .../dev/jorel/commandapi/nms/NMS_1_21_R2.java | 5 + .../dev/jorel/commandapi/nms/NMS_1_21_R3.java | 5 + .../dev/jorel/commandapi/nms/NMS_1_21_R1.java | 15 + .../commandapi-bukkit-nms-common/pom.xml | 64 ++- .../dev/jorel/commandapi/nms/NMS_Common.java | 366 ++---------------- compileNMSCommon.sh | 23 ++ 13 files changed, 399 insertions(+), 359 deletions(-) rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/{commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions.java => commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java} (86%) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java create mode 100644 compileNMSCommon.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ad5a875b9..a1af6e568f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,15 +42,8 @@ jobs: - name: Check NMS_Common compiles against all compatible Minecraft versions run: | - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_17_R1 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_R1 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_2_R2 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_R1 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_3_R2 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_20_R1 - mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_20_2_R2; - # Not Spigot_1_20_4_R3. This isn't compatible with NMS_CommonWithFunctions - # mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_20_4_R3; + chmod +x ./compileNMSCommon.sh + ./compileNMSCommon.sh # - name: validate version-specific dependencies (nms-common) # run: | 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 0b5737ff94..b8404bac15 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 @@ -39,6 +39,8 @@ import dev.jorel.commandapi.*; import dev.jorel.commandapi.wrappers.*; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.arguments.*; import org.bukkit.Bukkit; @@ -169,7 +171,7 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) -public class NMS_1_20_R2 extends NMS_CommonWithFunctions { +public class NMS_1_20_R2 extends NMS_CommonWithFunctions_1_20_R2 { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; @@ -200,6 +202,11 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentBlockPredicate() { return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); @@ -210,6 +217,11 @@ public final ArgumentType _ArgumentBlockState() { return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentChatComponent() { + return ComponentArgument.textComponent(); + } + @Override public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); @@ -241,6 +253,11 @@ public final ArgumentType _ArgumentParticle() { return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentSyntheticBiome() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); @@ -294,6 +311,11 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str 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))); + } + @Override public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); @@ -340,6 +362,16 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return VanillaCommandWrapper.getListener(sender.getSource()); } + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { return DimensionArgument.getDimension(cmdCtx, key).getWorld(); @@ -502,6 +534,11 @@ public final org.bukkit.loot.LootTable getLootTable(CommandContextgetMinecraftServer().getLootData().getLootTable(resourceLocation)); } + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); + } + @Differs(from = "1.20.1", by = "Uses CraftParticle#minecraftToBukkit instead of CraftParticle#toBukkit") @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { @@ -591,6 +628,17 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); } + @Override + public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + return ScoreHolderArgument.getNames(cmdCtx, key); + } + + @Override + public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ScoreHolderArgument.getName(cmdCtx, key); + } + @Override public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { CommandSourceStack css = cmdCtx.getSource(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java similarity index 86% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java index ee9f375b07..dc1e59ebf2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java @@ -20,18 +20,8 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.*; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import java.util.function.ToIntFunction; - -import org.bukkit.NamespacedKey; - import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; - import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.Unimplemented; import dev.jorel.commandapi.wrappers.FunctionWrapper; @@ -40,6 +30,15 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; +import org.bukkit.NamespacedKey; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.function.ToIntFunction; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; /** * Common NMS code To ensure that this code actually works across all versions @@ -56,7 +55,7 @@ * Any of these that do not work should be removed or implemented otherwise * (introducing another NMS_Common module perhaps? */ -public abstract class NMS_CommonWithFunctions extends NMS_Common { +public abstract class NMS_CommonWithFunctions_1_20_R2 extends NMS_Common { private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); @@ -74,13 +73,8 @@ private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { } return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); } - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftEntity") - public abstract FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException; @Override - // TODO: This has its own implementation for 1.17, 1.18 and 1.18.2 public SimpleFunctionWrapper getFunction(NamespacedKey key) { final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); @@ -94,7 +88,6 @@ public SimpleFunctionWrapper getFunction(NamespacedKey key) { } @Override - // TODO: This has its own implementation for 1.17, 1.18 and 1.18.2 public Set getFunctions() { Set result = new HashSet<>(); for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { @@ -103,9 +96,4 @@ public Set getFunctions() { return result; } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, from = "1.18.2", to = "1.19") - @Differs(from = "1.18.2", by = "getTag() now returns a Collection<> instead of a Tag<>, so don't have to call .getValues()") - public abstract SimpleFunctionWrapper[] getTag(NamespacedKey key); - } 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 d7222fb040..378161b76a 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 @@ -40,6 +40,9 @@ import java.util.function.ToIntFunction; import dev.jorel.commandapi.*; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.arguments.MessageArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -226,6 +229,11 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentBlockPredicate() { return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); @@ -236,6 +244,11 @@ public final ArgumentType _ArgumentBlockState() { return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentChatComponent() { + return ComponentArgument.textComponent(); + } + @Override public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); @@ -262,6 +275,11 @@ public final ArgumentType _ArgumentItemStack() { return ItemArgument.item(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentParticle() { return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); @@ -365,6 +383,11 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str 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))); + } + @Override public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); @@ -416,6 +439,16 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -620,6 +653,11 @@ public final org.bukkit.loot.LootTable getLootTable(CommandContextgetMinecraftServer().getLootData().getLootTable(resourceLocation)); } + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); + } + @Differs(from = "1.20.1", by = "Uses CraftParticle#minecraftToBukkit instead of CraftParticle#toBukkit") @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { 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 c666e479d0..935be738ab 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 @@ -244,6 +244,11 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentBlockPredicate() { return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); @@ -291,6 +296,11 @@ public final ArgumentType _ArgumentParticle() { return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentSyntheticBiome() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); @@ -471,6 +481,11 @@ public final BaseComponent[] getChat(CommandContext cmdCtx, return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); } + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { 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 1c7e4465ff..cae2ae10d7 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 @@ -44,6 +44,8 @@ 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.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandFunction; @@ -146,7 +148,7 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) -public class NMS_1_20_R1 extends NMS_CommonWithFunctions { +public class NMS_1_20_R1 extends NMS_CommonWithFunctions_1_20_R1 { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; @@ -177,6 +179,11 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentBlockPredicate() { return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); @@ -187,6 +194,11 @@ public final ArgumentType _ArgumentBlockState() { return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentChatComponent() { + return ComponentArgument.textComponent(); + } + @Override public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); @@ -213,6 +225,11 @@ public final ArgumentType _ArgumentItemStack() { return ItemArgument.item(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentParticle() { return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); @@ -271,6 +288,11 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceLocationArgument.getAdvancement(cmdCtx, key).bukkit; } + @Override + public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + @Override public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); @@ -317,6 +339,16 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return VanillaCommandWrapper.getListener(sender.getSource()); } + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { return DimensionArgument.getDimension(cmdCtx, key).getWorld(); @@ -484,6 +516,11 @@ public final org.bukkit.loot.LootTable getLootTable(CommandContextgetMinecraftServer().getLootData().getLootTable(resourceLocation)); } + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -571,6 +608,17 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key)); } + @Override + public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + return ScoreHolderArgument.getNames(cmdCtx, key); + } + + @Override + public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ScoreHolderArgument.getName(cmdCtx, key); + } + @Override public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { CommandSourceStack css = cmdCtx.getSource(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java new file mode 100644 index 0000000000..56c954c47e --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.preprocessor.Differs; +import dev.jorel.commandapi.preprocessor.Unimplemented; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; +import net.minecraft.commands.CommandFunction; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import org.bukkit.NamespacedKey; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.function.ToIntFunction; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; + +public abstract class NMS_CommonWithFunctions_1_20_R1 extends NMS_Common { + + private static NamespacedKey fromResourceLocation(ResourceLocation key) { + return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + } + + // Converts NMS function to SimpleFunctionWrapper + private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { + ToIntFunction appliedObj = (CommandSourceStack css) -> this.getMinecraftServer().getFunctions() + .execute(commandFunction, css); + + CommandFunction.Entry[] cArr = commandFunction.getEntries(); + String[] result = new String[cArr.length]; + for (int i = 0, size = cArr.length; i < size; i++) { + result[i] = cArr[i].toString(); + } + return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); + } + + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); + Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); + if(commandFunctionOptional.isPresent()) { + return convertFunction(commandFunctionOptional.get()); + } else { + throw new IllegalStateException("Failed to get defined function " + key + + "! This should never happen - please report this to the CommandAPI" + + "developers, we'd love to know how you got this error message!"); + } + } + + @Override + public Set getFunctions() { + Set result = new HashSet<>(); + for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { + result.add(fromResourceLocation(resourceLocation)); + } + return result; + } + +} 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 4738c84f56..2508c40184 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 @@ -491,6 +491,11 @@ public final BaseComponent[] getChat(CommandContext cmdCtx, return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); } + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { 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 4b3670d27c..7f8374d721 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 @@ -507,6 +507,11 @@ public final BaseComponent[] getChat(CommandContext cmdCtx, return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); } + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { 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 d94c804170..084200f9ca 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 @@ -247,6 +247,11 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentBlockPredicate() { return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); @@ -293,6 +298,11 @@ public final ArgumentType _ArgumentParticle() { return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); } + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceLocationArgument.id(); + } + @Override public final ArgumentType _ArgumentSyntheticBiome() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); @@ -469,6 +479,11 @@ public final BaseComponent[] getChat(CommandContext cmdCtx, return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); } + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index de1489d2e9..5ef12b8d0c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -134,7 +134,67 @@ - Spigot_1_20_4_R3 + Spigot_1_21_R4 + + + org.spigotmc + spigot + 1.21.5-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_21_R3 + + + org.spigotmc + spigot + 1.21.4-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_21_R2 + + + org.spigotmc + spigot + 1.21.2-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_21_R1 + + + org.spigotmc + spigot + 1.21.1-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_R4 + + + org.spigotmc + spigot + 1.20.6-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + Spigot_1_20_R3 org.spigotmc @@ -146,7 +206,7 @@ - Spigot_1_20_2_R2 + Spigot_1_20_R2 org.spigotmc 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 100351b9f1..5caaa11063 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 @@ -20,84 +20,75 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import com.mojang.brigadier.CommandDispatcher; 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.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; 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.preprocessor.Differs; -import dev.jorel.commandapi.preprocessor.Overridden; -import dev.jorel.commandapi.preprocessor.Unimplemented; +import dev.jorel.commandapi.wrappers.MathOperation; import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.*; -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.commands.CommandSourceStack; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.coordinates.*; +import net.minecraft.commands.arguments.AngleArgument; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.CompoundTagArgument; +import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.ObjectiveCriteriaArgument; +import net.minecraft.commands.arguments.OperationArgument; +import net.minecraft.commands.arguments.RangeArgument; +import net.minecraft.commands.arguments.ResourceLocationArgument; +import net.minecraft.commands.arguments.ScoreHolderArgument; +import net.minecraft.commands.arguments.ScoreboardSlotArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.TimeArgument; +import net.minecraft.commands.arguments.UuidArgument; +import net.minecraft.commands.arguments.coordinates.BlockPosArgument; +import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; +import net.minecraft.commands.arguments.coordinates.SwizzleArgument; +import net.minecraft.commands.arguments.coordinates.Vec2Argument; +import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.network.chat.Component.Serializer; +import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec2; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; +import org.bukkit.Axis; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; 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.*; +import java.util.EnumSet; +import java.util.Locale; +import java.util.UUID; import java.util.function.Function; -import java.util.function.Predicate; - -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.*; /** * Common NMS code To ensure that this code actually works across all versions - * of Minecraft that this is supposed to support (1.17+), you should be + * of Minecraft that this is supposed to support (1.20+), you should be * compiling this code against all of the declared Maven profiles specified in - * this submodule's pom.xml file, by running the following commands: - *
    - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_3_R2
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_R1
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_2_R2
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_R1
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_17_R1
  • - *
- * Any of these that do not work should be removed or implemented otherwise - * (introducing another NMS_Common module perhaps? + * this submodule's pom.xml file, by running the following command: + * ./compileNMSCommon + *

+ * In case that fails, the method that causes the failure should be implemented in all + * NMS classes to maintain an error-free NMS_Common module that is applicable to all + * versions. */ public abstract class NMS_Common extends CommandAPIBukkit { private static NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } - @Override - public ArgumentType _ArgumentAdvancement() { - return ResourceLocationArgument.id(); - } - @Override public final ArgumentType _ArgumentAngle() { return AngleArgument.angle(); @@ -108,25 +99,11 @@ public final ArgumentType _ArgumentAxis() { return SwizzleArgument.swizzle(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19") - public abstract ArgumentType _ArgumentBlockPredicate(); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19") - public abstract ArgumentType _ArgumentBlockState(); - @Override public final ArgumentType _ArgumentChat() { return MessageArgument.message(); } - @Override - @Overridden(in = "1.20.5", because = "This now takes in a CommandBuildContext") - public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(); - } - @Override public final ArgumentType _ArgumentChatFormat() { return ColorArgument.color(); @@ -137,22 +114,6 @@ public ArgumentType _ArgumentDimension() { return DimensionArgument.dimension(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19.3") - public abstract ArgumentType _ArgumentEnchantment(); - - @Override - // I mean... really? Why? - @Unimplemented(because = NAME_CHANGED, info = "a (1.17) -> entity (1.18) -> a (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "multipleEntities (1.17) -> entities (1.18) -> b (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "c (1.17) -> player (1.18) -> c (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "d (1.17) -> players (1.18) -> d (1.19)") - public abstract ArgumentType _ArgumentEntity(ArgumentSubType subType); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19.3") - public abstract ArgumentType _ArgumentEntitySummon(); - @Override public final ArgumentType _ArgumentFloatRange() { return RangeArgument.floatRange(); @@ -163,14 +124,6 @@ public final ArgumentType _ArgumentIntRange() { return RangeArgument.intRange(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19") - public abstract ArgumentType _ArgumentItemPredicate(); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19") - public abstract ArgumentType _ArgumentItemStack(); - @Override public final ArgumentType _ArgumentMathOperation() { return OperationArgument.operation(); @@ -181,24 +134,11 @@ public final ArgumentType _ArgumentMinecraftKeyRegistered() { return ResourceLocationArgument.id(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19.3") - public abstract ArgumentType _ArgumentMobEffect(); - @Override public final ArgumentType _ArgumentNBTCompound() { return CompoundTagArgument.compoundTag(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19.3") - public abstract ArgumentType _ArgumentParticle(); - - @Override - public ArgumentType _ArgumentRecipe() { - return ResourceLocationArgument.id(); - } - @Override public final ArgumentType _ArgumentPosition() { return BlockPosArgument.blockPos(); @@ -248,10 +188,6 @@ public final ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { }; } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.18.2") - public abstract ArgumentType _ArgumentSyntheticBiome(); - @Override public final ArgumentType _ArgumentTag() { return FunctionArgument.functions(); @@ -277,22 +213,6 @@ public final ArgumentType _ArgumentVec3(boolean centerPosition) { return Vec3Argument.vec3(centerPosition); } - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "SimpleHelpMap") - public abstract Map getHelpMap(); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) - public abstract String[] compatibleVersions(); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftItemStack") - public abstract String convert(ItemStack is); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) - public abstract String convert(ParticleData particle); - @Override public final String convert(PotionEffectType potion) { return potion.getName().toLowerCase(Locale.ENGLISH); @@ -303,30 +223,6 @@ public final String convert(Sound sound) { return sound.getKey().toString(); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19") - public abstract void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException; - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CustomHelpTopic") - public abstract HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, - String permission); - - @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); - @Override public final float getAngle(CommandContext cmdCtx, String key) { return AngleArgument.getAngle(cmdCtx, key); @@ -335,8 +231,8 @@ public final float getAngle(CommandContext cmdCtx, String ke @Override public final EnumSet getAxis(CommandContext cmdCtx, String key) { EnumSet set = EnumSet.noneOf(Axis.class); - EnumSet parsedEnumSet = SwizzleArgument.getSwizzle(cmdCtx, key); - for (net.minecraft.core.Direction.Axis element : parsedEnumSet) { + EnumSet parsedEnumSet = SwizzleArgument.getSwizzle(cmdCtx, key); + for (Direction.Axis element : parsedEnumSet) { set.add(switch (element) { case X -> Axis.X; case Y -> Axis.Y; @@ -346,34 +242,11 @@ public final EnumSet getAxis(CommandContext cmdCtx, St return set; } - @Override - @Unimplemented(because = NAME_CHANGED, from = "getWorld()", to = "f()", in = "1.19") - public abstract Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftBlockData") - public abstract BlockData getBlockState(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 BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - - @Override - public abstract CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - @Override public final BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { try { @@ -383,69 +256,6 @@ public final BukkitCommandSender getCommandSenderFromCo } } - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftWorld", info = "CraftWorld is implicitly referenced by ServerLevel#getWorld, due to package renaming, it can't resolve at runtime") - public abstract World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.19.3") - public abstract Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = NAME_CHANGED, from = "getKey()", to = "a()", in = "1.19") - public abstract EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.20.2") - public abstract FloatRange getFloatRange(CommandContext cmdCtx, String key); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftEntity") - public abstract FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, in = "1.17, 1.18 and 1.18.2") - public abstract SimpleFunctionWrapper getFunction(NamespacedKey key); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, in = "1.17, 1.18 and 1.18.2") - public abstract Set getFunctions(); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.20.2") - public abstract IntegerRange getIntRange(CommandContext cmdCtx, String key); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftItemStack") - public abstract ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftItemStack") - public abstract Predicate getItemStackPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - @Override - @Unimplemented(because = { NAME_CHANGED, REQUIRES_CSS }, from = "a, b", to = "c(), d()") - public abstract Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); - } - - @Override - @Unimplemented(because = { NAME_CHANGED, REQUIRES_CSS }, from = "getX(), getY(), getZ()", to = "u(), v(), w()") - public abstract Location getLocationBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = { NAME_CHANGED, REQUIRES_CSS }, from = "getX(), getY(), getZ()", to = "a(), b(), c()") - public abstract Location getLocationPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftLootTable") - public abstract LootTable getLootTable(CommandContext cmdCtx, String key); - @Override public final MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { // We run this to ensure the argument exists/parses properly @@ -453,13 +263,6 @@ public final MathOperation getMathOperation(CommandContext c return MathOperation.fromString(CommandAPIHandler.getRawArgumentInput(cmdCtx, key)); } - @Override - @Overridden(in = "1.17 common; 1.18", because = "1.17 uses ArgumentMinecraftKeyRegistered.f instead of ArgumentMinecraftKeyRegistered.e") - @Overridden(in = "1.20.5, 1.20.6", because = "ArgumentMinecraftKeyRegistered.e -> ArgumentMinecraftKeyRegistered.c") - public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { - return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - } - @Override public final Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor) { @@ -467,7 +270,6 @@ public final Object getNBTCompound(CommandContext cmdCtx, String key) throws CommandSyntaxException { String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); @@ -484,10 +286,6 @@ public final OfflinePlayer getOfflinePlayer(CommandContext c return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cmdCtx, key).iterator().next().getId()); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.18, 1.19") - public abstract ParticleData getParticle(CommandContext cmdCtx, String key); - @Override public final Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cmdCtx, key).iterator().next().getId()); @@ -498,82 +296,12 @@ public final Player getPlayer(CommandContext cmdCtx, String } } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.18") - public abstract Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException; - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, info = """ - 1.17 has what appears to be a different obfuscation for recipe.getId(). - I can't be bothered to figure out what it is, but all I know is it doesn't work, - and we need to move it outta here! - """) - public abstract Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; - @Override public final Rotation getRotation(CommandContext cmdCtx, String key) { Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); return new Rotation(rotation.y, rotation.x); } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, introducedIn = "1.20.2") - public abstract ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); - - @Override - // TODO: Overridden in 1.20.3 because this now returns a Collection - public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return ScoreHolderArgument.getNames(cmdCtx, key); - } - - @Override - // TODO: Overridden in 1.20.3 because this now returns a ScoreHolder - public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ScoreHolderArgument.getName(cmdCtx, key); - } - - @Override - // Whyyyyyyyyyyyyyyyyyyy - @Unimplemented(because = NAME_CHANGED, info = "CommandListenerWrapper changes:") - @Unimplemented(because = NAME_CHANGED, info = "getPosition (1.17) -> getPosition (1.18) -> e (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "i (1.17) -> getRotation (1.18) -> l (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "getEntity (1.17) -> getEntity (1.18) -> g (1.19)") - @Unimplemented(because = NAME_CHANGED, info = "getWorld (1.17) -> getLevel (1.18) -> f (1.19)") - public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "ProxiedNativeCommandSender") - public abstract NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftServer") - public abstract SimpleCommandMap getSimpleCommandMap(); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT, classNamed = "CraftSound") - public abstract Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, info = """ - The various methods that this uses is obfuscated to different method - names for different versions. For example, getMinecraftServer().getLootTables.getIds() - is mapped to a different method in 1.18 compared to 1.19.2. This also has various other - implications across all sorts of versions, so it's much more reliable to just implement - them in every version. - """) - public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders provider); - - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION, from = "1.18.2", to = "1.19") - @Differs(from = "1.18.2", by = "getTag() now returns a Collection<> instead of a Tag<>, so don't have to call .getValues()") - public abstract SimpleFunctionWrapper[] getTag(NamespacedKey key); - - @Override - @Unimplemented(because = NAME_CHANGED, info = "See https://github.com/JorelAli/CommandAPI/issues/524") - public abstract Set getTags(); - @Override public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); @@ -589,14 +317,4 @@ public final int getTime(CommandContext cmdCtx, String key) public final UUID getUUID(CommandContext cmdCtx, String key) { return UuidArgument.getUuid(cmdCtx, 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/compileNMSCommon.sh b/compileNMSCommon.sh new file mode 100644 index 0000000000..a1a989d835 --- /dev/null +++ b/compileNMSCommon.sh @@ -0,0 +1,23 @@ +echo "Compiling NMS_Common for Spigot 1.20.1..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 + +echo "Compiling NMS_Common for Spigot 1.20.2..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 + +echo "Compiling NMS_Common for Spigot 1.20.3 and 1.20.4..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 + +echo "Compiling NMS_Common for Spigot 1.20.5 and 1.20.6..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 + +echo "Compiling NMS_Common for Spigot 1.21 and 1.21.1..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 + +echo "Compiling NMS_Common for Spigot 1.21.2 and 1.21.3..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 + +echo "Compiling NMS_Common for Spigot 1.21.4..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 + +echo "Compiling NMS_Common for Spigot 1.21.5..." +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 \ No newline at end of file From cc3981b9a5b189f1f24305ae30ae47b61f2139ad Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:58:29 +0200 Subject: [PATCH 02/13] Use 1.21.3 dependency --- .../commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index 5ef12b8d0c..9cdc4229f2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -163,7 +163,7 @@ org.spigotmc spigot - 1.21.2-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT remapped-mojang provided From c9ae55df66722397ad3c2cd404b47434f071e91a Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:12:32 +0200 Subject: [PATCH 03/13] Use more GH Actions steps to fail the build when it isn't compatible with a version --- .github/workflows/build.yml | 29 +++++++++++++++++++++++++---- compileNMSCommon.sh | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a1af6e568f..ef45d4bf57 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,10 +40,31 @@ jobs: - name: Build the CommandAPI (Bukkit+Velocity) using maven run: mvn clean install --batch-mode -P Platform.Bukkit,Platform.Velocity - - name: Check NMS_Common compiles against all compatible Minecraft versions - run: | - chmod +x ./compileNMSCommon.sh - ./compileNMSCommon.sh + ### Check NMS_Common compiles against all compatible Minecraft versions + + - name: Compile NMS_Common for 1.20 and 1.20.1 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 + + - name: Compile NMS_Common for 1.20.2 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 + + - name: Compile NMS_Common for 1.20.3 and 1.20.4 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 + + - name: Compile NMS_Common for 1.20.5 and 1.20.6 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 + + - name: Compile NMS_Common for 1.21 and 1.21.1 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 + + - name: Compile NMS_Common for 1.21.2 and 1.21.3 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 + + - name: Compile NMS_Common for 1.21.4 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 + + - name: Compile NMS_Common for 1.21.5 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 # - name: validate version-specific dependencies (nms-common) # run: | diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index a1a989d835..121228677b 100644 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -1,4 +1,4 @@ -echo "Compiling NMS_Common for Spigot 1.20.1..." +echo "Compiling NMS_Common for Spigot 1.20 and 1.20.1..." mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 echo "Compiling NMS_Common for Spigot 1.20.2..." From 227e5fa0ccc2675ec601a2c39a39b020caa6cab7 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:50:29 +0200 Subject: [PATCH 04/13] Use --quiet flag in the script --- compileNMSCommon.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index 121228677b..00f0d1d436 100644 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -1,23 +1,23 @@ echo "Compiling NMS_Common for Spigot 1.20 and 1.20.1..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 --quiet echo "Compiling NMS_Common for Spigot 1.20.2..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 --quiet echo "Compiling NMS_Common for Spigot 1.20.3 and 1.20.4..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 --quiet echo "Compiling NMS_Common for Spigot 1.20.5 and 1.20.6..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 --quiet echo "Compiling NMS_Common for Spigot 1.21 and 1.21.1..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 --quiet echo "Compiling NMS_Common for Spigot 1.21.2 and 1.21.3..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 --quiet echo "Compiling NMS_Common for Spigot 1.21.4..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 --quiet echo "Compiling NMS_Common for Spigot 1.21.5..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 \ No newline at end of file +mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 --quiet \ No newline at end of file From 6db4696442db86e2f091084681b7ef7626a7b28a Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:55:56 +0200 Subject: [PATCH 05/13] Remove unused method --- .../src/main/java/dev/jorel/commandapi/nms/NMS_Common.java | 5 ----- 1 file changed, 5 deletions(-) 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 5caaa11063..4849ac3441 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 @@ -54,12 +54,10 @@ import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec2; import org.bukkit.Axis; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.command.CommandSender; @@ -85,9 +83,6 @@ * versions. */ public abstract class NMS_Common extends CommandAPIBukkit { - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } @Override public final ArgumentType _ArgumentAngle() { From 90ce2e0b96ab27aa86d9d28ee7ac7c76ca70132d Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:03:48 +0200 Subject: [PATCH 06/13] Remove NMS_CommonWithFunctions_XXX classes --- .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 170 +++++++++++------- .../nms/NMS_CommonWithFunctions_1_20_R2.java | 99 ---------- .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 83 +++++++-- .../nms/NMS_CommonWithFunctions_1_20_R1.java | 84 --------- 4 files changed, 179 insertions(+), 257 deletions(-) delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java 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 b8404bac15..1faf77e216 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 @@ -20,65 +20,6 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.*; -import dev.jorel.commandapi.wrappers.*; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.arguments.*; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R2.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R2.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R2.CraftServer; -import org.bukkit.craftbukkit.v1_20_R2.CraftSound; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R2.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_20_R2.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; import com.google.common.io.Files; import com.google.gson.GsonBuilder; @@ -90,7 +31,11 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.logging.LogUtils; - +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.CommandRegistrationStrategy; +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; @@ -99,15 +44,37 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; +import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; +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.NativeProxyCommandSender; +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; import net.minecraft.commands.CommandFunction; -import net.minecraft.commands.CommandFunction.Entry; import net.minecraft.commands.CommandSourceStack; 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; +import net.minecraft.commands.arguments.ResourceLocationArgument; +import net.minecraft.commands.arguments.ScoreHolderArgument; +import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; @@ -161,6 +128,59 @@ import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R2.CraftLootTable; +import org.bukkit.craftbukkit.v1_20_R2.CraftParticle; +import org.bukkit.craftbukkit.v1_20_R2.CraftServer; +import org.bukkit.craftbukkit.v1_20_R2.CraftSound; +import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_20_R2.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_20_R2.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; +import java.util.function.ToIntFunction; // Mojang-Mapped reflection /** @@ -171,7 +191,7 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) -public class NMS_1_20_R2 extends NMS_CommonWithFunctions_1_20_R2 { +public class NMS_1_20_R2 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; @@ -284,10 +304,10 @@ public final String convert(ParticleData particle) { } // Converts NMS function to SimpleFunctionWrapper - private final SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { + private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { ToIntFunction appliedObj = (CommandSourceStack css) -> this.getMinecraftServer().getFunctions().execute(commandFunction, css); - Entry[] cArr = commandFunction.getEntries(); + CommandFunction.Entry[] cArr = commandFunction.getEntries(); String[] result = new String[cArr.length]; for (int i = 0, size = cArr.length; i < size; i++) { result[i] = cArr[i].toString(); @@ -466,6 +486,28 @@ public final FunctionWrapper[] getFunction(CommandContext cm return result.toArray(new FunctionWrapper[0]); } + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); + Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); + if(commandFunctionOptional.isPresent()) { + return convertFunction(commandFunctionOptional.get()); + } else { + throw new IllegalStateException("Failed to get defined function " + key + + "! This should never happen - please report this to the CommandAPI" + + "developers, we'd love to know how you got this error message!"); + } + } + + @Override + public Set getFunctions() { + Set result = new HashSet<>(); + for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { + result.add(fromResourceLocation(resourceLocation)); + } + return result; + } + @Override public IntegerRange getIntRange(CommandContext cmdCtx, String key) { MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cmdCtx, key); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_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_CommonWithFunctions_1_20_R2.java deleted file mode 100644 index dc1e59ebf2..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R2.java +++ /dev/null @@ -1,99 +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.nms; - -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.jorel.commandapi.preprocessor.Differs; -import dev.jorel.commandapi.preprocessor.Unimplemented; -import dev.jorel.commandapi.wrappers.FunctionWrapper; -import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.minecraft.commands.CommandFunction; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import org.bukkit.NamespacedKey; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import java.util.function.ToIntFunction; - -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; - -/** - * Common NMS code To ensure that this code actually works across all versions - * of Minecraft that this is supposed to support (1.17+), you should be - * compiling this code against all of the declared Maven profiles specified in - * this submodule's pom.xml file, by running the following commands: - *

    - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_3_R2
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_19_R1
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_2_R2
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_18_R1
  • - *
  • mvn clean package -pl :commandapi-bukkit-nms-common -P Platform.Bukkit,Spigot_1_17_R1
  • - *
- * Any of these that do not work should be removed or implemented otherwise - * (introducing another NMS_Common module perhaps? - */ -public abstract class NMS_CommonWithFunctions_1_20_R2 extends NMS_Common { - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - // Converts NMS function to SimpleFunctionWrapper - private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { - ToIntFunction appliedObj = (CommandSourceStack css) -> this.getMinecraftServer().getFunctions() - .execute(commandFunction, css); - - CommandFunction.Entry[] cArr = commandFunction.getEntries(); - String[] result = new String[cArr.length]; - for (int i = 0, size = cArr.length; i < size; i++) { - result[i] = cArr[i].toString(); - } - return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); - } - - @Override - public SimpleFunctionWrapper getFunction(NamespacedKey key) { - final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); - Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); - if(commandFunctionOptional.isPresent()) { - return convertFunction(commandFunctionOptional.get()); - } else { - throw new IllegalStateException("Failed to get defined function " + key - + "! This should never happen - please report this to the CommandAPI" - + "developers, we'd love to know how you got this error message!"); - } - } - - @Override - public Set getFunctions() { - Set result = new HashSet<>(); - for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { - result.add(fromResourceLocation(resourceLocation)); - } - return result; - } - -} 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 cae2ae10d7..9d4a17fa55 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 @@ -31,7 +31,11 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.logging.LogUtils; -import dev.jorel.commandapi.*; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.CommandRegistrationStrategy; +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; @@ -40,7 +44,15 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.*; +import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; +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.NativeProxyCommandSender; +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; @@ -49,10 +61,19 @@ import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandFunction; -import net.minecraft.commands.CommandFunction.Entry; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; +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; +import net.minecraft.commands.arguments.ResourceLocationArgument; +import net.minecraft.commands.arguments.ScoreHolderArgument; +import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; @@ -67,7 +88,15 @@ import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.RegistryAccess.Frozen; -import net.minecraft.core.particles.*; +import net.minecraft.core.particles.BlockParticleOption; +import net.minecraft.core.particles.DustColorTransitionOptions; +import net.minecraft.core.particles.DustParticleOptions; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.SculkChargeParticleOptions; +import net.minecraft.core.particles.ShriekParticleOption; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.core.particles.VibrationParticleOption; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; @@ -97,12 +126,17 @@ import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.Particle; import org.bukkit.Particle.DustOptions; import org.bukkit.Particle.DustTransition; +import org.bukkit.Vibration; import org.bukkit.Vibration.Destination; import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; import org.bukkit.advancement.Advancement; import org.bukkit.block.Biome; import org.bukkit.block.Block; @@ -134,7 +168,14 @@ import java.io.StringWriter; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import java.util.function.ToIntFunction; @@ -148,7 +189,7 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) -public class NMS_1_20_R1 extends NMS_CommonWithFunctions_1_20_R1 { +public class NMS_1_20_R1 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; @@ -261,10 +302,10 @@ public final String convert(ParticleData particle) { } // Converts NMS function to SimpleFunctionWrapper - private final SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { + private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { ToIntFunction appliedObj = (CommandSourceStack css) -> this.getMinecraftServer().getFunctions().execute(commandFunction, css); - Entry[] cArr = commandFunction.getEntries(); + CommandFunction.Entry[] cArr = commandFunction.getEntries(); String[] result = new String[cArr.length]; for (int i = 0, size = cArr.length; i < size; i++) { result[i] = cArr[i].toString(); @@ -447,6 +488,28 @@ public final FunctionWrapper[] getFunction(CommandContext cm return result.toArray(new FunctionWrapper[0]); } + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); + Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); + if(commandFunctionOptional.isPresent()) { + return convertFunction(commandFunctionOptional.get()); + } else { + throw new IllegalStateException("Failed to get defined function " + key + + "! This should never happen - please report this to the CommandAPI" + + "developers, we'd love to know how you got this error message!"); + } + } + + @Override + public Set getFunctions() { + Set result = new HashSet<>(); + for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { + result.add(fromResourceLocation(resourceLocation)); + } + return result; + } + @Override public IntegerRange getIntRange(CommandContext cmdCtx, String key) { MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cmdCtx, key); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java deleted file mode 100644 index 56c954c47e..0000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_CommonWithFunctions_1_20_R1.java +++ /dev/null @@ -1,84 +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.nms; - -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.jorel.commandapi.preprocessor.Differs; -import dev.jorel.commandapi.preprocessor.Unimplemented; -import dev.jorel.commandapi.wrappers.FunctionWrapper; -import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.minecraft.commands.CommandFunction; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import org.bukkit.NamespacedKey; - -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import java.util.function.ToIntFunction; - -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; - -public abstract class NMS_CommonWithFunctions_1_20_R1 extends NMS_Common { - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - // Converts NMS function to SimpleFunctionWrapper - private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { - ToIntFunction appliedObj = (CommandSourceStack css) -> this.getMinecraftServer().getFunctions() - .execute(commandFunction, css); - - CommandFunction.Entry[] cArr = commandFunction.getEntries(); - String[] result = new String[cArr.length]; - for (int i = 0, size = cArr.length; i < size; i++) { - result[i] = cArr[i].toString(); - } - return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); - } - - @Override - public SimpleFunctionWrapper getFunction(NamespacedKey key) { - final ResourceLocation resourceLocation = new ResourceLocation(key.getNamespace(), key.getKey()); - Optional commandFunctionOptional = this.getMinecraftServer().getFunctions().get(resourceLocation); - if(commandFunctionOptional.isPresent()) { - return convertFunction(commandFunctionOptional.get()); - } else { - throw new IllegalStateException("Failed to get defined function " + key - + "! This should never happen - please report this to the CommandAPI" - + "developers, we'd love to know how you got this error message!"); - } - } - - @Override - public Set getFunctions() { - Set result = new HashSet<>(); - for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getFunctionNames()) { - result.add(fromResourceLocation(resourceLocation)); - } - return result; - } - -} From 3bdcce49887abff8b1dce5989701f738f785a083 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:30:31 +0200 Subject: [PATCH 07/13] Make sure specialsource uses the correct version --- .../commandapi-bukkit-nms-common/pom.xml | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index 9cdc4229f2..e23532fc6d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -99,7 +99,7 @@ net.md-5 specialsource-maven-plugin - 1.2.4 + 2.0.4 package @@ -135,6 +135,9 @@ Spigot_1_21_R4 + + 1.21.5-R0.1-SNAPSHOT + org.spigotmc @@ -147,6 +150,9 @@ Spigot_1_21_R3 + + 1.21.4-R0.1-SNAPSHOT + org.spigotmc @@ -159,6 +165,9 @@ Spigot_1_21_R2 + + 1.21.3-R0.1-SNAPSHOT + org.spigotmc @@ -171,6 +180,9 @@ Spigot_1_21_R1 + + 1.21.1-R0.1-SNAPSHOT + org.spigotmc @@ -183,6 +195,9 @@ Spigot_1_20_R4 + + 1.20.6-R0.1-SNAPSHOT + org.spigotmc @@ -195,6 +210,9 @@ Spigot_1_20_R3 + + 1.20.4-R0.1-SNAPSHOT + org.spigotmc @@ -207,6 +225,9 @@ Spigot_1_20_R2 + + 1.20.2-R0.1-SNAPSHOT + org.spigotmc @@ -219,6 +240,9 @@ Spigot_1_20_R1 + + 1.20.1-R0.1-SNAPSHOT + true From d4dabf3366612efe47a9cd416c10f28694db7906 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:12:45 +0200 Subject: [PATCH 08/13] Move methods out and into NMS_Common when possible --- README.md | 1 + .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 102 ++++---------- .../dev/jorel/commandapi/nms/NMS_1_20_R3.java | 112 ++++------------ .../dev/jorel/commandapi/nms/NMS_1_20_R4.java | 112 ++++------------ .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 102 ++++---------- .../dev/jorel/commandapi/nms/NMS_1_21_R2.java | 112 ++++------------ .../dev/jorel/commandapi/nms/NMS_1_21_R3.java | 112 ++++------------ .../dev/jorel/commandapi/nms/NMS_1_21_R4.java | 112 ++++------------ .../dev/jorel/commandapi/nms/NMS_1_21_R1.java | 112 ++++------------ .../commandapi-bukkit-nms-common/pom.xml | 115 ++++++---------- .../dev/jorel/commandapi/nms/NMS_Common.java | 126 +++++++++++++++--- 11 files changed, 372 insertions(+), 746 deletions(-) diff --git a/README.md b/README.md index 1bee9080d8..02a8bcb3f1 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,7 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): Bug Fixes:
  • Fixes command unregistration not working on Paper
  • +
  • Fixes the ObjectiveArgument and TeamArgument not working correctly
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 1faf77e216..d3dc99b46f 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 @@ -51,6 +51,7 @@ import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; 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; @@ -69,16 +70,19 @@ import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; +import net.minecraft.commands.arguments.TeamArgument; import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; @@ -163,6 +167,8 @@ import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.Recipe; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; import java.io.File; import java.io.IOException; @@ -218,8 +224,9 @@ public class NMS_1_20_R2 extends NMS_Common { serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override @@ -227,16 +234,6 @@ public ArgumentType _ArgumentAdvancement() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentChatComponent() { return ComponentArgument.textComponent(); @@ -247,32 +244,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceLocationArgument.id(); @@ -315,12 +286,6 @@ private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); } - @Override - public final void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { return new CustomHelpTopic(commandName, shortDescription, fullDescription, permission); @@ -365,13 +330,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -458,12 +416,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -546,30 +498,12 @@ public final Predicate getItemStackPredicate(Com return item -> predicate.test(CraftItemStack.asNMSCopy(item)); } - @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - @Override public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key); @@ -581,6 +515,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Differs(from = "1.20.1", by = "Uses CraftParticle#minecraftToBukkit instead of CraftParticle#toBukkit") @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { @@ -665,6 +605,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -805,6 +751,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 378161b76a..92f6fb07ff 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 @@ -40,9 +40,13 @@ import java.util.function.ToIntFunction; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.Rotation; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -187,6 +191,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -225,8 +231,9 @@ public class NMS_1_20_R3 extends NMS_Common { serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override @@ -234,16 +241,6 @@ public ArgumentType _ArgumentAdvancement() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentChatComponent() { return ComponentArgument.textComponent(); @@ -254,37 +251,11 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public final ArgumentType _ArgumentSyntheticBiome() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); @@ -364,13 +335,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -420,14 +384,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -523,14 +479,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -619,33 +567,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key); @@ -658,6 +584,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Differs(from = "1.20.1", by = "Uses CraftParticle#minecraftToBukkit instead of CraftParticle#toBukkit") @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { @@ -735,6 +667,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -886,6 +824,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 935be738ab..44b17dce9d 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 @@ -40,6 +40,10 @@ import java.util.function.ToIntFunction; import dev.jorel.commandapi.*; +import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -191,6 +195,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -240,24 +246,15 @@ public class NMS_1_20_R4 extends NMS_Common { vanillaCommandDispatcherFieldExists = fieldExists; } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override public ArgumentType _ArgumentAdvancement() { return ResourceLocationArgument.id(); } - - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } @Differs(from = "1.20.4", by = "Now needs a command build context") @Override @@ -270,32 +267,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceLocationArgument.id(); @@ -398,13 +369,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -456,14 +420,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -560,14 +516,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -644,33 +592,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); @@ -681,6 +607,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Differs(from = "1.20.4", by = "New particle option ColorParticleOption") @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { @@ -786,6 +718,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -932,6 +870,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 9d4a17fa55..cd70bf71ff 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 @@ -51,6 +51,7 @@ import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; 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; @@ -68,16 +69,19 @@ import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; +import net.minecraft.commands.arguments.TeamArgument; import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; @@ -161,6 +165,8 @@ import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.Recipe; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; import java.io.File; import java.io.IOException; @@ -216,8 +222,9 @@ public class NMS_1_20_R1 extends NMS_Common { serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override @@ -225,16 +232,6 @@ public ArgumentType _ArgumentAdvancement() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentChatComponent() { return ComponentArgument.textComponent(); @@ -245,37 +242,11 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public final ArgumentType _ArgumentSyntheticBiome() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); @@ -313,12 +284,6 @@ private SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.getId()), appliedObj, result); } - @Override - public final void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { return new CustomHelpTopic(commandName, shortDescription, fullDescription, permission); @@ -363,13 +328,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -460,12 +418,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -548,30 +500,12 @@ public final Predicate getItemStackPredicate(Com return item -> predicate.test(CraftItemStack.asNMSCopy(item)); } - @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - @Override public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Differs(from = "1.19.4", by = "Uses MinecraftServer#getLootData instead of MinecraftServer#getLootTables") @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { @@ -584,6 +518,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -666,6 +606,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.getId()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key)); @@ -805,6 +751,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 2508c40184..bf2595c610 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,10 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -199,6 +203,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -252,8 +258,9 @@ public class NMS_1_21_R2 extends NMS_Common { minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aE", "fuelValues", FuelValues.class); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Differs(from = "1.21.1", by = "New advancement argument implementation") @@ -261,16 +268,6 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { public ArgumentType _ArgumentAdvancement() { return ResourceKeyArgument.key(Registries.ADVANCEMENT); } - - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } @Override public ArgumentType _ArgumentChatComponent() { @@ -282,32 +279,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Differs(from = "1.21.1", by = "New recipe argument implementation") @Override public ArgumentType _ArgumentRecipe() { @@ -410,13 +381,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -467,14 +431,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -571,14 +527,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -656,33 +604,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); @@ -693,6 +619,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -796,6 +728,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -946,6 +884,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 7f8374d721..89e7d0036a 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 @@ -42,6 +42,10 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -204,6 +208,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -268,8 +274,9 @@ public class NMS_1_21_R3 extends NMS_Common { minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aE", "fuelValues", FuelValues.class); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Differs(from = "1.21.1", by = "New advancement argument implementation") @@ -277,16 +284,6 @@ private static NamespacedKey fromResourceLocation(ResourceLocation key) { public ArgumentType _ArgumentAdvancement() { return ResourceKeyArgument.key(Registries.ADVANCEMENT); } - - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } @Override public ArgumentType _ArgumentChatComponent() { @@ -298,32 +295,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Differs(from = "1.21.1", by = "New recipe argument implementation") @Override public ArgumentType _ArgumentRecipe() { @@ -426,13 +397,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -483,14 +447,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -587,14 +543,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -672,33 +620,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); @@ -709,6 +635,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -823,6 +755,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -973,6 +911,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java index 7e46106f60..8869a4551b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java @@ -42,6 +42,10 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -204,6 +208,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -268,24 +274,15 @@ public class NMS_1_21_R4 extends NMS_Common { minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aE", "fuelValues", FuelValues.class); } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override public ArgumentType _ArgumentAdvancement() { return ResourceKeyArgument.key(Registries.ADVANCEMENT); } - - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } @Override public ArgumentType _ArgumentChatComponent() { @@ -297,32 +294,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceKeyArgument.key(Registries.RECIPE); @@ -423,13 +394,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -480,14 +444,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -584,14 +540,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -668,33 +616,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); @@ -705,6 +631,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -818,6 +750,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -967,6 +905,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); 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 084200f9ca..781b8ad19c 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,10 @@ import java.util.function.Predicate; import java.util.function.ToIntFunction; +import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; @@ -194,6 +198,8 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; // Mojang-Mapped reflection /** @@ -243,8 +249,9 @@ public class NMS_1_21_R1 extends NMS_Common { vanillaCommandDispatcherFieldExists = fieldExists; } - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + @Override + protected CommandBuildContext getCommandBuildContext() { + return COMMAND_BUILD_CONTEXT; } @Override @@ -252,16 +259,6 @@ public ArgumentType _ArgumentAdvancement() { return ResourceLocationArgument.id(); } - @Override - public final ArgumentType _ArgumentBlockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentBlockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentChatComponent() { return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); @@ -272,32 +269,6 @@ public final ArgumentType _ArgumentEnchantment() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); } - @Override - public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public final ArgumentType _ArgumentItemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentItemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public final ArgumentType _ArgumentParticle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - @Override public ArgumentType _ArgumentRecipe() { return ResourceLocationArgument.id(); @@ -398,13 +369,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction dispatcher) - throws IOException { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); - } - @Override public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { @@ -455,14 +419,6 @@ public final Object getBiome(CommandContext cmdCtx, String k }; } - @Override - public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); - return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - @Override public final BlockData getBlockState(CommandContext cmdCtx, String key) { return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); @@ -559,14 +515,6 @@ public final Object getEntitySelector(CommandContext cmdCtx, }; } - @SuppressWarnings("deprecation") - @Override - public final EntityType getEntityType(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - return EntityType.fromName(net.minecraft.world.entity.EntityType - .getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); - } - @Override public FloatRange getFloatRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); @@ -644,33 +592,11 @@ public final Predicate getItemStackPredicate( } @Override - public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); - return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); - } - - @Override - public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); } - @Override - public final Location getLocationBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); - return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - - @Override - public final Location getLocationPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); - return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); - } - @Override public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); @@ -681,6 +607,12 @@ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); } + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + @Override public final ParticleData getParticle(CommandContext cmdCtx, String key) { final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); @@ -783,6 +715,12 @@ public final Recipe getRecipe(CommandContext cmdCtx, String return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); @@ -930,6 +868,12 @@ public Set getTags() { return result; } + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + @Override public World getWorldForCSS(CommandSourceStack css) { return (css.getLevel() == null) ? null : css.getLevel().getWorld(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index e23532fc6d..b7e6bf71db 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -137,124 +137,95 @@ Spigot_1_21_R4 1.21.5-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.21.5-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.21.5 +
Spigot_1_21_R3 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.21.4-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.21.4 + Spigot_1_21_R2 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.21.3-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.21.3 + Spigot_1_21_R1 1.21.1-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.21.1-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.21.1 + Spigot_1_20_R4 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.20.6-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.20.6 + Spigot_1_20_R3 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.20.4-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.20.4 + Spigot_1_20_R2 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT - - - org.spigotmc - spigot - 1.20.2-R0.1-SNAPSHOT - remapped-mojang - provided - - + + ${project.basedir}/target/1.20.2 + Spigot_1_20_R1 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + + ${project.basedir}/target/1.20.1 + + + + Spigot_1_20_R1_Release true - - - org.spigotmc - spigot - 1.20-R0.1-SNAPSHOT - remapped-mojang - provided - -
\ No newline at end of file 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 4849ac3441..4d5afdbe57 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 @@ -20,6 +20,9 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; +import com.google.common.io.Files; +import com.google.gson.GsonBuilder; +import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -27,25 +30,32 @@ import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.MathOperation; import dev.jorel.commandapi.wrappers.Rotation; +import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.AngleArgument; import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.CompoundTagArgument; import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.GameProfileArgument; import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ObjectiveCriteriaArgument; import net.minecraft.commands.arguments.OperationArgument; +import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; +import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.TeamArgument; import net.minecraft.commands.arguments.TimeArgument; import net.minecraft.commands.arguments.UuidArgument; +import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; import net.minecraft.commands.arguments.coordinates.RotationArgument; @@ -53,23 +63,39 @@ import net.minecraft.commands.arguments.coordinates.Vec2Argument; import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; +import net.minecraft.commands.arguments.item.ItemArgument; +import net.minecraft.commands.arguments.item.ItemPredicateArgument; +import net.minecraft.commands.synchronization.ArgumentUtils; +import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ColumnPos; +import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; import org.bukkit.Axis; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Sound; +import org.bukkit.block.Block; import org.bukkit.command.CommandSender; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; 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.nio.charset.StandardCharsets; import java.util.EnumSet; import java.util.Locale; import java.util.UUID; import java.util.function.Function; +import java.util.function.Predicate; /** * Common NMS code To ensure that this code actually works across all versions @@ -84,6 +110,12 @@ */ public abstract class NMS_Common extends CommandAPIBukkit { + protected static NamespacedKey fromResourceLocation(ResourceLocation key) { + return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); + } + + protected abstract CommandBuildContext getCommandBuildContext(); + @Override public final ArgumentType _ArgumentAngle() { return AngleArgument.angle(); @@ -94,6 +126,16 @@ public final ArgumentType _ArgumentAxis() { return SwizzleArgument.swizzle(); } + @Override + public final ArgumentType _ArgumentBlockPredicate() { + return BlockPredicateArgument.blockPredicate(getCommandBuildContext()); + } + + @Override + public final ArgumentType _ArgumentBlockState() { + return BlockStateArgument.block(getCommandBuildContext()); + } + @Override public final ArgumentType _ArgumentChat() { return MessageArgument.message(); @@ -105,10 +147,21 @@ public final ArgumentType _ArgumentChatFormat() { } @Override - public ArgumentType _ArgumentDimension() { + public final ArgumentType _ArgumentDimension() { return DimensionArgument.dimension(); } + @Override + public final ArgumentType _ArgumentEntity(ArgumentSubType subType) { + return switch (subType) { + case ENTITYSELECTOR_MANY_ENTITIES -> EntityArgument.entities(); + case ENTITYSELECTOR_MANY_PLAYERS -> EntityArgument.players(); + case ENTITYSELECTOR_ONE_ENTITY -> EntityArgument.entity(); + case ENTITYSELECTOR_ONE_PLAYER -> EntityArgument.player(); + default -> throw new IllegalArgumentException("Unexpected value: " + subType); + }; + } + @Override public final ArgumentType _ArgumentFloatRange() { return RangeArgument.floatRange(); @@ -119,6 +172,16 @@ public final ArgumentType _ArgumentIntRange() { return RangeArgument.intRange(); } + @Override + public final ArgumentType _ArgumentItemPredicate() { + return ItemPredicateArgument.itemPredicate(getCommandBuildContext()); + } + + @Override + public final ArgumentType _ArgumentItemStack() { + return ItemArgument.item(getCommandBuildContext()); + } + @Override public final ArgumentType _ArgumentMathOperation() { return OperationArgument.operation(); @@ -134,6 +197,11 @@ public final ArgumentType _ArgumentNBTCompound() { return CompoundTagArgument.compoundTag(); } + @Override + public final ArgumentType _ArgumentParticle() { + return ParticleArgument.particle(getCommandBuildContext()); + } + @Override public final ArgumentType _ArgumentPosition() { return BlockPosArgument.blockPos(); @@ -218,6 +286,12 @@ public final String convert(Sound sound) { return sound.getKey().toString(); } + @Override + public final void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException { + Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() + .toJson(ArgumentUtils.serializeNodeToJson(dispatcher, dispatcher.getRoot()))); + } + @Override public final float getAngle(CommandContext cmdCtx, String key) { return AngleArgument.getAngle(cmdCtx, key); @@ -237,6 +311,13 @@ public final EnumSet getAxis(CommandContext cmdCtx, St return set; } + @Override + public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { + Predicate predicate = BlockPredicateArgument.getBlockPredicate(cmdCtx, key); + return (Block block) -> predicate.test(new BlockInWorld(cmdCtx.getSource().getLevel(), + new BlockPos(block.getX(), block.getY(), block.getZ()), true)); + } + @Override public final ChatColor getChatColor(CommandContext cmdCtx, String key) { return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); @@ -251,6 +332,30 @@ public final BukkitCommandSender getCommandSenderFromCo } } + @SuppressWarnings("deprecation") + @Override + public final EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(ResourceArgument.getSummonableEntityType(cmdCtx, key).value()).getPath()); + } + + @Override + public final Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { + ColumnPos blockPos = ColumnPosArgument.getColumnPos(cmdCtx, key); + return new Location2D(getWorldForCSS(cmdCtx.getSource()), blockPos.x(), blockPos.z()); + } + + @Override + public final Location getLocationBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { + BlockPos blockPos = BlockPosArgument.getSpawnablePos(cmdCtx, key); + return new Location(getWorldForCSS(cmdCtx.getSource()), blockPos.getX(), blockPos.getY(), blockPos.getZ()); + } + + @Override + public final Location getLocationPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { + Vec3 vecPos = Vec3Argument.getCoordinates(cmdCtx, key).getPosition(cmdCtx.getSource()); + return new Location(getWorldForCSS(cmdCtx.getSource()), vecPos.x(), vecPos.y(), vecPos.z()); + } + @Override public final MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { // We run this to ensure the argument exists/parses properly @@ -264,13 +369,6 @@ public final Object getNBTCompound(CommandContext cmdCtx, String key) - throws CommandSyntaxException { - String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); - return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); - } - @Override public final String getObjectiveCriteria(CommandContext cmdCtx, String key) { return ObjectiveCriteriaArgument.getCriteria(cmdCtx, key).getName(); @@ -291,18 +389,6 @@ public final Player getPlayer(CommandContext cmdCtx, String } } - @Override - public final Rotation getRotation(CommandContext cmdCtx, String key) { - Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); - return new Rotation(rotation.y, rotation.x); - } - - @Override - public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { - String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); - return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); - } - @Override public final int getTime(CommandContext cmdCtx, String key) { return cmdCtx.getArgument(key, Integer.class); From 84b2461f125005759b1df013b783fdea45493086 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:21:10 +0200 Subject: [PATCH 09/13] Make compileNMSCommon.sh more compact --- compileNMSCommon.sh | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index 00f0d1d436..cf60e4bbda 100644 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -1,23 +1,13 @@ -echo "Compiling NMS_Common for Spigot 1.20 and 1.20.1..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 --quiet - -echo "Compiling NMS_Common for Spigot 1.20.2..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 --quiet - -echo "Compiling NMS_Common for Spigot 1.20.3 and 1.20.4..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 --quiet - -echo "Compiling NMS_Common for Spigot 1.20.5 and 1.20.6..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 --quiet - -echo "Compiling NMS_Common for Spigot 1.21 and 1.21.1..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 --quiet - -echo "Compiling NMS_Common for Spigot 1.21.2 and 1.21.3..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 --quiet - -echo "Compiling NMS_Common for Spigot 1.21.4..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 --quiet - -echo "Compiling NMS_Common for Spigot 1.21.5..." -mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 --quiet \ No newline at end of file +compileVersion() { + echo "Compiling NMS_Common for Spigot $1..." + mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,"$2" --quiet +} + +compileVersion "1.20 and 1.20.1" "Spigot_1_20_R1" +compileVersion "1.20.2" "Spigot_1_20_R2" +compileVersion "1.20.3 and 1.20.4" "Spigot_1_20_R3" +compileVersion "1.20.5 and 1.20.6" "Spigot_1_20_R4" +compileVersion "1.21 and 1.21.1" "Spigot_1_21_R1" +compileVersion "1.21.2 and 1.21.3" "Spigot_1_21_R2" +compileVersion "1.21.4" "Spigot_1_21_R3" +compileVersion "1.21.5" "Spigot_1_21_R4" \ No newline at end of file From 43e292913b86beab93e32b8077b7d1c0f2a28860 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:38:15 +0200 Subject: [PATCH 10/13] There's no need to have this static --- .../src/main/java/dev/jorel/commandapi/nms/NMS_Common.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 4d5afdbe57..4b76e13c23 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 @@ -32,7 +32,6 @@ import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.MathOperation; -import dev.jorel.commandapi.wrappers.Rotation; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.AngleArgument; @@ -71,7 +70,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ColumnPos; import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import org.bukkit.Axis; import org.bukkit.Bukkit; @@ -85,8 +83,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; import java.io.File; import java.io.IOException; @@ -110,7 +106,7 @@ */ public abstract class NMS_Common extends CommandAPIBukkit { - protected static NamespacedKey fromResourceLocation(ResourceLocation key) { + public final NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } From 47e9b669489c699f8676eee986d439d47503d71c Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Fri, 18 Apr 2025 18:52:31 -0400 Subject: [PATCH 11/13] Test comparing NMS_Common bytecode Expand compileNMSCommon.sh script to generate diffs for the bytecode I want to see if `exit 1` in the script makes the GitHub Actions build fail --- .github/workflows/build.yml | 43 +-------- .../commandapi-bukkit-nms-common/pom.xml | 27 ------ compileNMSCommon.sh | 91 ++++++++++++++++++- 3 files changed, 91 insertions(+), 70 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef45d4bf57..2f27dd07ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,47 +42,8 @@ jobs: ### Check NMS_Common compiles against all compatible Minecraft versions - - name: Compile NMS_Common for 1.20 and 1.20.1 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R1 - - - name: Compile NMS_Common for 1.20.2 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R2 - - - name: Compile NMS_Common for 1.20.3 and 1.20.4 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R3 - - - name: Compile NMS_Common for 1.20.5 and 1.20.6 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_20_R4 - - - name: Compile NMS_Common for 1.21 and 1.21.1 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R1 - - - name: Compile NMS_Common for 1.21.2 and 1.21.3 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R2 - - - name: Compile NMS_Common for 1.21.4 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R3 - - - name: Compile NMS_Common for 1.21.5 - run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 - - # - name: validate version-specific dependencies (nms-common) - # run: | - # nms_common_path="commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/target/classes/dev/jorel/commandapi/nms/NMS_Common.class" - # if ! command -v javap &> /dev/null - # then - # echo "javap could not be found, skipping NMS Common validation check" - # exit - # else - # javapcommand=$(javap -v $nms_common_path | grep -E '#[0-9]+ = Class ' | cut -c 46- | sort | grep 'org/bukkit/craftbukkit') - # if [[ -n "$javapcommand" ]]; then - # echo "NMS Common has version-specific dependencies!" - # echo $javapcommand - # exit 1 - # else - # echo "NMS Common has no version-specific dependencies :)" - # fi - # fi + - name: Check NMS_Common compiles identically for all versions + run: ./compileNMSCommon.sh ### Bukkit tests across all NMS versions ### # Dev note: Yes, I know I could put this under one run section, but it's a million times easier diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index b7e6bf71db..d6d1f05335 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -140,9 +140,6 @@ 1.21.5-R0.1-SNAPSHOT 1.21.5-R0.1-SNAPSHOT - - ${project.basedir}/target/1.21.5 -
Spigot_1_21_R3 @@ -151,9 +148,6 @@ 1.21.4-R0.1-SNAPSHOT 1.21.4-R0.1-SNAPSHOT - - ${project.basedir}/target/1.21.4 - Spigot_1_21_R2 @@ -162,9 +156,6 @@ 1.21.3-R0.1-SNAPSHOT 1.21.3-R0.1-SNAPSHOT - - ${project.basedir}/target/1.21.3 - Spigot_1_21_R1 @@ -173,9 +164,6 @@ 1.21.1-R0.1-SNAPSHOT 1.21.1-R0.1-SNAPSHOT - - ${project.basedir}/target/1.21.1 - Spigot_1_20_R4 @@ -184,9 +172,6 @@ 1.20.6-R0.1-SNAPSHOT 1.20.6-R0.1-SNAPSHOT - - ${project.basedir}/target/1.20.6 - Spigot_1_20_R3 @@ -195,9 +180,6 @@ 1.20.4-R0.1-SNAPSHOT 1.20.4-R0.1-SNAPSHOT - - ${project.basedir}/target/1.20.4 - Spigot_1_20_R2 @@ -206,9 +188,6 @@ 1.20.2-R0.1-SNAPSHOT 1.20.2-R0.1-SNAPSHOT - - ${project.basedir}/target/1.20.2 - Spigot_1_20_R1 @@ -217,12 +196,6 @@ 1.20.1-R0.1-SNAPSHOT 1.20.1-R0.1-SNAPSHOT - - ${project.basedir}/target/1.20.1 - - - - Spigot_1_20_R1_Release true diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index cf60e4bbda..72edbc8acd 100644 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -1,6 +1,70 @@ +# Make sure we are running at the script's location (CommandAPI root) +cd "${0%/*}" || (echo "cd failed" && exit) + +BUILD_DIR="./commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/target" +DIFF_DIR="./nmsCommonDiff" +NEW_JAR="./newJar.jar" +NEW_CLASSES="./newClasses" +PREV_CLASSES="./prevClasses" + +# Refresh diff directory +rm -rf "$DIFF_DIR" +mkdir -p "$DIFF_DIR" + compileVersion() { echo "Compiling NMS_Common for Spigot $1..." - mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,"$2" --quiet + + mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true \ + -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,"$2" --quiet + + # Find the spigot-mapped jar + for jar in "$BUILD_DIR"/CommandAPI-*.jar; do + if [[ "$jar" != *"original-"* && "$jar" == *").jar" ]]; then + echo "Found JAR: $jar" + cp "$jar" "$NEW_JAR" + break + fi + done + + if [ ! -e "$NEW_JAR" ]; then + # Couldn't find the jar with NMS_Common, so compilation failed + echo "Failed to compile $1" + + # Clean up + rm -rf "$PREV_CLASSES" + # Fail + exit 1 + fi + + # Unzip jar so we can view the classes + unzip -q "$NEW_JAR" -d "$NEW_CLASSES" + rm "$NEW_JAR" + + # Replace all class files with their bytecode so we can compare by text + find "$NEW_CLASSES" -name "*.class" | while read -r class; do + class_name="${class%.class}" + echo "Getting bytecode for $class_name" + + javap -c -p "$class" > "$class_name.txt" + rm "$class" + done + + if [ -d "$PREV_CLASSES" ]; then + # Generate diff against the previous version to detect changes + diff_file="$DIFF_DIR/$1.diff" + git diff --no-index "$PREV_CLASSES" "$NEW_CLASSES" > "$diff_file" + + if [ ! -s "$diff_file" ]; then + # diff file is empty, so no problems here + echo "No changes in $1" + rm "$diff_file" + fi + + rm -r "$PREV_CLASSES" + fi + + # Make new classes the previous classes for the next try + mv "$NEW_CLASSES/" "$PREV_CLASSES/" } compileVersion "1.20 and 1.20.1" "Spigot_1_20_R1" @@ -10,4 +74,27 @@ compileVersion "1.20.5 and 1.20.6" "Spigot_1_20_R4" compileVersion "1.21 and 1.21.1" "Spigot_1_21_R1" compileVersion "1.21.2 and 1.21.3" "Spigot_1_21_R2" compileVersion "1.21.4" "Spigot_1_21_R3" -compileVersion "1.21.5" "Spigot_1_21_R4" \ No newline at end of file +compileVersion "1.21.5" "Spigot_1_21_R4" + +# Clean up +rm -rf "$PREV_CLASSES" + +# Report if any diff was found +if [ -z "$(ls -A "$DIFF_DIR")" ]; then + # Diff directory is empty, no problems :) + echo "No differences detected" + + rm -r "$DIFF_DIR" +else + echo "Differences found!" + + for diff in "$DIFF_DIR"/*; do + echo "=== $diff ===" + cat "$diff" + done + + echo "Inspect the $DIFF_DIR directory for details" + + # fail + exit 1 +fi \ No newline at end of file From 2144b716e1929fd1b3c0e4a89ea297e9ebd50a7a Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:04:44 -0400 Subject: [PATCH 12/13] Fix indentation and maybe make script runnable by GH Actions --- compileNMSCommon.sh | 54 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index 72edbc8acd..d24540960e 100644 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Make sure we are running at the script's location (CommandAPI root) cd "${0%/*}" || (echo "cd failed" && exit) @@ -12,12 +14,12 @@ rm -rf "$DIFF_DIR" mkdir -p "$DIFF_DIR" compileVersion() { - echo "Compiling NMS_Common for Spigot $1..." + echo "Compiling NMS_Common for Spigot $1..." - mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true \ - -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,"$2" --quiet + mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true \ + -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,"$2" --quiet - # Find the spigot-mapped jar + # Find the spigot-mapped jar for jar in "$BUILD_DIR"/CommandAPI-*.jar; do if [[ "$jar" != *"original-"* && "$jar" == *").jar" ]]; then echo "Found JAR: $jar" @@ -27,13 +29,13 @@ compileVersion() { done if [ ! -e "$NEW_JAR" ]; then - # Couldn't find the jar with NMS_Common, so compilation failed - echo "Failed to compile $1" + # Couldn't find the jar with NMS_Common, so compilation failed + echo "Failed to compile $1" - # Clean up - rm -rf "$PREV_CLASSES" - # Fail - exit 1 + # Clean up + rm -rf "$PREV_CLASSES" + # Fail + exit 1 fi # Unzip jar so we can view the classes @@ -42,25 +44,25 @@ compileVersion() { # Replace all class files with their bytecode so we can compare by text find "$NEW_CLASSES" -name "*.class" | while read -r class; do - class_name="${class%.class}" - echo "Getting bytecode for $class_name" + class_name="${class%.class}" + echo "Getting bytecode for $class_name" - javap -c -p "$class" > "$class_name.txt" - rm "$class" + javap -c -p "$class" > "$class_name.txt" + rm "$class" done if [ -d "$PREV_CLASSES" ]; then - # Generate diff against the previous version to detect changes - diff_file="$DIFF_DIR/$1.diff" - git diff --no-index "$PREV_CLASSES" "$NEW_CLASSES" > "$diff_file" - - if [ ! -s "$diff_file" ]; then - # diff file is empty, so no problems here - echo "No changes in $1" - rm "$diff_file" - fi - - rm -r "$PREV_CLASSES" + # Generate diff against the previous version to detect changes + diff_file="$DIFF_DIR/$1.diff" + git diff --no-index "$PREV_CLASSES" "$NEW_CLASSES" > "$diff_file" + + if [ ! -s "$diff_file" ]; then + # diff file is empty, so no problems here + echo "No changes in $1" + rm "$diff_file" + fi + + rm -r "$PREV_CLASSES" fi # Make new classes the previous classes for the next try @@ -89,7 +91,7 @@ else echo "Differences found!" for diff in "$DIFF_DIR"/*; do - echo "=== $diff ===" + echo "=== $diff ===" cat "$diff" done From 2c12daa0511083be71ace698a738dd5ca8f48934 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:19:07 -0400 Subject: [PATCH 13/13] Actually make script runnable by GH Actions? --- compileNMSCommon.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 compileNMSCommon.sh diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh old mode 100644 new mode 100755