示例#1
0
  @Override
  public void perform() {
    String tag = this.argAsString(0);

    if (fme.hasFaction()) {
      msg("<b>You must leave your current faction first.");
      return;
    }

    if (Guilds.i.isTagTaken(tag)) {
      msg("<b>That tag is already in use.");
      return;
    }

    ArrayList<String> tagValidationErrors = Guilds.validateTag(tag);
    if (tagValidationErrors.size() > 0) {
      sendMessage(tagValidationErrors);
      return;
    }

    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // sure they can pay
    if (!canAffordCommand(Conf.econCostCreate, "to create a new faction")) return;

    // trigger the faction creation event (cancellable)
    FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
    Bukkit.getServer().getPluginManager().callEvent(createEvent);
    if (createEvent.isCancelled()) return;

    // then make 'em pay (if applicable)
    if (!payForCommand(
        Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return;

    Guild faction = Guilds.i.create();

    // TODO: Why would this even happen??? Auto increment clash??
    if (faction == null) {
      msg("<b>There was an internal error while trying to create your faction. Please try again.");
      return;
    }

    // finish setting up the Faction
    faction.setTag(tag);

    // trigger the faction join event for the creator
    FPlayerJoinEvent joinEvent =
        new FPlayerJoinEvent(
            GuildPlayers.i.get(me), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE);
    Bukkit.getServer().getPluginManager().callEvent(joinEvent);
    // join event cannot be cancelled or you'll have an empty faction

    // finish setting up the FPlayer
    fme.setRole(Role.ADMIN);
    fme.setFaction(faction);

    for (GuildPlayer follower : GuildPlayers.i.getOnline()) {
      follower.msg(
          "%s<i> created a new faction %s",
          fme.describeTo(follower, true), faction.getTag(follower));
    }

    msg("<i>You should now: %s", p.cmdBase.cmdDescription.getUseageTemplate());

    if (Conf.logFactionCreate) GuildsMain.p.log(fme.getName() + " created a new faction: " + tag);
  }
示例#2
0
  @Override
  public void perform() {
    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // 'em pay
    if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions"))
      return;

    ArrayList<Guild> factionList = new ArrayList<Guild>(Guilds.i.get());
    factionList.remove(Guilds.i.getNone());
    factionList.remove(Guilds.i.getSafeZone());
    factionList.remove(Guilds.i.getWarZone());

    // Sort by total followers first
    Collections.sort(
        factionList,
        new Comparator<Guild>() {
          @Override
          public int compare(Guild f1, Guild f2) {
            int f1Size = f1.getFPlayers().size();
            int f2Size = f2.getFPlayers().size();
            if (f1Size < f2Size) return 1;
            else if (f1Size > f2Size) return -1;
            return 0;
          }
        });

    // Then sort by how many members are online now
    Collections.sort(
        factionList,
        new Comparator<Guild>() {
          @Override
          public int compare(Guild f1, Guild f2) {
            int f1Size = f1.getFPlayersWhereOnline(true).size();
            int f2Size = f2.getFPlayersWhereOnline(true).size();
            if (f1Size < f2Size) return 1;
            else if (f1Size > f2Size) return -1;
            return 0;
          }
        });

    ArrayList<String> lines = new ArrayList<String>();

    /*		// this code was really slow on large servers, getting full info for every faction and then only showing 9 of them; rewritten below
    	lines.add(p.txt.parse("<i>Factionless<i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
    	for (Faction faction : factionList)
    	{
    		lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d",
    			faction.getTag(fme),
    			faction.getFPlayersWhereOnline(true).size(),
    			faction.getFPlayers().size(),
    			faction.getLandRounded(),
    			faction.getPowerRounded(),
    			faction.getPowerMaxRounded())
    		);
    	}

    	sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
    */

    factionList.add(0, Guilds.i.getNone());

    final int pageheight = 9;
    int pagenumber = this.argAsInt(0, 1);
    int pagecount = (factionList.size() / pageheight) + 1;
    if (pagenumber > pagecount) pagenumber = pagecount;
    else if (pagenumber < 1) pagenumber = 1;
    int start = (pagenumber - 1) * pageheight;
    int end = start + pageheight;
    if (end > factionList.size()) end = factionList.size();

    lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount));

    for (Guild faction : factionList.subList(start, end)) {
      if (faction.isNone()) {
        lines.add(
            p.txt.parse(
                "<i>Factionless<i> %d online",
                Guilds.i.getNone().getFPlayersWhereOnline(true).size()));
        continue;
      }
      lines.add(
          p.txt.parse(
              "%s<i> %d/%d online, %d/%d/%d",
              faction.getTag(fme),
              faction.getFPlayersWhereOnline(true).size(),
              faction.getFPlayers().size(),
              faction.getLandRounded(),
              faction.getPowerRounded(),
              faction.getPowerMaxRounded()));
    }

    sendMessage(lines);
  }