示例#1
0
  public void removeSelfFromTown() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();
    if (t == null) {
      localSender.sendMessage(
          ERR + "You're either not a member of a town, or your active town isn't set.");
      localSender.sendMessage("To set your active town to your own town, use /town active reset");
      return;
    }

    if (t.playerIsMayor(localSender.getPlayer())) {
      localSender.sendMessage(
          ERR
              + "You're the mayor. You need to specify a new mayor before leaving your current town.");
      return;
    }

    t.removePlayer(localSender.getPlayer());

    localSender.sendMessage(
        ChatColor.DARK_RED + "You have left " + localSender.getActiveTown().getTownName() + ".");
  }
示例#2
0
  public void setMayor(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();
    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    Player p = server.getPlayerExact(playerName);

    if (!(localSender.hasExternalPermissions("ADMIN")
        || t.getMayor().equals(localSender.getPlayer().getUniqueId()))) {
      localSender.notifyInsufPermissions();
      return;
    }

    if (p == null) {
      localSender.sendMessage(ERR + playerName + " either does not exist or is not online.");
      return;
    }

    if (!t.playerIsResident(p)) {
      localSender.sendMessage(ERR + "That player is not a member of the town.");
      return;
    }

    localSender.getActiveTown().setMayor(p);
    t.broadcastMessageToTown("The mayor of " + t.getTownName() + " is now " + p.getName() + "!");
  }
示例#3
0
  public void cancelInvitation(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (joinManager.clearInvitationForPlayerFromTown(playerName, t))
      localSender.sendMessage(
          ChatColor.GOLD + "The invitation for " + playerName + " has been withdrawn.");
    else
      localSender.sendMessage(
          ERR
              + playerName
              + " does not have any pending invitations from "
              + t.getTownName()
              + ".");
  }
示例#4
0
  public void setTownSpawn() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!t.playerIsInsideTownBorders(localSender.getPlayer())) {
      localSender.sendMessage(ERR + "You need to be inside your town borders to do that.");
      return;
    }

    t.setSpawn(localSender.getPlayer().getLocation());
    localSender.sendMessage("Town spawn location updated.");
  }
示例#5
0
  public void listResidents(int page) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    page--; // shift to 0-indexing

    if (page < 0) {
      localSender.sendMessage(ERR + "Invalid page.");
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }
    localSender.sendMessage(
        ChatColor.AQUA + "Players in " + t.getTownName() + "(page " + page + "):");

    Set<String> names = t.getResidentNames();
    String[] players = names.toArray(new String[names.size()]);

    for (int i = page * RESULTS_PER_PAGE;
        i < players.length && i < page * RESULTS_PER_PAGE + RESULTS_PER_PAGE;
        i++) {
      localSender.sendMessage(ChatColor.YELLOW + players[i]);
    }
  }
示例#6
0
  public void setDefaultPlotPrice(String plotPrice) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    BigDecimal price;

    try {
      price = new BigDecimal(plotPrice);
    } catch (NumberFormatException nfe) {
      localSender.sendMessage(ERR + "Error parsing plot price: " + nfe.getMessage());
      return;
    }

    t.setDefaultPlotPrice(price);
    localSender.sendMessage(
        SUCC + "The default price of plots in " + t.getTownName() + " has been set to " + price);
  }
示例#7
0
  public void warpToSpawn() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasExternalPermissions(Perms.WARP.toString())) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    Location spawn = t.getTownSpawn();
    if (spawn == null) {
      localSender.sendMessage(ERR + "Town spawn not set.");
      return;
    }

    localSender.getPlayer().teleport(spawn);
    localSender.sendMessage(
        ChatColor.DARK_GRAY + "Teleported to " + t.getTownName() + "! Welcome!");
  }
示例#8
0
  public void setTownJoinMethod(String s_method) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    TownJoinMethod method;
    try {
      method = TownJoinMethod.parseMethod(s_method);
    } catch (TownJoinMethodFormatException ex) {
      localSender.sendMessage(ERR + ex.getMessage());
      return;
    }

    // TODO: Refactor Town so that it holds a TownJoinMethod instead of a boolean that determines
    // economy joins or invites.
    if (method == TownJoinMethod.ECONOMY) t.setEconomyJoins(true);
    else if (method == TownJoinMethod.INVITATION) t.setEconomyJoins(false);

    localSender.sendMessage(SUCC + "Town join method updated.");
  }
