예제 #1
0
  /**
   * Found command.
   *
   * @param player The player.
   * @param name The name to found as.
   * @param type The type of government.
   * @return The first error.
   */
  public String doFound(MPlayer player, String name, GovType type) {
    if (!player.hasPermission("mafiacraft.citizen")) {
      return player.getLocale().localize("action.general.not-citizen");
    }

    if (!type.canFound()) {
      return player.getLocale().localize("command.government.error.found", type.getName());
    }

    double balance = player.getMoney();
    double cost = Config.getDouble("mafia.found");

    if (balance < cost) {
      return player
          .getLocale()
          .localize("command.government.error.no-money.found", StringUtils.formatCurrency(cost));
    }

    if (player.getGovernment() != null) {
      return player.getLocale().localize("action.government.error.in-gov");
    }

    name = name.trim();
    boolean result = ValidationUtils.validateName(name);
    if (!result) {
      return player.getLocale().localize("command.government.error.invalid-name", name);
    }

    if (Mafiacraft.getGovernmentManager().getGovernment(name) != null) {
      return player.getLocale().localize("action.government.error.exists");
    }

    // Found the government
    Government founded = Mafiacraft.getGovernmentManager().createGovernment(name, type);
    if (!founded.addAffiliate(player)) {
      return player.getLocale().localize("error.fatal.adding");
    }

    founded.setLeader(player);

    double startupCapital = Config.getDouble("mafia.startupcapital");
    founded.addMoney(startupCapital);

    player.sendMessage(
        MsgColor.SUCCESS
            + player
                .getLocale()
                .localize("command.government.success.founded", type.getName(), name));
    return null;
  }
예제 #2
0
  public String doCreateDivision(MPlayer player, String name) {
    if (!player.hasPermission("mafiacraft.citizen")) {
      return "You must be a citizen to use this command. "
          + "Apply for citizen on the website at "
          + MsgColor.URL
          + "http://voxton.net/"
          + ".";
    }

    Government gov = player.getGovernment();
    if (gov == null) {
      return "You are not in a government!";
    }

    if (!player.getPosition().isAtLeast(Position.VICE_LEADER)) {
      return "You do not have the proper rank to do this.";
    }

    name = name.trim();
    if (!ValidationUtils.validateName(name)) {
      return "invalid name";
    }

    if (!gov.canHaveMoreDivisions()) {
      return "The "
          + gov.getType().getName()
          + " has too many "
          + gov.getType().getLocale("divisions")
          + ". Make sure all of your "
          + gov.getType().getLocale("divisions")
          + " have greater than 5 players each.";
    }

    Division div = gov.createDivision().setManager(player.getName()).setName(name);

    gov.subtractMoney(Config.getDouble("prices.mafia.regimefound"));
    div.addMoney(Config.getDouble("mafia.regimestartup"));

    player.sendMessage(
        MsgColor.SUCCESS
            + "You have founded a "
            + gov.getType().getLocale("division")
            + " successfully.");
    return null;
  }