barao45 Posted November 7, 2021 Posted November 7, 2021 THanks for your answers frinds. i could implement my voiced command. But. a question. In the constructor shows something like this, but how it is posible to run others comands like .online or .repair if the are not added in this Class VoicedCommandHandler?. public class VoicedCommandHandler implements IHandler<IVoicedCommandHandler, String> { private final Map<String, IVoicedCommandHandler> _datatable; protected VoicedCommandHandler() { _datatable = new HashMap<>(); registerHandler(new SevenRB()); registerHandler(new RaidVCmd()); } @Override public void registerHandler(IVoicedCommandHandler handler) { String[] ids = handler.getVoicedCommandList(); for (String id : ids) { _datatable.put(id, handler); } } @Override public synchronized void removeHandler(IVoicedCommandHandler handler) { String[] ids = handler.getVoicedCommandList(); for (String id : ids) { _datatable.remove(id); } } @Override public IVoicedCommandHandler getHandler(String voicedCommand) { String command = voicedCommand; if (voicedCommand.contains(" ")) { command = voicedCommand.substring(0, voicedCommand.indexOf(" ")); } return _datatable.get(command); } @Override public int size() { return _datatable.size(); } public static VoicedCommandHandler getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final VoicedCommandHandler _instance = new VoicedCommandHandler(); } } Quote
Zake Posted November 7, 2021 Posted November 7, 2021 On 11/7/2021 at 6:13 AM, barao45 said: THanks for your answers frinds. i could implement my voiced command. But. a question. In the constructor shows something like this, but how it is posible to run others comands like .online or .repair if the are not added in this Class VoicedCommandHandler?. public class VoicedCommandHandler implements IHandler<IVoicedCommandHandler, String> { private final Map<String, IVoicedCommandHandler> _datatable; protected VoicedCommandHandler() { _datatable = new HashMap<>(); registerHandler(new SevenRB()); registerHandler(new RaidVCmd()); } @Override public void registerHandler(IVoicedCommandHandler handler) { String[] ids = handler.getVoicedCommandList(); for (String id : ids) { _datatable.put(id, handler); } } @Override public synchronized void removeHandler(IVoicedCommandHandler handler) { String[] ids = handler.getVoicedCommandList(); for (String id : ids) { _datatable.remove(id); } } @Override public IVoicedCommandHandler getHandler(String voicedCommand) { String command = voicedCommand; if (voicedCommand.contains(" ")) { command = voicedCommand.substring(0, voicedCommand.indexOf(" ")); } return _datatable.get(command); } @Override public int size() { return _datatable.size(); } public static VoicedCommandHandler getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final VoicedCommandHandler _instance = new VoicedCommandHandler(); } } Expand Commands can be executed once they are registered in handler Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.