@Override public Object resolveArgument( MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { System.out.println("resolveArgument"); CommandMap commandMap = new CommandMap(); HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); Enumeration<?> enumeration = request.getParameterNames(); String key = null; String[] values = null; while (enumeration.hasMoreElements()) { key = (String) enumeration.nextElement(); values = request.getParameterValues(key); if (values != null) { commandMap.put(key, (values.length > 1) ? values : values[0]); } } return commandMap; }
/** * Used by the {@link CmdRegistration} to register the command. * * <p><b>Do not call this to register a command!</b> * * <p>You'll have to use {@link CmdRegistration#register(Plugin, BaseCmd)} to register a command * properly! Also don't forget to call {@link CmdRegistration#unregister(Plugin)} in onDisable() * * @param plugin The plugin that registered the command. * @throws CmdAlreadyRegisteredException When the command is already registered. */ public void register(Plugin plugin) throws CmdAlreadyRegisteredException { setUsage(getUsage(plugin.getServer().getConsoleSender(), getBaseCmd().getName())); if (this.plugin != null) { throw new CmdAlreadyRegisteredException(plugin, this); } this.plugin = plugin; try { Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap"); f.setAccessible(true); CommandMap commandMap = (CommandMap) f.get(Bukkit.getServer()); commandMap.register(plugin.getName(), this); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } }
/** Return the CommandMap for this instance of DataHandler. */ private synchronized CommandMap getCommandMap() { if (currentCommandMap != null) return currentCommandMap; else return CommandMap.getDefaultCommandMap(); }