示例#9
0
  private void listTerritories(int page) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    page--; // shift to 0-indexing

    if (page < 0) {
      localSender.sendMessage(ERR + "Invalid page.");
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }
    localSender.sendMessage(ChatColor.AQUA + "Existing territories (page " + page + "):");

    String[] territs =
        t.getTerritoriesCollection().toArray(new String[t.getTerritoriesCollection().size()]);

    for (int i = page * RESULTS_PER_PAGE;
        i < territs.length && i < page * RESULTS_PER_PAGE + RESULTS_PER_PAGE;
        i++) {
      localSender.sendMessage(ChatColor.YELLOW + territs[i]);
    }
  }
示例#10
0
  public void setTownFriendlyFire(String sFriendlyFire) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    boolean friendlyFire;

    friendlyFire = sFriendlyFire.equalsIgnoreCase("on");

    t.setFriendlyFire(friendlyFire);

    localSender.sendMessage(
        ChatColor.GREEN
            + "Friendly fire in "
            + t.getTownName()
            + " is now "
            + (friendlyFire ? "on" : "off")
            + ".");
  }
示例#11
0
  public void openBankDepositBox() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();
    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    localSender.getPlayer().openInventory(t.getBank().getNewDepositBox(localSender.getPlayer()));
  }
示例#12
0
  public void printMOTD() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    localSender.sendMessage(t.getTownMOTD());
  }
示例#13
0
  public void removePlayerFromTown(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    OfflinePlayer removeMe = server.getOfflinePlayer(playerName);
    Town removeFrom = localSender.getActiveTown();

    if (!removeMe.hasPlayedBefore()) {
      localSender.sendMessage(
          ERR + "No player named '" + playerName + "' has ever played on this server.");
      return;
    }

    if (removeFrom == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!removeFrom.playerIsResident(removeMe)) {
      localSender.sendMessage(
          ERR + removeMe.getName() + " is not a resident of " + removeFrom.getTownName() + ".");
      return;
    }

    if (removeFrom.playerIsMayor(removeMe)) {
      localSender.sendMessage(ERR + "A mayor cannot be removed from his own town.");
      return;
    }

    if (removeFrom.playerIsAssistant(removeMe)
        && !localSender.hasExternalPermissions(Perms.ADMIN.toString())
        && !removeFrom.playerIsMayor(localSender.getPlayer())) {
      localSender.sendMessage(
          ERR + "Only the mayor or admins can remove assistants from the town.");
      return;
    }

    localSender.getActiveTown().removePlayer(removeMe);

    Town.recursivelyRemovePlayerFromTown(removeMe, removeFrom);

    localSender.sendMessage("\"" + playerName + "\" was removed from the town.");
    Player onlinePlayer = removeMe.getPlayer();
    if (onlinePlayer != null)
      onlinePlayer.sendMessage(
          ChatColor.DARK_RED
              + "You have been removed from "
              + removeFrom.getTownName()
              + " by "
              + localSender.getPlayer().getName());
  }
示例#14
0
  public void openBlockBank() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();
    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    localSender.getPlayer().openInventory(t.getBank().getBankInventory());
  }
示例#15
0
  public void setTownPlotBuyability(String s_buyability) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!MCTConfig.ECONOMY_ENABLED.getBoolean()) {
      localSender.sendMessage(ERR + "The economy is not enabled for your server.");
      return;
    }

    boolean buyability;

    try {
      buyability = Boolean.parseBoolean(s_buyability);
    } catch (Exception e) {
      localSender.sendMessage(
          ERR + "Error in parsing boolean: expected true/false, found " + s_buyability);
      return;
    }

    t.setBuyablePlots(buyability);
    if (buyability)
      localSender.sendMessage(
          ChatColor.GOLD
              + t.getTownName()
              + "'s plots can now be sold and new plots are buyable by default.");
    else
      localSender.sendMessage(
          ChatColor.GOLD + t.getTownName() + "'s plots are no longer for sale.");
  }
