--- a/net/minecraft/server/commands/SummonCommand.java
+++ b/net/minecraft/server/commands/SummonCommand.java
@@ -1,11 +1,12 @@
 package net.minecraft.server.commands;
 
 import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
 import net.minecraft.commands.CommandBuildContext;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.arguments.CompoundTagArgument;
 import net.minecraft.commands.arguments.ResourceArgument;
 import net.minecraft.commands.arguments.coordinates.Vec3Argument;
@@ -20,80 +21,55 @@
 import net.minecraft.world.entity.EntityType;
 import net.minecraft.world.entity.Mob;
 import net.minecraft.world.entity.MobSpawnType;
+import net.minecraft.world.entity.SpawnGroupData;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.phys.Vec3;
 
 public class SummonCommand {
+
     private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.summon.failed"));
     private static final SimpleCommandExceptionType ERROR_DUPLICATE_UUID = new SimpleCommandExceptionType(Component.translatable("commands.summon.failed.uuid"));
     private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(Component.translatable("commands.summon.invalidPosition"));
 
+    public SummonCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext registryAccess) {
-        dispatcher.register(
-            Commands.literal("summon")
-                .requires(source -> source.hasPermission(2))
-                .then(
-                    Commands.argument("entity", ResourceArgument.resource(registryAccess, Registries.ENTITY_TYPE))
-                        .suggests(SuggestionProviders.SUMMONABLE_ENTITIES)
-                        .executes(
-                            context -> spawnEntity(
-                                    context.getSource(),
-                                    ResourceArgument.getSummonableEntityType(context, "entity"),
-                                    context.getSource().getPosition(),
-                                    new CompoundTag(),
-                                    true
-                                )
-                        )
-                        .then(
-                            Commands.argument("pos", Vec3Argument.vec3())
-                                .executes(
-                                    context -> spawnEntity(
-                                            context.getSource(),
-                                            ResourceArgument.getSummonableEntityType(context, "entity"),
-                                            Vec3Argument.getVec3(context, "pos"),
-                                            new CompoundTag(),
-                                            true
-                                        )
-                                )
-                                .then(
-                                    Commands.argument("nbt", CompoundTagArgument.compoundTag())
-                                        .executes(
-                                            context -> spawnEntity(
-                                                    context.getSource(),
-                                                    ResourceArgument.getSummonableEntityType(context, "entity"),
-                                                    Vec3Argument.getVec3(context, "pos"),
-                                                    CompoundTagArgument.getCompoundTag(context, "nbt"),
-                                                    false
-                                                )
-                                        )
-                                )
-                        )
-                )
-        );
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("summon").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("entity", ResourceArgument.resource(registryAccess, Registries.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES).executes((commandcontext) -> {
+            return SummonCommand.spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), ((CommandSourceStack) commandcontext.getSource()).getPosition(), new CompoundTag(), true);
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", Vec3Argument.vec3()).executes((commandcontext) -> {
+            return SummonCommand.spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), Vec3Argument.getVec3(commandcontext, "pos"), new CompoundTag(), true);
+        })).then(net.minecraft.commands.Commands.argument("nbt", CompoundTagArgument.compoundTag()).executes((commandcontext) -> {
+            return SummonCommand.spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), Vec3Argument.getVec3(commandcontext, "pos"), CompoundTagArgument.getCompoundTag(commandcontext, "nbt"), false);
+        })))));
     }
 
     public static Entity createEntity(CommandSourceStack source, Holder.Reference<EntityType<?>> entityType, Vec3 pos, CompoundTag nbt, boolean initialize) throws CommandSyntaxException {
-        BlockPos blockPos = BlockPos.containing(pos);
-        if (!Level.isInSpawnableBounds(blockPos)) {
-            throw INVALID_POSITION.create();
+        BlockPos blockposition = BlockPos.containing(pos);
+
+        if (!Level.isInSpawnableBounds(blockposition)) {
+            throw SummonCommand.INVALID_POSITION.create();
         } else {
-            CompoundTag compoundTag = nbt.copy();
-            compoundTag.putString("id", entityType.key().location().toString());
-            ServerLevel serverLevel = source.getLevel();
-            Entity entity = EntityType.loadEntityRecursive(compoundTag, serverLevel, entityx -> {
-                entityx.moveTo(pos.x, pos.y, pos.z, entityx.getYRot(), entityx.getXRot());
-                return entityx;
+            CompoundTag nbttagcompound1 = nbt.copy();
+
+            nbttagcompound1.putString("id", entityType.key().location().toString());
+            ServerLevel worldserver = source.getLevel();
+            Entity entity = EntityType.loadEntityRecursive(nbttagcompound1, worldserver, (entity1) -> {
+                entity1.moveTo(pos.x, pos.y, pos.z, entity1.getYRot(), entity1.getXRot());
+                entity1.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.COMMAND; // Paper - Entity#getEntitySpawnReason
+                return entity1;
             });
+
             if (entity == null) {
-                throw ERROR_FAILED.create();
+                throw SummonCommand.ERROR_FAILED.create();
             } else {
                 if (initialize && entity instanceof Mob) {
-                    ((Mob)entity)
-                        .finalizeSpawn(source.getLevel(), source.getLevel().getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null);
+                    ((Mob) entity).finalizeSpawn(source.getLevel(), source.getLevel().getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, (SpawnGroupData) null);
                 }
 
-                if (!serverLevel.tryAddFreshEntityWithPassengers(entity)) {
-                    throw ERROR_DUPLICATE_UUID.create();
+                if (!worldserver.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.COMMAND)) { // CraftBukkit - pass a spawn reason of "COMMAND"
+                    throw SummonCommand.ERROR_DUPLICATE_UUID.create();
                 } else {
                     return entity;
                 }
@@ -102,8 +78,11 @@
     }
 
     private static int spawnEntity(CommandSourceStack source, Holder.Reference<EntityType<?>> entityType, Vec3 pos, CompoundTag nbt, boolean initialize) throws CommandSyntaxException {
-        Entity entity = createEntity(source, entityType, pos, nbt, initialize);
-        source.sendSuccess(() -> Component.translatable("commands.summon.success", entity.getDisplayName()), true);
+        Entity entity = SummonCommand.createEntity(source, entityType, pos, nbt, initialize);
+
+        source.sendSuccess(() -> {
+            return Component.translatable("commands.summon.success", entity.getDisplayName());
+        }, true);
         return 1;
     }
 }
