Esempio n. 1
0
  /**
   * Removes ownership of the current Chunk from the Player
   *
   * @param player The Player selling the Chunk
   */
  public static void sell(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "own")) {
      player.sendMessage(permissionMsg);
      return;
    }

    // Retrieve the OwnedChunk that the Player is in
    String world = player.getWorld().getName();
    Chunk chunk = player.getLocation().getBlock().getChunk();
    int x = chunk.getX();
    int z = chunk.getZ();
    OwnedChunk ownedChunk = MyChunks.findOwnedChunk(world, x, z);

    // Cancel if the Chunk is not owned
    if (ownedChunk == null) {
      player.sendMessage(MyChunks.doNotOwnMsg);
      return;
    }

    // Cancel if the OwnedChunk is owned by someone else
    if (!ownedChunk.owner.equals(player.getName()))
      if (MyChunks.hasPermission(player, "admin")) Econ.sell(player, ownedChunk.owner);
      else {
        player.sendMessage(MyChunks.doNotOwnMsg);
        return;
      }
    else Econ.sell(player);

    MyChunks.removeOwnedChunk(world, x, z);
  }
Esempio n. 2
0
  /**
   * Gives ownership of the current Chunk to the Player
   *
   * @param player The Player buying the Chunk
   */
  public static void buy(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "own")) {
      player.sendMessage(permissionMsg);
      return;
    }

    // Retrieve the OwnedChunk that the Player is in
    Chunk chunk = player.getLocation().getBlock().getChunk();
    String world = player.getWorld().getName();
    int x = chunk.getX();
    int z = chunk.getZ();
    OwnedChunk ownedChunk = MyChunks.getOwnedChunk(world, x, z);

    // If the owner of the OwnedChunk is not blank then the Chunk is already claimed
    if (ownedChunk.owner != null) {
      player.sendMessage(claimedMsg);
      return;
    }

    ownedChunk.owner = player.getName();

    int limit = MyChunks.getOwnLimit(player);
    int owned = 0;

    // Don't check how many are owned if the Player is not limited
    if (limit != -1) {
      // Retrieve the ChunkCounter value of the Player
      Object object = MyChunks.chunkCounter.get(player.getName());
      if (object != null) owned = (Integer) object;

      // Cancel if the Player owns their maximum limit
      if (owned >= limit) {
        player.sendMessage(limitMsg);
        return;
      }
    }

    // Charge the Player only if they don't have the 'chunkown.free' node
    if (MyChunks.hasPermission(player, "free")) player.sendMessage(buyFreeMsg);
    else if (!Econ.buy(player)) {
      // Delete the OwnedChunk because the Player could not afford it
      MyChunks.removeOwnedChunk(world, x, z);
      return;
    }

    // Increment the ChunkCounter of the Player
    MyChunks.chunkCounter.put(ownedChunk.owner, owned + 1);

    markCorners(chunk);
    MyChunks.save();
  }