Tweaks
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package io.dico.dicore.command.parameter.type;
|
||||||
|
|
||||||
|
import io.dico.dicore.command.CommandException;
|
||||||
|
import io.dico.dicore.command.parameter.ArgumentBuffer;
|
||||||
|
import io.dico.dicore.command.parameter.Parameter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EnumParameterType<E extends Enum> extends SimpleParameterType<E, Void> {
|
||||||
|
private final E[] universe;
|
||||||
|
|
||||||
|
public EnumParameterType(Class<E> returnType) {
|
||||||
|
super(returnType);
|
||||||
|
universe = returnType.getEnumConstants();
|
||||||
|
if (universe == null) {
|
||||||
|
throw new IllegalArgumentException("returnType must be an enum");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected E parse(Parameter<E, Void> parameter, CommandSender sender, String input) throws CommandException {
|
||||||
|
for (E constant : universe) {
|
||||||
|
if (constant.name().equalsIgnoreCase(input)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw CommandException.invalidArgument(parameter.getName(), "the enum value does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public List<String> complete(Parameter<E, Void> parameter, CommandSender sender, Location location, ArgumentBuffer buffer) {
|
||||||
|
String input = buffer.next().toUpperCase();
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (E constant : universe) {
|
||||||
|
if (constant.name().toUpperCase().startsWith(input.toUpperCase())) {
|
||||||
|
result.add(constant.name().toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,6 +23,11 @@ public class MapBasedParameterTypeSelector implements IParameterTypeSelector {
|
|||||||
if (useDefault && out == null) {
|
if (useDefault && out == null) {
|
||||||
out = defaultSelector.selectExact(key);
|
out = defaultSelector.selectExact(key);
|
||||||
}
|
}
|
||||||
|
if (out == null && key.getReturnType().isEnum()) {
|
||||||
|
//noinspection unchecked
|
||||||
|
out = new EnumParameterType(key.getReturnType());
|
||||||
|
addType(false, out);
|
||||||
|
}
|
||||||
return cast(out);
|
return cast(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public class ReflectiveRegistration {
|
|||||||
|
|
||||||
String[] parameterNames = lookupParameterNames(method, parameters, start);
|
String[] parameterNames = lookupParameterNames(method, parameters, start);
|
||||||
for (int i = start, n = parameters.length; i < n; i++) {
|
for (int i = start, n = parameters.length; i < n; i++) {
|
||||||
if (parameters[i].getType().getName().equals("kotlin.coroutines.experimental.Continuation")) {
|
if (parameters[i].getType().getName().equals("kotlin.coroutines.Continuation")) {
|
||||||
List<String> temp = new ArrayList<>(Arrays.asList(parameterNames));
|
List<String> temp = new ArrayList<>(Arrays.asList(parameterNames));
|
||||||
temp.remove(i - start);
|
temp.remove(i - start);
|
||||||
parameterNames = temp.toArray(new String[0]);
|
parameterNames = temp.toArray(new String[0]);
|
||||||
|
|||||||
@@ -5,50 +5,51 @@ import io.dico.dicore.command.ICommandAddress
|
|||||||
import io.dico.dicore.command.ICommandDispatcher
|
import io.dico.dicore.command.ICommandDispatcher
|
||||||
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
|
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
|
||||||
import io.dico.parcels2.ParcelsPlugin
|
import io.dico.parcels2.ParcelsPlugin
|
||||||
|
import io.dico.parcels2.logger
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.Queue
|
import java.util.Queue
|
||||||
|
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher =
|
||||||
//@formatter:off
|
with(CommandBuilder()) {
|
||||||
return CommandBuilder()
|
setChatController(ParcelsChatController())
|
||||||
.setChatController(ParcelsChatController())
|
addParameterType(false, ParcelParameterType(plugin.parcelProvider))
|
||||||
.addParameterType(false, ParcelParameterType(plugin.parcelProvider))
|
addParameterType(false, ProfileParameterType())
|
||||||
.addParameterType(true, ParcelTarget.PType(plugin.parcelProvider))
|
addParameterType(true, ParcelTarget.PType(plugin.parcelProvider))
|
||||||
|
|
||||||
.group("parcel", "plot", "plots", "p")
|
group("parcel", "plot", "plots", "p") {
|
||||||
.addRequiredPermission("parcels.command")
|
addRequiredPermission("parcels.command")
|
||||||
.registerCommands(CommandsGeneral(plugin))
|
registerCommands(CommandsGeneral(plugin))
|
||||||
.registerCommands(CommandsAddedStatusLocal(plugin))
|
registerCommands(CommandsAddedStatusLocal(plugin))
|
||||||
|
|
||||||
.group("option", "opt", "o")
|
group("option", "opt", "o") {
|
||||||
.apply { CommandsParcelOptions.setGroupDescription(this) }
|
CommandsParcelOptions.setGroupDescription(this)
|
||||||
.registerCommands(CommandsParcelOptions(plugin))
|
registerCommands(CommandsParcelOptions(plugin))
|
||||||
.parent()
|
}
|
||||||
|
|
||||||
.group("global", "g")
|
group("global", "g") {
|
||||||
.registerCommands(CommandsAddedStatusGlobal(plugin))
|
registerCommands(CommandsAddedStatusGlobal(plugin))
|
||||||
.parent()
|
}
|
||||||
|
|
||||||
.group("admin", "a")
|
group("admin", "a") {
|
||||||
.registerCommands(CommandsAdmin(plugin))
|
registerCommands(CommandsAdmin(plugin))
|
||||||
.parent()
|
}
|
||||||
|
|
||||||
.putDebugCommands(plugin)
|
if (!logger.isDebugEnabled) return@group
|
||||||
|
|
||||||
.parent()
|
group("debug", "d") {
|
||||||
.generateHelpAndSyntaxCommands()
|
registerCommands(CommandsDebug(plugin))
|
||||||
.getDispatcher()
|
}
|
||||||
//@formatter:on
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun CommandBuilder.putDebugCommands(plugin: ParcelsPlugin): CommandBuilder {
|
generateHelpAndSyntaxCommands()
|
||||||
//if (!logger.isDebugEnabled) return this
|
getDispatcher()
|
||||||
//@formatter:off
|
}
|
||||||
return group("debug", "d")
|
|
||||||
.registerCommands(CommandsDebug(plugin))
|
inline fun CommandBuilder.group(name: String, vararg aliases: String, config: CommandBuilder.() -> Unit) {
|
||||||
.parent()
|
group(name, *aliases)
|
||||||
//@formatter:on
|
config()
|
||||||
|
parent()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CommandBuilder.generateHelpAndSyntaxCommands(): CommandBuilder {
|
private fun CommandBuilder.generateHelpAndSyntaxCommands(): CommandBuilder {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import io.dico.dicore.command.parameter.type.ParameterType
|
|||||||
import io.dico.parcels2.Parcel
|
import io.dico.parcels2.Parcel
|
||||||
import io.dico.parcels2.ParcelProvider
|
import io.dico.parcels2.ParcelProvider
|
||||||
import io.dico.parcels2.ParcelWorld
|
import io.dico.parcels2.ParcelWorld
|
||||||
|
import io.dico.parcels2.PlayerProfile
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
@@ -44,3 +45,12 @@ class ParcelParameterType(val parcelProvider: ParcelProvider) : ParameterType<Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ProfileParameterType : ParameterType<PlayerProfile, Void>(PlayerProfile::class.java) {
|
||||||
|
|
||||||
|
override fun parse(parameter: Parameter<PlayerProfile, Void>, sender: CommandSender, buffer: ArgumentBuffer): PlayerProfile {
|
||||||
|
val input = buffer.next()
|
||||||
|
return PlayerProfile.byName(input, allowReal = true, allowFake = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class ParcelListeners(
|
|||||||
if (ppa.isNullOr { hasBlockVisitors }) event.isCancelled = true
|
if (ppa.isNullOr { hasBlockVisitors }) event.isCancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private val bedTypes = EnumSet.copyOf(getMaterialsWithWoodTypePrefix("BED").toList())
|
private val bedTypes = EnumSet.copyOf(getMaterialsWithWoolColorPrefix("BED").toList())
|
||||||
/*
|
/*
|
||||||
* Prevents players from placing liquids, using flint and steel, changing redstone components,
|
* Prevents players from placing liquids, using flint and steel, changing redstone components,
|
||||||
* using inputs (unless allowed by the plot),
|
* using inputs (unless allowed by the plot),
|
||||||
|
|||||||
Reference in New Issue
Block a user