示例#1
0
  // /town leave
  public static void leave(Player player) {
    PlayerData playerData = Players.get(player.getName());
    String townName = playerData.townName;

    // Ensure that the player is currently a resident of a town
    if (townName.equals("")) {
      Util.message(player, "You do not have a town to leave.");
      return;
    }
    // Ensure that the player is not the mayor
    if (playerData.isMayor) {
      Util.message(
          player, "Town mayors cannot use '/town leave'; contact an admin to shut down your town.");
      return;
    }

    // Remove the player from the town in the database
    RageMod.database.townLeave(playerData.name);

    // Update the playerData
    playerData.townName = "";
    playerData.isMayor = false;
    playerData.spawn_IsSet = false;
    playerData.treasuryBalance = 0;
    Players.update(playerData);

    Util.message(player, "You are no longer a resident of " + townName + ".");
  }
示例#2
0
  // /town evict <player_name>
  public static void evict(Player player, String targetPlayerName) {
    PlayerData playerData = Players.get(player.getName());
    PlayerData targetPlayerData = Players.get(targetPlayerName);

    // Ensure that the current player is the mayor
    if (!playerData.isMayor) {
      Util.message(player, "Only town mayors can use /town evict.");
      return;
    }
    // Check to see if target player exists
    if (targetPlayerData == null) {
      Util.message(player, "Player " + targetPlayerName + " does not exist.");
      return;
    }
    // Ensure that the target player is a resident of the mayor's town
    if (!targetPlayerData.townName.equals(playerData.townName)) {
      Util.message(player, targetPlayerName + " is not a resident of " + playerData.townName + ".");
      return;
    }

    // Remove the target from the player's town
    RageMod.database.townLeave(targetPlayerName);

    // Update the playerData
    targetPlayerData.townName = "";
    targetPlayerData.spawn_IsSet = false;
    Players.update(targetPlayerData);

    Util.message(
        player, targetPlayerData.name + " is no longer a resident of " + playerData.townName + ".");
  }
示例#3
0
  // /town withdrawl <amount>
  public static void withdrawl(Player player, String amountString) {
    PlayerData playerData = Players.get(player.getName());
    double amount;
    Holdings holdings = iConomy.getAccount(player.getName()).getHoldings();
    PlayerTown playerTown = PlayerTowns.get(playerData.townName);

    // Make sure the player is a resident of a town
    if (playerData.townName.equals("")) {
      Util.message(player, "Only town residents can use the deposit command.");
      return;
    }
    // Ensure that the typed amount is a valid number
    try {
      amount = Double.parseDouble(amountString);
    } catch (Exception ex) {
      Util.message(player, "Invalid amount.");
      return;
    }
    // Ensure that the amount is greater than 0
    if (amount <= 0) {
      Util.message(player, "Invalid amount.");
      return;
    }
    // Make sure the player has a high enough balance to make the withdrawl
    if (playerData.treasuryBalance < amount) {
      Util.message(
          player,
          "You only have " + iConomy.format(playerData.treasuryBalance) + " in the treasury.");
      return;
    }
    // Make sure the withdrawl wouldn't put the town below its minimum balance
    if (playerTown.treasuryBalance - amount < playerTown.minimumBalance) {
      Util.message(player, "This transaction would put the town below its minimum balance.");
      return;
    }

    // Add the amount to the player's balance
    holdings.add(amount);

    // Update the database
    RageMod.database.townDeposit(playerTown.id_PlayerTown, playerData.id_Player, (amount * -1));

    // Update the town data
    playerTown.treasuryBalance -= amount;
    PlayerTowns.put(playerTown);

    // Update the player data
    playerData.treasuryBalance -= amount;
    Players.update(playerData);

    Util.message(player, "Withdrew " + iConomy.format(amount) + " from town treasury.");
  }
示例#4
0
  // /town add <player_name>
  public static void add(Player player, String targetPlayerName) {
    PlayerData playerData = Players.get(player.getName());
    PlayerData targetPlayerData = Players.get(targetPlayerName);

    // Check to see if target player exists
    if (targetPlayerData == null) {
      Util.message(player, "Player " + targetPlayerName + " does not exist.");
      return;
    }
    // Ensure that the current player is the mayor
    if (!playerData.isMayor) {
      Util.message(player, "Only town mayors can use '/town add'.");
      return;
    }
    // Ensure that the target player is not currently a resident of a town
    if (!targetPlayerData.townName.equals("")) {
      Util.message(
          player,
          targetPlayerName + " is already a resident of '" + targetPlayerData.townName + "'.");
      return;
    }
    // Ensure that the target player is the same faction as the mayor
    if (playerData.id_Faction != targetPlayerData.id_Faction) {
      Util.message(player, "You can only add players that are the same faction as you.");
      return;
    }
    if (PlayerTowns.get(playerData.townName).isFull()) {
      Util.message(player, "Your town already has the maximum number of residents for its level.");
      return;
    }

    // Add the target to the player's town
    RageMod.database.townAdd(targetPlayerName, playerData.townName);

    // Update the playerData
    targetPlayerData.townName = playerData.townName;
    // This will give the player's balance back if they were a previous resident of the town
    targetPlayerData.treasuryBalance =
        RageMod.database.getPlayerTreasuryBalance(
            targetPlayerData.id_Player, PlayerTowns.get(playerData.townName).id_PlayerTown);
    Players.update(targetPlayerData);

    Util.message(
        player, targetPlayerData.name + " is now a resident of " + playerData.townName + ".");
  }
