示例#1
0
  @Override
  public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
    if (!(source instanceof Player)) {
      source.sendMessage(Constants.MUST_BE_PLAYER_MSG);
      return CommandResult.empty();
    }
    Player player = (Player) source;

    Optional<Warp> optWarp = args.getOne("warp");
    if (!optWarp.isPresent()) {
      source.sendMessage(Constants.WARP_NOT_FOUND_MSG);
      return CommandResult.empty();
    }

    Warp warp = optWarp.get();

    if (this.plugin.getUtil().hasPermission(player, warp) == false) {
      player.sendMessage(Constants.NO_PERMISSION_MSG);
      return CommandResult.empty();
    }

    this.plugin.getWarpManager().scheduleWarp(player, warp);

    return CommandResult.success();
  }
示例#2
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()));
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    Optional<Player> p = ctx.<Player>getOne("player");

    if (src instanceof Player) {
      Player player = (Player) src;

      if (player.hasPermission("heal.others") && p.isPresent()) {
        Player recipient = p.get();
        recipient.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
        recipient.sendMessage(
            Texts.of(
                TextColors.GREEN,
                "Success: ",
                TextColors.YELLOW,
                "You've been healed by " + player.getName()));
        src.sendMessage(
            Texts.of(
                TextColors.GREEN,
                "Success: ",
                TextColors.YELLOW,
                "You've healed " + recipient.getName()));
      } else if (p.isPresent()) {
        player.sendMessage(
            Texts.of(
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "You do not have permission to heal other players!"));
      } else {
        player.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
        src.sendMessage(
            Texts.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've been healed."));
      }
    } else if (src instanceof ConsoleSource) {
      src.sendMessage(
          Texts.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /heal!"));
    } else if (src instanceof CommandBlockSource) {
      src.sendMessage(
          Texts.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /heal!"));
    }

    return CommandResult.success();
  }
  /**
   * Gets the currently loaded warps, paginates them into pages of size WARPS_PER_PAGE, and sends
   * the warp names in a message to the player
   *
   * @param source
   * @param args
   * @return
   * @throws CommandException
   */
  @Override
  public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {

    if (this.plugin.getWarpManager().getPayload().isEmpty()) {
      source.sendMessage(Constants.NO_WARPS_MSG);
      return CommandResult.success();
    }

    List<Text> warpNames = new ArrayList<Text>();

    for (Warp w : this.plugin.getWarpManager().getPayload()) {
      if (this.plugin.getUtil().hasPermission(source, w)) {
        warpNames.add(Texts.of(Util.warpText(w), TextColors.WHITE, " - ", Util.deleteWarpText(w)));
      }
    }

    PaginationService paginationService =
        this.plugin.getGame().getServiceManager().provide(PaginationService.class).get();
    paginationService
        .builder()
        .contents(warpNames)
        .title(Texts.of(TextColors.BLUE, "Warps"))
        .paddingString("-")
        .sendTo(source);

    return CommandResult.success();
  }
示例#5
0
 public CommandResult process(CommandSource src, String arguments) {
   if (!(src instanceof Player)) {
     src.sendMessage(Texts.of("You cannot use these subcommands."));
     return CommandResult.success();
   }
   Player player = ((Player) src).getPlayer().get();
   if (!player.hasPermission("multiworld.use")) {
     player.sendMessage(
         Texts.of(
             TextColors.DARK_GRAY,
             "[",
             TextColors.BLUE,
             "MultiWorld",
             TextColors.DARK_GRAY,
             "] ",
             TextColors.RED,
             "You do not have permission!"));
     return CommandResult.success();
   }
   String[] args = arguments.toString().split(" ");
   if (args.length > 5 || args.length == 0) {
     sendHelp(player);
     return CommandResult.success();
   }
   player.sendMessage(
       Texts.of(TextColors.BLUE, "MultiWorld version: " + MultiWorld.getInstance().mwVersion));
   return CommandResult.success();
 }
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    ConfigurationNode node =
        plugin.rootNode.getNode(
            "commands", args.getOne(util.getStringFromKey("command.param.name")).get().toString());

    node.getNode(CommandSetting.MESSAGE.getName())
        .setValue(args.getOne(util.getStringFromKey("command.param.message")).get().toString());

    node.getNode(CommandSetting.COMMAND.getName())
        .setValue(
            Arrays.asList(
                args.getOne(util.getStringFromKey("command.param.command"))
                    .get()
                    .toString()
                    .split(" ")));

    util.saveConfig();
    util.registerCommand(node);

    plugin.commandMap.put(node.getKey().toString(), node);

    util.updateEditCmd();
    util.updateDeleteCmd();

    src.sendMessage(util.getTextFromJsonByKey("command.add.success", node.getKey()));

    return CommandResult.success();
  }
 public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
   if (src instanceof Player) {
     Player player = (Player) src;
     if (Utils.isSpawnInConfig()) {
       if (!Objects.equals(player.getWorld().getName(), Utils.getSpawnWorldName())) {
         Vector3d position =
             new Vector3d(
                 Utils.getSpawn(player).getX(),
                 Utils.getSpawn(player).getY(),
                 Utils.getSpawn(player).getZ());
         player.transferToWorld(Utils.getSpawnWorldName(), position);
         src.sendMessage(
             Texts.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
         return CommandResult.success();
       } else {
         Location<World> spawn =
             new Location<>(
                 player.getWorld(),
                 Utils.getSpawn(player).getX(),
                 Utils.getSpawn(player).getY(),
                 Utils.getSpawn(player).getZ());
         player.setLocation(spawn);
       }
       src.sendMessage(
           Texts.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to Spawn"));
     } else {
       src.sendMessage(
           Texts.of(
               TextColors.DARK_RED, "Error! ", TextColors.RED, "Spawn has not been set yet!"));
     }
   } else if (src instanceof ConsoleSource) {
     src.sendMessage(
         Texts.of(
             TextColors.DARK_RED,
             "Error! ",
             TextColors.RED,
             "Must be an in-game player to use /spawn!"));
   } else if (src instanceof CommandBlockSource) {
     src.sendMessage(
         Texts.of(
             TextColors.DARK_RED,
             "Error! ",
             TextColors.RED,
             "Must be an in-game player to use /spawn!"));
   }
   return CommandResult.success();
 }
 public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
   Player p = ctx.<Player>getOne("player").get();
   String command = ctx.<String>getOne("command").get();
   if (src instanceof Player) {
     Player player = (Player) src;
     CommandService cmdService = game.getCommandDispatcher();
     if (!(p.hasPermission("sudo.exempt"))) {
       cmdService.process(p, command);
       player.sendMessage(
           Texts.of(
               TextColors.GREEN,
               "Success! ",
               TextColors.GOLD,
               "Forcing " + p.getName() + " to run /" + command));
       p.sendMessage(
           Texts.of(
               TextColors.GOLD,
               "[Sudo]: ",
               TextColors.WHITE,
               player.getName() + " has forced you to run /" + command));
     } else {
       player.sendMessage(
           Texts.of(
               TextColors.DARK_RED,
               "Error! ",
               TextColors.RED,
               "This player is exempt from sudo!"));
     }
   } else if (src instanceof ConsoleSource) {
     src.sendMessage(
         Texts.of(
             TextColors.DARK_RED,
             "Error! ",
             TextColors.RED,
             "Must be an in-game player to use /sudo!"));
   } else if (src instanceof CommandBlockSource) {
     src.sendMessage(
         Texts.of(
             TextColors.DARK_RED,
             "Error! ",
             TextColors.RED,
             "Must be an in-game player to use /sudo!"));
   }
   return CommandResult.success();
 }
示例#9
0
 @Subscribe
 public void onCommand(CommandEvent event) {
   switch (event.getCommand().toLowerCase()) {
     case "plotme":
       {
         CommandSource source = event.getSource();
         if (Settings.USE_PLOTME_ALIAS) {
           SpongeMain.THIS
               .getGame()
               .getCommandDispatcher()
               .process(source, ("plots " + event.getArguments()).trim());
         } else {
           source.sendMessage(SpongeMain.THIS.getText(C.NOT_USING_PLOTME.s()));
         }
         event.setCancelled(true);
       }
   }
   // TODO
 }
示例#10
0
 public CommandResult execute(CommandSource cS, CommandContext args) throws CommandException {
   cS.sendMessage(Texts.of("Spongy's config file has been reloaded."));
   try {
     Main.access.mainConfig.save(Main.access.mConCache);
     Main.access.userConfig.save(Main.access.uConCache);
     Main.access.mConCache = Main.access.mainConfig.load();
     Main.access.uConCache = Main.access.userConfig.load();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return CommandResult.empty();
 }
示例#11
0
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    String kitName = args.<String>getOne("kit name").get();
    boolean oneTime = false;
    int interval = 0;

    if (args.<Integer>getOne("kit interval").isPresent()) {
      interval = args.<Integer>getOne("kit interval").get();
    } else if (args.<Boolean>getOne("one-time").isPresent()) {
      oneTime = true;
    }

    // Sets the Interval
    if (!oneTime) {
      Utils.setInterval(interval, kitName);
    } else if (oneTime) {
      Utils.setInterval(kitName, oneTime);
    }

    src.sendMessage(
        Texts.of(TextColors.GOLD, "Success! ", TextColors.YELLOW, "The interval was changed!"));
    return CommandResult.success();
  }
示例#12
0
  @Override
  public CommandResult process(CommandSource sender, String arguments) throws CommandException {

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

    if (!PermissionsUtils.has(sender, "core.tp")) {
      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, "/tp <player> [target]"));
      return CommandResult.success();
    }
    if (args.length < 1 || args.length > 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tp <player> [target]"));
      return CommandResult.success();
    }

    Player player = null;
    Player target = null;

    if (args.length == 1) {

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

      player = (Player) sender;
      target = ServerUtils.getPlayer(args[0]);

    } else if (args.length == 2) {

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

      player = ServerUtils.getPlayer(args[0]);
      target = ServerUtils.getPlayer(args[1]);
    }

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

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

    player.setLocation(target.getLocation());

    if (args.length == 1) {

      sender.sendMessage(
          Texts.of(TextColors.GRAY, "Teleported to ", TextColors.YELLOW, target.getName()));

    } else if (args.length == 2) {

      sender.sendMessage(
          Texts.of(
              TextColors.GRAY,
              "Teleported ",
              TextColors.YELLOW,
              player.getName(),
              TextColors.GRAY,
              " to ",
              TextColors.YELLOW,
              target.getName()));
    }

    return CommandResult.success();
  }
