Skip to content
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

Feat: Add 'with' methods to CommandSourceStack #11868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.papermc.paper.command.brigadier;

import com.mojang.brigadier.RedirectModifier;
import com.mojang.brigadier.tree.CommandNode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -48,4 +50,24 @@ public interface CommandSourceStack {
* @return entity that executes this command
*/
@Nullable Entity getExecutor();

/**
* Creates a new CommandSourceStack object with a different location for redirecting commands to other nodes.
*
* @param location The location to create a new CommandSourceStack object with
* @return The newly created CommandSourceStack
* @see #getLocation()
* @see com.mojang.brigadier.builder.ArgumentBuilder#fork(CommandNode, RedirectModifier)
*/
CommandSourceStack withLocation(Location location);

/**
* Creates a new CommandSourceStack object with a different executor for redirecting commands to other nodes.
*
* @param executor The executing entity to create a new CommandSourceStack object with
* @return The newly created CommandSourceStack
* @see #getExecutor()
* @see com.mojang.brigadier.builder.ArgumentBuilder#fork(CommandNode, RedirectModifier)
*/
CommandSourceStack withExecutor(Entity executor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ when if this was fixed on the client, that wouldn't be needed.
Mojira Issue: https://bugs.mojang.com/browse/MC-235045

diff --git a/net/minecraft/commands/CommandSourceStack.java b/net/minecraft/commands/CommandSourceStack.java
index 704a63890a06d793f8ac3452838917e7c7335232..75262c8c9eaecb4a88a94f4076d67119c67a97da 100644
index cf923441da598637be74a5ffa4b4f948e01ff532..cbf32be9235921ebcaca88225120c2ca70a72771 100644
--- a/net/minecraft/commands/CommandSourceStack.java
+++ b/net/minecraft/commands/CommandSourceStack.java
@@ -652,4 +652,20 @@ public class CommandSourceStack implements ExecutionCommandSource<CommandSourceS
@@ -676,4 +676,20 @@ public class CommandSourceStack implements ExecutionCommandSource<CommandSourceS
return this.source.getBukkitSender(this);
}
// CraftBukkit end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@

public CommandSourceStack(
CommandSource source,
@@ -187,6 +_,30 @@
this.chatMessageChainer
);
}
+
+ // Paper start - Expose 'with' functions from the CommandSourceStack
+ @Override
+ public CommandSourceStack withLocation(org.bukkit.Location location) {
+ return this.getLocation().equals(location)
+ ? this
+ : new CommandSourceStack(
+ this.source,
+ new Vec3(location.x(), location.y(), location.z()),
+ new Vec2(location.getPitch(), location.getYaw()),
+ ((org.bukkit.craftbukkit.CraftWorld) location.getWorld()).getHandle(),
+ this.permissionLevel,
+ this.textName,
+ this.displayName,
+ this.server,
+ this.entity,
+ this.silent,
+ this.resultCallback,
+ this.anchor,
+ this.signingContext,
+ this.chatMessageChainer
+ );
+ }
+ // Paper end - Expose 'with' functions from the CommandSourceStack

public CommandSourceStack withRotation(Vec2 rotation) {
return this.rotation.equals(rotation)
@@ -391,9 +_,44 @@

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package io.papermc.paper.command.brigadier;

import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.google.common.base.Preconditions;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.NonNull;
Strokkur424 marked this conversation as resolved.
Show resolved Hide resolved
import org.jspecify.annotations.Nullable;

public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBrigadierCommandSource {

net.minecraft.commands.CommandSourceStack getHandle();

@Override
default @NotNull Location getLocation() {
default @NonNull Location getLocation() {
Vec2 rot = this.getHandle().getRotation();
Vec3 pos = this.getHandle().getPosition();
Level level = this.getHandle().getLevel();
Expand All @@ -24,7 +26,7 @@ public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBriga
}

@Override
@NotNull
@NonNull
default CommandSender getSender() {
return this.getHandle().getBukkitSender();
}
Expand All @@ -40,6 +42,12 @@ default Entity getExecutor() {
return nmsEntity.getBukkitEntity();
}

@Override
default CommandSourceStack withExecutor(@NonNull Entity executor) {
Preconditions.checkNotNull(executor, "Executor cannot be null.");
return this.getHandle().withEntity(((CraftEntity) executor).getHandle());
}

// OLD METHODS
@Override
default org.bukkit.entity.Entity getBukkitEntity() {
Expand Down
Loading