2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions.commands;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-07-18 22:06:02 +02:00
|
|
|
|
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.util.TextUtil;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
public class FCommandList extends FBaseCommand {
|
|
|
|
|
|
|
|
public FCommandList() {
|
2011-03-22 18:48:09 +01:00
|
|
|
aliases.add("list");
|
|
|
|
aliases.add("ls");
|
|
|
|
|
2011-06-30 12:56:02 +02:00
|
|
|
senderMustBePlayer = false;
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
optionalParameters.add("page");
|
|
|
|
|
|
|
|
helpDescription = "Show a list of the factions";
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasPermission(CommandSender sender) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-03-22 15:45:41 +01:00
|
|
|
public void perform() {
|
|
|
|
ArrayList<Faction> FactionList = new ArrayList<Faction>(Faction.getAll());
|
2011-03-23 17:39:56 +01:00
|
|
|
FactionList.remove(Faction.getNone());
|
|
|
|
FactionList.remove(Faction.getSafeZone());
|
2011-05-29 23:28:29 +02:00
|
|
|
FactionList.remove(Faction.getWarZone());
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
int page = 1;
|
|
|
|
if (parameters.size() > 0) {
|
|
|
|
try {
|
|
|
|
page = Integer.parseInt(parameters.get(0));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
// wasn't an integer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page -= 1;
|
|
|
|
|
|
|
|
// Sort by total followers first
|
|
|
|
Collections.sort(FactionList, new Comparator<Faction>(){
|
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
2011-03-22 19:25:11 +01:00
|
|
|
if (f1.getFPlayers().size() < f2.getFPlayers().size())
|
2011-03-22 15:45:41 +01:00
|
|
|
return 1;
|
|
|
|
else if (f1.getFPlayers().size() > f2.getFPlayers().size())
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Then sort by how many members are online now
|
|
|
|
Collections.sort(FactionList, new Comparator<Faction>(){
|
|
|
|
@Override
|
|
|
|
public int compare(Faction f1, Faction f2) {
|
|
|
|
if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size())
|
|
|
|
return 1;
|
|
|
|
else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size())
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
FactionList.add(0, Faction.getNone());
|
2011-03-22 19:25:11 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
int maxPage = (int)Math.floor((double)FactionList.size() / 9D);
|
|
|
|
if (page < 0 || page > maxPage) {
|
|
|
|
sendMessage("The faction list is only " + (maxPage+1) + " page(s) long");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String header = "Faction List";
|
|
|
|
if (maxPage > 1) header += " (page " + (page+1) + " of " + (maxPage+1) + ")";
|
|
|
|
sendMessage(TextUtil.titleize(header));
|
|
|
|
|
|
|
|
int maxPos = (page+1) * 9;
|
|
|
|
if (maxPos > FactionList.size()) maxPos = FactionList.size();
|
|
|
|
for (int pos = page * 9; pos < maxPos; pos++) {
|
|
|
|
Faction faction = FactionList.get(pos);
|
2011-03-22 17:20:21 +01:00
|
|
|
if (faction.getId() == 0) {
|
2011-06-30 12:56:02 +02:00
|
|
|
sendMessage("Factionless"+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size() + " online");
|
2011-03-22 15:45:41 +01:00
|
|
|
} else {
|
|
|
|
sendMessage(faction.getTag(me)+Conf.colorSystem+" "+faction.getFPlayersWhereOnline(true).size()+"/"+faction.getFPlayers().size()+" online, "+faction.getLandRounded()+"/"+faction.getPowerRounded()+"/"+faction.getPowerMaxRounded());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|