[FEATURE] Команды, Reload/Reconfigurable не зависят от регистра

This commit is contained in:
Gravit 2019-03-28 12:07:54 +07:00
parent 3d82253308
commit fee94ff368
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 9 additions and 8 deletions

View file

@ -11,16 +11,16 @@ public class ReconfigurableManager {
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>(); private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
public void registerReconfigurable(String name, Reconfigurable reconfigurable) { public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), VerifyHelper.putIfAbsent(RECONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name)); String.format("Reloadable has been already registered: '%s'", name));
} }
public void printHelp(String name) { public void printHelp(String name) {
RECONFIGURABLE.get(name).printConfigHelp(); RECONFIGURABLE.get(name.toLowerCase()).printConfigHelp();
} }
public void call(String name, String action, String[] args) { public void call(String name, String action, String[] args) {
RECONFIGURABLE.get(name).reconfig(action, args); RECONFIGURABLE.get(name.toLowerCase()).reconfig(action.toLowerCase(), args);
} }
public void printReconfigurables() { public void printReconfigurables() {

View file

@ -11,8 +11,8 @@ public class ReloadManager {
private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>(); private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>();
public void registerReloadable(String name, Reloadable reloadable) { public void registerReloadable(String name, Reloadable reloadable) {
VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"), VerifyHelper.putIfAbsent(RELOADABLES, name.toLowerCase(), Objects.requireNonNull(reloadable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name)); String.format("Reloadable has been already registered: '%s'", name.toLowerCase()));
} }
public void reloadAll() { public void reloadAll() {
@ -26,7 +26,7 @@ public void reloadAll() {
} }
public void reload(String name) throws Exception { public void reload(String name) throws Exception {
RELOADABLES.get(name).reload(); RELOADABLES.get(name.toLowerCase()).reload();
} }
public void printReloadables() { public void printReloadables() {

View file

@ -21,6 +21,7 @@ public void eval(String line, boolean bell) {
String[] args; String[] args;
try { try {
args = CommonHelper.parseCommand(line); args = CommonHelper.parseCommand(line);
if(args.length > 0) args[0] = args[0].toLowerCase();
} catch (Exception e) { } catch (Exception e) {
LogHelper.error(e); LogHelper.error(e);
return; return;
@ -72,8 +73,8 @@ private void readLoop() throws IOException {
public void registerCommand(String name, Command command) { public void registerCommand(String name, Command command) {
VerifyHelper.verifyIDName(name); VerifyHelper.verifyIDName(name);
VerifyHelper.putIfAbsent(commands, name, Objects.requireNonNull(command, "command"), VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"),
String.format("Command has been already registered: '%s'", name)); String.format("Command has been already registered: '%s'", name.toLowerCase()));
} }
@Override @Override