add Range annotation

This commit is contained in:
Jesse Boyd 2019-07-29 05:26:44 +10:00
parent da858f2131
commit 1c256c1f5a
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 44 additions and 45 deletions

View File

@ -324,7 +324,7 @@ public class GeneralCommands {
checkRandomization = false; checkRandomization = false;
} else { } else {
if (argLower.equals("#copy") || argLower.equals("#clipboard")) { if (argLower.equals("#copy") || argLower.equals("#clipboard")) {
Clipboard clipboard = worldEdit.getSessionManager().get(player).getClipboard().getClipboard(); Clipboard clipboard = session.getClipboard().getClipboard();
util = TextureUtil.fromClipboard(clipboard); util = TextureUtil.fromClipboard(clipboard);
} else if (argLower.equals("*") || argLower.equals("true")) { } else if (argLower.equals("*") || argLower.equals("true")) {
util = Fawe.get().getTextureUtil(); util = Fawe.get().getTextureUtil();

View File

@ -20,9 +20,11 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT; import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
@ -274,7 +276,7 @@ public class GenerationCommands {
int size, int size,
@Arg(desc = "The type of forest", def = "tree") @Arg(desc = "The type of forest", def = "tree")
TreeType type, TreeType type,
@Arg(desc = "The density of the forest, between 0 and 100", def = "5") @Range(min = 0, max = 100) @Arg(desc = "The density of the forest, between 0 and 100", def = "5")
double density) throws WorldEditException { double density) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100"); checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
density /= 100; density /= 100;

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
@ -219,7 +220,7 @@ public class HistoryCommands {
) )
@CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"}) @CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"})
public void undo(Player player, LocalSession session, public void undo(Player player, LocalSession session,
@Arg(desc = "Number of undoes to perform", def = "1") @Range(min = 1) @Arg(desc = "Number of undoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Undo this player's operations", def = "") @Arg(name = "player", desc = "Undo this player's operations", def = "")
String playerName, String playerName,
@ -266,7 +267,7 @@ public class HistoryCommands {
) )
@CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"}) @CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"})
public void redo(Player player, LocalSession session, public void redo(Player player, LocalSession session,
@Arg(desc = "Number of redoes to perform", def = "1") @Range(min = 1) @Arg(desc = "Number of redoes to perform", def = "1")
int times, int times,
@Arg(name = "player", desc = "Redo this player's operations", def = "") @Arg(name = "player", desc = "Redo this player's operations", def = "")
String playerName) throws WorldEditException { String playerName) throws WorldEditException {

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION; import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
@ -216,7 +217,7 @@ public class RegionCommands {
@Selection Region region, @Selection Region region,
@Arg(desc = "The pattern of blocks to place") @Arg(desc = "The pattern of blocks to place")
Pattern pattern, Pattern pattern,
@Arg(desc = "The thickness of the line", def = "0") @Range(min = 1) @Arg(desc = "The thickness of the line", def = "0")
int thickness, int thickness,
@Switch(name = 'h', desc = "Generate only a shell") @Switch(name = 'h', desc = "Generate only a shell")
boolean shell) throws WorldEditException { boolean shell) throws WorldEditException {
@ -546,7 +547,7 @@ public class RegionCommands {
boolean skipEntities, boolean skipEntities,
@Switch(name = 'a', desc = "Ignore air blocks") @Switch(name = 'a', desc = "Ignore air blocks")
boolean ignoreAirBlocks, boolean ignoreAirBlocks,
@Switch(name = 'm', desc = "TODO") @Switch(name = 'm', desc = "Source mask")
Mask sourceMask, Mask sourceMask,
InjectedValueAccess context) throws WorldEditException { InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationStack(() -> { player.checkConfirmationStack(() -> {
@ -672,7 +673,7 @@ public class RegionCommands {
@Logging(REGION) @Logging(REGION)
public void hollow(FawePlayer player, EditSession editSession, public void hollow(FawePlayer player, EditSession editSession,
@Selection Region region, @Selection Region region,
@Arg(desc = "Thickness of the shell to leave", def = "0") @Range(min = 0) @Arg(desc = "Thickness of the shell to leave", def = "0")
int thickness, int thickness,
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air") @Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
Pattern pattern, Pattern pattern,

View File

@ -91,13 +91,13 @@ import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.inject.InjectedValueAccess; import org.jetbrains.annotations.NotNull;
/** /**
* Utility commands. * Utility commands.
@ -190,9 +190,9 @@ public class UtilityCommands {
public int fill(Player player, LocalSession session, EditSession editSession, public int fill(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The blocks to fill with") @Arg(desc = "The blocks to fill with")
Pattern pattern, Pattern pattern,
@Arg(desc = "The radius to fill in") @Range(min=1) @Arg(desc = "The radius to fill in")
double radius, double radius,
@Arg(desc = "The depth to fill", def = "1") @Range(min=1) @Arg(desc = "The depth to fill", def = "1")
int depth, int depth,
@Arg(desc = "Direction to fill", def = "down") BlockVector3 direction) throws WorldEditException { @Arg(desc = "Direction to fill", def = "down") BlockVector3 direction) throws WorldEditException {
radius = Math.max(1, radius); radius = Math.max(1, radius);
@ -285,7 +285,7 @@ public class UtilityCommands {
public int fillr(Player player, LocalSession session, EditSession editSession, public int fillr(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The blocks to fill with") @Arg(desc = "The blocks to fill with")
Pattern pattern, Pattern pattern,
@Arg(desc = "The radius to fill in") @Range(min=1) @Arg(desc = "The radius to fill in")
double radius, double radius,
@Arg(desc = "The depth to fill", def = "") @Arg(desc = "The depth to fill", def = "")
Integer depth) throws WorldEditException { Integer depth) throws WorldEditException {
@ -307,7 +307,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.drain") @CommandPermissions("worldedit.drain")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int drain(Player player, LocalSession session, EditSession editSession, public int drain(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius to drain") @Range(min=0) @Arg(desc = "The radius to drain")
double radius, double radius,
@Switch(name = 'w', desc = "Also un-waterlog blocks") @Switch(name = 'w', desc = "Also un-waterlog blocks")
boolean waterlogged) throws WorldEditException { boolean waterlogged) throws WorldEditException {
@ -327,7 +327,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.fixlava") @CommandPermissions("worldedit.fixlava")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int fixLava(Player player, LocalSession session, EditSession editSession, public int fixLava(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius to fix in") @Range(min=0) @Arg(desc = "The radius to fix in")
double radius) throws WorldEditException { double radius) throws WorldEditException {
radius = Math.max(0, radius); radius = Math.max(0, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -344,7 +344,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.fixwater") @CommandPermissions("worldedit.fixwater")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int fixWater(Player player, LocalSession session, EditSession editSession, public int fixWater(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius to fix in") @Range(min=0) @Arg(desc = "The radius to fix in")
double radius) throws WorldEditException { double radius) throws WorldEditException {
radius = Math.max(0, radius); radius = Math.max(0, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -361,7 +361,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.removeabove") @CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int removeAbove(Player player, LocalSession session, EditSession editSession, public int removeAbove(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The apothem of the square to remove from", def = "1") @Range(min=1) @Arg(desc = "The apothem of the square to remove from", def = "1")
int size, int size,
@Arg(desc = "The maximum height above you to remove from", def = "") @Arg(desc = "The maximum height above you to remove from", def = "")
Integer height) throws WorldEditException { Integer height) throws WorldEditException {
@ -406,7 +406,7 @@ public class UtilityCommands {
public int removeNear(Player player, LocalSession session, EditSession editSession, public int removeNear(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The mask of blocks to remove") @Arg(desc = "The mask of blocks to remove")
Mask mask, Mask mask,
@Arg(desc = "The radius of the square to remove from", def = "50") @Range(min=1) @Arg(desc = "The radius of the square to remove from", def = "50")
int radius) throws WorldEditException { int radius) throws WorldEditException {
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -424,7 +424,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.replacenear") @CommandPermissions("worldedit.replacenear")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int replaceNear(Player player, LocalSession session, EditSession editSession, public int replaceNear(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius of the square to remove in") @Range(min=1) @Arg(desc = "The radius of the square to remove in")
int radius, int radius,
@Arg(desc = "The mask matching blocks to remove", def = "") @Arg(desc = "The mask matching blocks to remove", def = "")
Mask from, Mask from,
@ -455,7 +455,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.snow") @CommandPermissions("worldedit.snow")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int snow(Player player, LocalSession session, EditSession editSession, public int snow(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius of the circle to snow in", def = "10") @Range(min=1) @Arg(desc = "The radius of the circle to snow in", def = "10")
double size) throws WorldEditException { double size) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
we.checkMaxRadius(size); we.checkMaxRadius(size);
@ -473,7 +473,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.thaw") @CommandPermissions("worldedit.thaw")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int thaw(Player player, LocalSession session, EditSession editSession, public int thaw(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius of the circle to thaw in", def = "10") @Range(min=1) @Arg(desc = "The radius of the circle to thaw in", def = "10")
double size) throws WorldEditException { double size) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
we.checkMaxRadius(size); we.checkMaxRadius(size);
@ -491,7 +491,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.green") @CommandPermissions("worldedit.green")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public int green(Player player, LocalSession session, EditSession editSession, public int green(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius of the circle to convert in", def = "10") @Range(min=1) @Arg(desc = "The radius of the circle to convert in", def = "10")
double size, double size,
@Switch(name = 'f', desc = "Also convert coarse dirt") @Switch(name = 'f', desc = "Also convert coarse dirt")
boolean convertCoarse) throws WorldEditException { boolean convertCoarse) throws WorldEditException {
@ -512,7 +512,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.extinguish") @CommandPermissions("worldedit.extinguish")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void extinguish(Player player, LocalSession session, EditSession editSession, public void extinguish(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The radius of the square to remove in", def = "") @Range(min=1) @Arg(desc = "The radius of the square to remove in", def = "")
Integer radius) throws WorldEditException { Integer radius) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
@ -595,7 +595,7 @@ public class UtilityCommands {
public int remove(Actor actor, public int remove(Actor actor,
@Arg(desc = "The type of entity to remove") @Arg(desc = "The type of entity to remove")
EntityRemover remover, EntityRemover remover,
@Arg(desc = "The radius of the cuboid to remove from") @Range(min=-1) @Arg(desc = "The radius of the cuboid to remove from")
int radius) throws WorldEditException { int radius) throws WorldEditException {
Player player = actor instanceof Player ? (Player) actor : null; Player player = actor instanceof Player ? (Player) actor : null;
@ -707,8 +707,8 @@ public class UtilityCommands {
PrintCommandHelp.help(command, page, listSubCommands, we, actor); PrintCommandHelp.help(command, page, listSubCommands, we, actor);
} }
public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) { public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) {
list(dir, actor, args, page, -1, formatName, playerFolder, new RunnableVal3<Builder, URI, String>() { list(dir, actor, args, page, -1, formatName, playerFolder, false, false, new RunnableVal3<Builder, URI, String>() {
@Override @Override
public void run(Builder m, URI uri, String fileName) { public void run(Builder m, URI uri, String fileName) {
m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, "")); m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, ""));
@ -719,7 +719,7 @@ public class UtilityCommands {
}); });
} }
public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3<Builder, URI, String> eachMsg) { public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst, RunnableVal3<Builder, URI, String> eachMsg) {
List<File> fileList = new ArrayList<>(); List<File> fileList = new ArrayList<>();
if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console
page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add); page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add);
@ -739,7 +739,7 @@ public class UtilityCommands {
return; return;
} }
final int sortType = 0; //args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; final int sortType = oldFirst ? -1 : newFirst ? 1 : 0;
// cleanup file list // cleanup file list
fileList.sort((f1, f2) -> { fileList.sort((f1, f2) -> {
boolean dir1 = f1.isDirectory(); boolean dir1 = f1.isDirectory();
@ -766,12 +766,12 @@ public class UtilityCommands {
int limit = Math.min(offset + perPage, fileList.size()); int limit = Math.min(offset + perPage, fileList.size());
String fullArgs = (String) args.getLocals().get("arguments"); // String fullArgs = (String) args.getLocals().get("arguments");
String baseCmd = null; // String baseCmd = null;
if (fullArgs != null) { // if (fullArgs != null) {
baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs; // baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs;
} // }
@NonNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount)); @NotNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount));
UUID uuid = playerFolder ? actor.getUniqueId() : null; UUID uuid = playerFolder ? actor.getUniqueId() : null;
for (int i = offset; i < limit; i++) { for (int i = offset; i < limit; i++) {
@ -779,22 +779,17 @@ public class UtilityCommands {
File file = fileList.get(i); File file = fileList.get(i);
eachMsg.run(m, file.toURI(), getPath(dir, file, uuid)); eachMsg.run(m, file.toURI(), getPath(dir, file, uuid));
} }
if (baseCmd != null) { // if (baseCmd != null) {
//TODO m.newline().paginate(baseCmd, page, pageCount); // //TODO m.newline().paginate(baseCmd, page, pageCount);
} // }
actor.print(m.build()); actor.print(m.build());
} }
public static int getFiles(File root, Actor actor, InjectedValueAccess args, int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile, ListFilters... filters) { public static int getFiles(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
// TODO NOT IMPLEMENTED replace getFiles
return page;
}
public static int getFiles(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
Consumer<File> rootFunction = forEachFile; Consumer<File> rootFunction = forEachFile;
//schem list all <path> //schem list all <path>
int len = args.argsLength(); int len = args.size();
List<String> filters = new ArrayList<>(); List<String> filters = new ArrayList<>();
String dirFilter = File.separator; String dirFilter = File.separator;
@ -803,8 +798,8 @@ public class UtilityCommands {
boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS; boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
if (len > 0) { if (len > 0) {
int max = len; int max = len;
if (MathMan.isInteger(args.getString(len - 1))) { if (MathMan.isInteger(args.get(len - 1))) {
page = args.getInteger(--len); page = Integer.parseInt(args.get(--len));
} }
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
String arg = ""; String arg = "";