Skip to content

Commit

Permalink
Replace -b with custom syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Mar 28, 2022
1 parent 04bf63c commit 89b99e1
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/net/ME1312/CBS/Command.java
Expand Up @@ -75,10 +75,9 @@ public boolean execute(CommandSender sender, String label, String[] args) {
sender.sendMessage("");
sender.sendMessage(GRAY + ITALIC.toString() + UNDERLINE + desc.getWebsite() + "/wiki/Flags");
sender.sendMessage("");
} else if (args[0].matches("-+m")) {
if (args.length > 1) { // Minimal mode (-m) has the sender run the command as themselves. No further permission checks required.
boolean success = run(sender, sender, args, 1);
if (!success) {
} else if (args[0].matches("-+m(?:;.*)?")) {
if (args.length != 1) { // Minimal mode (-m) has the sender run the command as themselves. No further permission checks required.
if (!run(sender, sender, args, 1)) {
if (sender instanceof BlockCommandSender) {
throw FAILURE;
} else {
Expand Down Expand Up @@ -145,14 +144,10 @@ public boolean execute(CommandSender sender, String label, String[] args) {

int i = 0;
try {
boolean parsing = true, starting = true;
for (int c; parsing && i < args.length && args[i].startsWith("-"); ++i, starting = true) {
boolean starting = true;
for (int c; i < args.length && args[i].startsWith("-"); ++i, starting = true) {
for (PrimitiveIterator.OfInt $i = args[i].codePoints().iterator(); $i.hasNext(); ) {
switch (c = $i.nextInt()) {
case 'b': {
parsing = false;
break;
}
case 'd': {
debug = true;
break;
Expand Down Expand Up @@ -221,6 +216,9 @@ public boolean execute(CommandSender sender, String label, String[] args) {
case 'm': {
throw new CommandException("The " + DARK_RED + "-m" + RED + " flag cannot be combined with any other flags");
}
case ';': {
throw FAILURE;
}
case '-': if (starting) {
continue;
}
Expand All @@ -235,6 +233,9 @@ public boolean execute(CommandSender sender, String label, String[] args) {
if (sender instanceof BlockCommandSender) throw FAILURE;
sender.sendMessage(prefix(RED, DARK_RED) + e.getMessage());
return true;
} catch (RuntimeException e) {
if (e != FAILURE) throw e;
++i;
}

if (world == null) {
Expand Down Expand Up @@ -343,7 +344,7 @@ public List<String> tabComplete(CommandSender sender, String label, String[] arg
final LinkedList<Integer> available = new LinkedList<Integer>(FLAGS.keySet());
final LinkedList<String> values = new LinkedList<String>();
final String LAST = (args.length > 0)?args[args.length - 1]:"";
available.addFirst((int) 'b');
available.addFirst((int) ';');
available.add((int) 'm');

int i = 0;
Expand All @@ -353,15 +354,14 @@ public List<String> tabComplete(CommandSender sender, String label, String[] arg
Flag flag;
boolean starting = true;
for (int x; parsing && args[i].startsWith("-"); i = x, starting = true) {
for (PrimitiveIterator.OfInt $i = args[i].codePoints().iterator(); $i.hasNext(); ) {
for (PrimitiveIterator.OfInt $i = args[i].codePoints().iterator(); $i.hasNext(); ) try {
if ((flag = FLAGS.get(x = $i.nextInt())) != null) {
available.removeAll(flag.overrides);
values.addAll(flag.arguments);
} else if (x == 'b') {
available.remove((Object) x);
parsing = false;
available.removeAll(flag.overrides);
} else if (x == 'm') {
available.clear();
} else if (x == ';') {
throw FAILURE;
} else if (x == '-' && starting) {
continue;
}
Expand All @@ -370,6 +370,11 @@ public List<String> tabComplete(CommandSender sender, String label, String[] arg
available.remove((Object) (int) 'm');
starting = false;
}
} catch (RuntimeException e) {
if (e != FAILURE) throw e;
available.clear();
parsing = false;
break;
}

try { // definition of variable x changes here!
Expand Down

0 comments on commit 89b99e1

Please sign in to comment.