Exemple #1
0
  @Override
  public void load(LWC lwc) {
    configuration = Configuration.load("doors.yml");
    doors = new LinkedList<DoorAction>();
    enabled = configuration.getBoolean("doors.enabled", true);

    String action = configuration.getString("doors.action");

    if (action == null) {
      this.action = Action.NULL;
      return;
    }

    if (action.equalsIgnoreCase("openAndClose")) {
      this.action = Action.OPEN_AND_CLOSE;
      this.interval = configuration.getInt("doors.interval", 3);
    } else if (action.equalsIgnoreCase("toggle")) {
      this.action = Action.TOGGLE;
    }

    // start the task
    DoorTask doorTask = new DoorTask();
    lwc.getPlugin()
        .getServer()
        .getScheduler()
        .scheduleSyncRepeatingTask(lwc.getPlugin(), doorTask, 20, 20);
  }
Exemple #2
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;
  }