restructure dirs + add rawInput parameter at ArgumentType#checkValue
This commit is contained in:
parent
aae7a160ac
commit
f1e9ac5ea9
29 changed files with 85 additions and 81 deletions
|
|
@ -1,11 +0,0 @@
|
|||
package de.kentoj.scrow.bukkit.services.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
|
||||
public interface CommandExecutor {
|
||||
|
||||
/**
|
||||
* @return true on success, 1 on failure
|
||||
*/
|
||||
void execute(CommandContext ctx);
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
package de.kentoj.scrow.bukkit.services.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.ArgumentType;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.services.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public interface CommandManager {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
package de.kentoj.scrow.bukkit.services.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.ArgumentType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.services.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface SuggestionProvider {
|
||||
|
||||
Set<String> suggest(CommandContext context);
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface SuggestionProvider {
|
||||
|
||||
Set<String> suggest(CommandContext context);
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
package de.kentoj.scrow.bukkit.services.command.execution;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ArgumentData<T> {
|
||||
|
|
@ -11,5 +12,5 @@ public interface ArgumentData<T> {
|
|||
/**
|
||||
* @return null if the default value for the type was used
|
||||
*/
|
||||
@Nullable String getRawValue();
|
||||
@Nullable String getRawInput();
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
package de.kentoj.scrow.bukkit.services.command.execution;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.execution;
|
||||
|
||||
public interface CommandExecutor {
|
||||
|
||||
void execute(CommandContext ctx);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.bukkit.services.command;
|
||||
package de.kentoj.scrow.bukkit.services.command.literal;
|
||||
|
||||
public interface ArgumentReader {
|
||||
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2;
|
||||
package de.kentoj.scrow.bukkit.services.command.literal;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.SuggestionProvider;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.ArgumentType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2.literal;
|
||||
package de.kentoj.scrow.bukkit.services.command.literal;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.CommandExecutor;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandExecutor;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.cmds2.literal;
|
||||
package de.kentoj.scrow.bukkit.services.command.literal;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.type;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
|
||||
import java.util.Set;
|
||||
|
|
@ -15,7 +15,7 @@ public interface ArgumentType<T> {
|
|||
/**
|
||||
* @throws CommandInvocationException if the given value may not be used
|
||||
*/
|
||||
void checkValue(CommandContext ctx, T value) throws CommandInvocationException;
|
||||
void checkValue(CommandContext ctx, T value, String rawInput) throws CommandInvocationException;
|
||||
|
||||
Set<String> getDefaultSuggestions(CommandContext ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.type;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.kentoj.scrow.bukkit.services.command.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
|
@ -33,7 +33,7 @@ public class NumberArgumentType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(CommandContext ctx, Integer value) throws CommandInvocationException {
|
||||
public void checkValue(CommandContext ctx, Integer value, String rawInput) throws CommandInvocationException {
|
||||
if (value < min) throw new CommandInvocationException("Value too small -- " + value);
|
||||
if (value > max) throw new CommandInvocationException("Value too large -- " + value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.services.command.type;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
|
@ -36,8 +36,8 @@ public class PlayerArgumentType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(CommandContext ctx, Player value) throws CommandInvocationException {
|
||||
if (value == null) throw new CommandInvocationException("Player is not online");
|
||||
public void checkValue(CommandContext ctx, Player value, String rawInput) throws CommandInvocationException {
|
||||
if (value == null) throw new CommandInvocationException("Player is not online -- " + rawInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -74,7 +74,7 @@ public class PlayerArgumentType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(CommandContext ctx, OfflinePlayer value) throws CommandInvocationException {
|
||||
public void checkValue(CommandContext ctx, OfflinePlayer value, String rawInput) throws CommandInvocationException {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import de.kentoj.scrow.bukkit.cmds2.CommandFactoryImpl;
|
|||
import de.kentoj.scrow.bukkit.cmds2.bukkit.BukkitCommandManager;
|
||||
import de.kentoj.scrow.bukkit.economy.InMemoryEconomyService;
|
||||
import de.kentoj.scrow.bukkit.economy.MongoEconomyService;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.Commands;
|
||||
import de.kentoj.scrow.bukkit.services.command.Commands;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bson.UuidRepresentation;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.SuggestionProvider;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.SuggestionProvider;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.ArgumentType;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandFactory;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.CommandFactory;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.ArgumentType;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.CommandExecutor;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandExecutor;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.Literal;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package de.kentoj.scrow.bukkit.cmds2.bukkit;
|
|||
|
||||
import de.kentoj.scrow.bukkit.cmds2.parsing.ArgumentReaderImpl;
|
||||
import de.kentoj.scrow.bukkit.cmds2.parsing.CommandProcessor;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2.bukkit;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.CommandManager;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2.bukkit;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2.parsing;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import lombok.Value;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -9,5 +9,5 @@ import org.jetbrains.annotations.Nullable;
|
|||
public class ArgumentDataImpl<T> implements ArgumentData<T> {
|
||||
T value;
|
||||
CommandArgument<T> argument;
|
||||
@Nullable String rawValue;
|
||||
@Nullable String rawInput;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2.parsing;
|
||||
|
||||
import de.kentoj.scrow.bukkit.services.command.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package de.kentoj.scrow.bukkit.cmds2.parsing;
|
||||
|
||||
import de.kentoj.scrow.bukkit.cmds2.CommandContextImpl;
|
||||
import de.kentoj.scrow.bukkit.services.command.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.ArgumentReader;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.ArgumentData;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.Literal;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.exception.CommandInvocationException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -60,9 +60,9 @@ public class CommandProcessor {
|
|||
return new ArgumentDataImpl<>(defaultValue, argument, null);
|
||||
}
|
||||
|
||||
final var rawValue = argument.getType().readRawInput(argumentReader);
|
||||
T value = argument.getType().parseInput(rawValue);
|
||||
argument.getType().checkValue(new CommandContextImpl(sender, arguments), value);
|
||||
return new ArgumentDataImpl<>(value, argument, rawValue);
|
||||
final var rawInput = argument.getType().readRawInput(argumentReader);
|
||||
T value = argument.getType().parseInput(rawInput);
|
||||
argument.getType().checkValue(new CommandContextImpl(sender, arguments), value, rawInput);
|
||||
return new ArgumentDataImpl<>(value, argument, rawInput);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.economy.command;
|
||||
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.Commands;
|
||||
import de.kentoj.scrow.bukkit.services.command.cmds2.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.CommandArgument;
|
||||
import de.kentoj.scrow.bukkit.services.command.execution.CommandContext;
|
||||
import de.kentoj.scrow.bukkit.services.command.Commands;
|
||||
import de.kentoj.scrow.bukkit.services.command.literal.RootLiteral;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.NumberArgumentType;
|
||||
import de.kentoj.scrow.bukkit.services.command.type.PlayerArgumentType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue