Fix world argument not selecting own world in setdifficulty
Fixes part of
@@ -17,14 +17,11 @@ import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.CommandElement;
import org.spongepowered.api.command.args.GenericArguments;
-import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.util.annotation.NonnullByDefault;
import org.spongepowered.api.world.difficulty.Difficulty;
import org.spongepowered.api.world.storage.WorldProperties;
-import java.util.Optional;
-
@NoModifiers
@NonnullByDefault
@Permissions(prefix = "world", suggestedLevel = SuggestedLevel.ADMIN)
@@ -45,25 +42,12 @@ public class SetDifficultyWorldCommand extends AbstractCommand<CommandSource> {
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
Difficulty difficultyInput = args.<Difficulty>getOne(difficulty).get();
- Optional<WorldProperties> optWorldProperties = args.getOne(world);
+ WorldProperties worldProperties = getWorldFromUserOrArgs(src, this.world, args);
- if (optWorldProperties.isPresent()) {
- optWorldProperties.get().setDifficulty(difficultyInput);
- src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setdifficulty.success",
- optWorldProperties.get().getWorldName(),
- Util.getTranslatableIfPresent(difficultyInput)));
- } else {
- if (src instanceof Player) {
- Player player = (Player) src;
- player.getWorld().getProperties().setDifficulty(difficultyInput);
+ worldProperties.setDifficulty(difficultyInput);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setdifficulty.success",
- optWorldProperties.get().getWorldName(),
+ worldProperties.getWorldName(),
Util.getTranslatableIfPresent(difficultyInput)));
- } else {
- src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.player"));
- return CommandResult.empty();
- }
- }
return CommandResult.success();
}
