8000 Paper CommandAPI by DerEchtePilz · Pull Request #517 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Paper CommandAPI #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lifecycle event registration
Needs more testing.
  • Loading branch information
DerEchtePilz committed Jun 23, 2025
commit 81d77adc23b092bef1bd945a0d7cbf233a8340d1
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;

// Mojang-Mapped reflection
Expand All @@ -204,9 +205,9 @@ public class NMS_1_20_R4 extends NMS_Common {
private static final SafeVarHandle<BlockInput, CompoundTag> blockInputTag;

// Derived from net.minecraft.commands.Commands;
private final CommandBuildContext commandBuildContext;
private final Supplier<CommandBuildContext> commandBuildContext;

public NMS_1_20_R4(CommandBuildContext commandBuildContext) {
public NMS_1_20_R4(Supplier<CommandBuildContext> commandBuildContext) {
this.commandBuildContext = commandBuildContext;
}

Expand All @@ -224,7 +225,7 @@ public NMS_1_20_R4(CommandBuildContext commandBuildContext) {

@Override
protected CommandBuildContext getCommandBuildContext() {
return commandBuildContext;
return commandBuildContext.get();
}

@Override
Expand All @@ -235,12 +236,12 @@ public ArgumentType<?> _ArgumentAdvancement() {
@Differs(from = "1.20.4", by = "Now needs a command build context")
@Override
public ArgumentType<?> _ArgumentChatComponent() {
return ComponentArgument.textComponent(commandBuildContext);
return ComponentArgument.textComponent(commandBuildContext.get());
}

@Override
public final ArgumentType<?> _ArgumentEnchantment() {
return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT);
}

@Override
Expand All @@ -250,7 +251,7 @@ public ArgumentType<?> _ArgumentRecipe() {

@Override
public final ArgumentType<?> _ArgumentSyntheticBiome() {
return ResourceArgument.resource(commandBuildContext, Registries.BIOME);
return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME);
}

@Override
Expand All @@ -265,7 +266,7 @@ public String[] compatibleVersions() {

private String serializeNMSItemStack(ItemStack is) {
final DataComponentMap patchedMap = PatchedDataComponentMap.fromPatch(PatchedDataComponentMap.EMPTY, is.getComponentsPatch());
return new ItemInput(is.getItemHolder(), patchedMap).serialize(commandBuildContext);
return new ItemInput(is.getItemHolder(), patchedMap).serialize(commandBuildContext.get());
}

@Differs(from = "1.20.4", by = "Everything")
Expand Down Expand Up @@ -953,7 +954,7 @@ public final void reloadDataPacks() {
@Override
public Message generateMessageFromJson(String json) {
// TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here
return Serializer.fromJson(json, commandBuildContext);
return Serializer.fromJson(json, commandBuildContext.get());
}

@SuppressWarnings("unchecked")
Expand All @@ -968,11 +969,11 @@ public <T> T getMinecraftServer() {

@Override
public ArgumentType<?> _ArgumentMobEffect() {
return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT);
}

@Override
public ArgumentType<?> _ArgumentEntitySummon() {
return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;

// Mojang-Mapped reflection
Expand All @@ -210,9 +211,9 @@ public class NMS_1_21_R2 extends NMS_Common {
private static final SafeVarHandle<BlockInput, CompoundTag> blockInputTag;

// Derived from net.minecraft.commands.Commands;
private final CommandBuildContext commandBuildContext;
private final Supplier<CommandBuildContext> commandBuildContext;

public NMS_1_21_R2(CommandBuildContext commandBuildContext) {
public NMS_1_21_R2(Supplier<CommandBuildContext> commandBuildContext) {
this.commandBuildContext = commandBuildContext;
}

Expand Down Expand Up @@ -242,7 +243,7 @@ public NMS_1_21_R2(CommandBuildContext commandBuildContext) {

@Override
protected CommandBuildContext getCommandBuildContext() {
return commandBuildContext;
return commandBuildContext.get();
}

@Differs(from = "1.21.1", by = "New advancement argument implementation")
Expand All @@ -253,12 +254,12 @@ public ArgumentType<?> _ArgumentAdvancement() {

@Override
public ArgumentType<?> _ArgumentChatComponent() {
return ComponentArgument.textComponent(commandBuildContext);
return ComponentArgument.textComponent(commandBuildContext.get());
}

@Override
public final ArgumentType<?> _ArgumentEnchantment() {
return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT);
}

@Differs(from = "1.21.1", by = "New recipe argument implementation")
Expand All @@ -269,7 +270,7 @@ public ArgumentType<?> _ArgumentRecipe() {

@Override
public final ArgumentType<?> _ArgumentSyntheticBiome() {
return ResourceArgument.resource(commandBuildContext, Registries.BIOME);
return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME);
}

@Override
Expand All @@ -284,7 +285,7 @@ public String[] compatibleVersions() {

@Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map")
private String serializeNMSItemStack(ItemStack is) {
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext);
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get());
}

@Override
Expand Down Expand Up @@ -989,7 +990,7 @@ public final void reloadDataPacks() {
@Override
public Message generateMessageFromJson(String json) {
// TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here
return Serializer.fromJson(json, commandBuildContext);
return Serializer.fromJson(json, commandBuildContext.get());
}

@SuppressWarnings("unchecked")
Expand All @@ -1004,12 +1005,12 @@ public <T> T getMinecraftServer() {

@Override
public ArgumentType<?> _ArgumentMobEffect() {
return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT);
}

@Override
public ArgumentType<?> _ArgumentEntitySummon() {
return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;

// Mojang-Mapped reflection
Expand All @@ -216,9 +217,9 @@ public class NMS_1_21_R3 extends NMS_Common {
private static final SafeVarHandle<BlockInput, CompoundTag> blockInputTag;

// Derived from net.minecraft.commands.Commands;
private final CommandBuildContext commandBuildContext;
private final Supplier<CommandBuildContext> commandBuildContext;

public NMS_1_21_R3(CommandBuildContext commandBuildContext) {
public NMS_1_21_R3(Supplier<CommandBuildContext> commandBuildContext) {
this.commandBuildContext = commandBuildContext;
}

Expand Down Expand Up @@ -258,7 +259,7 @@ public NMS_1_21_R3(CommandBuildContext commandBuildContext) {

@Override
protected CommandBuildContext getCommandBuildContext() {
return commandBuildContext;
return commandBuildContext.get();
}

@Differs(from = "1.21.1", by = "New advancement argument implementation")
Expand All @@ -269,12 +270,12 @@ public ArgumentType<?> _ArgumentAdvancement() {

@Override
public ArgumentType<?> _ArgumentChatComponent() {
return ComponentArgument.textComponent(commandBuildContext);
return ComponentArgument.textComponent(commandBuildContext.get());
}

@Override
public final ArgumentType<?> _ArgumentEnchantment() {
return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT);
}

@Differs(from = "1.21.1", by = "New recipe argument implementation")
Expand All @@ -285,7 +286,7 @@ public ArgumentType<?> _ArgumentRecipe() {

@Override
public final ArgumentType<?> _ArgumentSyntheticBiome() {
return ResourceArgument.resource(commandBuildContext, Registries.BIOME);
return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME);
}

@Override
Expand All @@ -300,7 +301,7 @@ public String[] compatibleVersions() {

@Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map")
private String serializeNMSItemStack(ItemStack is) {
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext);
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get());
}

@Override
Expand Down Expand Up @@ -1035,7 +1036,7 @@ public final void reloadDataPacks() {
@Override
public Message generateMessageFromJson(String json) {
// TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here
return Serializer.fromJson(json, commandBuildContext);
return Serializer.fromJson(json, commandBuildContext.get());
}

@SuppressWarnings("unchecked")
Expand All @@ -1050,12 +1051,12 @@ public <T> T getMinecraftServer() {

@Override
public ArgumentType<?> _ArgumentMobEffect() {
return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT);
}

@Override
public ArgumentType<?> _ArgumentEntitySummon() {
return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;

// Mojang-Mapped reflection
Expand All @@ -216,9 +217,9 @@ public class NMS_1_21_R4 extends NMS_Common {
private static final SafeVarHandle<BlockInput, CompoundTag> blockInputTag;

// Derived from net.minecraft.commands.Commands;
private final CommandBuildContext commandBuildContext;
private final Supplier<CommandBuildContext> commandBuildContext;

public NMS_1_21_R4(CommandBuildContext commandBuildContext) {
public NMS_1_21_R4(Supplier<CommandBuildContext> commandBuildContext) {
this.commandBuildContext = commandBuildContext;
}

Expand Down Expand Up @@ -258,7 +259,7 @@ public NMS_1_21_R4(CommandBuildContext commandBuildContext) {

@Override
protected CommandBuildContext getCommandBuildContext() {
return commandBuildContext;
return commandBuildContext.get();
}

@Override
Expand All @@ -268,12 +269,12 @@ public ArgumentType<?> _ArgumentAdvancement() {

@Override
public ArgumentType<?> _ArgumentChatComponent() {
return ComponentArgument.textComponent(commandBuildContext);
return ComponentArgument.textComponent(commandBuildContext.get());
}

@Override
public final ArgumentType<?> _ArgumentEnchantment() {
return ResourceArgument.resource(commandBuildContext, Registries.ENCHANTMENT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT);
}

@Override
Expand All @@ -283,7 +284,7 @@ public ArgumentType<?> _ArgumentRecipe() {

@Override
public final ArgumentType<?> _ArgumentSyntheticBiome() {
return ResourceArgument.resource(commandBuildContext, Registries.BIOME);
return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME);
}

@Override
Expand All @@ -297,7 +298,7 @@ public String[] compatibleVersions() {
};

private String serializeNMSItemStack(ItemStack is) {
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext);
return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get());
}

@Override
Expand Down Expand Up @@ -1028,7 +1029,7 @@ public final void reloadDataPacks() {
@Override
public Message generateMessageFromJson(String json) {
// TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here
return Serializer.fromJson(json, commandBuildContext);
return Serializer.fromJson(json, commandBuildContext.get());
}

@SuppressWarnings("unchecked")
Expand All @@ -1043,11 +1044,11 @@ public <T> T getMinecraftServer() {

@Override
public ArgumentType<?> _ArgumentMobEffect() {
return ResourceArgument.resource(commandBuildContext, Registries.MOB_EFFECT);
return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT);
}

@Override
public ArgumentType<?> _ArgumentEntitySummon() {
return ResourceArgument.resource(commandBuildContext, Registries.ENTITY_TYPE);
return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE);
}
}
Loading
0