Improved invalid syntax handling
This commit is contained in:
@@ -274,14 +274,14 @@ public class Language {
|
||||
public List<String> translateSubcategoryList(String subcategory) {
|
||||
List<String> message = null;
|
||||
String name = this.name;
|
||||
if (subcategory != null && subcategory.length() > 0) {
|
||||
if (subcategory != null && !subcategory.isEmpty()) {
|
||||
name += "." + subcategory.toLowerCase();
|
||||
}
|
||||
if (lang != null && !lang.isNull()) {
|
||||
message = lang.getStringList(name);
|
||||
}
|
||||
|
||||
if (message == null || message.size() == 0) {
|
||||
if (message == null || message.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return message.stream().map(Language::convert).toList();
|
||||
|
||||
@@ -92,7 +92,7 @@ public class APCommand extends Command {
|
||||
sender.sendLang(Language.L.NOTPLAYERERROR);
|
||||
} catch (SyntaxException e) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
List<String> help = HelpCommand.getHelpFor(getLabel());
|
||||
List<String> help = HelpCommand.getHelpFor(c.getLabel());
|
||||
if (help != null) {
|
||||
for (String helpLine : help) {
|
||||
sender.sendMessageRaw(helpLine);
|
||||
|
||||
@@ -5,6 +5,8 @@ import dev.heliosares.auxprotect.core.APPermission;
|
||||
import dev.heliosares.auxprotect.core.Command;
|
||||
import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.exceptions.CommandException;
|
||||
import dev.heliosares.auxprotect.exceptions.SyntaxException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,11 +17,9 @@ public class ActivityCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
}
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) throws CommandException {
|
||||
if (args.length != 2 && args.length != 3) throw new SyntaxException();
|
||||
|
||||
String cmd = plugin.getCommandPrefix()
|
||||
+ String.format(" lookup #activity user:%s action:activity time:", args[1]);
|
||||
if (args.length > 2) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.database.ConnectionPool;
|
||||
import dev.heliosares.auxprotect.database.Table;
|
||||
import dev.heliosares.auxprotect.exceptions.CommandException;
|
||||
import dev.heliosares.auxprotect.exceptions.SyntaxException;
|
||||
import dev.heliosares.auxprotect.utils.StackUtil;
|
||||
import dev.heliosares.auxprotect.utils.TimeUtil;
|
||||
|
||||
@@ -179,7 +181,7 @@ public class DumpCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) {
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) throws CommandException {
|
||||
boolean simple = false;
|
||||
boolean chat = false;
|
||||
boolean file = false;
|
||||
@@ -193,8 +195,7 @@ public class DumpCommand extends Command {
|
||||
// case "file" -> file = true;
|
||||
case "config" -> config = true;
|
||||
default -> {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
throw new SyntaxException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.core.Language.L;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
@@ -26,8 +27,8 @@ public class HelpCommand extends Command {
|
||||
} else {
|
||||
String arg = args[1].toLowerCase();
|
||||
try {
|
||||
helpOn = commands.stream().filter(c -> c.matches(arg)).findAny().get();
|
||||
} catch (NullPointerException e) {
|
||||
helpOn = commands.stream().filter(c -> c.matches(arg)).findAny().orElseThrow();
|
||||
} catch (NoSuchElementException e) {
|
||||
sender.sendLang(L.UNKNOWN_SUBCOMMAND);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import dev.heliosares.auxprotect.adapters.sender.SenderAdapter;
|
||||
import dev.heliosares.auxprotect.core.*;
|
||||
import dev.heliosares.auxprotect.core.Parameters.Flag;
|
||||
import dev.heliosares.auxprotect.database.*;
|
||||
import dev.heliosares.auxprotect.exceptions.BusyException;
|
||||
import dev.heliosares.auxprotect.exceptions.LookupException;
|
||||
import dev.heliosares.auxprotect.exceptions.ParseException;
|
||||
import dev.heliosares.auxprotect.exceptions.*;
|
||||
import dev.heliosares.auxprotect.spigot.AuxProtectSpigot;
|
||||
import dev.heliosares.auxprotect.utils.*;
|
||||
import net.coreprotect.CoreProtect;
|
||||
@@ -168,11 +166,9 @@ public class LookupCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
}
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) throws CommandException {
|
||||
if (args.length < 2) throw new SyntaxException();
|
||||
|
||||
if (!plugin.getSqlManager().isConnected()) {
|
||||
sender.sendLang(Language.L.DATABASE_BUSY);
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,8 @@ import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.database.Table;
|
||||
import dev.heliosares.auxprotect.exceptions.BusyException;
|
||||
import dev.heliosares.auxprotect.exceptions.CommandException;
|
||||
import dev.heliosares.auxprotect.exceptions.SyntaxException;
|
||||
import dev.heliosares.auxprotect.utils.TimeUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
@@ -20,11 +22,8 @@ public class PurgeCommand extends Command {
|
||||
super(plugin, "purge", APPermission.PURGE, true);
|
||||
}
|
||||
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) {
|
||||
if (args.length != 3) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
}
|
||||
public void onCommand(SenderAdapter sender, String label, String[] args) throws CommandException {
|
||||
if (args.length != 3) throw new SyntaxException();
|
||||
if (!plugin.getSqlManager().isConnected()) {
|
||||
sender.sendLang(Language.L.DATABASE_BUSY);
|
||||
return;
|
||||
@@ -46,12 +45,11 @@ public class PurgeCommand extends Command {
|
||||
return;
|
||||
}
|
||||
final Table table = table_;
|
||||
long time_ = 0;
|
||||
long time_;
|
||||
try {
|
||||
time_ = TimeUtil.stringToMillis(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
throw new SyntaxException();
|
||||
}
|
||||
|
||||
if (time_ < Table.MIN_PURGE_INTERVAL) {
|
||||
|
||||
@@ -47,8 +47,7 @@ public class TimeCommand extends Command {
|
||||
time = TimeUtil.stringToMillis(timeStr);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
throw new SyntaxException();
|
||||
}
|
||||
builder = new ComponentBuilder(Language.convert("&9" + timeStr + "&f " + (add ? "from now" : "ago") + ":"));
|
||||
}
|
||||
|
||||
@@ -181,8 +181,7 @@ public class XrayCommand extends Command {
|
||||
if (args.length != 3 && args.length != 4) throw new IllegalArgumentException();
|
||||
target = UUID.fromString(args[2]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendLang(Language.L.INVALID_SYNTAX);
|
||||
return;
|
||||
throw new SyntaxException();
|
||||
}
|
||||
boolean confirmed = args.length == 4 && args[3].equalsIgnoreCase("-i");
|
||||
plugin.runAsync(() -> {
|
||||
|
||||
Reference in New Issue
Block a user