mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 19:12:22 +01:00
05f977e3d1
Adds AsyncPlayerSendCommandsEvent - Allows modifying on a per command basis what command data they see. Adds CommandRegisteredEvent - Allows manipulating the CommandNode to add more children/metadata for the client
109 lines
5.1 KiB
Diff
109 lines
5.1 KiB
Diff
--- a/net/minecraft/commands/CommandSourceStack.java
|
|
+++ b/net/minecraft/commands/CommandSourceStack.java
|
|
@@ -45,8 +45,9 @@
|
|
import net.minecraft.world.level.dimension.DimensionType;
|
|
import net.minecraft.world.phys.Vec2;
|
|
import net.minecraft.world.phys.Vec3;
|
|
+import com.mojang.brigadier.tree.CommandNode; // CraftBukkit
|
|
|
|
-public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider {
|
|
+public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider, com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource { // Paper - Brigadier API
|
|
|
|
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player"));
|
|
public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity"));
|
|
@@ -65,6 +66,8 @@
|
|
private final Vec2 rotation;
|
|
private final CommandSigningContext signingContext;
|
|
private final TaskChainer chatMessageChainer;
|
|
+ public volatile CommandNode currentCommand; // CraftBukkit
|
|
+ public boolean bypassSelectorPermissions = false; // Paper - add bypass for selector permissions
|
|
|
|
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
|
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
|
@@ -169,11 +172,45 @@
|
|
return this.textName;
|
|
}
|
|
|
|
+ // Paper start - Brigadier API
|
|
@Override
|
|
+ public org.bukkit.entity.Entity getBukkitEntity() {
|
|
+ return getEntity() != null ? getEntity().getBukkitEntity() : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.World getBukkitWorld() {
|
|
+ return getLevel() != null ? getLevel().getWorld() : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.Location getBukkitLocation() {
|
|
+ Vec3 pos = getPosition();
|
|
+ org.bukkit.World world = getBukkitWorld();
|
|
+ Vec2 rot = getRotation();
|
|
+ return world != null && pos != null ? new org.bukkit.Location(world, pos.x, pos.y, pos.z, rot != null ? rot.y : 0, rot != null ? rot.x : 0) : null;
|
|
+ }
|
|
+ // Paper end - Brigadier API
|
|
+
|
|
+ @Override
|
|
public boolean hasPermission(int level) {
|
|
+ // CraftBukkit start
|
|
+ CommandNode currentCommand = this.currentCommand;
|
|
+ if (currentCommand != null) {
|
|
+ return this.hasPermission(level, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
return this.permissionLevel >= level;
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ public boolean hasPermission(int i, String bukkitPermission) {
|
|
+ // World is null when loading functions
|
|
+ return ((this.getLevel() == null || !this.getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || this.getBukkitSender().hasPermission(bukkitPermission);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public Vec3 getPosition() {
|
|
return this.worldPosition;
|
|
}
|
|
@@ -302,21 +339,26 @@
|
|
while (iterator.hasNext()) {
|
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
- if (entityplayer.commandSource() != this.source && this.server.getPlayerList().isOp(entityplayer.getGameProfile())) {
|
|
+ if (entityplayer.commandSource() != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit
|
|
entityplayer.sendSystemMessage(ichatmutablecomponent);
|
|
}
|
|
}
|
|
}
|
|
|
|
- if (this.source != this.server && this.server.getGameRules().getBoolean(GameRules.RULE_LOGADMINCOMMANDS)) {
|
|
+ if (this.source != this.server && this.server.getGameRules().getBoolean(GameRules.RULE_LOGADMINCOMMANDS) && !org.spigotmc.SpigotConfig.silentCommandBlocks) { // Spigot
|
|
this.server.sendSystemMessage(ichatmutablecomponent);
|
|
}
|
|
|
|
}
|
|
|
|
public void sendFailure(Component message) {
|
|
+ // Paper start - Add UnknownCommandEvent
|
|
+ this.sendFailure(message, true);
|
|
+ }
|
|
+ public void sendFailure(Component message, boolean withStyle) {
|
|
+ // Paper end - Add UnknownCommandEvent
|
|
if (this.source.acceptsFailure() && !this.silent) {
|
|
- this.source.sendSystemMessage(Component.empty().append(message).withStyle(ChatFormatting.RED));
|
|
+ this.source.sendSystemMessage(withStyle ? Component.empty().append(message).withStyle(ChatFormatting.RED) : message); // Paper - Add UnknownCommandEvent
|
|
}
|
|
|
|
}
|
|
@@ -400,4 +442,10 @@
|
|
public boolean isSilent() {
|
|
return this.silent;
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ public org.bukkit.command.CommandSender getBukkitSender() {
|
|
+ return this.source.getBukkitSender(this);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|