mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 03:29:06 +00:00
Revert "Revert "Merge pull request #561 from CocoTheOwner/DecreeCommands""
This reverts commit a451189d83.
This commit is contained in:
@@ -47,13 +47,21 @@ public class DecreeNode {
|
||||
* @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> required = new KList<>();
|
||||
KList<DecreeParameter> optional = new KList<>();
|
||||
|
||||
for (Parameter i : method.getParameters()) {
|
||||
p.add(new DecreeParameter(i));
|
||||
DecreeParameter p = new DecreeParameter(i);
|
||||
if (p.isRequired()){
|
||||
required.add(p);
|
||||
} else {
|
||||
optional.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
required.addAll(optional);
|
||||
|
||||
return p;
|
||||
return required;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -56,6 +56,9 @@ public class BiomeHandler implements DecreeParameterHandler<IrisBiome> {
|
||||
|
||||
@Override
|
||||
public IrisBiome parse(String in) throws DecreeParsingException, DecreeWhichException {
|
||||
if (in.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KList<IrisBiome> options = getPossibilities(in);
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@ public class BooleanHandler implements DecreeParameterHandler<Boolean> {
|
||||
@Override
|
||||
public Boolean parse(String in) throws DecreeParsingException {
|
||||
try {
|
||||
if (in.equals("null") || in.equals("other") || in.equals("flip")) {
|
||||
return null;
|
||||
}
|
||||
return Boolean.parseBoolean(in);
|
||||
} catch (Throwable e) {
|
||||
throw new DecreeParsingException("Unable to parse boolean \"" + in + "\"");
|
||||
|
||||
@@ -56,6 +56,9 @@ public class RegionHandler implements DecreeParameterHandler<IrisRegion> {
|
||||
|
||||
@Override
|
||||
public IrisRegion parse(String in) throws DecreeParsingException, DecreeWhichException {
|
||||
if (in.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
KList<IrisRegion> options = getPossibilities(in);
|
||||
|
||||
|
||||
@@ -43,14 +43,7 @@ public class VectorHandler implements DecreeParameterHandler<Vector> {
|
||||
|
||||
@Override
|
||||
public KList<Vector> getPossibilities() {
|
||||
KList<Vector> vx = new KList<>();
|
||||
VolmitSender s = DecreeContext.get();
|
||||
|
||||
if (s.isPlayer()) {
|
||||
vx.add(s.player().getLocation().toVector());
|
||||
}
|
||||
|
||||
return vx;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,13 @@ import org.bukkit.World;
|
||||
public class WorldHandler implements DecreeParameterHandler<World> {
|
||||
@Override
|
||||
public KList<World> getPossibilities() {
|
||||
return new KList<>(Bukkit.getWorlds());
|
||||
KList<World> options = new KList<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
if (!world.getName().toLowerCase().startsWith("iris/")){
|
||||
options.add(world);
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.util.plugin;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.decree.DecreeParameter;
|
||||
import com.volmit.iris.util.decree.virtual.VirtualDecreeCommand;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
@@ -42,6 +43,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Comparator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -426,55 +428,101 @@ public class VolmitSender implements CommandSender {
|
||||
|
||||
public void sendDecreeHelpNode(VirtualDecreeCommand i) {
|
||||
if (isPlayer()) {
|
||||
//@builder
|
||||
String s = (
|
||||
|
||||
String newline = "<reset>\n";
|
||||
|
||||
/// Command
|
||||
// Contains main command & aliases
|
||||
String realText = i.getPath() + " >" + "<#46826a>⇀<gradient:#42ecf5:#428df5> " + i.getName();
|
||||
String hoverTitle = i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", ");
|
||||
String description = "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription();
|
||||
String usage = "<#bbe03f>✒ <#a8e0a2><font:minecraft:uniform>";
|
||||
String onClick;
|
||||
if (i.isNode()) {
|
||||
if (i.getNode().getParameters().isEmpty()){
|
||||
usage += "There are no parameters. Click to run.";
|
||||
onClick = "run_command";
|
||||
} else {
|
||||
usage += "Hover over all of the parameters to learn more.";
|
||||
onClick = "suggest_command";
|
||||
}
|
||||
} else {
|
||||
usage += "This is a command category. Click to run.";
|
||||
onClick = "run_command";
|
||||
}
|
||||
|
||||
String suggestion = "";
|
||||
String suggestions = "";
|
||||
if (i.isNode() && i.getNode().getParameters().isNotEmpty()) {
|
||||
suggestion += newline + "<#aebef2>✦ <#5ef288><font:minecraft:uniform>" + i.getParentPath() + " <#42ecf5>" + i.getName() + " "
|
||||
+ i.getNode().getParameters().convert((f) -> "<#d665f0>" + f.example()).toString(" ");
|
||||
suggestions += newline + "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i);
|
||||
}
|
||||
|
||||
/// Params
|
||||
StringBuilder nodes = new StringBuilder();
|
||||
if (i.isNode()){
|
||||
for (DecreeParameter p : i.getNode().getParameters()) {
|
||||
|
||||
String nTitle = "<gradient:#d665f0:#a37feb>" + p.getName();
|
||||
String nHoverTitle = p.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ");
|
||||
String nDescription = "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + p.getDescription();
|
||||
String nUsage;
|
||||
String context = "";
|
||||
if (p.isRequired()){
|
||||
nUsage = "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required.";
|
||||
} else if (p.hasDefault()) {
|
||||
nUsage = "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \""+ p.getParam().defaultValue()+"\" if undefined.";
|
||||
} else {
|
||||
nUsage = "<#a73abd>✔ <#78dcf0><font:minecraft:uniform>This parameter is optional.";
|
||||
}
|
||||
if (p.isContextual()){
|
||||
context = "<#ff9900>➱ <#ffcc00><font:minecraft:uniform>The value may be derived from environment context" + newline;
|
||||
}
|
||||
String type = "<#cc00ff>✢ <#ff33cc><font:minecraft:uniform>This parameter is of type " + p.getType().getSimpleName();
|
||||
String fullTitle;
|
||||
if (p.isRequired()){
|
||||
fullTitle = "<red>[" + nTitle + "<red>] ";
|
||||
} else {
|
||||
fullTitle = "<#4f4f4f>⊰" + nTitle + "<#4f4f4f>⊱";
|
||||
}
|
||||
|
||||
nodes
|
||||
.append("<hover:show_text:'")
|
||||
.append(nHoverTitle).append(newline)
|
||||
.append(nDescription).append(newline)
|
||||
.append(context)
|
||||
.append(nUsage).append(newline)
|
||||
.append(type)
|
||||
.append("'>")
|
||||
.append(fullTitle)
|
||||
.append("</hover>");
|
||||
}
|
||||
} else {
|
||||
nodes = new StringBuilder("<gradient:#afe3d3:#a2dae0> - Category of Commands");
|
||||
}
|
||||
|
||||
/// Wrapper
|
||||
String wrapper =
|
||||
"<hover:show_text:'" +
|
||||
i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription() + "<reset>\n"
|
||||
+ "<#bbe03f>✒ <#a8e0a2>" + (i.isNode()
|
||||
? ((i.getNode().getParameters().isEmpty()
|
||||
? "<font:minecraft:uniform>There are no parameters.<reset>"
|
||||
: "<font:minecraft:uniform>Hover over all of the parameters to learn more.<reset>" + "\n"))
|
||||
: "<font:minecraft:uniform>This is a command category. Run <reset><#98eda5>" + i.getPath())
|
||||
+ (i.isNode()
|
||||
? (i.getNode().getParameters().isNotEmpty())
|
||||
? "<#aebef2>✦ <#5ef288><font:minecraft:uniform>"
|
||||
+ i.getParentPath()
|
||||
+ " <#42ecf5>"
|
||||
+ i.getName() + " "
|
||||
+ i.getNode().getParameters().convert((f)
|
||||
-> "<#d665f0>" + f.example())
|
||||
.toString(" ") + "\n"
|
||||
: ""
|
||||
: "")
|
||||
+ (i.isNode() ? "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "<reset>" : "")
|
||||
+ "'><click:" + (i.isNode() ? "suggest_command" : "run_command") + ":" + i.getPath() + " >"
|
||||
+ "<#46826a>⇀<gradient:#42ecf5:#428df5> " + i.getName() + "</click></hover>"
|
||||
+ (i.isNode() ?
|
||||
" " + i.getNode().getParameters().convert((f)
|
||||
-> "<hover:show_text:'"
|
||||
+ f.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ") + "\n"
|
||||
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + f.getDescription() + "<reset>\n"
|
||||
+ (f.isRequired()
|
||||
? "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required."
|
||||
: (f.hasDefault()
|
||||
? "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \"" + f.getParam().defaultValue() + "\" if undefined."
|
||||
: "<#a73abd>✔ <#78dcf0><font:minecraft:uniform>This parameter is optional.")) + "<reset>\n"
|
||||
+ (f.isContextual() ? "<#ff9900>➱ <#ffcc00><font:minecraft:uniform>The value may be derived from environment context <reset>\n" : "")
|
||||
+ "<#cc00ff>✢ <#ff33cc><font:minecraft:uniform>This parameter is of type " + f.getType().getSimpleName()
|
||||
+ "'>"
|
||||
+ (f.isRequired() ? "<red>[" : "")
|
||||
+ "<gradient:#d665f0:#a37feb>" + f.getName()
|
||||
+ (f.isRequired() ? "<red>]<gray>" : "")
|
||||
+ "</hover>").toString(" ")
|
||||
: "<gradient:#afe3d3:#a2dae0> - Category of Commands"
|
||||
)
|
||||
);
|
||||
//@done
|
||||
sendMessageRaw(s);
|
||||
System.out.println(s);
|
||||
hoverTitle + newline +
|
||||
description + newline +
|
||||
usage +
|
||||
suggestion + //Newlines for suggestions are added when they're built, to prevent blanklines.
|
||||
suggestions + // ^
|
||||
"'>" +
|
||||
"<click:" +
|
||||
onClick +
|
||||
":" +
|
||||
realText +
|
||||
"</click>" +
|
||||
"</hover>" +
|
||||
" " +
|
||||
nodes;
|
||||
|
||||
sendMessageRaw(wrapper);
|
||||
} else {
|
||||
sendMessage(i.getPath() + "()");
|
||||
sendMessage(i.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user