mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
Feat: Add 'with' methods to CommandSourceStack (#11868)
This commit is contained in:
parent
c94922514a
commit
c2f24e1567
@ -1,5 +1,7 @@
|
|||||||
package io.papermc.paper.command.brigadier;
|
package io.papermc.paper.command.brigadier;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.RedirectModifier;
|
||||||
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -48,4 +50,24 @@ public interface CommandSourceStack {
|
|||||||
* @return entity that executes this command
|
* @return entity that executes this command
|
||||||
*/
|
*/
|
||||||
@Nullable Entity getExecutor();
|
@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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
Mojira Issue: https://bugs.mojang.com/browse/MC-235045
|
||||||
|
|
||||||
diff --git a/net/minecraft/commands/CommandSourceStack.java b/net/minecraft/commands/CommandSourceStack.java
|
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
|
--- a/net/minecraft/commands/CommandSourceStack.java
|
||||||
+++ b/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);
|
return this.source.getBukkitSender(this);
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
@ -18,6 +18,37 @@
|
|||||||
|
|
||||||
public CommandSourceStack(
|
public CommandSourceStack(
|
||||||
CommandSource source,
|
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 @@
|
@@ -391,9 +_,44 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
package io.papermc.paper.command.brigadier;
|
package io.papermc.paper.command.brigadier;
|
||||||
|
|
||||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.Vec2;
|
import net.minecraft.world.phys.Vec2;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jspecify.annotations.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBrigadierCommandSource {
|
public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBrigadierCommandSource {
|
||||||
|
|
||||||
net.minecraft.commands.CommandSourceStack getHandle();
|
net.minecraft.commands.CommandSourceStack getHandle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default @NotNull Location getLocation() {
|
default @NonNull Location getLocation() {
|
||||||
Vec2 rot = this.getHandle().getRotation();
|
Vec2 rot = this.getHandle().getRotation();
|
||||||
Vec3 pos = this.getHandle().getPosition();
|
Vec3 pos = this.getHandle().getPosition();
|
||||||
Level level = this.getHandle().getLevel();
|
Level level = this.getHandle().getLevel();
|
||||||
@ -24,7 +26,7 @@ public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBriga
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
default CommandSender getSender() {
|
default CommandSender getSender() {
|
||||||
return this.getHandle().getBukkitSender();
|
return this.getHandle().getBukkitSender();
|
||||||
}
|
}
|
||||||
@ -40,6 +42,12 @@ public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBriga
|
|||||||
return nmsEntity.getBukkitEntity();
|
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
|
// OLD METHODS
|
||||||
@Override
|
@Override
|
||||||
default org.bukkit.entity.Entity getBukkitEntity() {
|
default org.bukkit.entity.Entity getBukkitEntity() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user