mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 12:31:59 +01:00
Test implement new flag system.
This commit is contained in:
parent
03d1b3682d
commit
b3b8a5ed73
@ -17,7 +17,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.MVFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.NoValueFlag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.OptionalFlag;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
@ -90,7 +90,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
return flagsKeys;
|
||||
}
|
||||
|
||||
Flag<?> flag = MVFlags.getByKey(mostRecentArg);
|
||||
Flag<?> flag = Flags.getByKey(mostRecentArg);
|
||||
if (flag == null) {
|
||||
flagsKeys.removeAll(args);
|
||||
return flagsKeys;
|
||||
|
@ -19,9 +19,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.contexts.PlayerWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import com.onarandombox.MultiverseCore.enums.WorldValidationResult;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -8,7 +8,6 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools;
|
||||
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.ConditionFailedException;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.PaperCommandContexts;
|
||||
import co.aikar.commands.annotation.Values;
|
||||
@ -23,19 +22,15 @@ import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commands.EnvironmentCommand;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.WorldValidationResult;
|
||||
import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import sun.management.Sensor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
@ -4,7 +4,7 @@ import co.aikar.commands.InvalidCommandArgument;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.MVFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flags;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -44,7 +44,7 @@ public class WorldFlags {
|
||||
|
||||
Flag<?> currentFlag = null;
|
||||
for (String arg : args) {
|
||||
Flag<?> flag = MVFlags.getByKey(arg);
|
||||
Flag<?> flag = Flags.getByKey(arg);
|
||||
if (currentFlag == null) {
|
||||
if (flag == null) {
|
||||
throw new InvalidCommandArgument(String.format("'%s' is not a valid flag key.", arg));
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public abstract class Flag<T> {
|
||||
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
MVFlags.flagMap.put(this.key, this);
|
||||
Flags.flagMap.put(this.key, this);
|
||||
}
|
||||
|
||||
public abstract @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin);
|
||||
|
@ -18,7 +18,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class MVFlags {
|
||||
public class Flags {
|
||||
|
||||
protected static final Map<String, Flag<?>> flagMap = new HashMap<>();
|
||||
|
@ -0,0 +1,67 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandFlag<T> {
|
||||
|
||||
protected final String name;
|
||||
protected final String identifier;
|
||||
protected final Class<T> type;
|
||||
protected final ValueRequirement valueRequirement;
|
||||
protected final List<String> aliases;
|
||||
|
||||
public CommandFlag(String name, String identifier, Class<T> type, ValueRequirement valueRequirement) {
|
||||
this.name = name;
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
this.valueRequirement = valueRequirement;
|
||||
this.aliases = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
public Class<T> getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public ValueRequirement getValueRequirement() {
|
||||
return this.valueRequirement;
|
||||
}
|
||||
|
||||
public Collection<String> getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
CommandFlag<T> addAlias(String alias) {
|
||||
this.aliases.add(alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract Collection<String> suggestValue();
|
||||
|
||||
public abstract T getValue(@NotNull String input) throws FlagParseFailedException;
|
||||
|
||||
public T getValue() throws FlagParseFailedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getDefaultValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum ValueRequirement {
|
||||
NONE,
|
||||
OPTIONAL,
|
||||
REQUIRED
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FlagGroup {
|
||||
|
||||
public static FlagGroup of(CommandFlag<?>...flags) {
|
||||
return new FlagGroup(flags);
|
||||
}
|
||||
|
||||
private final Set<CommandFlag<?>> flags;
|
||||
private final Map<String, CommandFlag<?>> keyFlagMap;
|
||||
|
||||
private FlagGroup(CommandFlag<?>[] commandFlags) {
|
||||
this.flags = new HashSet<>();
|
||||
this.keyFlagMap = new HashMap<>();
|
||||
for (CommandFlag<?> flag : commandFlags) {
|
||||
addFlag(flag);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFlag(CommandFlag<?> flag) {
|
||||
this.flags.add(flag);
|
||||
this.keyFlagMap.put(flag.getName(), flag);
|
||||
for (String flagAlias : flag.getAliases()) {
|
||||
this.keyFlagMap.put(flagAlias, flag);
|
||||
}
|
||||
}
|
||||
|
||||
public CommandFlag<?> getByKey(String key) {
|
||||
return this.keyFlagMap.get(key);
|
||||
}
|
||||
|
||||
public Collection<CommandFlag<?>> getFlags() {
|
||||
return this.flags;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
|
||||
public class FlagParseFailedException extends InvalidCommandArgument {
|
||||
|
||||
public FlagParseFailedException() {
|
||||
}
|
||||
|
||||
public FlagParseFailedException(String message, Object...replacements) {
|
||||
super(String.format(message, replacements), true);
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.onarandombox.MultiverseCore.commandTools.flags.CommandFlag.ValueRequirement;
|
||||
|
||||
public class FlagResult {
|
||||
|
||||
public static FlagResult parse(String[] args, FlagGroup flagGroup) throws FlagParseFailedException {
|
||||
FlagResult flagResult = new FlagResult();
|
||||
|
||||
// First arg must be a flag.
|
||||
CommandFlag<?> currentFlag = flagGroup.getByKey(args[0]);
|
||||
boolean completed = false;
|
||||
|
||||
// Parse the arguments.
|
||||
for (int i = 1, argsLength = args.length; i <= argsLength; i++) {
|
||||
// Don't allow null flag obviously.
|
||||
if (currentFlag == null) {
|
||||
throw new FlagParseFailedException("%s is not a valid flag.", args[i-1]);
|
||||
}
|
||||
// THis ensures that flag is not null during final parse.
|
||||
if (i >= argsLength) {
|
||||
break;
|
||||
}
|
||||
|
||||
CommandFlag<?> nextFlag = flagGroup.getByKey(args[i]);
|
||||
|
||||
switch (currentFlag.getValueRequirement()) {
|
||||
case NONE:
|
||||
// Arg must be a flag key.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
currentFlag = nextFlag;
|
||||
break;
|
||||
case OPTIONAL:
|
||||
// Arg can be a flag key or value.
|
||||
if (nextFlag != null) {
|
||||
// It's a key.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
currentFlag = nextFlag;
|
||||
break;
|
||||
}
|
||||
// It's a value.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(args[i]), true);
|
||||
if (i == argsLength - 1) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
currentFlag = flagGroup.getByKey(args[++i]);
|
||||
break;
|
||||
case REQUIRED:
|
||||
// Arg must be a flag value.
|
||||
if (nextFlag != null) {
|
||||
// It's a key.
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.",
|
||||
currentFlag.getName(), currentFlag.getIdentifier());
|
||||
}
|
||||
// It's a value.
|
||||
flagResult.add(currentFlag, currentFlag.getValue(args[i]), true);
|
||||
if (i == argsLength - 1) {
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
currentFlag = flagGroup.getByKey(args[++i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse final flag.
|
||||
if (!completed) {
|
||||
if (currentFlag.getValueRequirement() == ValueRequirement.REQUIRED) {
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.",
|
||||
currentFlag.getName(), currentFlag.getIdentifier());
|
||||
}
|
||||
flagResult.add(currentFlag, currentFlag.getValue(), false);
|
||||
}
|
||||
|
||||
return flagResult;
|
||||
}
|
||||
|
||||
private final Map<CommandFlag<?>, SingleFlagResult<?>> resultMap;
|
||||
|
||||
public FlagResult() {
|
||||
resultMap = new HashMap<>();
|
||||
}
|
||||
|
||||
private void add(CommandFlag<?> flag, Object value, boolean fromInput) {
|
||||
resultMap.put(flag, new SingleFlagResult<>(value, fromInput));
|
||||
}
|
||||
|
||||
public <T> T getValue(CommandFlag<T> flag) {
|
||||
SingleFlagResult<?> result = resultMap.get(flag);
|
||||
if (result == null) {
|
||||
return flag.getDefaultValue();
|
||||
}
|
||||
return (T) result.value;
|
||||
}
|
||||
|
||||
public boolean isByUserInput(CommandFlag<?> flag) {
|
||||
SingleFlagResult<?> result = resultMap.get(flag);
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
return result.fromInput;
|
||||
}
|
||||
|
||||
public boolean isDefaulted(CommandFlag<?> flag) {
|
||||
return resultMap.get(flag) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FlagResult{" +
|
||||
"resultMap=" + resultMap +
|
||||
'}';
|
||||
}
|
||||
|
||||
private class SingleFlagResult<T> {
|
||||
private final T value;
|
||||
private final boolean fromInput;
|
||||
|
||||
private SingleFlagResult(T value, boolean fromInput) {
|
||||
this.fromInput = fromInput;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SingleFlagResult{" +
|
||||
"value=" + value +
|
||||
", fromInput=" + fromInput +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import org.bukkit.WorldType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class MVFlags {
|
||||
|
||||
private static MultiverseCore multiverse;
|
||||
|
||||
public static void setCoreInstance(MultiverseCore plugin) {
|
||||
multiverse = plugin;
|
||||
}
|
||||
|
||||
public static final CommandFlag<String> SEED = new RequiredCommandFlag<String>("Seed", "-s", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Arrays.asList("seed", String.valueOf(new Random().nextLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
public static final CommandFlag<String> RANDOM_SEED = new OptionalCommandFlag<String>("Seed", "-s", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Arrays.asList("seed", String.valueOf(new Random().nextLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
public static final CommandFlag<WorldType> WORLD_TYPE = new RequiredCommandFlag<WorldType>("WorldType", "-t", WorldType.class) {
|
||||
|
||||
private final Map<String, WorldType> typeAlias = new HashMap<String, WorldType>(4){{
|
||||
put("normal", WorldType.NORMAL);
|
||||
put("flat", WorldType.FLAT);
|
||||
put("largebiomes", WorldType.LARGE_BIOMES);
|
||||
put("amplified", WorldType.AMPLIFIED);
|
||||
}};
|
||||
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return typeAlias.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
WorldType type = typeAlias.get(input);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
try {
|
||||
return WorldType.valueOf(input.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new FlagParseFailedException("'%s' is not a valid. See /mv env for available World Type.", input);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getDefaultValue() {
|
||||
return WorldType.NORMAL;
|
||||
}
|
||||
};
|
||||
|
||||
public final static CommandFlag<String> GENERATOR = new RequiredCommandFlag<String>("Generator", "-g", String.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return multiverse.getMVWorldManager().getAvailableWorldGenerators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
String[] genArray = input.split(":");
|
||||
String generator = genArray[0];
|
||||
String generatorId = (genArray.length > 1) ? genArray[1] : "";
|
||||
if (multiverse.getMVWorldManager().getChunkGenerator(generator, generatorId, "test") == null) {
|
||||
throw new FlagParseFailedException("Invalid generator string '%s'. See /mv gens for available generators.", input);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
};
|
||||
|
||||
public final static CommandFlag<Boolean> GENERATE_STRUCTURES = new RequiredCommandFlag<Boolean>("GenerateStructures", "-a", Boolean.class) {
|
||||
@Override
|
||||
public Collection<String> suggestValue() {
|
||||
return Arrays.asList("true", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
return input.equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefaultValue() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public final static CommandFlag<Boolean> SPAWN_ADJUST = new NoValueCommandFlag<Boolean>("AdjustSpawn", "-n", Boolean.class) {
|
||||
@Override
|
||||
public Boolean getValue() throws FlagParseFailedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getDefaultValue() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static void register(CommandFlag<?> flag) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class NoValueCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public NoValueCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<String> suggestValue() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T getValue(@NotNull String input) throws FlagParseFailedException {
|
||||
throw new FlagParseFailedException("%s flag '%s' does not require a value.", this.name, this.identifier);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
public abstract class OptionalCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public OptionalCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.OPTIONAL);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.onarandombox.MultiverseCore.commandTools.flags;
|
||||
|
||||
public abstract class RequiredCommandFlag<T> extends CommandFlag<T> {
|
||||
|
||||
public RequiredCommandFlag(String name, String identifier, Class<T> type) {
|
||||
super(name, identifier, type, ValueRequirement.REQUIRED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T getValue() throws FlagParseFailedException {
|
||||
throw new FlagParseFailedException("%s flag '%s' requires a value input.", this.name, this.identifier);
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.commandTools.queue;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.data.type.CommandBlock;
|
||||
|
@ -12,14 +12,16 @@ import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.contexts.WorldFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.MVFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flags.FlagGroup;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flags.FlagResult;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flags.MVFlags;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
@ -27,13 +29,16 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class CreateCommand extends MultiverseCommand {
|
||||
|
||||
private static final Set<Flag<?>> FLAG_SET = new HashSet<>(MVFlags.all());
|
||||
private static final FlagGroup FLAG_GROUP = FlagGroup.of(
|
||||
MVFlags.WORLD_TYPE,
|
||||
MVFlags.SEED,
|
||||
MVFlags.GENERATOR,
|
||||
MVFlags.GENERATE_STRUCTURES,
|
||||
MVFlags.SPAWN_ADJUST
|
||||
);
|
||||
|
||||
public CreateCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
@ -48,7 +53,7 @@ public class CreateCommand extends MultiverseCommand {
|
||||
|
||||
@Syntax("<name>")
|
||||
@Description("New world name.")
|
||||
@NotNull @Flags("trim") @Conditions("creatableWorldName") String worldName,
|
||||
@NotNull @co.aikar.commands.annotation.Flags("trim") @Conditions("creatableWorldName") String worldName,
|
||||
|
||||
@Syntax("<env>")
|
||||
@Description("The world's environment. See: /mv env")
|
||||
@ -58,7 +63,8 @@ public class CreateCommand extends MultiverseCommand {
|
||||
@Description("Other world settings. See: http://gg.gg/nn8bl")
|
||||
@Nullable @Optional String[] flagsArray) {
|
||||
|
||||
WorldFlags flags = new WorldFlags(this.plugin, sender, flagsArray, FLAG_SET);
|
||||
FlagResult flags = FlagResult.parse(flagsArray, FLAG_GROUP);
|
||||
Logging.info(String.valueOf(flags));
|
||||
|
||||
Command.broadcastCommandMessage(sender, String.format("Starting creation of world '%s'...", worldName));
|
||||
Command.broadcastCommandMessage(sender, (this.plugin.getMVWorldManager().addWorld(
|
||||
|
@ -12,14 +12,13 @@ import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.contexts.WorldFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.MVFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flags;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
@ -34,8 +33,8 @@ import java.util.Set;
|
||||
public class ImportCommand extends MultiverseCommand {
|
||||
|
||||
private static final Set<Flag<?>> FLAG_SET = new HashSet<Flag<?>>(2) {{
|
||||
add(MVFlags.GENERATOR);
|
||||
add(MVFlags.SPAWN_ADJUST);
|
||||
add(Flags.GENERATOR);
|
||||
add(Flags.SPAWN_ADJUST);
|
||||
}};
|
||||
|
||||
public ImportCommand(MultiverseCore plugin) {
|
||||
@ -51,7 +50,7 @@ public class ImportCommand extends MultiverseCommand {
|
||||
|
||||
@Syntax("<name>")
|
||||
@Description("Folder name of the world.")
|
||||
@NotNull @Flags("trim") @Conditions("importableWorldName") String worldName,
|
||||
@NotNull @co.aikar.commands.annotation.Flags("trim") @Conditions("importableWorldName") String worldName,
|
||||
|
||||
@Syntax("<env>")
|
||||
@Description("The world's environment. See: /mv env")
|
||||
@ -69,8 +68,8 @@ public class ImportCommand extends MultiverseCommand {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
flags.getValue(MVFlags.GENERATOR),
|
||||
flags.getValue(MVFlags.SPAWN_ADJUST))
|
||||
flags.getValue(Flags.GENERATOR),
|
||||
flags.getValue(Flags.SPAWN_ADJUST))
|
||||
)
|
||||
? String.format("%sComplete!", ChatColor.GREEN)
|
||||
: String.format("%sFailed! See console for more details.", ChatColor.RED));
|
||||
|
@ -15,7 +15,6 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.page.PageDisplay;
|
||||
import com.onarandombox.MultiverseCore.commandTools.contexts.PageFilter;
|
||||
|
@ -18,7 +18,6 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.inline.KeyValueDisplay;
|
||||
|
@ -11,15 +11,14 @@ 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.Optional;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.contexts.WorldFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.MVFlags;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flag;
|
||||
import com.onarandombox.MultiverseCore.commandTools.flag.Flags;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -32,7 +31,7 @@ import java.util.Set;
|
||||
public class RegenCommand extends MultiverseCommand {
|
||||
|
||||
private static final Set<Flag<?>> FLAG_SET = new HashSet<Flag<?>>(1) {{
|
||||
add(MVFlags.SEED);
|
||||
add(Flags.SEED);
|
||||
}};
|
||||
|
||||
public RegenCommand(MultiverseCore plugin) {
|
||||
@ -48,7 +47,7 @@ public class RegenCommand extends MultiverseCommand {
|
||||
|
||||
@Syntax("<world>")
|
||||
@Description("World that you want to regen.")
|
||||
@NotNull @Flags("other") MultiverseWorld world,
|
||||
@NotNull @co.aikar.commands.annotation.Flags("other") MultiverseWorld world,
|
||||
|
||||
@Syntax("[-s [seed]]")
|
||||
@Description("Other world settings. See: http://gg.gg/nn8lk")
|
||||
@ -73,9 +72,9 @@ public class RegenCommand extends MultiverseCommand {
|
||||
//TODO: API should allow regen of unloaded worlds.
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().regenWorld(
|
||||
world.getName(),
|
||||
flags.isByInput(MVFlags.SEED),
|
||||
flags.getValue(MVFlags.SEED).equalsIgnoreCase("random"),
|
||||
flags.getValue(MVFlags.SEED))
|
||||
flags.isByInput(Flags.SEED),
|
||||
flags.getValue(Flags.SEED).equalsIgnoreCase("random"),
|
||||
flags.getValue(Flags.SEED))
|
||||
)
|
||||
? String.format("%sWorld Regenerated!", ChatColor.GREEN)
|
||||
: String.format("%sWorld could not be regenerated!", ChatColor.RED));
|
||||
|
Loading…
Reference in New Issue
Block a user