forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaperCommandSourceStack.java
More file actions
89 lines (73 loc) · 2.93 KB
/
PaperCommandSourceStack.java
File metadata and controls
89 lines (73 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package io.papermc.paper.command.brigadier;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.google.common.base.Preconditions;
import io.papermc.paper.adventure.PaperAdventure;
import net.kyori.adventure.text.ComponentLike;
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.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
public interface PaperCommandSourceStack extends CommandSourceStack, BukkitBrigadierCommandSource {
net.minecraft.commands.CommandSourceStack getHandle();
@Override
default @NonNull Location getLocation() {
Vec2 rot = this.getHandle().getRotation();
Vec3 pos = this.getHandle().getPosition();
Level level = this.getHandle().getLevel();
return new Location(level.getWorld(), pos.x, pos.y, pos.z, rot.y, rot.x);
}
@Override
default @NonNull CommandSender getSender() {
return this.getHandle().getBukkitSender();
}
@Override
default @Nullable Entity getExecutor() {
net.minecraft.world.entity.Entity nmsEntity = this.getHandle().getEntity();
if (nmsEntity == null) {
return null;
}
return nmsEntity.getBukkitEntity();
}
@Override
default @NonNull CommandSourceStack withExecutor(@NonNull Entity executor) {
Preconditions.checkNotNull(executor, "Executor cannot be null.");
return this.getHandle().withEntity(((CraftEntity) executor).getHandle());
}
@Override
default void sendToTarget(final @NonNull ComponentLike message) {
Preconditions.checkNotNull(message, "message cannot be null.");
this.getHandle().sendSystemMessage(PaperAdventure.asVanilla(message.asComponent()));
}
@Override
default void sendSuccess(final @NonNull ComponentLike message, final boolean allowInformingAdmins) {
Preconditions.checkNotNull(message, "message cannot be null.");
this.getHandle().sendSuccess(() -> PaperAdventure.asVanilla(message.asComponent()), allowInformingAdmins);
}
@Override
default void sendFailure(final @NonNull ComponentLike message) {
Preconditions.checkNotNull(message, "message cannot be null.");
this.getHandle().sendFailure(PaperAdventure.asVanilla(message.asComponent()), false);
}
// OLD METHODS
@Override
default org.bukkit.entity.Entity getBukkitEntity() {
return this.getExecutor();
}
@Override
default org.bukkit.World getBukkitWorld() {
return this.getLocation().getWorld();
}
@Override
default org.bukkit.Location getBukkitLocation() {
return this.getLocation();
}
@Override
default CommandSender getBukkitSender() {
return this.getSender();
}
}