示例#13
0
 public boolean testPermission(CommandSource source) {
   return source.hasPermission("multiworld.use");
 }
示例#14
0
  public CommandTicketCreate(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 (args.length < 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/ticket create <message>"));
      return;
    }

    Player player = (Player) sender;
    String message = CommandUtils.combineArgs(1, args);

    int tickets = 0;
    for (Entry<Integer, CoreTicket> e : CoreDatabase.getTickets().entrySet()) {
      CoreTicket ticket = e.getValue();
      if (!ticket.getStatus().equalsIgnoreCase("open")) continue;
      if (!ticket.getUUID().equalsIgnoreCase(player.getUniqueId().toString())) continue;
      tickets += 1;
    }

    int possible = 0;
    for (int i = 1; i <= 100; i++) {
      if (PermissionsUtils.has(player, "core.ticket.create." + i)) possible = i;
    }

    if (!PermissionsUtils.has(player, "core.ticket.create-unlimited") && possible <= tickets) {
      if (possible == 1)
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      else
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      return;
    }

    int id = CoreDatabase.getTickets().size() + 1;

    String world = player.getWorld().getName();

    double x = player.getLocation().getX();
    double y = player.getLocation().getY();
    double z = player.getLocation().getZ();
    double yaw = player.getRotation().getX();
    double pitch = player.getRotation().getY();

    double time = System.currentTimeMillis();

    CoreTicket ticket =
        new CoreTicket(
            id,
            player.getUniqueId().toString(),
            message,
            time,
            new ArrayList<String>(),
            world,
            x,
            y,
            z,
            yaw,
            pitch,
            "",
            "medium",
            "open");
    ticket.insert();

    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Ticket ",
            TextColors.GREEN,
            "#",
            id,
            TextColors.GRAY,
            " has been created!"));
  }
