mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Merge pull request #527 from CocoTheOwner/decree+
Document, simplify & further
This commit is contained in:
commit
7ace88ae0d
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface Decree {
|
|
||||||
String name() default "methodName";
|
|
||||||
|
|
||||||
String description() default "No Description Provided";
|
|
||||||
|
|
||||||
DecreeOrigin origin() default DecreeOrigin.BOTH;
|
|
||||||
|
|
||||||
String[] aliases() default "";
|
|
||||||
}
|
|
@ -18,11 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
import com.volmit.iris.core.project.loader.IrisData;
|
|
||||||
import com.volmit.iris.engine.IrisComplex;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.context.IrisContext;
|
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -33,7 +29,6 @@ import lombok.Data;
|
|||||||
public class DecreeContext {
|
public class DecreeContext {
|
||||||
private static ChronoLatch cl = new ChronoLatch(60000);
|
private static ChronoLatch cl = new ChronoLatch(60000);
|
||||||
private static final KMap<Thread, VolmitSender> context = new KMap<>();
|
private static final KMap<Thread, VolmitSender> context = new KMap<>();
|
||||||
private final VolmitSender sender;
|
|
||||||
|
|
||||||
public static VolmitSender get() {
|
public static VolmitSender get() {
|
||||||
return context.get(Thread.currentThread());
|
return context.get(Thread.currentThread());
|
||||||
|
@ -19,64 +19,72 @@
|
|||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
|
import com.volmit.iris.util.decree.exceptions.DecreeInstanceException;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DecreeNode {
|
public class DecreeNode {
|
||||||
private final Method method;
|
private final Method method;
|
||||||
|
private final Decree decree;
|
||||||
|
|
||||||
public DecreeNode(Method method)
|
public DecreeNode(Method method) throws DecreeInstanceException {
|
||||||
{
|
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
this.decree = method.getDeclaredAnnotation(Decree.class);
|
||||||
|
if (decree == null){
|
||||||
|
throw new DecreeInstanceException("Cannot instantiate DecreeNode on method not annotated by @Decree");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<DecreeParameter> getParameters()
|
/**
|
||||||
{
|
* Get the parameters of this decree node
|
||||||
|
* @return The list of parameters if ALL are annotated by @{@link Param}, else null
|
||||||
|
*/
|
||||||
|
public KList<DecreeParameter> getParameters() {
|
||||||
KList<DecreeParameter> p = new KList<>();
|
KList<DecreeParameter> p = new KList<>();
|
||||||
|
|
||||||
for(Parameter i : method.getParameters())
|
for(Parameter i : method.getParameters())
|
||||||
{
|
{
|
||||||
p.add(new DecreeParameter(i));
|
try {
|
||||||
|
p.add(new DecreeParameter(i));
|
||||||
|
} catch (DecreeInstanceException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName() {
|
||||||
{
|
return decree.name().equals(Decree.METHOD_NAME) ? method.getName() : decree.name();
|
||||||
Decree p = method.getDeclaredAnnotation(Decree.class);
|
|
||||||
return p == null || p.name().equals("methodName") ? method.getName() : p.name();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecreeOrigin getOrigin()
|
public DecreeOrigin getOrigin() {
|
||||||
{
|
return decree.origin();
|
||||||
Decree p = method.getDeclaredAnnotation(Decree.class);
|
|
||||||
return p == null ? DecreeOrigin.BOTH : p.origin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription()
|
public String getDescription() {
|
||||||
{
|
return decree.description().isEmpty() ? Decree.DEFAULT_DESCRIPTION : decree.description();
|
||||||
Decree p = method.getDeclaredAnnotation(Decree.class);
|
|
||||||
return p != null ? p.description() : "No Description Provided";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<String> getAliases()
|
public KList<String> getAliases() {
|
||||||
{
|
|
||||||
Decree p = method.getDeclaredAnnotation(Decree.class);
|
|
||||||
KList<String> d = new KList<>();
|
KList<String> d = new KList<>();
|
||||||
|
|
||||||
if(p != null)
|
if (Arrays.equals(decree.aliases(), new String[]{Decree.NO_ALIASES})){
|
||||||
{
|
return d;
|
||||||
for(String i : p.aliases())
|
}
|
||||||
{
|
|
||||||
if(i.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
d.add(i);
|
for(String i : decree.aliases())
|
||||||
|
{
|
||||||
|
if(i.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -18,8 +18,26 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
|
|
||||||
public enum DecreeOrigin {
|
public enum DecreeOrigin {
|
||||||
PLAYER,
|
PLAYER,
|
||||||
CONSOLE,
|
CONSOLE,
|
||||||
BOTH
|
/**
|
||||||
|
* Both the player and the console
|
||||||
|
*/
|
||||||
|
BOTH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the origin is valid for a sender
|
||||||
|
* @param sender The sender to check
|
||||||
|
* @return True if valid for origin
|
||||||
|
*/
|
||||||
|
public boolean validFor(VolmitSender sender){
|
||||||
|
if (sender.isPlayer()){
|
||||||
|
return this.equals(PLAYER) || this.equals(BOTH);
|
||||||
|
} else {
|
||||||
|
return this.equals(CONSOLE) || this.equals(BOTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,55 +19,59 @@
|
|||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
|
import com.volmit.iris.util.decree.exceptions.DecreeInstanceException;
|
||||||
|
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DecreeParameter {
|
public class DecreeParameter {
|
||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
|
private final Param param;
|
||||||
|
|
||||||
public DecreeParameter(Parameter parameter)
|
public DecreeParameter(Parameter parameter) throws DecreeInstanceException {
|
||||||
{
|
|
||||||
this.parameter = parameter;
|
this.parameter = parameter;
|
||||||
|
this.param = parameter.getDeclaredAnnotation(Param.class);
|
||||||
|
if (param == null){
|
||||||
|
throw new DecreeInstanceException("Cannot instantiate DecreeParameter on parameter not annotated by @Param");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DecreeParameterHandler<?> getHandler()
|
public DecreeParameterHandler<?> getHandler() {
|
||||||
{
|
return DecreeSystem.getHandler(getType());
|
||||||
return DecreeSystem.handle(getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getType()
|
public Class<?> getType() {
|
||||||
{
|
|
||||||
return parameter.getType();
|
return parameter.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName() {
|
||||||
{
|
return param.name().isEmpty() ? parameter.getName() : param.name();
|
||||||
Param p = parameter.getDeclaredAnnotation(Param.class);
|
|
||||||
return p == null ? parameter.getName() : p.name().isEmpty() ? parameter.getName() : p.name();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription()
|
public String getDescription() {
|
||||||
{
|
return param.description().isEmpty() ? Param.DEFAULT_DESCRIPTION : param.description();
|
||||||
Param p = parameter.getDeclaredAnnotation(Param.class);
|
|
||||||
return p.name().isEmpty() ? parameter.getName() : p.name();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<String> getAliases()
|
public boolean isRequired() {
|
||||||
{
|
return param.value().equals(Param.REQUIRED);
|
||||||
Param p = parameter.getDeclaredAnnotation(Param.class);
|
}
|
||||||
KList<String> d= new KList<>();
|
|
||||||
|
|
||||||
if(p != null)
|
public KList<String> getAliases() {
|
||||||
|
KList<String> d = new KList<>();
|
||||||
|
|
||||||
|
if (Arrays.equals(param.aliases(), new String[]{Param.NO_ALIAS})){
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String i : param.aliases())
|
||||||
{
|
{
|
||||||
for(String i : p.aliases())
|
if(i.isEmpty())
|
||||||
{
|
{
|
||||||
if(i.isEmpty())
|
continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
d.add(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -19,52 +19,84 @@
|
|||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||||
import java.util.Locale;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface DecreeParameterHandler<T> {
|
public interface DecreeParameterHandler<T> {
|
||||||
|
/**
|
||||||
|
* Should return the possible values for this type
|
||||||
|
* @return Possibilities for this type.
|
||||||
|
*/
|
||||||
KList<T> getPossibilities();
|
KList<T> getPossibilities();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converting the type back to a string (inverse of the {@link #parse(String) parse} method)
|
||||||
|
* @param t The input of the designated type to convert to a String
|
||||||
|
* @return The resulting string
|
||||||
|
*/
|
||||||
String toString(T t);
|
String toString(T t);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should parse a String into the designated type
|
||||||
|
* @param in The string to parse
|
||||||
|
* @return The value extracted from the string, of the designated type
|
||||||
|
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
||||||
|
* @throws DecreeWhichException Thrown when multiple results are possible
|
||||||
|
*/
|
||||||
T parse(String in) throws DecreeParsingException, DecreeWhichException;
|
T parse(String in) throws DecreeParsingException, DecreeWhichException;
|
||||||
|
|
||||||
boolean supports(Class<?> type);
|
/**
|
||||||
|
* Returns whether a certain type is supported by this handler<br>
|
||||||
|
* By default, this checks if the {@link #parse(String) parse} method returns the corresponding type.
|
||||||
|
* Hence, this should only be overwritten if multiple types, outside the designated one, are supported.
|
||||||
|
* @param type The type to check
|
||||||
|
* @return True if supported, false if not
|
||||||
|
*/
|
||||||
|
default boolean supports(Class<?> type){
|
||||||
|
try {
|
||||||
|
if (this.getClass().getMethod("parse", String.class).getReturnType().equals(type)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (NoSuchMethodException ignored){}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The possible entries for the inputted string (support for autocomplete on partial entries)
|
||||||
|
* @param input The inputted string to check against
|
||||||
|
* @return A {@link KList} of possibilities
|
||||||
|
*/
|
||||||
default KList<T> getPossibilities(String input)
|
default KList<T> getPossibilities(String input)
|
||||||
{
|
{
|
||||||
KList<T> p = getPossibilities();
|
input = input.trim();
|
||||||
KList<T> m = new KList<>();
|
KList<T> possible = getPossibilities();
|
||||||
|
KList<T> matches = new KList<>();
|
||||||
|
|
||||||
if(p != null)
|
if (possible == null || possible.isEmpty()){
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.isEmpty())
|
||||||
{
|
{
|
||||||
if(input.trim().isEmpty())
|
return getPossibilities();
|
||||||
{
|
}
|
||||||
return getPossibilities();
|
|
||||||
}
|
|
||||||
|
|
||||||
KList<String> f = p.convert(this::toString);
|
KList<String> converted = possible.convert(v -> toString(v).trim());
|
||||||
|
|
||||||
for(int i = 0; i < f.size(); i++)
|
for(int i = 0; i < converted.size(); i++)
|
||||||
|
{
|
||||||
|
String g = converted.get(i);
|
||||||
|
// if
|
||||||
|
// G == I or
|
||||||
|
// I in G or
|
||||||
|
// G in I
|
||||||
|
if(g.equalsIgnoreCase(input) || g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase()))
|
||||||
{
|
{
|
||||||
String g = f.get(i);
|
matches.add(possible.get(i));
|
||||||
if(g.equalsIgnoreCase(input))
|
|
||||||
{
|
|
||||||
m.add(p.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < f.size(); i++)
|
|
||||||
{
|
|
||||||
String g = f.get(i);
|
|
||||||
if(g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase()))
|
|
||||||
{
|
|
||||||
m.addIfMissing(p.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m;
|
return matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,12 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
public class DecreeSystem {
|
public class DecreeSystem {
|
||||||
private static final KList<DecreeParameterHandler<?>> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler<?>) i);
|
private static final KList<DecreeParameterHandler<?>> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler<?>) i);
|
||||||
|
|
||||||
public static DecreeParameterHandler<?> handle(Class<?> type)
|
/**
|
||||||
|
* Get the handler for the specified type
|
||||||
|
* @param type The type to handle
|
||||||
|
* @return The corresponding {@link DecreeParameterHandler}, or null
|
||||||
|
*/
|
||||||
|
public static DecreeParameterHandler<?> getHandler(Class<?> type)
|
||||||
{
|
{
|
||||||
for(DecreeParameterHandler<?> i : handlers)
|
for(DecreeParameterHandler<?> i : handlers)
|
||||||
{
|
{
|
||||||
@ -33,7 +38,6 @@ public class DecreeSystem {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,26 +18,19 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class EXAMPLE
|
public class EXAMPLE extends DecreeCommand {
|
||||||
{
|
|
||||||
@Decree
|
@Decree
|
||||||
public void kick(
|
public void kick(
|
||||||
@Param(name = "player", description = "The Player to kick from the server", aliases = "p")
|
@Param(name = "player", description = "The Player to kick from the server", aliases = "p")
|
||||||
Player player,
|
Player player,
|
||||||
@Param(name = "reason", description = "A reason to kick the player for", aliases = "r")
|
@Param(name = "reason", description = "A reason to kick the player for", value = "No reason!", aliases = "k")
|
||||||
String reason)
|
String reason)
|
||||||
{
|
{
|
||||||
player.kickPlayer(reason);
|
player.kickPlayer(reason);
|
||||||
DecreeContext.get().sendMessage("Kicked " + player.getName());
|
DecreeContext.get().sendMessage("Kicked " + player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree
|
|
||||||
public void kick(
|
|
||||||
@Param(name = "player", description = "The Player to kick from the server", aliases = "p")
|
|
||||||
Player player)
|
|
||||||
{
|
|
||||||
kick(player, "No Reason!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.PARAMETER)
|
|
||||||
public @interface Param {
|
|
||||||
String name();
|
|
||||||
String description() default "No Description Provided";
|
|
||||||
String[] aliases() default "";
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.decree.annotations;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||||
|
public @interface Decree {
|
||||||
|
|
||||||
|
String METHOD_NAME = "Default Method Name";
|
||||||
|
|
||||||
|
String DEFAULT_DESCRIPTION = "No Description Provided";
|
||||||
|
|
||||||
|
String NO_ALIASES = "No Aliases";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this command, which is the Method's name by default
|
||||||
|
*/
|
||||||
|
String name() default METHOD_NAME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The description of this command.<br>
|
||||||
|
* Is {@link #DEFAULT_DESCRIPTION} by default
|
||||||
|
*/
|
||||||
|
String description() default DEFAULT_DESCRIPTION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The origin this command must come from.<br>
|
||||||
|
* Must be elements of the {@link DecreeOrigin} enum<br>
|
||||||
|
* By default, is {@link DecreeOrigin#BOTH}, meaning both console & player can send the command
|
||||||
|
*/
|
||||||
|
DecreeOrigin origin() default DecreeOrigin.BOTH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The aliases of this parameter (instead of just the {@link #name() name} (if specified) or Method Name (name of method))<br>
|
||||||
|
* Can be initialized as just a string (ex. "alias") or as an array (ex. {"alias1", "alias2"})<br>
|
||||||
|
* If someone uses /plugin foo and you specify alias="f" here, /plugin f will do the exact same.
|
||||||
|
*/
|
||||||
|
String[] aliases() default {NO_ALIASES};
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.decree.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.PARAMETER)
|
||||||
|
public @interface Param {
|
||||||
|
String REQUIRED = "REQUIRED";
|
||||||
|
|
||||||
|
String NO_ALIAS = "No Aliases Provided";
|
||||||
|
|
||||||
|
String DEFAULT_DESCRIPTION = "No Description Provided";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main name of this command.<br>
|
||||||
|
* Required parameter.<br>
|
||||||
|
* This is what is used in game, alongside any (if specified) {@link #aliases() aliases}
|
||||||
|
*/
|
||||||
|
String name();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The description of this parameter, used in help-popups in game.<br>
|
||||||
|
* The default value is {@link #DEFAULT_DESCRIPTION}
|
||||||
|
*/
|
||||||
|
String description() default DEFAULT_DESCRIPTION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default value for this argument.<br>
|
||||||
|
* The entered string is parsed to the value similarly to how commandline-text would be.<br>
|
||||||
|
* Default is {@link #REQUIRED}, which indicates the variable MUST be defined by the person running the command.<br>
|
||||||
|
* If you define this, the variable automatically becomes non-required, but can still be set.
|
||||||
|
*/
|
||||||
|
String value() default REQUIRED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The aliases of this parameter (instead of just the {@link #name() name} (if specified) or Method Name (name of method))<br>
|
||||||
|
* Can be initialized as just a string (ex. "alias") or as an array (ex. {"alias1", "alias2"})<br>
|
||||||
|
* If someone uses /plugin foo bar=baz and you specify alias="b" here, /plugin foo b=baz will do the exact same.
|
||||||
|
*/
|
||||||
|
String[] aliases() default {NO_ALIAS};
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.volmit.iris.util.decree.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when classes are instantiated that fail because of a missing or faulty decree component
|
||||||
|
*/
|
||||||
|
public class DecreeInstanceException extends Exception {
|
||||||
|
public DecreeInstanceException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -16,8 +16,11 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when a decree parameter is parsed, but parsing fails
|
||||||
|
*/
|
||||||
public class DecreeParsingException extends Exception{
|
public class DecreeParsingException extends Exception{
|
||||||
public DecreeParsingException(String message) {
|
public DecreeParsingException(String message) {
|
||||||
super(message);
|
super(message);
|
@ -16,10 +16,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.volmit.iris.util.decree;
|
package com.volmit.iris.util.decree.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when more than one option is available for a singular mapping<br>
|
||||||
|
* Like having a hashmap where one input maps to two outputs.
|
||||||
|
*/
|
||||||
public class DecreeWhichException extends Exception{
|
public class DecreeWhichException extends Exception{
|
||||||
public DecreeWhichException() {
|
public DecreeWhichException() {
|
||||||
super();
|
super("More than one option for the entered input");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
public class ByteHandler implements DecreeParameterHandler<Byte> {
|
public class ByteHandler implements DecreeParameterHandler<Byte> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
public class DoubleHandler implements DecreeParameterHandler<Double> {
|
public class DoubleHandler implements DecreeParameterHandler<Double> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
public class FloatHandler implements DecreeParameterHandler<Float> {
|
public class FloatHandler implements DecreeParameterHandler<Float> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,8 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import net.kyori.adventure.text.minimessage.parser.ParsingException;
|
|
||||||
|
|
||||||
public class IntegerHandler implements DecreeParameterHandler<Integer> {
|
public class IntegerHandler implements DecreeParameterHandler<Integer> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
public class LongHandler implements DecreeParameterHandler<Long> {
|
public class LongHandler implements DecreeParameterHandler<Long> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,13 +20,12 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.DecreeWhichException;
|
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PlayerHandler implements DecreeParameterHandler<Player> {
|
public class PlayerHandler implements DecreeParameterHandler<Player> {
|
||||||
@Override
|
@Override
|
||||||
@ -60,7 +59,7 @@ public class PlayerHandler implements DecreeParameterHandler<Player> {
|
|||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
throw new DecreeParsingException("Unable to find Player \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Player \"" + in + "\" because of an uncaught exception: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
public class ShortHandler implements DecreeParameterHandler<Short> {
|
public class ShortHandler implements DecreeParameterHandler<Short> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstraction can sometimes breed stupidity
|
* Abstraction can sometimes breed stupidity
|
||||||
|
@ -20,22 +20,20 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.DecreeWhichException;
|
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class WorldHandler implements DecreeParameterHandler<World> {
|
public class WorldHandler implements DecreeParameterHandler<World> {
|
||||||
@Override
|
@Override
|
||||||
public KList<World> getPossibilities() {
|
public KList<World> getPossibilities() {
|
||||||
return new KList<>(new ArrayList<>(Bukkit.getWorlds()));
|
return new KList<>(Bukkit.getWorlds());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(World player) {
|
public String toString(World world) {
|
||||||
return player.getName();
|
return world.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,10 +54,12 @@ public class WorldHandler implements DecreeParameterHandler<World> {
|
|||||||
|
|
||||||
return options.get(0);
|
return options.get(0);
|
||||||
}
|
}
|
||||||
|
catch(DecreeParsingException e){
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
throw new DecreeParsingException("Unable to find World \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find World \"" + in + "\" because of an uncaught exception: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user