Пример #1
0
  // Block is the container or door, signBlock is the owning [Private] sign.
  // Returns true if it should be allowed, false if it should be canceled.
  private static boolean canInteract(Block block, Block signBlock, Player player, boolean isDoor) {
    // Check if the block is owned first.

    // Moved to outer..

    // Lets see if the player is allowed to touch...

    Sign sign = (Sign) signBlock.getState();
    int length = player.getName().length();
    String line;

    if (length > 15) length = 15;

    // Check owner.

    line = sign.getLine(1).replaceAll("(?i)\u00A7[0-F]", "");

    if (line.equals(player.getName().substring(0, length))) return (true);
    if (plugin.inGroup(block.getWorld(), player, line)) return (true);

    // Check main two users.

    int y;

    for (y = 2; y <= 3; ++y)
      if (!sign.getLine(y).isEmpty()) {
        line = sign.getLine(y).replaceAll("(?i)\u00A7[0-F]", "");

        if (plugin.inGroup(block.getWorld(), player, line)) return (true);
        if (line.equalsIgnoreCase(player.getName().substring(0, length))) return (true);
      }

    // Check for more users.

    List<Block> list = Lockette.findBlockUsers(block, signBlock);
    int x, count = list.size();
    Sign sign2;

    for (x = 0; x < count; ++x) {
      sign2 = (Sign) list.get(x).getState();

      for (y = 1; y <= 3; ++y)
        if (!sign2.getLine(y).isEmpty()) {
          line = sign2.getLine(y).replaceAll("(?i)\u00A7[0-F]", "");

          if (plugin.inGroup(block.getWorld(), player, line)) return (true);
          if (line.equalsIgnoreCase(player.getName().substring(0, length))) return (true);
        }
    }

    // Check admin list last.

    boolean snoop = false;

    if (isDoor) {
      if (Lockette.adminBypass) {
        if (plugin.hasPermission(block.getWorld(), player, "lockette.admin.bypass")) snoop = true;

        if (snoop) {
          Lockette.log.info(
              "["
                  + plugin.getDescription().getName()
                  + "] (Admin) "
                  + player.getName()
                  + " has bypassed a door owned by "
                  + sign.getLine(1));

          plugin.localizedMessage(player, null, "msg-admin-bypass", sign.getLine(1));
          return (true);
        }
      }
    } else if (Lockette.adminSnoop) {
      if (plugin.hasPermission(block.getWorld(), player, "lockette.admin.snoop")) snoop = true;

      if (snoop) {
        Lockette.log.info(
            "["
                + plugin.getDescription().getName()
                + "] (Admin) "
                + player.getName()
                + " has snooped around in a container owned by "
                + sign.getLine(1)
                + "!");

        plugin.localizedMessage(
            player, Lockette.broadcastSnoopTarget, "msg-admin-snoop", sign.getLine(1));
        return (true);
      }
    }

    // Don't have permission.

    return (false);
  }
Пример #2
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String[] command = event.getMessage().split(" ", 3);

    if (command.length < 1) return;
    if (!(command[0].equalsIgnoreCase("/lockette") || command[0].equalsIgnoreCase("/lock"))) return;
    event.setCancelled(true);

    Player player = event.getPlayer();

    // Reload config files, for admins only.
    if (command.length == 2) {
      if (command[1].equalsIgnoreCase("reload")) {
        if (!plugin.hasPermission(player.getWorld(), player, "lockette.admin.reload")) return;

        plugin.loadProperties(true);

        plugin.localizedMessage(player, Lockette.broadcastReloadTarget, "msg-admin-reload");
        return;
      }

      if (command[1].equalsIgnoreCase("version")) {
        player.sendMessage(
            ChatColor.RED
                + "Lockette version "
                + plugin.getDescription().getVersion()
                + " loaded.  (Core: "
                + Lockette.getCoreVersion()
                + ")");
        return;
      }

      if (command[1].equalsIgnoreCase("fix")) {
        if (fixDoor(player)) {
          plugin.localizedMessage(player, null, "msg-error-fix");
        }
        return;
      }
    }

    // Edit sign text.
    if ((command.length == 2) || (command.length == 3)) {
      if (command[1].equals("1")
          || command[1].equals("2")
          || command[1].equals("3")
          || command[1].equals("4")) {
        Block block = plugin.playerList.get(player.getName());
        // boolean		error = false;

        // Check if the selected block is a valid sign.

        if (block == null) {
          plugin.localizedMessage(player, null, "msg-error-edit");
          return;
        } else if (block.getTypeId() != Material.WALL_SIGN.getId()) {
          plugin.localizedMessage(player, null, "msg-error-edit");
          return;
        }

        Sign sign = (Sign) block.getState();
        Sign owner = sign;
        String text = sign.getLine(0).replaceAll("(?i)\u00A7[0-F]", "").toLowerCase();
        boolean privateSign;

        // Check if it is our sign that is selected.

        if (text.equals("[private]") || text.equalsIgnoreCase(Lockette.altPrivate))
          privateSign = true;
        else if (text.equals("[more users]") || text.equalsIgnoreCase(Lockette.altMoreUsers)) {
          privateSign = false;

          Block checkBlock = Lockette.getSignAttachedBlock(block);
          if (checkBlock == null) {
            plugin.localizedMessage(player, null, "msg-error-edit");
            return;
          }

          Block signBlock = Lockette.findBlockOwner(checkBlock);
          if (signBlock == null) {
            plugin.localizedMessage(player, null, "msg-error-edit");
            return;
          }

          owner = (Sign) signBlock.getState();
        } else {
          plugin.localizedMessage(player, null, "msg-error-edit");
          return;
        }

        int length = player.getName().length();

        if (length > 15) length = 15;

        // Check owner.
        if (owner
                .getLine(1)
                .replaceAll("(?i)\u00A7[0-F]", "")
                .equals(player.getName().substring(0, length))
            || player.getName().equals("Acru")) { // Temp for Debugging.
          // if(sign.getLine(1).replaceAll("(?i)\u00A7[0-F]",
          // "").equals(player.getName().substring(0, length))){
          int line = Integer.parseInt(command[1]) - 1;

          // Disallow editing [Private] line 1/2 here.
          if (!player.getName().equals("Acru")) { // For debugging.
            if (line <= 0) return;
            else if (line <= 1) if (privateSign) return;
          }

          if (command.length == 3) {
            length = command[2].length();

            if (length > 15) length = 15;
            if (Lockette.colorTags)
              sign.setLine(
                  line, command[2].substring(0, length).replaceAll("&([0-9A-Fa-f])", "\u00A7$1"));
            else sign.setLine(line, command[2].substring(0, length));
          } else sign.setLine(line, "");
          sign.update();

          plugin.localizedMessage(player, null, "msg-owner-edit");
          return;
        } else {
          plugin.localizedMessage(player, null, "msg-error-edit");
          return;
        }
      }
    }

    // If none of the above, print out the help text.
    // Commands:
    // reload
    // 2-4 <text> - sign editing
    // link - linking?
    // set <value> <string> - config?

    plugin.localizedMessage(player, null, "msg-help-command1");
    plugin.localizedMessage(player, null, "msg-help-command2");
    plugin.localizedMessage(player, null, "msg-help-command3");
    plugin.localizedMessage(player, null, "msg-help-command4");
    plugin.localizedMessage(player, null, "msg-help-command5");
    plugin.localizedMessage(player, null, "msg-help-command6");
    plugin.localizedMessage(player, null, "msg-help-command7");
    plugin.localizedMessage(player, null, "msg-help-command8");
    plugin.localizedMessage(player, null, "msg-help-command9");
  }