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();
  }
Example #3
0
  /**
   * Display to the Player the info of the current Chunk Info displayed is the Location of the Chunk
   * and the current CoOwners
   *
   * @param player The Player requesting the info
   */
  public static void info(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "info")) {
      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 OwnedChunk does not exist
    if (ownedChunk == null) {
      player.sendMessage(unclaimedMsg);
      return;
    }

    // Display the world and x/y-coordinates of the center of the OwnedChunk to the Player
    player.sendMessage(
        "Chunk @ world="
            + world
            + " x="
            + (x * 16 + 8)
            + " z="
            + (z * 16 + 8)
            + " belongs to "
            + ownedChunk.owner);

    // Display CoOwners of OwnedChunk to Player
    String coOwners = "CoOwners:  ";
    for (String coOwner : ownedChunk.coOwners) coOwners = coOwners.concat(coOwner.concat(", "));
    player.sendMessage(coOwners.substring(0, coOwners.length() - 2));

    // Display CoOwner Groups of OwnedChunk to Player
    String groups = "CoOwner Groups:  ";
    for (String group : ownedChunk.groups) groups = groups.concat(group.concat(", "));
    player.sendMessage(groups.substring(0, groups.length() - 2));
  }
Example #4
0
  /**
   * Display to the Player all of the Chunks that they own
   *
   * @param player The Player requesting the list
   */
  public static void list(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "own")) {
      player.sendMessage(permissionMsg);
      return;
    }

    String name = player.getName();

    // Retrieve the ChunkCounter value to display to the Player
    int owned = 0;
    Object object = MyChunks.chunkCounter.get(name);
    if (object != null) owned = (Integer) object;
    player.sendMessage("Number of Chunks owned: " + owned);

    // Retrieve the ownLimit to display to the Player
    int ownLimit = MyChunks.getOwnLimit(player);
    if (ownLimit > -1) player.sendMessage("Total amount you may own: " + ownLimit);

    // 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)
          for (OwnedChunk ownedChunk : chunkList)
            // Display Chunk info if it is owned by the given Player
            if (ownedChunk.owner.equals(name))
              player.sendMessage(
                  "Chunk in world="
                      + ownedChunk.world
                      + ", centered @: x="
                      + (ownedChunk.x * 16 + 8)
                      + " z="
                      + (ownedChunk.z * 16 + 8));
      }
  }
Example #5
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();
  }
Example #6
0
  /**
   * Manages CoOwnership of the given Chunk if the Player is the Owner
   *
   * @param player The given Player who may be the Owner
   * @param type The given type: 'player' or 'group'
   * @param action The given action: 'add' or 'remove'
   * @param coOwner The given CoOwner
   */
  public static void coowner(Player player, String type, String action, String coOwner) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "coowner")) {
      player.sendMessage(permissionMsg);
      return;
    }

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

    // Cancel if the OwnedChunk does not exist
    if (ownedChunk == null) {
      player.sendMessage(unclaimedMsg);
      return;
    }

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

    // Determine the command to execute
    if (type.equals("player"))
      if (action.equals("add")) {
        // Cancel if the Player is already a CoOwner
        if (ownedChunk.coOwners.contains(coOwner)) {
          player.sendMessage(coOwner + " is already a CoOwner");
          return;
        }

        ownedChunk.coOwners.add(coOwner);
        player.sendMessage(coOwner + " added as a CoOwner");
      } else if (action.equals("remove")) ownedChunk.coOwners.remove(coOwner);
      else {
        sendHelp(player);
        return;
      }
    else if (type.equals("group"))
      if (action.equals("add")) {
        // Cancel if the Group is already a CoOwner
        if (ownedChunk.groups.contains(coOwner)) {
          player.sendMessage(coOwner + " is already a CoOwner");
          return;
        }

        ownedChunk.groups.add(coOwner);
        player.sendMessage(coOwner + " added as a CoOwner");
      } else if (action.equals("remove")) ownedChunk.groups.remove(coOwner);
      else {
        sendHelp(player);
        return;
      }
    else {
      sendHelp(player);
      return;
    }

    MyChunks.save();
  }