content: package me.alexdevs.solstice.modules.god.commands;
  
  import com.mojang.brigadier.builder.LiteralArgumentBuilder;
  import com.mojang.brigadier.context.CommandContext;
  import com.mojang.brigadier.exceptions.CommandSyntaxException;
  import eu.pb4.placeholders.api.PlaceholderContext;
  import me.alexdevs.solstice.Solstice;
  import me.alexdevs.solstice.api.module.ModCommand;
  import me.alexdevs.solstice.modules.god.GodModule;
  import me.alexdevs.solstice.modules.god.data.GodPlayerData;
  import net.minecraft.commands.CommandSourceStack;
  import net.minecraft.commands.arguments.EntityArgument;
  import net.minecraft.network.chat.Component;
  import net.minecraft.server.level.ServerPlayer;
  import org.jetbrains.annotations.Nullable;
  
  import java.util.List;
  import java.util.Map;
  
  import static net.minecraft.commands.Commands.argument;
  import static net.minecraft.commands.Commands.literal;
  
  public class GodCommand extends ModCommand<GodModule> {
      public GodCommand(GodModule module) {
          super(module);
      }
  
      @Override
      public List<String> getNames() {
          return List.of("god");
      }
  
      @Override
      public LiteralArgumentBuilder<CommandSourceStack> command(String name) {
          return literal(name)
                  .requires(require(3))
                  .executes(context -> execute(context, null))
                  .then(argument("player", EntityArgument.player())
                          .requires(require("others", 3))
                          .executes(context -> execute(context, EntityArgument.getPlayer(context, "player")))
                  );
      }
  
      private int execute(CommandContext<CommandSourceStack> context, @Nullable ServerPlayer player) throws CommandSyntaxException {
          var forOther = player != null;
          if (player == null) {
              player = context.getSource().getPlayerOrException();
          }
  
          var abilities = player.getAbilities();
          abilities.invulnerable = !abilities.invulnerable;
          player.onUpdateAbilities();
  
          var data = Solstice.playerData.get(player).getData(GodPlayerData.class);
          data.invulnerabilityEnabled = abilities.invulnerable;
  
          Component text;
          var sourceContext = PlaceholderContext.of(context.getSource());
          if (forOther) {
              var placeholders = Map.of(
                      "player", player.getDisplayName()
              );
  
              if (abilities.invulnerable) {
                  text = module.locale().get("enabledForOther", sourceContext, placeholders);
              } else {
                  text = module.locale().get("disabledForOther", sourceContext, placeholders);
              }
          } else {
              if (abilities.invulnerable) {
                  text = module.locale().get("enabled", sourceContext);
              } else {
                  text = module.locale().get("disabled", sourceContext);
              }
          }
  
          context.getSource().sendSuccess(() -> text, forOther);
  
          return 1;
      }
  }
  