Feat: Add 'with' methods to CommandSourceStack (#11868)

This commit is contained in:
Strokkur24
2025-01-11 22:29:16 +01:00
committed by GitHub
parent c94922514a
commit c2f24e1567
4 changed files with 67 additions and 6 deletions

View File

@@ -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;
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();
@@ -24,7 +26,7 @@ public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBriga
}
@Override
@NotNull
@NonNull
default CommandSender getSender() {
return this.getHandle().getBukkitSender();
}
@@ -40,6 +42,12 @@ public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBriga
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() {