示例#16
0
  public void depositCurrencyBank(String quantity) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!MCTConfig.ECONOMY_ENABLED.getBoolean()) {
      localSender.sendMessage(ERR + "The economy isn't enabled for your server.");
      return;
    }

    BigDecimal amt;
    try {
      amt = new BigDecimal(quantity);
    } catch (NumberFormatException nfe) {
      localSender.sendMessage(
          ERR + "Error parsing quantity \"" + quantity + "\" : " + nfe.getMessage());
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    EconomyResponse result =
        MCTowns.getEconomy().withdrawPlayer(localSender.getPlayer().getName(), amt.doubleValue());

    if (result.transactionSuccess()) {
      t.getBank().depositCurrency(amt);
      localSender.sendMessage(
          quantity
              + " was withdrawn from your account and deposited into "
              + t.getTownName()
              + "'s town bank.");
    } else {
      localSender.sendMessage(
          ERR + "Transaction failed; maybe you do not have enough money to do this?");
      localSender.sendMessage(ChatColor.GOLD + "Actual amount deposited: " + result.amount);
    }
  }
示例#17
0
  public void withdrawCurrencyBank(String quantity) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    if (!MCTConfig.ECONOMY_ENABLED.getBoolean()) {
      localSender.sendMessage(ERR + "The economy isn't enabled for your server.");
      return;
    }

    BigDecimal amt;
    try {
      amt = new BigDecimal(quantity);
    } catch (NumberFormatException nfe) {
      localSender.sendMessage(
          ERR + "Error parsing quantity \"" + quantity + "\" : " + nfe.getMessage());
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    // DO the withdrawl from the town bank
    amt = t.getBank().withdrawCurrency(amt);

    MCTowns.getEconomy().depositPlayer(localSender.getPlayer().getName(), amt.doubleValue());
    localSender.sendMessage(
        amt
            + " was withdrawn from "
            + t.getTownName()
            + "'s town bank and deposited into your account.");
  }
示例#18
0
  public void promoteToAssistant(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();
    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!(localSender.hasExternalPermissions(Perms.ADMIN.toString())
        || t.playerIsMayor(localSender.getPlayer()))) {
      localSender.notifyInsufPermissions();
      return;
    }

    OfflinePlayer p = server.getOfflinePlayer(playerName);
    if (!p.hasPlayedBefore()) {
      localSender.sendMessage(ERR + playerName + " has never played on this server before.");
      return;
    }

    if (t.playerIsMayor(p)) {
      localSender.sendMessage(ERR + "That player is already the mayor of the town.");
      return;
    }

    if (!t.playerIsResident(p)) {
      localSender.sendMessage(ERR + p.getName() + " is not a resident of " + t.getTownName() + ".");
      return;
    }

    if (t.addAssistant(p)) {
      for (String territName : t.getTerritoriesCollection()) {
        townManager.getTerritory(territName).addPlayer(p);
      }

      localSender.sendMessage(
          playerName + " has been promoted to an assistant of " + t.getTownName() + ".");

      if (p.isOnline())
        p.getPlayer().sendMessage("You are now an Assistant Mayor of " + t.getTownName());
    } else localSender.sendMessage(ERR + playerName + " is already an assistant in this town.");
  }
示例#19
0
  public void setActiveTown(String townName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = townManager.getTown(townName);
    if (t == null) {
      localSender.sendMessage(ERR + "The town \"" + townName + "\" does not exist.");
      return;
    }

    if (!localSender.hasExternalPermissions(Perms.ADMIN.toString())
        && !t.playerIsResident(localSender.getPlayer())) {
      localSender.notifyInsufPermissions();
      return;
    }

    localSender.setActiveTown(townManager.getTown(townName));
    localSender.sendMessage("Active town set to " + townName);
  }
示例#20
0
  public void checkCurrencyBank() {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!MCTConfig.ECONOMY_ENABLED.getBoolean()) {
      localSender.sendMessage(ERR + "The economy isn't enabled for your server.");
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    localSender.sendMessage(
        ChatColor.BLUE + "Amount of currency in bank: " + t.getBank().getCurrencyBalance());
  }
示例#21
0
  public void setMOTD(String motd) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    t.setTownMOTD(motd);
    localSender.sendMessage("Town MOTD has been set.");
  }
