2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
2013-04-09 13:15:25 +02:00
|
|
|
import com.massivecraft.factions.ConfServer;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.Faction;
|
2013-04-09 12:58:39 +02:00
|
|
|
import com.massivecraft.factions.FactionColl;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-10 10:32:04 +02:00
|
|
|
import com.massivecraft.mcore.util.Txt;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsList extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsList()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.aliases.add("list");
|
|
|
|
this.aliases.add("ls");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("page", "1");
|
2011-06-30 12:56:02 +02:00
|
|
|
|
2013-04-09 12:56:29 +02:00
|
|
|
this.permission = Perm.LIST.node;
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 14:53:38 +02:00
|
|
|
public void perform()
|
|
|
|
{
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
2013-04-09 13:15:25 +02:00
|
|
|
if ( ! payForCommand(ConfServer.econCostList, "to list the factions", "for listing the factions")) return;
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-12 09:47:43 +02:00
|
|
|
ArrayList<Faction> factionList = new ArrayList<Faction>(FactionColl.get().getAll());
|
2011-10-24 02:33:30 +02:00
|
|
|
|
2013-04-12 09:47:43 +02:00
|
|
|
factionList.remove(FactionColl.get().getNone());
|
2011-10-24 02:33:30 +02:00
|
|
|
// TODO: Add flag SECRET To factions instead.
|
|
|
|
//factionList.remove(Factions.i.getSafeZone());
|
|
|
|
//factionList.remove(Factions.i.getWarZone());
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
// Sort by total followers first
|
2011-10-09 14:53:38 +02:00
|
|
|
Collections.sort(factionList, new Comparator<Faction>(){
|
2011-03-22 15:45:41 +01:00
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
2012-01-12 02:11:10 +01:00
|
|
|
int f1Size = f1.getFPlayers().size();
|
|
|
|
int f2Size = f2.getFPlayers().size();
|
|
|
|
if (f1Size < f2Size)
|
2011-03-22 15:45:41 +01:00
|
|
|
return 1;
|
2012-01-12 02:11:10 +01:00
|
|
|
else if (f1Size > f2Size)
|
2011-03-22 15:45:41 +01:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Then sort by how many members are online now
|
2011-10-09 14:53:38 +02:00
|
|
|
Collections.sort(factionList, new Comparator<Faction>(){
|
2011-03-22 15:45:41 +01:00
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
2012-01-12 02:11:10 +01:00
|
|
|
int f1Size = f1.getFPlayersWhereOnline(true).size();
|
|
|
|
int f2Size = f2.getFPlayersWhereOnline(true).size();
|
|
|
|
if (f1Size < f2Size)
|
2011-03-22 15:45:41 +01:00
|
|
|
return 1;
|
2012-01-12 02:11:10 +01:00
|
|
|
else if (f1Size > f2Size)
|
2011-03-22 15:45:41 +01:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
2011-03-22 19:25:11 +01:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
ArrayList<String> lines = new ArrayList<String>();
|
2012-11-06 16:43:27 +01:00
|
|
|
|
|
|
|
/* // this code was really slow on large servers, getting full info for every faction and then only showing 9 of them; rewritten below
|
2013-04-10 10:32:04 +02:00
|
|
|
lines.add(Txt.parse("<i>Factionless<i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
|
2011-10-09 14:53:38 +02:00
|
|
|
for (Faction faction : factionList)
|
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
lines.add(Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
2011-10-09 14:53:38 +02:00
|
|
|
faction.getTag(fme),
|
|
|
|
faction.getFPlayersWhereOnline(true).size(),
|
|
|
|
faction.getFPlayers().size(),
|
|
|
|
faction.getLandRounded(),
|
|
|
|
faction.getPowerRounded(),
|
|
|
|
faction.getPowerMaxRounded())
|
|
|
|
);
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-10 10:32:04 +02:00
|
|
|
sendMessage(Txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
|
2012-11-06 16:43:27 +01:00
|
|
|
*/
|
|
|
|
|
2013-04-12 09:47:43 +02:00
|
|
|
factionList.add(0, FactionColl.get().getNone());
|
2012-11-06 16:43:27 +01:00
|
|
|
|
|
|
|
final int pageheight = 9;
|
|
|
|
int pagenumber = this.argAsInt(0, 1);
|
|
|
|
int pagecount = (factionList.size() / pageheight) + 1;
|
2012-12-01 02:43:04 +01:00
|
|
|
if (pagenumber > pagecount)
|
|
|
|
pagenumber = pagecount;
|
|
|
|
else if (pagenumber < 1)
|
|
|
|
pagenumber = 1;
|
2012-11-06 16:43:27 +01:00
|
|
|
int start = (pagenumber - 1) * pageheight;
|
|
|
|
int end = start + pageheight;
|
|
|
|
if (end > factionList.size())
|
|
|
|
end = factionList.size();
|
|
|
|
|
2013-04-10 10:32:04 +02:00
|
|
|
lines.add(Txt.titleize("Faction List "+pagenumber+"/"+pagecount));
|
2012-11-06 16:43:27 +01:00
|
|
|
|
|
|
|
for (Faction faction : factionList.subList(start, end))
|
|
|
|
{
|
|
|
|
if (faction.isNone())
|
|
|
|
{
|
2013-04-12 09:47:43 +02:00
|
|
|
lines.add(Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getFPlayersWhereOnline(true).size()));
|
2012-11-06 16:43:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-10 10:32:04 +02:00
|
|
|
lines.add(Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
2012-11-06 16:43:27 +01:00
|
|
|
faction.getTag(fme),
|
|
|
|
faction.getFPlayersWhereOnline(true).size(),
|
|
|
|
faction.getFPlayers().size(),
|
|
|
|
faction.getLandRounded(),
|
|
|
|
faction.getPowerRounded(),
|
|
|
|
faction.getPowerMaxRounded())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(lines);
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
}
|