Example #1
0
  public CommandCoreDatabase(CommandSource sender, String[] args) {

    if (!PermissionsUtils.has(sender, "core.core.database")) {
      sender.sendMessage(
          Texts.builder("You do not have permissions!").color(TextColors.RED).build());
      return;
    }

    int homes = 0;
    for (Entry<String, CorePlayer> e : CoreDatabase.getPlayers().entrySet()) {
      CorePlayer p = e.getValue();
      homes += p.getHomes().size();
    }

    sender.sendMessage(Texts.of(TextColors.GOLD, "Core Database:"));
    sender.sendMessage(
        Texts.of(
            TextColors.GRAY, "Players: ", TextColors.YELLOW, CoreDatabase.getPlayers().size()));
    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Bans: ", TextColors.YELLOW, CoreDatabase.getBans().size()));
    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Mutes: ", TextColors.YELLOW, CoreDatabase.getMutes().size()));
    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Spawns: ", TextColors.YELLOW, CoreDatabase.getSpawns().size()));
    sender.sendMessage(Texts.of(TextColors.GRAY, "Homes: ", TextColors.YELLOW, homes));
    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Warps: ", TextColors.YELLOW, CoreDatabase.getWarps().size()));
    sender.sendMessage(
        Texts.of(
            TextColors.GRAY, "Tickets: ", TextColors.YELLOW, CoreDatabase.getTickets().size()));
  }
Example #2
0
  @Override
  public CommandResult process(CommandSource sender, String arguments) throws CommandException {

    String[] args = arguments.split(" ");

    if (sender instanceof Player == false) {
      sender.sendMessage(
          Texts.builder("Cannot be run by the console!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (!PermissionsUtils.has(sender, "core.tpa")) {
      sender.sendMessage(
          Texts.builder("You do not have permissions!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (arguments.equalsIgnoreCase("")) {
      sender.sendMessage(Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tpa <player>"));
      return CommandResult.success();
    }
    if (args.length < 1 || args.length > 1) {
      sender.sendMessage(Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tpa <player>"));
      return CommandResult.success();
    }

    Player s = (Player) sender;
    String uuid = s.getUniqueId().toString();

    Player player = CoreServer.getPlayer(args[0]);

    if (player == null) {
      sender.sendMessage(Texts.builder("Player not found!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    CorePlayer p = CoreDatabase.getPlayer(player.getUniqueId().toString());
    HashMap<String, Double> tpa = p.getTPA();
    HashMap<String, Double> tpahere = p.getTPAHere();

    double duration = 0;
    if (tpa.containsKey(uuid)) duration = tpa.get(uuid);
    if (duration != 0) {
      if (duration <= System.currentTimeMillis()) {
        tpa.remove(uuid);
        p.setTPA(tpa);
      } else {
        sender.sendMessage(
            Texts.builder("You already requested a teleport from that player!")
                .color(TextColors.RED)
                .build());
        return CommandResult.success();
      }
    }

    duration = 0;

    if (tpahere.containsKey(uuid)) duration = tpahere.get(uuid);
    if (duration != 0) {
      if (duration <= System.currentTimeMillis()) {
        tpahere.remove(uuid);
        p.setTPAHere(tpahere);
      } else {
        sender.sendMessage(
            Texts.builder("You already requested a teleport from that player!")
                .color(TextColors.RED)
                .build());
        return CommandResult.success();
      }
    }

    duration = System.currentTimeMillis() + 30 * 1000;

    tpa.put(uuid, duration);
    p.setTPA(tpa);

    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Teleport request has been sent to ",
            TextColors.YELLOW,
            player.getName()));
    player.sendMessage(
        Texts.of(
            TextColors.YELLOW,
            sender.getName(),
            TextColors.GRAY,
            " requested to teleport to you."));
    player.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Type ",
            TextColors.YELLOW,
            "/tpaccept ",
            sender.getName(),
            TextColors.GRAY,
            " or",
            TextColors.YELLOW,
            " /tpdeny ",
            sender.getName()));
    player.sendMessage(Texts.of(TextColors.GRAY, "to accept/decline the request."));

    return CommandResult.success();
  }