示例#22
0
  public void warpToOtherSpawn(String townName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasExternalPermissions(Perms.WARP_FOREIGN.toString())) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town t = townManager.getTown(townName);

    if (t == null) {
      localSender.sendMessage(ERR + "That town doesn't exist.");
      return;
    }

    localSender.getPlayer().teleport(t.getTownSpawn());

    localSender.sendMessage(INFO + "Teleported to " + t.getTownName() + "! Welcome!");
  }
示例#23
0
  public void rejectRequest(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Player p = server.getPlayer(playerName);
    Town t = localSender.getActiveTown();

    //        if (p == null) {
    //            senderWrapper.sendMessage(ERR + "Player does not exist or is not online.");
    //            return;
    //        }
    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!joinManager.clearRequest((p == null ? playerName : p.getName()), t))
      localSender.sendMessage(ERR + "No matching request found.");
    else {
      localSender.sendMessage(
          ChatColor.GOLD
              + (p == null ? playerName : p.getName())
              + "'s request has been rejected.");

      if (p != null)
        p.sendMessage(
            ChatColor.DARK_RED + "Your request to join " + t.getTownName() + " has been rejected.");
    }
  }
示例#24
0
  public void demoteFromAssistant(String playerName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    Town t = localSender.getActiveTown();
    OfflinePlayer p = server.getOfflinePlayer(playerName);

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (!(localSender.hasExternalPermissions(Perms.ADMIN.toString())
        || t.playerIsMayor(localSender.getPlayer()))) {
      localSender.notifyInsufPermissions();
      return;
    }

    if (!p.hasPlayedBefore()) {
      localSender.sendMessage(ERR + playerName + " has never played on this server before.");
      return;
    }

    if (!t.playerIsResident(p)) {
      localSender.sendMessage(ERR + playerName + " is not a resident of " + t.getTownName() + ".");
      return;
    }

    if (t.removeAssistant(p)) {
      localSender.sendMessage(p.getName() + " has been demoted.");
      if (p.isOnline())
        p.getPlayer()
            .sendMessage(
                ChatColor.DARK_RED + "You are no longer an assistant mayor for " + t.getTownName());

      for (String territName : t.getTerritoriesCollection()) {
        townManager.getTerritory(territName).removePlayer(p);
      }
    } else localSender.sendMessage(ERR + p.getName() + " is not an assistant in this town.");
  }
