package com.ptsmods.morecommands.commands.server.elevated;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.ptsmods.morecommands.arguments.EnumArgumentType;
import com.ptsmods.morecommands.miscellaneous.Command;
import net.minecraft.command.argument.Vec3ArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;

public class ExplodeCommand extends Command {
    @Override
    public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
        dispatcher.register(literalReqOp("explode").executes(ctx -> execute(ctx, null, 4f, false, Explosion.DestructionType.BREAK, true))
        .then(argument("pos", Vec3ArgumentType.vec3())
                .executes(ctx -> execute(ctx, Vec3ArgumentType.getVec3(ctx, "pos"), 4f, false, Explosion.DestructionType.BREAK, true))
                .then(argument("power", FloatArgumentType.floatArg(0f))
                        .executes(ctx -> execute(ctx, Vec3ArgumentType.getVec3(ctx, "pos"), ctx.getArgument("power", Float.class), false, Explosion.DestructionType.BREAK, true))
                        .then(argument("fire", BoolArgumentType.bool())
                                .executes(ctx -> execute(ctx, Vec3ArgumentType.getVec3(ctx, "pos"), ctx.getArgument("power", Float.class),
                                        ctx.getArgument("fire", Boolean.class), Explosion.DestructionType.BREAK, true))
                                .then(argument("destruct", EnumArgumentType.enumType(Explosion.DestructionType.class, Explosion.DestructionType.values()))
                                        .executes(ctx -> execute(ctx, Vec3ArgumentType.getVec3(ctx, "pos"), ctx.getArgument("power", Float.class),
                                                ctx.getArgument("fire", Boolean.class), EnumArgumentType.getEnum(ctx, "destruct"), true))
                                        .then(argument("launch", BoolArgumentType.bool())
                                                .executes(ctx -> execute(ctx, Vec3ArgumentType.getVec3(ctx, "pos"), ctx.getArgument("power", Float.class),
                                                        ctx.getArgument("fire", Boolean.class), EnumArgumentType.getEnum(ctx, "destruct"), ctx.getArgument("launch", Boolean.class)))))))));
    }

    private int execute(CommandContext<ServerCommandSource> ctx, Vec3d pos, float power, boolean fire, Explosion.DestructionType destruct, boolean launch) {
        if (pos == null) pos = ctx.getSource().getPosition();
        World world = ctx.getSource().getWorld();
        Explosion explosion = world.createExplosion(ctx.getSource().getEntity() != null && !launch ? ctx.getSource().getEntity() : null, pos.getX(), pos.getY(), pos.getZ(), power, fire, destruct);
        explosion.affectWorld(true);
        return explosion.getAffectedBlocks().size();
    }
}

@@ -803,16 +803,33 @@
 xplode%22)
+%0A                
 .execute
@@ -899,32 +899,40 @@
 e.BREAK, true))%0A
+        
         .then(ar
@@ -978,32 +978,40 @@
                 
+      
+  
 .executes(ctx -%3E
@@ -1121,32 +1121,40 @@
                 
+        
 .then(argument(%22
@@ -1209,32 +1209,40 @@
                 
+     
+   
 .executes(ctx -%3E
@@ -1395,32 +1395,40 @@
                 
+        
 .then(argument(%22
@@ -1483,32 +1483,40 @@
                 
+    
+    
 .executes(ctx -%3E
@@ -1638,32 +1638,40 @@
                 
+        
 ctx.getArgument(
@@ -1758,32 +1758,40 @@
                 
+   
+     
 .then(argument(%22
@@ -1929,32 +1929,40 @@
                 
+        
 .executes(ctx -%3E
@@ -2092,32 +2092,40 @@
                 
+  
+      
 ctx.getArgument(
@@ -2230,32 +2230,40 @@
                 
+        
 .then(argument(%22
@@ -2336,32 +2336,40 @@
                 
+ 
+       
 .executes(ctx -%3E
@@ -2451,32 +2451,40 @@
 , Float.class),%0A
+        
                 

Fix explode formatting