public boolean lwcProtected(Block block) {
    if (lwc == null) {
      return false;
    }

    Protection protection = lwc.findProtection(block); // also accepts x, y, z

    if (protection != null) {
      return true;
    }
    return false;
  }
 public static boolean isProtected(Block chest) {
   if (lwc != null) {
     Protection lwcProt = lwc.findProtection(chest);
     if (lwcProt != null) {
       return true;
     }
   }
   if (lockette != null) {
     boolean lockProt = Lockette.isProtected(chest);
     if (lockProt) {
       return true;
     }
   }
   return false;
 }
 public static String protectedByWho(Block chest) {
   if (chest == null) {
     return null;
   }
   String name = "";
   if (lwc != null) {
     Protection prot = lwc.findProtection(chest);
     if (prot != null) {
       name = prot.getOwner();
     }
   }
   if (lockette != null) {
     name = Lockette.getProtectedOwner(chest);
   }
   return name;
 }
Esempio n. 4
0
  @Override
  public Result onProtectionInteract(
      LWC lwc,
      Player player,
      Protection protection,
      List<String> actions,
      boolean canAccess,
      boolean canAdmin) {
    if (!enabled || action == Action.NULL) {
      return DEFAULT;
    }

    if (!canAccess) {
      return DEFAULT;
    }

    // get the blocks for the door
    List<Block> blocks =
        lwc.getProtectionSet(
            protection.getBukkitWorld(), protection.getX(), protection.getY(), protection.getZ());

    // only send them one message :-)
    boolean sentMessage = false;

    // search around for iron doors if enabled
    if (configuration.getBoolean("doors.doubleDoors", true)) {
      Block protectionBlock = protection.getBlock();
      Block temp = null;

      BlockFace[] faces =
          new BlockFace[] {BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH};

      for (BlockFace face : faces) {
        if (isValid((temp = protectionBlock.getFace(face)).getType())) {
          Protection found = lwc.findProtection(temp);

          if (found != null) {
            if (lwc.canAccessProtection(player, found)) {
              // we can access it, add it to the blocks
              blocks.addAll(
                  lwc.getProtectionSet(
                      found.getBukkitWorld(), found.getX(), found.getY(), found.getZ()));
            }
          }
        }
      }
    }

    for (Block block : blocks) {
      if (!isValid(block.getType())) {
        continue;
      }

      // create the door instance
      Door door = new Door(block.getType(), block.getData());

      // process the current door's data
      byte data = initializeDoorData(door);

      switch (this.action) {
        case TOGGLE:
          if ((block.getData() & 0x4) != 0x4) {
            data |= 0x4;
          }

          if (!sentMessage) {
            sentMessage = true;

            if (isDoorOpen(door)) {
              // lwc.sendLocale(player, "protection.doors.open");
            } else {
              // lwc.sendLocale(player, "protection.doors.close");
            }
          }

          break;

        case OPEN_AND_CLOSE:
          if ((block.getData() & 0x4) != 0x4) {
            data |= 0x4;
          }

          if (!sentMessage) {
            sentMessage = true;

            if (isDoorOpen(door)) {
              // lwc.sendLocale(player, "protection.doors.open");
            } else {
              // lwc.sendLocale(player, "protection.doors.close");
            }
          }

          if (!isDoorOpen(door)) {
            Location location =
                new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());

            DoorAction doorAction = new DoorAction();
            doorAction.location = location;
            doorAction.triggerTime = System.currentTimeMillis() + (interval * 1000L);

            doors.push(doorAction);
          }

          break;
      }

      // update the door
      block.setData(data);
    }

    return DEFAULT;
  }