示例#25
0
  public void addTerritorytoTown(String territName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    boolean autoActive = !cmd.hasFlag(ECommand.DISABLE_AUTOACTIVE);
    boolean admin = cmd.hasFlag(ECommand.ADMIN);
    boolean adminAllowed = localSender.hasExternalPermissions(Perms.ADMIN.toString());

    if (!adminAllowed && admin) {
      localSender.sendMessage(
          ChatColor.DARK_RED
              + "You're not permitted to run this command with administrative priviliges!");
      return;
    }

    if (!(MCTConfig.MAYORS_CAN_BUY_TERRITORIES.getBoolean() || adminAllowed)) {
      localSender.sendMessage(
          ChatColor.BLUE + "Mayors are not allowed to add territories and you're not an admin.");
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if ((t.getSize() < MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt()) && !admin) {
      localSender.sendMessage(
          ERR + "You don't have enough people in your town to buy territories yet.");
      localSender.sendMessage(
          ERR
              + "You have "
              + t.getSize()
              + " people, but you need a total of "
              + MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt()
              + "!");
      return;
    }

    territName = MCTownsRegion.formatRegionName(t, TownLevel.TERRITORY, territName);

    World w = localSender.getPlayer().getWorld();

    if (w == null) {
      localSender.sendMessage(
          ERR + "You are in an invalid World. (Player::getWorld() returned null)");
      return;
    }

    ProtectedRegion region = this.getSelectedRegion(territName);

    if (region == null) {
      localSender.sendMessage(ERR + "No region selected!");
      return;
    }

    int max = MCTConfig.TERRITORY_XZ_SIZE_LIMIT.getInt(),
        cur = WGUtils.getNumXZBlocksInRegion(region);
    if (cur > max && !localSender.hasExternalPermissions(Perms.ADMIN.toString())) {
      localSender.sendMessageF(
          "%sYou're not allowed to make a territory that big. (Current: %s, Limit: %s)",
          ERR, cur, max);
      return;
    }

    BigDecimal colPrice = new BigDecimal(MCTConfig.PRICE_PER_XZ_BLOCK.getString());
    // charge the player if they're not running this as an admin and buyable territories is enabled
    // and the price is more than 0
    if (!admin && colPrice.compareTo(BigDecimal.ZERO) > 0) {
      BigDecimal price = colPrice.multiply(new BigDecimal(WGUtils.getNumXZBlocksInRegion(region)));

      if (t.getBank().getCurrencyBalance().compareTo(price) < 0) {
        // If they can't afford it...
        localSender.sendMessage(
            ERR
                + "There is not enough money in your "
                + INFO
                + "town's bank account"
                + ERR
                + " to buy a region that large.");
        localSender.sendMessage(ERR + "Total Price: " + price);
        localSender.sendMessage(
            INFO + "Add money to your town's bank with: /town bank deposit currency <amount>");
        return;
      }

      // otherwise...
      t.getBank().withdrawCurrency(price);

      localSender.sendMessage(
          ChatColor.GREEN + "Purchase success! Total price was: " + price.toString());
    }

    try {
      townManager.addTerritory(territName, w, region, t);
    } catch (TownManager.InvalidWorldGuardRegionNameException
        | TownManager.RegionAlreadyExistsException ex) {
      localSender.sendMessage(ERR + ex.getLocalizedMessage());
      return;
    }

    region.getOwners().addPlayer(UUIDs.getNameForUUID(t.getMayor()));
    for (String assistantName : t.getAssistantNames()) region.getOwners().addPlayer(assistantName);

    localSender.sendMessage(SUCC + "Territory added.");

    if (autoActive) {
      localSender.setActiveTerritory(townManager.getTerritory(territName));
      localSender.sendMessage(
          ChatColor.LIGHT_PURPLE + "Active territory set to newly created territory.");
    }
  }
示例#26
0
  public void invitePlayerToTown(String invitee) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }
    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if (t.usesEconomyJoins()) {
      localSender.sendMessage(t.getTownName() + " doesn't use the invitation system.");
      return;
    }

    OfflinePlayer p = server.getOfflinePlayer(invitee);
    if (!p.isOnline() && !p.hasPlayedBefore()) {
      localSender.sendMessage(ERR + invitee + " has never played on this server before.");
      return;
    }

    if (!MCTConfig.PLAYERS_CAN_JOIN_MULTIPLE_TOWNS.getBoolean()
        && townManager.playerIsAlreadyInATown(p)) {
      localSender.sendMessage(ERR + p.getName() + " is already in a town.");
      return;
    }

    if (t.playerIsResident(p)) {
      localSender.sendMessage(ERR + p.getName() + " is already a member of " + t.getTownName());
      return;
    }

    if (joinManager.getIssuedInvitesForTown(t).contains(p.getName())) {
      localSender.sendMessage(ERR + p.getName() + " is already invited to join " + t.getTownName());
      return;
    }

    for (Player pl : Bukkit.getOnlinePlayers()) {
      if (pl.getName().equalsIgnoreCase(p.getName()) && !pl.getName().equals(p.getName())) {
        localSender.sendMessage(
            INFO
                + "NOTE: You invited "
                + p.getName()
                + ", did you mean to invite "
                + pl.getName()
                + "? (Names are CaSe SeNsItIvE!)");
      }
    }

    if (joinManager.requestExists(p.getName(), t)) {
      t.addPlayer(p);
      if (p.isOnline()) p.getPlayer().sendMessage("You have joined " + t.getTownName() + "!");
      broadcastTownJoin(t, p.getName());
      joinManager.clearRequest(p.getName(), t);
    } else {
      joinManager.invitePlayerToTown(p.getName(), t);
      localSender.sendMessage(
          SUCC + p.getName() + " has been invited to join " + t.getTownName() + ".");
      if (p.isOnline()) {
        p.getPlayer()
            .sendMessage(
                ChatColor.DARK_GREEN
                    + "You have been invited to join the town "
                    + t.getTownName()
                    + "!");
        p.getPlayer()
            .sendMessage(ChatColor.DARK_GREEN + "To join, type /mct join " + t.getTownName());
      }
    }
  }