mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-09 09:16:12 +00:00
CHATTY
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.decree;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package com.volmit.iris.util.decree;
|
||||
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
|
||||
public interface DecreeExecutor {
|
||||
@@ -26,6 +28,16 @@ public interface DecreeExecutor {
|
||||
return DecreeContext.get();
|
||||
}
|
||||
|
||||
default Engine engine()
|
||||
{
|
||||
if(sender().isPlayer())
|
||||
{
|
||||
return IrisToolbelt.access(sender().player().getWorld()).getEngine();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
default <T> T get(T v, T ifUndefined)
|
||||
{
|
||||
return v == null ? ifUndefined : v;
|
||||
|
||||
@@ -82,4 +82,21 @@ public class DecreeParameter {
|
||||
public Object getDefaultValue() throws DecreeParsingException, DecreeWhichException {
|
||||
return param.defaultValue().isEmpty() ? null : getHandler().parse(param.defaultValue());
|
||||
}
|
||||
|
||||
public boolean hasDefault() {
|
||||
return !param.defaultValue().isEmpty();
|
||||
}
|
||||
|
||||
public String example() {
|
||||
KList<?> ff = getHandler().getPossibilities();
|
||||
ff = ff != null ? ff : new KList<>();
|
||||
KList<String> f = ff.convert((i) -> getHandler().toStringForce(i));
|
||||
if(f.isEmpty())
|
||||
{
|
||||
f = new KList<>();
|
||||
f.add(getHandler().getRandomDefault());
|
||||
}
|
||||
|
||||
return f.getRandom();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ public interface DecreeParameterHandler<T> {
|
||||
*/
|
||||
String toString(T t);
|
||||
|
||||
default String toStringForce(Object t)
|
||||
{
|
||||
return toString((T)t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should parse a String into the designated type
|
||||
* @param in The string to parse
|
||||
@@ -90,4 +95,9 @@ public interface DecreeParameterHandler<T> {
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
default String getRandomDefault()
|
||||
{
|
||||
return "NOEXAMPLE";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ public @interface Decree {
|
||||
*/
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Only allow if studio mode is enabled
|
||||
* @return defaults to false
|
||||
*/
|
||||
boolean studio() default false;
|
||||
|
||||
boolean sync() default false;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -88,4 +89,10 @@ public class BiomeHandler implements DecreeParameterHandler<IrisBiome> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(IrisBiome.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return "biome";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class ByteHandler implements DecreeParameterHandler<Byte> {
|
||||
@Override
|
||||
@@ -50,4 +51,10 @@ public class ByteHandler implements DecreeParameterHandler<Byte> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(Byte.class) || type.equals(byte.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return RNG.r.i(0, Byte.MAX_VALUE) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +89,10 @@ public class DimensionHandler implements DecreeParameterHandler<IrisDimension> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(IrisDimension.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return "dimension";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class DoubleHandler implements DecreeParameterHandler<Double> {
|
||||
@Override
|
||||
@@ -50,4 +52,10 @@ public class DoubleHandler implements DecreeParameterHandler<Double> {
|
||||
public String toString(Double f) {
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return Form.f(RNG.r.d(0, 99.99), 1) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FloatHandler implements DecreeParameterHandler<Float> {
|
||||
@Override
|
||||
@@ -50,4 +52,10 @@ public class FloatHandler implements DecreeParameterHandler<Float> {
|
||||
public String toString(Float f) {
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return Form.f(RNG.r.d(0, 99.99), 1) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class IntegerHandler implements DecreeParameterHandler<Integer> {
|
||||
@Override
|
||||
@@ -50,4 +52,10 @@ public class IntegerHandler implements DecreeParameterHandler<Integer> {
|
||||
public String toString(Integer f) {
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return RNG.r.i(0, 99) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class LongHandler implements DecreeParameterHandler<Long> {
|
||||
@Override
|
||||
@@ -50,4 +51,10 @@ public class LongHandler implements DecreeParameterHandler<Long> {
|
||||
public String toString(Long f) {
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return RNG.r.i(0, 99) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,4 +67,10 @@ public class PlayerHandler implements DecreeParameterHandler<Player> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(Player.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return "playername";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,10 @@ public class RegionHandler implements DecreeParameterHandler<IrisRegion> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(IrisRegion.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return "region";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class ShortHandler implements DecreeParameterHandler<Short> {
|
||||
@Override
|
||||
@@ -50,4 +51,10 @@ public class ShortHandler implements DecreeParameterHandler<Short> {
|
||||
public String toString(Short f) {
|
||||
return f.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return RNG.r.i(0, 99) + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
/**
|
||||
* Abstraction can sometimes breed stupidity
|
||||
@@ -45,4 +46,11 @@ public class StringHandler implements DecreeParameterHandler<String> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return new KList<String>().qadd("text").qadd("string")
|
||||
.qadd("blah").qadd("derp").qadd("yolo").getRandom();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,4 +67,10 @@ public class WorldHandler implements DecreeParameterHandler<World> {
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(World.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault()
|
||||
{
|
||||
return "world";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.decree.virtual;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.decree.DecreeContext;
|
||||
@@ -82,10 +83,11 @@ public class VirtualDecreeCommand {
|
||||
|
||||
if(childRoot == null)
|
||||
{
|
||||
i.set(v, i.getType().getConstructor().newInstance());
|
||||
childRoot = i.getType().getConstructor().newInstance();
|
||||
i.set(v, childRoot);
|
||||
}
|
||||
|
||||
c.getNodes().add(createRoot(c, v));
|
||||
c.getNodes().add(createRoot(c, childRoot));
|
||||
}
|
||||
|
||||
for(Method i : v.getClass().getDeclaredMethods())
|
||||
@@ -120,11 +122,20 @@ public class VirtualDecreeCommand {
|
||||
return "/" + n.reverse().qadd(getName()).toString(" ");
|
||||
}
|
||||
|
||||
public String getParentPath()
|
||||
{
|
||||
return getParent().getPath();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return isNode() ? getNode().getName() : getType().getDeclaredAnnotation(Decree.class).name();
|
||||
}
|
||||
|
||||
private boolean isStudio() {
|
||||
return isNode() ? getNode().getDecree().studio() : getType().getDeclaredAnnotation(Decree.class).studio();
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return isNode() ? getNode().getDescription() : getType().getDeclaredAnnotation(Decree.class).description();
|
||||
@@ -262,6 +273,12 @@ public class VirtualDecreeCommand {
|
||||
|
||||
public boolean invoke(VolmitSender sender, KList<String> args, KList<Integer> skip)
|
||||
{
|
||||
if(isStudio() && !IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)");
|
||||
return false;
|
||||
}
|
||||
|
||||
Iris.debug("@ " + getPath() + " with " + args.toString(", "));
|
||||
if(isNode())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user