From 9cf399f956869c8354b62060296eb17bedf42a9e Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Thu, 12 Aug 2021 03:15:53 -0400 Subject: [PATCH] RECOVERY --- .../com/volmit/iris/util/decree/Decree.java | 33 ++++++++ .../iris/util/decree/DecreeCommand.java | 22 +++++ .../iris/util/decree/DecreeContext.java | 55 ++++++++++++ .../volmit/iris/util/decree/DecreeNode.java | 84 +++++++++++++++++++ .../volmit/iris/util/decree/DecreeOrigin.java | 25 ++++++ .../iris/util/decree/DecreeParameter.java | 75 +++++++++++++++++ .../util/decree/DecreeParameterHandler.java | 70 ++++++++++++++++ .../util/decree/DecreeParsingException.java | 25 ++++++ .../volmit/iris/util/decree/DecreeSystem.java | 39 +++++++++ .../util/decree/DecreeWhichException.java | 25 ++++++ .../com/volmit/iris/util/decree/EXAMPLE.java | 43 ++++++++++ .../com/volmit/iris/util/decree/Param.java | 32 +++++++ .../util/decree/handlers/ByteHandler.java | 53 ++++++++++++ .../util/decree/handlers/DoubleHandler.java | 53 ++++++++++++ .../util/decree/handlers/FloatHandler.java | 53 ++++++++++++ .../util/decree/handlers/IntegerHandler.java | 54 ++++++++++++ .../util/decree/handlers/LongHandler.java | 53 ++++++++++++ .../util/decree/handlers/PlayerHandler.java | 71 ++++++++++++++++ .../util/decree/handlers/ShortHandler.java | 53 ++++++++++++ .../util/decree/handlers/StringHandler.java | 48 +++++++++++ .../util/decree/handlers/WorldHandler.java | 70 ++++++++++++++++ 21 files changed, 1036 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/decree/Decree.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeCommand.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeContext.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeNode.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeParameter.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeSystem.java create mode 100644 src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java create mode 100644 src/main/java/com/volmit/iris/util/decree/EXAMPLE.java create mode 100644 src/main/java/com/volmit/iris/util/decree/Param.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java diff --git a/src/main/java/com/volmit/iris/util/decree/Decree.java b/src/main/java/com/volmit/iris/util/decree/Decree.java new file mode 100644 index 000000000..2b6a73ccb --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/Decree.java @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +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 ""; +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/DecreeCommand.java new file mode 100644 index 000000000..255190726 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeCommand.java @@ -0,0 +1,22 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +public class DecreeCommand { +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeContext.java b/src/main/java/com/volmit/iris/util/decree/DecreeContext.java new file mode 100644 index 000000000..16380897f --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeContext.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +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.context.IrisContext; +import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.ChronoLatch; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DecreeContext { + private static ChronoLatch cl = new ChronoLatch(60000); + private static final KMap context = new KMap<>(); + private final VolmitSender sender; + + public static VolmitSender get() { + return context.get(Thread.currentThread()); + } + + public static void touch(VolmitSender c) { + synchronized (context) { + context.put(Thread.currentThread(), c); + + if (cl.flip()) { + for (Thread i : context.k()) { + if (!i.isAlive()) { + context.remove(i); + } + } + } + } + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java new file mode 100644 index 000000000..02b1b440a --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java @@ -0,0 +1,84 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +import com.volmit.iris.util.collection.KList; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class DecreeNode { + private final Method method; + + public DecreeNode(Method method) + { + this.method = method; + } + + public KList getParameters() + { + KList p = new KList<>(); + + for(Parameter i : method.getParameters()) + { + p.add(new DecreeParameter(i)); + } + + return p; + } + + public String getName() + { + Decree p = method.getDeclaredAnnotation(Decree.class); + return p == null || p.name().equals("methodName") ? method.getName() : p.name(); + } + + public DecreeOrigin getOrigin() + { + Decree p = method.getDeclaredAnnotation(Decree.class); + return p == null ? DecreeOrigin.BOTH : p.origin(); + } + + public String getDescription() + { + Decree p = method.getDeclaredAnnotation(Decree.class); + return p != null ? p.description() : "No Description Provided"; + } + + public KList getAliases() + { + Decree p = method.getDeclaredAnnotation(Decree.class); + KList d = new KList<>(); + + if(p != null) + { + for(String i : p.aliases()) + { + if(i.isEmpty()) + { + continue; + } + + d.add(i); + } + } + + return d; + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java new file mode 100644 index 000000000..e9e5a688c --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +public enum DecreeOrigin { + PLAYER, + CONSOLE, + BOTH +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java new file mode 100644 index 000000000..47dffbd2d --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -0,0 +1,75 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +import com.volmit.iris.util.collection.KList; + +import java.lang.reflect.Parameter; + +public class DecreeParameter { + private final Parameter parameter; + + public DecreeParameter(Parameter parameter) + { + this.parameter = parameter; + } + + public DecreeParameterHandler getHandler() + { + return DecreeSystem.handle(getType()); + } + + public Class getType() + { + return parameter.getType(); + } + + public String getName() + { + Param p = parameter.getDeclaredAnnotation(Param.class); + return p == null ? parameter.getName() : p.name().isEmpty() ? parameter.getName() : p.name(); + } + + public String getDescription() + { + Param p = parameter.getDeclaredAnnotation(Param.class); + return p.name().isEmpty() ? parameter.getName() : p.name(); + } + + public KList getAliases() + { + Param p = parameter.getDeclaredAnnotation(Param.class); + KList d= new KList<>(); + + if(p != null) + { + for(String i : p.aliases()) + { + if(i.isEmpty()) + { + continue; + } + + d.add(i); + } + } + + return d; + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java new file mode 100644 index 000000000..e7f789254 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -0,0 +1,70 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KSet; + +import java.util.Locale; + +public interface DecreeParameterHandler { + KList getPossibilities(); + + String toString(T t); + + T parse(String in) throws DecreeParsingException, DecreeWhichException; + + boolean supports(Class type); + + default KList getPossibilities(String input) + { + KList p = getPossibilities(); + KList m = new KList<>(); + + if(p != null) + { + if(input.trim().isEmpty()) + { + return getPossibilities(); + } + + KList f = p.convert(this::toString); + + for(int i = 0; i < f.size(); i++) + { + String g = f.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; + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java b/src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java new file mode 100644 index 000000000..4971809b4 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +public class DecreeParsingException extends Exception{ + public DecreeParsingException(String message) { + super(message); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java new file mode 100644 index 000000000..35b141865 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -0,0 +1,39 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +import com.volmit.iris.Iris; +import com.volmit.iris.util.collection.KList; + +public class DecreeSystem { + private static final KList> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler) i); + + public static DecreeParameterHandler handle(Class type) + { + for(DecreeParameterHandler i : handlers) + { + if(i.supports(type)) + { + return i; + } + } + + return null; + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java b/src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java new file mode 100644 index 000000000..9ec282769 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +public class DecreeWhichException extends Exception{ + public DecreeWhichException() { + super(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java b/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java new file mode 100644 index 000000000..bd65c3919 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree; + +import org.bukkit.entity.Player; + +public class EXAMPLE +{ + @Decree + public void kick( + @Param(name = "player", description = "The Player to kick from the server", aliases = "p") + Player player, + @Param(name = "reason", description = "A reason to kick the player for", aliases = "r") + String reason) + { + player.kickPlayer(reason); + 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!"); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/Param.java b/src/main/java/com/volmit/iris/util/decree/Param.java new file mode 100644 index 000000000..9b3b5f532 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/Param.java @@ -0,0 +1,32 @@ +/* + * 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 . + */ + +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 ""; +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java new file mode 100644 index 000000000..448f0c603 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +public class ByteHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public String toString(Byte aByte) { + return aByte.toString(); + } + + @Override + public Byte parse(String in) throws DecreeParsingException { + try + { + return Byte.parseByte(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse byte \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Byte.class) || type.equals(byte.class); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java new file mode 100644 index 000000000..947482fc0 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +public class DoubleHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public Double parse(String in) throws DecreeParsingException { + try + { + return Double.parseDouble(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse double \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Double.class) || type.equals(double.class); + } + + @Override + public String toString(Double f) { + return f.toString(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java new file mode 100644 index 000000000..93d21ea19 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +public class FloatHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public Float parse(String in) throws DecreeParsingException { + try + { + return Float.parseFloat(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse float \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Float.class) || type.equals(float.class); + } + + @Override + public String toString(Float f) { + return f.toString(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java new file mode 100644 index 000000000..c5329b4ba --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java @@ -0,0 +1,54 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; +import net.kyori.adventure.text.minimessage.parser.ParsingException; + +public class IntegerHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public Integer parse(String in) throws DecreeParsingException { + try + { + return Integer.parseInt(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse integer \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Integer.class) || type.equals(int.class); + } + + @Override + public String toString(Integer f) { + return f.toString(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java new file mode 100644 index 000000000..0efc70992 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +public class LongHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public Long parse(String in) throws DecreeParsingException { + try + { + return Long.parseLong(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse long \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Long.class) || type.equals(long.class); + } + + @Override + public String toString(Long f) { + return f.toString(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java new file mode 100644 index 000000000..be3f34d51 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java @@ -0,0 +1,71 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.DecreeWhichException; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.stream.Collectors; + +public class PlayerHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return new KList<>(new ArrayList<>(Bukkit.getOnlinePlayers())); + } + + @Override + public String toString(Player player) { + return player.getName(); + } + + @Override + public Player parse(String in) throws DecreeParsingException, DecreeWhichException { + try + { + KList options = getPossibilities(in); + + if(options.isEmpty()) + { + throw new DecreeParsingException("Unable to find Player \"" + in + "\""); + } + + else if(options.size() > 1) + { + throw new DecreeWhichException(); + } + + return options.get(0); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to find Player \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Player.class); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java new file mode 100644 index 000000000..de364981d --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +public class ShortHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public Short parse(String in) throws DecreeParsingException { + try + { + return Short.parseShort(in); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to parse short \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(Short.class) || type.equals(short.class); + } + + @Override + public String toString(Short f) { + return f.toString(); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java new file mode 100644 index 000000000..6c481dd1d --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java @@ -0,0 +1,48 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; + +/** + * Abstraction can sometimes breed stupidity + */ +public class StringHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return null; + } + + @Override + public String toString(String s) { + return s; + } + + @Override + public String parse(String in) throws DecreeParsingException { + return in; + } + + @Override + public boolean supports(Class type) { + return type.equals(String.class); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java new file mode 100644 index 000000000..0b26f4e45 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java @@ -0,0 +1,70 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.DecreeWhichException; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.util.ArrayList; + +public class WorldHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + return new KList<>(new ArrayList<>(Bukkit.getWorlds())); + } + + @Override + public String toString(World player) { + return player.getName(); + } + + @Override + public World parse(String in) throws DecreeParsingException, DecreeWhichException { + try + { + KList options = getPossibilities(in); + + if(options.isEmpty()) + { + throw new DecreeParsingException("Unable to find World \"" + in + "\""); + } + + else if(options.size() > 1) + { + throw new DecreeWhichException(); + } + + return options.get(0); + } + + catch(Throwable e) + { + throw new DecreeParsingException("Unable to find World \"" + in + "\""); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(World.class); + } +}