Example #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);
  }
Example #2
0
  /**
   * Removes all the Chunks that are owned by the given Player A Chunk is owned buy a Player if the
   * owner field is the Player's name
   *
   * @param player The name of the Player
   */
  public static void clear(Player player) {
    String name = player.getName();

    // Iterate through all OwnedChunks
    for (int i = 0; i < 100; i++)
      for (int j = 0; j < 100; j++) {
        LinkedList<OwnedChunk> chunkList = (LinkedList<OwnedChunk>) MyChunks.matrix[i][j];
        if (chunkList != null) {
          Iterator itr = chunkList.iterator();
          while (itr.hasNext()) {
            OwnedChunk ownedChunk = (OwnedChunk) itr.next();

            // Sell the Chunk if it is owned by the given Player
            if (ownedChunk.owner.equals(name)) {
              itr.remove();
              Econ.sell(player);
            }
          }

          // Delete the ChunkList if it is empty
          if (chunkList.isEmpty()) MyChunks.matrix[i][j] = null;
        }
      }

    // Reset the ChunkCounter of the Player to 0
    MyChunks.chunkCounter.put(player.getName(), 0);

    MyChunks.save();
  }