/**
  * Registers all listener found in the specified directory.
  *
  * @param path The path to the directory containing the listeners
  * @param origin The origin to register all found listeners to
  */
 @Override
 public void registerListeners(String path, Plugin origin) {
   try {
     for (ClassPath.ClassInfo classInfo :
         ClassPath.from(origin.getClass().getClassLoader()).getTopLevelClasses(path)) {
       Class<?> clazz = classInfo.load();
       if (MessageListener.class.isAssignableFrom(clazz)) {
         this.registerListener((MessageListener) clazz.newInstance(), origin);
         origin.getLogger().info("Registered plugin message listener: " + clazz.getName());
       }
     }
   } catch (IOException | IllegalAccessException | InstantiationException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  @Override
  public void execute(Plugin plugin, HttpServletRequest req, HttpServletResponse res, String[] args)
      throws IOException, SQLException {
    String fallback = BungeeWeb.getConfig().getString("server.language");
    String lang = req.getParameter("lang");

    if (lang == null) lang = fallback;

    File file = new File(plugin.getDataFolder(), "lang/" + lang + ".json");
    InputStream stream;
    if (file.exists()) {
      stream = new FileInputStream(file);
    } else {
      stream = plugin.getResourceAsStream("lang/en.json");
    }

    ByteStreams.copy(stream, res.getOutputStream());
  }
  @Override
  public void handle(
      String target, Request baseReq, HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    res.setStatus(HttpServletResponse.SC_OK);
    res.setCharacterEncoding("utf8");
    baseReq.setHandled(true);

    if (target.equalsIgnoreCase("/console")) {
      String apikey = req.getParameter("apikey");
      String cmd = req.getParameter("cmd");
      HashMap<String, Object> out = new HashMap<String, Object>();

      if (apikey == null || cmd == null) {
        out.put("error", "Missing parameters. Required parameters: apikey, cmd");
      } else {
        if (BungeeHTTPConsole.getConfig().getList("apikeys").contains(apikey)) {
          WebCommandSender sender = new WebCommandSender();
          plugin.getProxy().getPluginManager().dispatchCommand(sender, cmd);

          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            //
          }

          out.put("result", sender.getMessages());
        } else {
          out.put("error", "The API key you provided is invalid.");
        }
      }

      res.getWriter().print(gson.toJson(out));
    } else {
      res.getWriter().print("BungeeHTTPConsole");
    }
  }