package io.github.aquerr.eaglefactions.commands;

import com.flowpowered.noise.module.combiner.Power;
import io.github.aquerr.eaglefactions.EagleFactions;
import io.github.aquerr.eaglefactions.PluginInfo;
import io.github.aquerr.eaglefactions.services.PowerService;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.math.BigDecimal;

public class SetPowerCommand implements CommandExecutor
{
    @Override
    public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
    {
        Player selectedPlayer = context.<Player>getOne("player").get();
        BigDecimal power = context.<BigDecimal>getOne("power").get();

        if(source instanceof Player)
        {
            Player player = (Player)source;

            if(EagleFactions.AdminList.contains(player.getUniqueId().toString()))
            {
                if(selectedPlayer != null)
                {
                    PowerService.setPower(selectedPlayer.getUniqueId(), power);

                    player.sendMessage(Text.of(PluginInfo.PluginPrefix, TextColors.GREEN, "Player's power has been changed!"));
                    return CommandResult.success();
                }
                else
                {
                    player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "There is no such player."));
                }
            }
            else
            {
                player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You need to toggle faction admin mode to do this!"));
            }
        }
        else
        {
            source.sendMessage (Text.of (PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
        }

        return CommandResult.success();
    }
}

@@ -715,16 +715,43 @@
 Decimal;
+%0Aimport java.util.Optional;
 %0A%0Apublic
@@ -933,22 +933,32 @@
         
+Optional%3C
 Player
+%3E
  selecte
@@ -999,22 +999,16 @@
 player%22)
-.get()
 ;%0A      
@@ -1009,16 +1009,25 @@
         
+Optional%3C
 BigDecim
@@ -1028,16 +1028,17 @@
 gDecimal
+%3E
  power =
@@ -1077,14 +1077,8 @@
 er%22)
-.get()
 ;%0A%0A 
@@ -1317,32 +1317,100 @@
               %7B%0A
+                    if(power.isPresent())%0A                    %7B%0A    
                 
@@ -1446,24 +1446,30 @@
 ectedPlayer.
+get().
 getUniqueId(
@@ -1476,20 +1476,30 @@
 ), power
-);%0A%0A
+.get());%0A%0A    
         
@@ -1630,32 +1630,36 @@
                 
+    
 return CommandRe
@@ -1670,24 +1670,116 @@
 .success();%0A
+                    %7D%0A                    else%0A                    %7B%0A%0A                    %7D%0A
             

Add optionals to SetPowerCommand's arguments