Exemplo n.º 1
0
 @Override
 public void init(JDA jda, ServerConfig cfg) {
   synchronized (jda) {
     if (!initialized) {
       initialized = true;
       Item.init();
       SolarSystem.init();
     }
   }
 }
Exemplo n.º 2
0
  public Map<String, Command> getCommands() {
    Map<String, Command> registry = new HashMap<>();

    registry.put(
        "route",
        setAccess(
            new CommandWrapper(
                "Gets the amount of jumps between 2 Systems.\n"
                    + "Usage: `route SYS1 SYS2` where sys1/sys2 are the system-names (or prefixes of them).",
                (msg, cfg) -> {
                  String[] split = MessageUtil.getArgs(msg, cfg);
                  if (split.length > 2) {
                    SolarSystem start = SolarSystem.get(split[1]);
                    SolarSystem end = SolarSystem.get(split[2]);
                    boolean unique = true;
                    if (start == null) {
                      Set<SolarSystem> all = SolarSystem.getAll(split[1]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "Start System not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "Start System not unique... Possible: " + getSystemList(all));
                      }
                      unique = false;
                    }
                    if (end == null) {
                      Set<SolarSystem> all = SolarSystem.getAll(split[2]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "End System not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "End System not unique... Possible: " + getSystemList(all));
                      }
                      unique = false;
                    }
                    if (unique) {
                      JSONArray array =
                          makeGetRequest(
                              "http://api.eve-central.com/api/route/from/"
                                  + start.id
                                  + "/to/"
                                  + end.id);
                      MessageUtil.reply(
                          msg,
                          cfg,
                          "There are "
                              + array.length()
                              + " jumps between "
                              + start.name
                              + " and "
                              + end.name);
                    }
                  }
                })));
    registry.put(
        "nexthub",
        setAccess(
            new CommandWrapper(
                "Gets the closest trade-hub to the provided System (and the jump count).\n"
                    + "Usage: `nexthub SYS` where sys is the system-name (or a prefix of one).",
                (msg, cfg) -> {
                  String[] split = MessageUtil.getArgs(msg, cfg);
                  if (split.length > 1) {
                    SolarSystem start = SolarSystem.get(split[1]);
                    if (start == null) {
                      Set<SolarSystem> all = SolarSystem.getAll(split[1]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "System not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "System not unique... Possible: " + getSystemList(all));
                      }
                    } else {
                      SolarSystem closest = null;
                      int closestJumps = Integer.MAX_VALUE;
                      for (SolarSystem hub : SolarSystem.hubs) {
                        JSONArray array =
                            makeGetRequest(
                                "http://api.eve-central.com/api/route/from/"
                                    + start.id
                                    + "/to/"
                                    + hub.id);
                        if (array.length() < closestJumps) {
                          closest = hub;
                          closestJumps = array.length();
                        }
                      }
                      if (closest != null) {
                        MessageUtil.reply(
                            msg,
                            cfg,
                            "Closest Hub to "
                                + start.name
                                + " is "
                                + closest.name
                                + " with "
                                + closestJumps
                                + " jumps distance");
                      }
                    }
                  }
                })));
    registry.put(
        "price",
        setAccess(
            new CommandWrapper(
                "Gets the buy/sell price of provided item in Jita.\n"
                    + "Usage: `price NAME` where name is the item name (or a prefix of it).",
                (msg, cfg) -> {
                  String[] split = MessageUtil.getArgs(msg, cfg, 2);
                  if (split.length > 1) {
                    Item i = Item.get(split[1]);
                    if (i == null) {
                      Set<Item> all = Item.getAll(split[1]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "Item not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "Item not unique... Possible: " + getItemList(all));
                      }
                    } else {
                      JSONArray array =
                          makeGetRequest(
                              "http://api.eve-central.com/api/marketstat/json?typeid="
                                  + i.id
                                  + "&usesystem="
                                  + SolarSystem.get("jita").id);
                      double maxbuy = array.getJSONObject(0).getJSONObject("buy").getDouble("max");
                      double minsell =
                          array.getJSONObject(0).getJSONObject("sell").getDouble("min");
                      MessageUtil.reply(
                          msg,
                          cfg,
                          String.format(
                              "Stats for %s in Jita: Sell: %,.2f; Buy: %,.2f",
                              i.name, minsell, maxbuy));
                    }
                  }
                })));
    registry.put(
        "pricein",
        setAccess(
            new CommandWrapper(
                "Gets the buy/sell price of provided item in the provided System.\n"
                    + "Usage: `pricein NAME SYS` where name/sys are the item/system name (or a prefix of them).",
                (msg, cfg) -> {
                  String[] split = MessageUtil.getArgs(msg, cfg, 3);
                  if (split.length > 2) {
                    boolean unique = true;
                    Item i = Item.get(split[1]);
                    if (i == null) {
                      Set<Item> all = Item.getAll(split[1]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "Item not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "Item not unique... Possible: " + getItemList(all));
                      }
                      unique = false;
                    }
                    SolarSystem sys = SolarSystem.get(split[2]);
                    if (sys == null) {
                      Set<SolarSystem> all = SolarSystem.getAll(split[2]);
                      if (all.size() == 0) {
                        MessageUtil.reply(msg, cfg, "System not found!");
                      } else {
                        MessageUtil.reply(
                            msg, cfg, "System not unique... Possible: " + getSystemList(all));
                      }
                      unique = false;
                    }
                    if (unique) {
                      JSONArray array =
                          makeGetRequest(
                              "http://api.eve-central.com/api/marketstat/json?typeid="
                                  + i.id
                                  + "&usesystem="
                                  + sys.id);
                      double maxbuy = array.getJSONObject(0).getJSONObject("buy").getDouble("max");
                      double minsell =
                          array.getJSONObject(0).getJSONObject("sell").getDouble("min");
                      MessageUtil.reply(
                          msg,
                          cfg,
                          String.format(
                              "Stats for %s in %s: Sell: %,.2f; Buy: %,.2f",
                              i.name, sys.name, minsell, maxbuy));
                    }
                  }
                })));
    return registry;
  }