示例#15
0
  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));
  }
示例#16
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));
  }
示例#17
0
 @Override
 public boolean testPermission(CommandSource sender) {
   return permission.equals("") ? true : sender.hasPermission(permission);
 }
示例#18
0
  @Override
  public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) {

    if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) {

      Direction back =
          SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN;

      Location baseBlock = block.getRelative(back);

      Location otherSide = getOtherEnd(block, back, maximumLength);
      if (otherSide == null) {
        if (human instanceof CommandSource)
          ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build());
        return true;
      }

      Location otherBase = otherSide.getRelative(back.getOpposite());

      if (!baseBlock.getBlock().equals(otherBase.getBlock())) {
        if (human instanceof CommandSource)
          ((CommandSource) human)
              .sendMessage(Texts.builder("Both ends must be the same material!").build());
        return true;
      }

      int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default.

      Location left = baseBlock.getRelative(SignUtil.getLeft(block));
      Location right = baseBlock.getRelative(SignUtil.getRight(block));

      // Calculate left distance
      Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block));

      while (true) {
        if (leftBlocks >= maximumWidth) break;
        if (left.getBlock().equals(baseBlock.getBlock())
            && otherLeft.getBlock().equals(baseBlock.getBlock())) {
          leftBlocks++;
          left = left.getRelative(SignUtil.getLeft(block));
          otherLeft = otherLeft.getRelative(SignUtil.getLeft(block));
        } else {
          break;
        }
      }

      // Calculate right distance
      Location otherRight = otherBase.getRelative(SignUtil.getRight(block));

      while (true) {
        if (rightBlocks >= maximumWidth) break;
        if (right.getBlock().equals(baseBlock.getBlock())
            && otherRight.getBlock().equals(baseBlock.getBlock())) {
          rightBlocks++;
          right = right.getRelative(SignUtil.getRight(block));
          otherRight = otherRight.getRelative(SignUtil.getRight(block));
        } else {
          break;
        }
      }

      baseBlock = baseBlock.getRelative(back);

      BlockState type = block.getRelative(back).getBlock();
      if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState))
        type = BlockTypes.AIR.getDefaultState();

      while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) {

        baseBlock.setBlock(type);

        left = baseBlock.getRelative(SignUtil.getLeft(block));

        for (int i = 0; i < leftBlocks; i++) {
          left.setBlock(type);
          left = left.getRelative(SignUtil.getLeft(block));
        }

        right = baseBlock.getRelative(SignUtil.getRight(block));

        for (int i = 0; i < rightBlocks; i++) {
          right.setBlock(type);
          right = right.getRelative(SignUtil.getRight(block));
        }

        baseBlock = baseBlock.getRelative(back);
      }
    } else {
      if (human instanceof CommandSource)
        ((CommandSource) human)
            .sendMessage(Texts.builder("Door not activatable from here!").build());
      return false;
    }

    return true;
  }
示例#19
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();
  }