mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
CMD Fixes
This commit is contained in:
parent
f951ee1f91
commit
52ba831b1c
@ -65,6 +65,12 @@ public interface DecreeParameterHandler<T> {
|
|||||||
*/
|
*/
|
||||||
default KList<T> getPossibilities(String input)
|
default KList<T> getPossibilities(String input)
|
||||||
{
|
{
|
||||||
|
if(input.trim().isEmpty())
|
||||||
|
{
|
||||||
|
KList<T> f = getPossibilities();
|
||||||
|
return f == null ? new KList<>() : f;
|
||||||
|
}
|
||||||
|
|
||||||
input = input.trim();
|
input = input.trim();
|
||||||
KList<T> possible = getPossibilities();
|
KList<T> possible = getPossibilities();
|
||||||
KList<T> matches = new KList<>();
|
KList<T> matches = new KList<>();
|
||||||
|
@ -47,9 +47,15 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
return new KList<>();
|
Iris.debug("TAB COMPLETE ======================================================");
|
||||||
|
KList<String> enhanced = new KList<>(args);
|
||||||
|
KList<String> v = getRoot().tabComplete(enhanced, enhanced.toString(" "));
|
||||||
|
Iris.debug("input: '" + enhanced.toString(" ") + "'");
|
||||||
|
v.removeDuplicates();
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
J.aBukkit(() -> {
|
J.aBukkit(() -> {
|
||||||
@ -62,6 +68,11 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static KList<String> enhanceArgs(String[] args)
|
static KList<String> enhanceArgs(String[] args)
|
||||||
|
{
|
||||||
|
return enhanceArgs(args, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static KList<String> enhanceArgs(String[] args, boolean trim)
|
||||||
{
|
{
|
||||||
KList<String> a = new KList<>();
|
KList<String> a = new KList<>();
|
||||||
|
|
||||||
@ -73,15 +84,26 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
StringBuilder flat = new StringBuilder();
|
StringBuilder flat = new StringBuilder();
|
||||||
for(String i : args)
|
for(String i : args)
|
||||||
{
|
{
|
||||||
if(i.trim().isEmpty())
|
if(trim)
|
||||||
{
|
{
|
||||||
continue;
|
if(i.trim().isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
flat.append(" ").append(i.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat.append(" ").append(i.trim());
|
else
|
||||||
|
{
|
||||||
|
if(i.endsWith(" "))
|
||||||
|
{
|
||||||
|
flat.append(" ").append(i.trim()).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flat = new StringBuilder(flat.substring(1).trim());
|
flat = new StringBuilder(flat.length() > 0 ? trim ? flat.toString().trim().length() > 0 ?flat.substring(1).trim() : flat.toString().trim() : flat.substring(1) : flat);
|
||||||
StringBuilder arg = new StringBuilder();
|
StringBuilder arg = new StringBuilder();
|
||||||
boolean quoting = false;
|
boolean quoting = false;
|
||||||
|
|
||||||
@ -93,7 +115,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if(i == ' ' && !quoting)
|
if(i == ' ' && !quoting)
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -113,7 +135,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if(hasNext && j == ' ')
|
if(hasNext && j == ' ')
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -122,7 +144,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
else if(!hasNext)
|
else if(!hasNext)
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -137,7 +159,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,142 @@ public class VirtualDecreeCommand {
|
|||||||
return node != null;
|
return node != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KList<String> tabComplete(KList<String> args, String raw)
|
||||||
|
{
|
||||||
|
KList<Integer> skip = new KList<>();
|
||||||
|
KList<String> tabs = new KList<>();
|
||||||
|
invokeTabComplete(args, skip, tabs, raw);
|
||||||
|
return tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean invokeTabComplete(KList<String> args, KList<Integer> skip, KList<String> tabs, String raw)
|
||||||
|
{
|
||||||
|
if(isStudio() && !IrisSettings.get().isStudio())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isNode())
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
skip.add(hashCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args.isEmpty())
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String head = args.get(0);
|
||||||
|
|
||||||
|
if (args.size() > 1 || head.endsWith(" "))
|
||||||
|
{
|
||||||
|
VirtualDecreeCommand match = matchNode(head, skip);
|
||||||
|
|
||||||
|
if(match != null)
|
||||||
|
{
|
||||||
|
args.pop();
|
||||||
|
return match.invokeTabComplete(args, skip, tabs, raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
skip.add(hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tab(KList<String> args, KList<String> tabs) {
|
||||||
|
String last = null;
|
||||||
|
KList<DecreeParameter> ignore = new KList<>();
|
||||||
|
Runnable la = () -> {
|
||||||
|
|
||||||
|
};
|
||||||
|
for(String a : args)
|
||||||
|
{
|
||||||
|
la.run();
|
||||||
|
last = a;
|
||||||
|
la = () -> {
|
||||||
|
if(isNode())
|
||||||
|
{
|
||||||
|
String sea = a.contains("=") ? a.split("\\Q=\\E")[0] : a;
|
||||||
|
sea = sea.trim();
|
||||||
|
|
||||||
|
searching: for(DecreeParameter i : getNode().getParameters())
|
||||||
|
{
|
||||||
|
for(String m : i.getNames())
|
||||||
|
{
|
||||||
|
if(m.equalsIgnoreCase(sea) || m.toLowerCase().contains(sea.toLowerCase()) || sea.toLowerCase().contains(m.toLowerCase()))
|
||||||
|
{
|
||||||
|
ignore.add(i);
|
||||||
|
continue searching;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(last != null)
|
||||||
|
{
|
||||||
|
if (isNode()) {
|
||||||
|
for(DecreeParameter i : getNode().getParameters())
|
||||||
|
{
|
||||||
|
if(ignore.contains(i))
|
||||||
|
{
|
||||||
|
Iris.info(i.getName() + " is ignored");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int g = 0;
|
||||||
|
|
||||||
|
if(last.contains("="))
|
||||||
|
{
|
||||||
|
String[] vv = last.trim().split("\\Q=\\E");
|
||||||
|
String vx = vv.length == 2 ? vv[1] : "";
|
||||||
|
for(String f : i.getHandler().getPossibilities(vx).convert((v) -> i.getHandler().toStringForce(v)))
|
||||||
|
{
|
||||||
|
g++;
|
||||||
|
tabs.add(i.getName() +"="+ f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(String f : i.getHandler().getPossibilities("").convert((v) -> i.getHandler().toStringForce(v)))
|
||||||
|
{
|
||||||
|
g++;
|
||||||
|
tabs.add(i.getName() +"="+ f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(g == 0)
|
||||||
|
{
|
||||||
|
tabs.add(i.getName() + "=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(VirtualDecreeCommand i : getNodes())
|
||||||
|
{
|
||||||
|
String m = i.getName();
|
||||||
|
if(m.equalsIgnoreCase(last) || m.toLowerCase().contains(last.toLowerCase()) || last.toLowerCase().contains(m.toLowerCase()))
|
||||||
|
{
|
||||||
|
tabs.addAll(i.getNames());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private KMap<String, Object> map(VolmitSender sender, KList<String> in)
|
private KMap<String, Object> map(VolmitSender sender, KList<String> in)
|
||||||
{
|
{
|
||||||
KMap<String, Object> data = new KMap<>();
|
KMap<String, Object> data = new KMap<>();
|
||||||
@ -396,8 +532,43 @@ public class VirtualDecreeCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KList<VirtualDecreeCommand> matchAllNodes(String in)
|
||||||
|
{
|
||||||
|
KList<VirtualDecreeCommand> g = new KList<>();
|
||||||
|
|
||||||
|
if(in.trim().isEmpty())
|
||||||
|
{
|
||||||
|
g.addAll(nodes);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(VirtualDecreeCommand i : nodes)
|
||||||
|
{
|
||||||
|
if(i.matches(in))
|
||||||
|
{
|
||||||
|
g.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(VirtualDecreeCommand i : nodes)
|
||||||
|
{
|
||||||
|
if(i.deepMatches(in))
|
||||||
|
{
|
||||||
|
g.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g.removeDuplicates();
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
public VirtualDecreeCommand matchNode(String in, KList<Integer> skip)
|
public VirtualDecreeCommand matchNode(String in, KList<Integer> skip)
|
||||||
{
|
{
|
||||||
|
if(in.trim().isEmpty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for(VirtualDecreeCommand i : nodes)
|
for(VirtualDecreeCommand i : nodes)
|
||||||
{
|
{
|
||||||
if(skip.contains(i.hashCode()))
|
if(skip.contains(i.hashCode()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user