mirror of https://github.com/Minestom/Minestom.git
Usage sample for every Argument
This commit is contained in:
parent
6217280466
commit
3e4ccbe75a
|
@ -68,7 +68,7 @@ public interface CommandProcessor {
|
|||
* WARNING: {@link #enableWritingTracking()} needs to return true, you need to override it by default.
|
||||
*
|
||||
* @param text the whole player text
|
||||
* @return the array containing all the suggestion for the current arg (split " ")
|
||||
* @return the array containing all the suggestion for the current arg (split " "), can be null
|
||||
* @see #enableWritingTracking()
|
||||
*/
|
||||
default String[] onWrite(String text) {
|
||||
|
|
|
@ -165,15 +165,14 @@ public class Command {
|
|||
* when in a dynamic argument ({@link ArgumentDynamicWord} and {@link ArgumentDynamicStringArray}).
|
||||
*
|
||||
* @param text the whole player's text
|
||||
* @return the array containing all the suggestion for the current arg (split " ")
|
||||
* @return the array containing all the suggestion for the current arg (split " "), can be null
|
||||
*/
|
||||
public String[] onDynamicWrite(String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a {@link CommandSender} executes this command.
|
||||
* Executed before any syntax callback.
|
||||
* Called when a {@link CommandSender} executes this command before any syntax callback.
|
||||
* <p>
|
||||
* WARNING: the {@link CommandCondition} is not executed, and all the {@link CommandSyntax} are not checked,
|
||||
* this is called every time a {@link CommandSender} send a command which start by {@link #getName()} or {@link #getAliases()}.
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
/**
|
||||
* Represents a boolean value.
|
||||
* <p>
|
||||
* Example: true
|
||||
*/
|
||||
public class ArgumentBoolean extends Argument<Boolean> {
|
||||
|
||||
public static final int NOT_BOOLEAN_ERROR = 1;
|
||||
|
|
|
@ -2,6 +2,10 @@ package net.minestom.server.command.builder.arguments;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Same as {@link ArgumentStringArray} with the exception
|
||||
* that this argument can trigger {@link net.minestom.server.command.builder.Command#onDynamicWrite(String)}.
|
||||
*/
|
||||
public class ArgumentDynamicStringArray extends Argument<String[]> {
|
||||
|
||||
public ArgumentDynamicStringArray(String id) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
/**
|
||||
* Same as {@link ArgumentWord} with the exception
|
||||
* that this argument can trigger {@link net.minestom.server.command.builder.Command#onDynamicWrite(String)}.
|
||||
*/
|
||||
public class ArgumentDynamicWord extends Argument<String> {
|
||||
|
||||
public ArgumentDynamicWord(String id) {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
/**
|
||||
* Argument which will take a quoted string.
|
||||
* <p>
|
||||
* Example: "Hey I am a string"
|
||||
*/
|
||||
public class ArgumentString extends Argument<String> {
|
||||
|
||||
public static final int QUOTE_ERROR = 1;
|
||||
|
|
|
@ -2,6 +2,11 @@ package net.minestom.server.command.builder.arguments;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents an argument which will take all the remaining of the command.
|
||||
* <p>
|
||||
* Example: Hey I am a string
|
||||
*/
|
||||
public class ArgumentStringArray extends Argument<String[]> {
|
||||
|
||||
public ArgumentStringArray(String id) {
|
||||
|
|
|
@ -11,7 +11,9 @@ import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
|
|||
import net.minestom.server.command.builder.arguments.number.ArgumentLong;
|
||||
|
||||
/**
|
||||
* Convenient class listing all the basic {@link Argument}
|
||||
* Convenient class listing all the basics {@link Argument}.
|
||||
* <p>
|
||||
* Please see the specific class documentation for further info.
|
||||
*/
|
||||
public class ArgumentType {
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
package net.minestom.server.command.builder.arguments;
|
||||
|
||||
/**
|
||||
* Represents a single word in the command.
|
||||
* <p>
|
||||
* You can specify the only correct words with {@link #from(String...)}.
|
||||
* <p>
|
||||
* Example: hey
|
||||
*/
|
||||
public class ArgumentWord extends Argument<String> {
|
||||
|
||||
public static final int SPACE_ERROR = 1;
|
||||
|
|
|
@ -4,8 +4,9 @@ import net.minestom.server.chat.ChatColor;
|
|||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
|
||||
/**
|
||||
* Represent an argument which will give you a {@link ChatColor}
|
||||
* Chat format: red, white, reset, etc...
|
||||
* Represents an argument which will give you a {@link ChatColor}.
|
||||
* <p>
|
||||
* Example: red, white, reset
|
||||
*/
|
||||
public class ArgumentColor extends Argument<ChatColor> {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
// TODO
|
||||
|
||||
/**
|
||||
* Represent the target selector argument
|
||||
* Represents the target selector argument.
|
||||
* https://minecraft.gamepedia.com/Commands#Target_selectors
|
||||
*/
|
||||
public class ArgumentEntities extends Argument<ArrayList<Entity>> {
|
||||
|
|
|
@ -5,8 +5,9 @@ import net.minestom.server.utils.math.FloatRange;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represent an argument which will give you an {@link FloatRange}
|
||||
* Chat format: ..3, 3.., 5..10, 15
|
||||
* Represents an argument which will give you an {@link FloatRange}.
|
||||
* <p>
|
||||
* Example: ..3, 3.., 5..10, 15
|
||||
*/
|
||||
public class ArgumentFloatRange extends ArgumentRange<FloatRange> {
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@ import net.minestom.server.utils.math.IntRange;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represent an argument which will give you an {@link IntRange}
|
||||
* Chat format: ..3, 3.., 5..10, 15
|
||||
* Represents an argument which will give you an {@link IntRange}.
|
||||
* <p>
|
||||
* Example: ..3, 3.., 5..10, 15
|
||||
*/
|
||||
public class ArgumentIntRange extends ArgumentRange<IntRange> {
|
||||
|
||||
|
|
|
@ -12,6 +12,13 @@ import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
|||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Argument which can be used to retrieve an {@link ItemStack} from its material and with NBT data.
|
||||
* <p>
|
||||
* It is the same type as the one used in the /give command.
|
||||
* <p>
|
||||
* Example: diamond_sword{display:{Name:"{\"text\":\"Sword of Power\"}"}}
|
||||
*/
|
||||
public class ArgumentItemStack extends Argument<ItemStack> {
|
||||
|
||||
public static final int NO_MATERIAL = 1;
|
||||
|
|
|
@ -8,6 +8,11 @@ import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
|||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Argument used to retrieve a {@link NBTCompound} if you need key-value data.
|
||||
* <p>
|
||||
* Example: {display:{Name:"{\"text\":\"Sword of Power\"}"}}
|
||||
*/
|
||||
public class ArgumentNbtCompoundTag extends Argument<NBTCompound> {
|
||||
|
||||
public static final int INVALID_NBT = 1;
|
||||
|
|
|
@ -7,6 +7,12 @@ import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
|||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Argument used to retrieve a {@link NBT} based object, can be a
|
||||
* {@link org.jglrxavpok.hephaistos.nbt.NBTCompound} or {@link org.jglrxavpok.hephaistos.nbt.NBTList}
|
||||
* <p>
|
||||
* Example: {display:{Name:"{\"text\":\"Sword of Power\"}"}} or [{display:{Name:"{\"text\":\"Sword of Power\"}"}}]
|
||||
*/
|
||||
public class ArgumentNbtTag extends Argument<NBT> {
|
||||
|
||||
public static final int INVALID_NBT = 1;
|
||||
|
|
|
@ -2,6 +2,11 @@ package net.minestom.server.command.builder.arguments.minecraft;
|
|||
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
|
||||
/**
|
||||
* Abstract class used by {@link ArgumentIntRange} and {@link ArgumentFloatRange}.
|
||||
*
|
||||
* @param <T> the type of the range
|
||||
*/
|
||||
public abstract class ArgumentRange<T> extends Argument<T> {
|
||||
|
||||
public static final int FORMAT_ERROR = -1;
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import it.unimi.dsi.fastutil.chars.CharArrayList;
|
||||
import it.unimi.dsi.fastutil.chars.CharList;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represent an argument giving a time (day/second/tick)
|
||||
* Chat format: 50d, 25s, 75t
|
||||
* Represents an argument giving a time (day/second/tick).
|
||||
* <p>
|
||||
* Example: 50d, 25s, 75t
|
||||
*/
|
||||
public class ArgumentTime extends Argument<UpdateOption> {
|
||||
|
||||
public static final int INVALID_TIME_FORMAT = -2;
|
||||
public static final int NO_NUMBER = -3;
|
||||
private static final List<Character> suffixes = Arrays.asList('d', 's', 't');
|
||||
|
||||
private static final CharList SUFFIXES = new CharArrayList(new char[]{'d', 's', 't'});
|
||||
|
||||
public ArgumentTime(String id) {
|
||||
super(id);
|
||||
|
@ -24,8 +25,9 @@ public class ArgumentTime extends Argument<UpdateOption> {
|
|||
@Override
|
||||
public int getCorrectionResult(String value) {
|
||||
final char lastChar = value.charAt(value.length() - 1);
|
||||
if (!suffixes.contains(lastChar))
|
||||
if (!SUFFIXES.contains(lastChar))
|
||||
return INVALID_TIME_FORMAT;
|
||||
|
||||
value = value.substring(0, value.length() - 1);
|
||||
try {
|
||||
// Check if value is a number
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minestom.server.potion.PotionEffect;
|
|||
import net.minestom.server.registry.Registries;
|
||||
|
||||
/**
|
||||
* Represent an argument giving a potion type
|
||||
* Represents an argument giving a {@link PotionEffect}.
|
||||
*/
|
||||
public class ArgumentPotionEffect extends ArgumentRegistry<PotionEffect> {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
/**
|
||||
* Responsible for the {@link Chunk} generation, can be set using {@link Instance#setChunkGenerator(ChunkGenerator)}.
|
||||
* <p>
|
||||
* Called if {@link IChunkLoader} hasn't been able to load it.
|
||||
* Called if the instance {@link IChunkLoader} hasn't been able to load the chunk.
|
||||
*/
|
||||
public interface ChunkGenerator {
|
||||
|
||||
|
|
Loading…
Reference in New Issue