--- a/net/minecraft/world/level/block/entity/CommandBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/CommandBlockEntity.java
@@ -15,10 +15,18 @@
 import net.minecraft.world.phys.Vec3;
 
 public class CommandBlockEntity extends BlockEntity {
+
     private boolean powered;
     private boolean auto;
     private boolean conditionMet;
     private final BaseCommandBlock commandBlock = new BaseCommandBlock() {
+        // CraftBukkit start
+        @Override
+        public org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper) {
+            return new org.bukkit.craftbukkit.v1_20_R2.command.CraftBlockCommandSender(wrapper, CommandBlockEntity.this);
+        }
+        // CraftBukkit end
+
         @Override
         public void setCommand(String command) {
             super.setCommand(command);
@@ -27,13 +35,14 @@
 
         @Override
         public ServerLevel getLevel() {
-            return (ServerLevel)CommandBlockEntity.this.level;
+            return (ServerLevel) CommandBlockEntity.this.level;
         }
 
         @Override
         public void onUpdated() {
-            BlockState blockState = CommandBlockEntity.this.level.getBlockState(CommandBlockEntity.this.worldPosition);
-            this.getLevel().sendBlockUpdated(CommandBlockEntity.this.worldPosition, blockState, blockState, 3);
+            BlockState iblockdata = CommandBlockEntity.this.level.getBlockState(CommandBlockEntity.this.worldPosition);
+
+            this.getLevel().sendBlockUpdated(CommandBlockEntity.this.worldPosition, iblockdata, iblockdata, 3);
         }
 
         @Override
@@ -43,8 +52,9 @@
 
         @Override
         public CommandSourceStack createCommandSourceStack() {
-            Direction direction = CommandBlockEntity.this.getBlockState().getValue(CommandBlock.FACING);
-            return new CommandSourceStack(this, Vec3.atCenterOf(CommandBlockEntity.this.worldPosition), new Vec2(0.0F, direction.toYRot()), this.getLevel(), 2, this.getName().getString(), this.getName(), this.getLevel().getServer(), (Entity)null);
+            Direction enumdirection = (Direction) CommandBlockEntity.this.getBlockState().getValue(CommandBlock.FACING);
+
+            return new CommandSourceStack(this, Vec3.atCenterOf(CommandBlockEntity.this.worldPosition), new Vec2(0.0F, enumdirection.toYRot()), this.getLevel(), 2, this.getName().getString(), this.getName(), this.getLevel().getServer(), (Entity) null);
         }
 
         @Override
@@ -97,17 +107,19 @@
     }
 
     public void setAutomatic(boolean auto) {
-        boolean bl = this.auto;
+        boolean flag1 = this.auto;
+
         this.auto = auto;
-        if (!bl && auto && !this.powered && this.level != null && this.getMode() != CommandBlockEntity.Mode.SEQUENCE) {
+        if (!flag1 && auto && !this.powered && this.level != null && this.getMode() != CommandBlockEntity.Mode.SEQUENCE) {
             this.scheduleTick();
         }
 
     }
 
     public void onModeSwitch() {
-        CommandBlockEntity.Mode mode = this.getMode();
-        if (mode == CommandBlockEntity.Mode.AUTO && (this.powered || this.auto) && this.level != null) {
+        CommandBlockEntity.Mode tileentitycommand_type = this.getMode();
+
+        if (tileentitycommand_type == CommandBlockEntity.Mode.AUTO && (this.powered || this.auto) && this.level != null) {
             this.scheduleTick();
         }
 
@@ -115,6 +127,7 @@
 
     private void scheduleTick() {
         Block block = this.getBlockState().getBlock();
+
         if (block instanceof CommandBlock) {
             this.markConditionMet();
             this.level.scheduleTick(this.worldPosition, block, 1);
@@ -129,10 +142,12 @@
     public boolean markConditionMet() {
         this.conditionMet = true;
         if (this.isConditional()) {
-            BlockPos blockPos = this.worldPosition.relative(this.level.getBlockState(this.worldPosition).getValue(CommandBlock.FACING).getOpposite());
-            if (this.level.getBlockState(blockPos).getBlock() instanceof CommandBlock) {
-                BlockEntity blockEntity = this.level.getBlockEntity(blockPos);
-                this.conditionMet = blockEntity instanceof CommandBlockEntity && ((CommandBlockEntity)blockEntity).getCommandBlock().getSuccessCount() > 0;
+            BlockPos blockposition = this.worldPosition.relative(((Direction) this.level.getBlockState(this.worldPosition).getValue(CommandBlock.FACING)).getOpposite());
+
+            if (this.level.getBlockState(blockposition).getBlock() instanceof CommandBlock) {
+                BlockEntity tileentity = this.level.getBlockEntity(blockposition);
+
+                this.conditionMet = tileentity instanceof CommandBlockEntity && ((CommandBlockEntity) tileentity).getCommandBlock().getSuccessCount() > 0;
             } else {
                 this.conditionMet = false;
             }
@@ -142,24 +157,21 @@
     }
 
     public CommandBlockEntity.Mode getMode() {
-        BlockState blockState = this.getBlockState();
-        if (blockState.is(Blocks.COMMAND_BLOCK)) {
-            return CommandBlockEntity.Mode.REDSTONE;
-        } else if (blockState.is(Blocks.REPEATING_COMMAND_BLOCK)) {
-            return CommandBlockEntity.Mode.AUTO;
-        } else {
-            return blockState.is(Blocks.CHAIN_COMMAND_BLOCK) ? CommandBlockEntity.Mode.SEQUENCE : CommandBlockEntity.Mode.REDSTONE;
-        }
+        BlockState iblockdata = this.getBlockState();
+
+        return iblockdata.is(Blocks.COMMAND_BLOCK) ? CommandBlockEntity.Mode.REDSTONE : (iblockdata.is(Blocks.REPEATING_COMMAND_BLOCK) ? CommandBlockEntity.Mode.AUTO : (iblockdata.is(Blocks.CHAIN_COMMAND_BLOCK) ? CommandBlockEntity.Mode.SEQUENCE : CommandBlockEntity.Mode.REDSTONE));
     }
 
     public boolean isConditional() {
-        BlockState blockState = this.level.getBlockState(this.getBlockPos());
-        return blockState.getBlock() instanceof CommandBlock ? blockState.getValue(CommandBlock.CONDITIONAL) : false;
+        BlockState iblockdata = this.level.getBlockState(this.getBlockPos());
+
+        return iblockdata.getBlock() instanceof CommandBlock ? (Boolean) iblockdata.getValue(CommandBlock.CONDITIONAL) : false;
     }
 
     public static enum Mode {
-        SEQUENCE,
-        AUTO,
-        REDSTONE;
+
+        SEQUENCE, AUTO, REDSTONE;
+
+        private Mode() {}
     }
 }
