Implement DifficultyCommand

This commit is contained in:
Ben Woo 2023-09-20 11:54:37 +08:00
parent d422c240cf
commit 4b483bdd96
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
2 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1,49 @@
package org.mvplugins.multiverse.core.commands;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import jakarta.inject.Inject;
import org.bukkit.Difficulty;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
@Service
@CommandAlias("mv")
class DifficultyCommand extends MultiverseCommand {
@Inject
DifficultyCommand(@NotNull MVCommandManager commandManager) {
super(commandManager);
}
@Subcommand("difficulty")
@CommandPermission("multiverse.core.difficulty")
@CommandCompletion("@difficulty @mvworlds:scope=both")
@Syntax("<difficulty> [world]")
void onDifficultyCommand(
MVCommandIssuer issuer,
@Syntax("<difficulty>")
@Description("")
Difficulty difficulty,
@Flags("resolve=issuerAware")
@Syntax("[world]")
@Description("")
// TODO: Change to MultiverseWorld
LoadedMultiverseWorld world) {
world.setDifficulty(difficulty)
.onSuccess(w -> issuer.sendInfo("Difficulty set to " + difficulty + " for world " + world.getName()))
.onFailure(failure -> issuer.sendError(failure.getMessage()));
}
}

View File

@ -18,6 +18,7 @@ import com.dumptruckman.minecraft.util.Logging;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import io.vavr.control.Try; import io.vavr.control.Try;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import org.bukkit.Difficulty;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Service;
@ -50,6 +51,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
registerAsyncCompletion("commands", this::suggestCommands); registerAsyncCompletion("commands", this::suggestCommands);
registerAsyncCompletion("destinations", this::suggestDestinations); registerAsyncCompletion("destinations", this::suggestDestinations);
registerStaticCompletion("difficulty", this::suggestDifficulty);
registerAsyncCompletion("flags", this::suggestFlags); registerAsyncCompletion("flags", this::suggestFlags);
registerStaticCompletion("gamerules", this::suggestGamerules); registerStaticCompletion("gamerules", this::suggestGamerules);
registerStaticCompletion("mvconfigs", config.getNodes().getNames()); registerStaticCompletion("mvconfigs", config.getNodes().getNames());
@ -97,6 +99,10 @@ public class MVCommandCompletions extends PaperCommandCompletions {
.suggestDestinations((BukkitCommandIssuer)context.getIssuer(), context.getInput()); .suggestDestinations((BukkitCommandIssuer)context.getIssuer(), context.getInput());
} }
private Collection<String> suggestDifficulty() {
return Arrays.stream(Difficulty.values()).map(Difficulty::name).toList();
}
private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) { private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) {
String groupName = context.getConfig("groupName", ""); String groupName = context.getConfig("groupName", "");
@ -106,7 +112,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
} }
private Collection<String> suggestGamerules() { private Collection<String> suggestGamerules() {
return Arrays.stream(GameRule.values()).map(GameRule::getName).collect(Collectors.toList()); return Arrays.stream(GameRule.values()).map(GameRule::getName).toList();
} }
private Collection<String> suggestMVWorlds(BukkitCommandCompletionContext context) { private Collection<String> suggestMVWorlds(BukkitCommandCompletionContext context) {