mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-24 11:37:58 +01:00
Implement DifficultyCommand
This commit is contained in:
parent
d422c240cf
commit
4b483bdd96
@ -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()));
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.vavr.control.Try;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameRule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
@ -50,6 +51,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
|
||||
registerAsyncCompletion("commands", this::suggestCommands);
|
||||
registerAsyncCompletion("destinations", this::suggestDestinations);
|
||||
registerStaticCompletion("difficulty", this::suggestDifficulty);
|
||||
registerAsyncCompletion("flags", this::suggestFlags);
|
||||
registerStaticCompletion("gamerules", this::suggestGamerules);
|
||||
registerStaticCompletion("mvconfigs", config.getNodes().getNames());
|
||||
@ -97,6 +99,10 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
.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) {
|
||||
String groupName = context.getConfig("groupName", "");
|
||||
|
||||
@ -106,7 +112,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user