コード例 #1
0
ファイル: CommandWarpInfo.java プロジェクト: Aaron1011/Core
  public CommandWarpInfo(CommandSource sender, String[] args) {

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

    if (args.length < 2 || args.length > 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/warp info <name>"));
      return;
    }

    String name = args[1].toLowerCase();
    CoreWarp warp = CoreDatabase.getWarp(name);

    if (warp == null) {
      sender.sendMessage(Texts.builder("Warp does not exist!").color(TextColors.RED).build());
      return;
    }

    if (!warp.getOwner().equalsIgnoreCase(sender.getName())
        && !PermissionsUtils.has(sender, "core.warp.info-others")) {
      sender.sendMessage(Texts.of(TextColors.RED, "You do not own this warp!"));
      return;
    }

    String invited = SerializeUtils.list(warp.getInvited());
    invited = invited.replaceAll(",", ", ");
    if (invited.equalsIgnoreCase("")) invited = "- none -";

    double x = warp.getX();
    x *= 100;
    x = Math.round(x);
    x /= 100;
    double y = warp.getY();
    y *= 100;
    y = Math.round(y);
    y /= 100;
    double z = warp.getZ();
    z *= 100;
    z = Math.round(z);
    z /= 100;

    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Information on Warp: ", TextColors.GOLD, warp.getName()));
    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Owner: ",
            TextColors.YELLOW,
            CoreDatabase.getPlayer(warp.getOwner()).getName()));
    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Location: ",
            TextColors.YELLOW,
            warp.getWorld(),
            " | x:",
            x,
            " y:",
            y,
            " z:",
            z));
    sender.sendMessage(
        Texts.of(TextColors.GRAY, "Private: ", TextColors.YELLOW, warp.getPrivate()));
    if (invited.equalsIgnoreCase("- none -"))
      sender.sendMessage(Texts.of(TextColors.GRAY, "Invited: ", TextColors.YELLOW, invited));
    else
      sender.sendMessage(
          Texts.of(
              TextColors.GRAY,
              "Invited: ",
              TextColors.YELLOW,
              "(",
              warp.getInvited().size(),
              ") ",
              invited));
  }
コード例 #2
0
  public CommandWarpTeleport(CommandSource sender, String[] args) {

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

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

    if (args.length != 1) {
      sender.sendMessage(Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/warp <name>"));
      return;
    }

    Player player = (Player) sender;

    String name = args[0].toLowerCase();
    CoreWarp warp = CoreDatabase.getWarp(name);

    if (warp == null) {
      sender.sendMessage(Texts.builder("Warp does not exist!").color(TextColors.RED).build());
      return;
    }

    if (PermissionsUtils.has(sender, "core.warp.teleport-unlimited")) {
      if (!player.transferToWorld(
          warp.getWorld(), new Vector3d(warp.getX(), warp.getY(), warp.getZ()))) {
        sender.sendMessage(
            Texts.builder("Target world does not exist anymore!").color(TextColors.RED).build());
        return;
      }
      sender.sendMessage(
          Texts.of(TextColors.GRAY, "Teleported to warp: ", TextColors.YELLOW, name));
      return;
    }

    if (!warp.getOwner().equalsIgnoreCase(sender.getName().toLowerCase())) {

      if (warp.getPrivate().equalsIgnoreCase("yes")
          && !PermissionsUtils.has(sender, "core.warp.teleport-invited")) {
        sender.sendMessage(
            Texts.of(TextColors.RED, "You do not have permissions to teleport to private warps!"));
        return;
      }

      if (warp.getPrivate().equalsIgnoreCase("yes")
          && !warp.getInvited().contains(sender.getName().toLowerCase())) {
        sender.sendMessage(Texts.of(TextColors.RED, "You are not invited to this warp!"));
        return;
      }
    }

    Location<World> loc =
        new Location<World>(
            Controller.getServer().getWorld(warp.getWorld()).get(),
            warp.getX(),
            warp.getY(),
            warp.getZ());
    player.setLocation(loc);

    sender.sendMessage(Texts.of(TextColors.GRAY, "Teleported to warp: ", TextColors.YELLOW, name));
  }
コード例 #3
0
ファイル: CommandTPA.java プロジェクト: KAISERslin/Core
  @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();
  }