Ejemplo n.º 1
0
  /**
   * Scrape data from a doot
   *
   * @param door
   * @return
   */
  private byte initializeDoorData(Door door) {
    byte data = 0x00;

    // get the hinge position
    switch (door.getHingeCorner()) {
      case NORTH_EAST:
        data |= 0x0;
        break;

      case SOUTH_EAST:
        data |= 0x1;
        break;

      case SOUTH_WEST:
        data |= 0x2;
        break;

      case NORTH_WEST:
        data |= 0x3;
        break;
    }

    if (door.isTopHalf()) {
      data |= 0x8;
    }

    return data;
  }
Ejemplo n.º 2
0
 /**
  * @param data
  * @return
  */
 private boolean isDoorOpen(Door door) {
   switch (door.getHingeCorner()) {
     default:
       return door.isOpen();
   }
 }
Ejemplo n.º 3
0
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    String playerName = player.getName();
    if (!plugin.getPlayerData().containsKey(playerName)) {
      plugin.getPlayerData().put(playerName, new PlayerData(plugin, playerName));
    }

    // If our user is select & is not holding an item, selection time
    if (plugin.getPlayerData().get(playerName).isSelecting()
        && player.getItemInHand().getType() == Material.AIR
        && event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      PlayerData pData = plugin.getPlayerData().get(playerName);
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (event.getAction() == Action.LEFT_CLICK_BLOCK) {

        if (Inn.doorAlreadyExists(x, y, z)) {
          player.sendMessage(ChatColor.RED + "This door is already registered!");
          return;
        }
        int[] xyz = {x, y, z};
        pData.setPositionA(xyz);
        player.sendMessage(ChatColor.DARK_AQUA + "Door selected");
        event.setCancelled(true);
        if (pData.getPositionA() != null) {
          player.sendMessage(
              ChatColor.DARK_AQUA
                  + "Type "
                  + ChatColor.WHITE
                  + "/inn create [Price]"
                  + ChatColor.DARK_AQUA
                  + ", if you're happy with your selection, otherwise keep selecting!");
        }
      }
      // Are we trying to delete a door?
    } else if (plugin.getPlayerData().get(playerName).isRemoving()
        && player.getItemInHand().getType() == Material.AIR
        && event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
        event.setCancelled(true);
        if (Inn.doorAlreadyExists(x, y, z)) {
          if (!IPermissions.permission(player, "inn.admin.delete", player.isOp())) {
            if (!Inn.getOwner(x, y, z).equalsIgnoreCase(playerName)) {
              player.sendMessage(ChatColor.RED + "You do not own this door!");
              return;
            }
          }
          String query = "DELETE FROM doors WHERE x=" + x + " AND y=" + y + " AND z=" + z;
          Inn.manageSQLite.deleteQuery(query);
          player.sendMessage(ChatColor.RED + "This Inn door has been deleted!");
          return;
        } else {
          player.sendMessage(ChatColor.RED + "This door is not a Inn door!");
        }
      }
      // Are we trying to open a door?
    } else if (event.getClickedBlock().getType() == Material.WOODEN_DOOR) {
      if (IPermissions.permission(player, "inn.bypass", player.isOp())) return;
      int x, y, z;
      Location loc = event.getClickedBlock().getLocation();
      x = loc.getBlockX();
      y = loc.getBlockY();
      z = loc.getBlockZ();
      Door door = (Door) event.getClickedBlock().getState().getData();
      if (door.isTopHalf()) y = y - 1;
      if (Inn.doorAlreadyExists(x, y, z)) {
        String owner = Inn.getOwner(x, y, z);
        if (owner.equalsIgnoreCase(playerName)) {
          player.sendMessage(ChatColor.GREEN + "This is your inn door!");
          return;
        }
        int price = Inn.getDoorPrice(x, y, z);
        if (Inn.isTimeoutExpired(x, y, z, playerName)) {
          MethodAccount playerAccount = plugin.Method.getAccount(playerName);
          if (playerAccount.hasEnough(price)) {
            playerAccount.subtract(price);
            MethodAccount playerAccount2 = plugin.Method.getAccount(owner);
            playerAccount2.add(price);
            Inn.addTimeout(x, y, z, playerName);
            player.sendMessage(ChatColor.DARK_AQUA + "You are entering " + owner + " inn room");

          } else event.setCancelled(true);
        } else return;
      }
    }
  }