diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 7ad5a875b9..2f27dd07ee 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -40,35 +40,10 @@ 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: |
- 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;
-
- # - 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
+ ### Check NMS_Common compiles against all compatible Minecraft versions
+
+ - 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/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 0b5737ff94..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
@@ -20,63 +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.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;
@@ -88,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;
@@ -97,19 +44,45 @@
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.Rotation;
+import dev.jorel.commandapi.wrappers.ScoreboardSlot;
+import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.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.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;
@@ -159,6 +132,61 @@
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 org.bukkit.scoreboard.Objective;
+import org.bukkit.scoreboard.Team;
+
+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
/**
@@ -169,7 +197,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_Common {
private static final SafeVarHandle> helpMapTopics;
private static final Field entitySelectorUsesSelector;
@@ -196,18 +224,19 @@ public class NMS_1_20_R2 extends NMS_CommonWithFunctions {
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
- public final ArgumentType> _ArgumentBlockPredicate() {
- return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentAdvancement() {
+ return ResourceLocationArgument.id();
}
@Override
- public final ArgumentType> _ArgumentBlockState() {
- return BlockStateArgument.block(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentChatComponent() {
+ return ComponentArgument.textComponent();
}
@Override
@@ -216,29 +245,8 @@ public final ArgumentType> _ArgumentEnchantment() {
}
@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);
+ public ArgumentType> _ArgumentRecipe() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -267,10 +275,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();
@@ -278,12 +286,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction commandFunct
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);
@@ -294,6 +296,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();
@@ -323,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());
@@ -340,6 +340,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();
@@ -406,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);
@@ -434,6 +438,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);
@@ -472,12 +498,6 @@ 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);
@@ -485,21 +505,20 @@ public final Location2D getLocation2DPrecise(CommandContext
}
@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());
+ public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) {
+ ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
+ return new CraftLootTable(fromResourceLocation(resourceLocation), this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
}
@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());
+ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) {
+ return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key));
}
@Override
- public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) {
- ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
- return new CraftLootTable(fromResourceLocation(resourceLocation), this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
+ 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")
@@ -586,11 +605,28 @@ 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());
}
+ @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 extends CommandSender> getSenderForCommand(CommandContext cmdCtx, boolean isNative) {
CommandSourceStack css = cmdCtx.getSource();
@@ -715,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 d7222fb040..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,6 +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;
@@ -184,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
/**
@@ -222,18 +231,19 @@ 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
- public final ArgumentType> _ArgumentBlockPredicate() {
- return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentAdvancement() {
+ return ResourceLocationArgument.id();
}
@Override
- public final ArgumentType> _ArgumentBlockState() {
- return BlockStateArgument.block(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentChatComponent() {
+ return ComponentArgument.textComponent();
}
@Override
@@ -242,29 +252,8 @@ public final ArgumentType> _ArgumentEnchantment() {
}
@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);
+ public ArgumentType> _ArgumentRecipe() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -346,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) {
@@ -365,6 +347,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();
@@ -397,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());
@@ -416,6 +395,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 {
@@ -490,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);
@@ -586,38 +567,27 @@ 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());
+ public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) {
+ ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
+ return new CraftLootTable(fromResourceLocation(resourceLocation),
+ this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
}
@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());
+ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) {
+ return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key));
}
@Override
- public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) {
- ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
- return new CraftLootTable(fromResourceLocation(resourceLocation),
- this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
+ 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")
@@ -697,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());
@@ -848,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 c666e479d0..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,18 +246,14 @@ 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
- public final ArgumentType> _ArgumentBlockPredicate() {
- return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT);
+ protected CommandBuildContext getCommandBuildContext() {
+ return COMMAND_BUILD_CONTEXT;
}
@Override
- public final ArgumentType> _ArgumentBlockState() {
- return BlockStateArgument.block(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentAdvancement() {
+ return ResourceLocationArgument.id();
}
@Differs(from = "1.20.4", by = "Now needs a command build context")
@@ -266,29 +268,8 @@ public final ArgumentType> _ArgumentEnchantment() {
}
@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);
+ public ArgumentType> _ArgumentRecipe() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -388,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) {
@@ -446,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());
@@ -471,6 +437,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 {
@@ -545,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);
@@ -629,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));
@@ -666,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) {
@@ -771,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());
@@ -917,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 1c7e4465ff..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
@@ -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,21 +44,44 @@
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.Rotation;
+import dev.jorel.commandapi.wrappers.ScoreboardSlot;
+import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.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;
-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.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;
@@ -65,7 +92,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;
@@ -95,12 +130,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;
@@ -125,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;
@@ -132,7 +174,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;
@@ -146,7 +195,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_Common {
private static final SafeVarHandle> helpMapTopics;
private static final Field entitySelectorUsesSelector;
@@ -173,18 +222,19 @@ public class NMS_1_20_R1 extends NMS_CommonWithFunctions {
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
- public final ArgumentType> _ArgumentBlockPredicate() {
- return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentAdvancement() {
+ return ResourceLocationArgument.id();
}
@Override
- public final ArgumentType> _ArgumentBlockState() {
- return BlockStateArgument.block(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentChatComponent() {
+ return ComponentArgument.textComponent();
}
@Override
@@ -193,29 +243,8 @@ public final ArgumentType> _ArgumentEnchantment() {
}
@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);
+ public ArgumentType> _ArgumentRecipe() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -244,10 +273,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();
@@ -255,12 +284,6 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction commandFunct
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);
@@ -271,6 +294,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();
@@ -300,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());
@@ -317,6 +338,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();
@@ -387,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);
@@ -415,6 +440,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);
@@ -453,35 +500,28 @@ 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);
}
+ @Differs(from = "1.19.4", by = "Uses MinecraftServer#getLootData instead of MinecraftServer#getLootTables")
@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());
+ public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) {
+ ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
+ return new CraftLootTable(fromResourceLocation(resourceLocation), this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
}
@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());
+ public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) {
+ return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key));
}
- @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) {
- ResourceLocation resourceLocation = ResourceLocationArgument.getId(cmdCtx, key);
- return new CraftLootTable(fromResourceLocation(resourceLocation), this.getMinecraftServer().getLootData().getLootTable(resourceLocation));
+ public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException {
+ String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName();
+ return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName);
}
@Override
@@ -566,11 +606,28 @@ 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));
}
+ @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 extends CommandSender> getSenderForCommand(CommandContext cmdCtx, boolean isNative) {
CommandSourceStack css = cmdCtx.getSource();
@@ -694,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 4738c84f56..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());
@@ -491,6 +447,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 {
@@ -566,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);
@@ -651,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));
@@ -688,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);
@@ -791,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());
@@ -941,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 4b3670d27c..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());
@@ -507,6 +463,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 {
@@ -582,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);
@@ -667,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));
@@ -704,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);
@@ -818,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());
@@ -968,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 d94c804170..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,18 +249,14 @@ 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
- public final ArgumentType> _ArgumentBlockPredicate() {
- return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT);
+ protected CommandBuildContext getCommandBuildContext() {
+ return COMMAND_BUILD_CONTEXT;
}
@Override
- public final ArgumentType> _ArgumentBlockState() {
- return BlockStateArgument.block(COMMAND_BUILD_CONTEXT);
+ public ArgumentType> _ArgumentAdvancement() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -268,29 +270,8 @@ public final ArgumentType> _ArgumentEnchantment() {
}
@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);
+ public ArgumentType> _ArgumentRecipe() {
+ return ResourceLocationArgument.id();
}
@Override
@@ -388,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) {
@@ -445,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());
@@ -469,6 +435,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 {
@@ -544,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);
@@ -629,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));
@@ -666,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);
@@ -768,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());
@@ -915,6 +868,12 @@ public Set