示例#5
0
  // /town deposit <amount>
  public static void deposit(Player player, String amountString) {
    PlayerData playerData = Players.get(player.getName());
    double amount;
    Holdings holdings = iConomy.getAccount(player.getName()).getHoldings();
    PlayerTown playerTown = PlayerTowns.get(playerData.townName);

    // Make sure the player is a resident of a town
    if (playerData.townName.equals("")) {
      Util.message(player, "Only town residents can use the deposit command.");
      return;
    }
    // Ensure that the typed amount is a valid number
    try {
      amount = Double.parseDouble(amountString);
    } catch (Exception ex) {
      Util.message(player, "Invalid amount.");
      return;
    }
    // Ensure that the amount is greater than 0 (no sneaky withdrawls!)
    if (amount <= 0) {
      Util.message(player, "Invalid amount.");
      return;
    }
    // Make sure the player has enough money to make the deposit
    if (!holdings.hasEnough(amount)) {
      Util.message(player, "You only have " + iConomy.format(holdings.balance()) + ".");
      return;
    }

    // Subtract the amount from the player's balance
    holdings.subtract(amount);

    // Update the database
    RageMod.database.townDeposit(playerTown.id_PlayerTown, playerData.id_Player, amount);

    // Update the town data
    playerTown.treasuryBalance += amount;
    PlayerTowns.put(playerTown);

    // Update the player data
    playerData.treasuryBalance += amount;
    Players.update(playerData);

    Util.message(player, "Deposited " + iConomy.format(amount) + " into town treasury.");
  }
示例#6
0
  // /town  create <town_name>
  public static void create(Player player, String townName) {
    PlayerData playerData = Players.get(player.getName());
    HashMap<String, Integer> nearbyTowns = PlayerTowns.checkForNearbyTowns(player.getLocation());
    Holdings holdings = iConomy.getAccount(player.getName()).getHoldings();
    int cost = RageConfig.townLevels.get(1).initialCost;

    // Ensure that the player is not currently a resident of a town
    if (!playerData.townName.equals("")) {
      Util.message(
          player,
          "You are already a resident of '"
              + playerData.townName
              + "'; you must use '/town leave' before you can create a new town.");
      return;
    }
    // Ensure that the town name is not taken
    if (PlayerTowns.get(townName) != null) {
      Util.message(player, "A town named " + townName + " already exists!");
      return;
    }
    // Ensure that the current zone is allowed to create towns
    if (!RageZones.checkPermission(player.getLocation(), Action.TOWN_CREATE)) {
      Util.message(player, "You cannot create a town in this zone.");
      return;
    }
    // Check for any towns that are too close to the current point - list all
    if (nearbyTowns.size() > 0) {
      String message = "You are too close to the following towns: ";
      for (String nearbyTownName : nearbyTowns.keySet()) {
        message += nearbyTownName + " (" + nearbyTowns.get(nearbyTownName) + "m) ";
      }
      Util.message(player, message);
      Util.message(
          player,
          "Towns must be a minimum distance of "
              + RageConfig.Town_MIN_DISTANCE_BETWEEN
              + "m apart.");
      return;
    }
    // Check to see if the player has enough money to join the specified faction
    if (!holdings.hasEnough(cost)) {
      Util.message(
          player,
          "You need at least "
              + iConomy.format(cost)
              + " to create a "
              + RageConfig.townLevels.get(1).name
              + ".");
      return;
    }

    // Subtract from player balance
    holdings.subtract(cost);

    // TODO: Check against NPC town names

    // Create the town if name selected, otherwise return message
    if (!townName.equals("")) {
      // Add the new town to the database
      int townID = RageMod.database.townCreate(player, townName);

      // Update PlayerTowns
      PlayerTown playerTown = new PlayerTown();
      playerTown.id_PlayerTown = townID;
      playerTown.townName = townName;
      playerTown.centerPoint =
          new Location2D((int) player.getLocation().getX(), (int) player.getLocation().getZ());
      playerTown.id_Faction = playerData.id_Faction;
      playerTown.bankruptDate = null;
      playerTown.townLevel = RageConfig.townLevels.get(1);
      playerTown.treasuryBalance = RageConfig.townLevels.get(1).minimumBalance;
      playerTown.minimumBalance = RageConfig.townLevels.get(1).minimumBalance;
      playerTown.mayor = playerData.name;
      playerTown.world = player.getWorld();

      playerTown.buildRegion();
      playerTown.createBorder();

      PlayerTowns.put(playerTown);

      // Update the playerData
      playerData.townName = townName;
      playerData.isMayor = true;
      playerData.currentTown = playerTown;
      playerData.treasuryBalance = cost;
      Players.update(playerData);

      Util.message(player, "Congratulations, you are the new mayor of " + townName + "!");
    } else {
      Util.message(
          player,
          "This location is valid for a new town - to create one, type '/town create <town_name>'");
    }
  }