2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
|
2014-11-13 19:45:57 +01:00
|
|
|
import mkremins.fanciful.FancyMessage;
|
2014-12-08 00:12:52 +01:00
|
|
|
|
2014-11-13 19:45:57 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
public class CmdList extends FCommand {
|
|
|
|
|
|
|
|
public CmdList() {
|
2014-07-01 22:10:18 +02:00
|
|
|
super();
|
|
|
|
this.aliases.add("list");
|
|
|
|
this.aliases.add("ls");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("page", "1");
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
this.permission = Permission.LIST.node;
|
|
|
|
this.disableOnLock = false;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
senderMustBePlayer = false;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
2014-04-04 20:55:21 +02:00
|
|
|
senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2014-12-08 00:12:52 +01:00
|
|
|
if (!payForCommand(Conf.econCostList, TL.COMMAND_LIST_TOLIST.toString() , TL.COMMAND_LIST_FORLIST.toString())) {
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
|
|
|
|
factionList.remove(Factions.getInstance().getNone());
|
|
|
|
factionList.remove(Factions.getInstance().getSafeZone());
|
|
|
|
factionList.remove(Factions.getInstance().getWarZone());
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// Sort by total followers first
|
|
|
|
Collections.sort(factionList, new Comparator<Faction>() {
|
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
2014-07-01 22:10:18 +02:00
|
|
|
int f1Size = f1.getFPlayers().size();
|
|
|
|
int f2Size = f2.getFPlayers().size();
|
|
|
|
if (f1Size < f2Size) {
|
|
|
|
return 1;
|
|
|
|
} else if (f1Size > f2Size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Then sort by how many members are online now
|
|
|
|
Collections.sort(factionList, new Comparator<Faction>() {
|
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
|
|
|
int f1Size = f1.getFPlayersWhereOnline(true).size();
|
|
|
|
int f2Size = f2.getFPlayersWhereOnline(true).size();
|
2014-07-01 22:10:18 +02:00
|
|
|
if (f1Size < f2Size) {
|
|
|
|
return 1;
|
|
|
|
} else if (f1Size > f2Size) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-13 19:45:57 +01:00
|
|
|
ArrayList<FancyMessage> lines = new ArrayList<FancyMessage>();
|
2012-11-06 16:43:30 +01:00
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
factionList.add(0, Factions.getInstance().getNone());
|
2012-11-06 16:43:30 +01:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
final int pageheight = 9;
|
|
|
|
int pagenumber = this.argAsInt(0, 1);
|
2014-04-04 20:55:21 +02:00
|
|
|
int pagecount = (factionList.size() / pageheight) + 1;
|
2014-07-01 22:10:18 +02:00
|
|
|
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();
|
|
|
|
}
|
2012-11-06 16:43:30 +01:00
|
|
|
|
2014-12-08 00:12:52 +01:00
|
|
|
lines.add(new FancyMessage(p.txt.titleize(TL.COMMAND_LIST_FACTIONLIST.toString() + pagenumber + "/" + pagecount)));
|
2012-11-06 16:43:30 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
for (Faction faction : factionList.subList(start, end)) {
|
|
|
|
if (faction.isNone()) {
|
2014-11-13 19:45:57 +01:00
|
|
|
String online = String.valueOf(faction.getFPlayersWhereOnline(true).size());
|
2014-12-08 00:12:52 +01:00
|
|
|
FancyMessage msg = new FancyMessage(TL.COMMAND_LIST_ONLINEFACTIONLESS.toString() + online).color(ChatColor.YELLOW);
|
2014-11-13 19:45:57 +01:00
|
|
|
lines.add(msg);
|
2014-04-04 20:55:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-13 19:45:57 +01:00
|
|
|
String online = " " + faction.getFPlayersWhereOnline(true).size() + "/" + faction.getFPlayers().size() + " online";
|
|
|
|
|
|
|
|
FancyMessage msg = new FancyMessage(faction.getTag(fme) + online).color(ChatColor.YELLOW).tooltip(getToolTips(faction));
|
|
|
|
lines.add(msg);
|
|
|
|
//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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
sendFancyMessage(lines);
|
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|