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;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2015-01-22 00:58:33 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2015-05-13 03:47:22 +02:00
|
|
|
import com.massivecraft.factions.zcore.util.TagUtil;
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2019-08-24 19:18:50 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
public class CmdList extends FCommand {
|
|
|
|
|
2019-08-24 19:18:50 +02:00
|
|
|
private String[] defaults = new String[3];
|
|
|
|
|
|
|
|
public CmdList() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("list");
|
|
|
|
this.aliases.add("ls");
|
|
|
|
|
|
|
|
// default values in case user has old config
|
|
|
|
defaults[0] = "&e&m----------&r&e[ &2Faction List &9{pagenumber}&e/&9{pagecount} &e]&m----------";
|
|
|
|
defaults[1] = "<i>Factionless<i> {factionless} online";
|
|
|
|
defaults[2] = "<a>{faction} <i>{online} / {members} online, <a>Land / Power / Maxpower: <i>{chunks}/{power}/{maxPower}";
|
|
|
|
|
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("page", "1");
|
|
|
|
|
2019-09-14 21:13:01 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.LIST)
|
|
|
|
.playerOnly()
|
|
|
|
.build();
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-14 21:13:01 +02:00
|
|
|
public void perform(CommandContext context) {
|
2019-08-24 19:18:50 +02:00
|
|
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
2019-09-14 21:13:01 +02:00
|
|
|
if (!context.payForCommand(Conf.econCostList, "to list the factions", "for listing the factions"))
|
2019-08-24 19:18:50 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
|
|
|
|
factionList.remove(Factions.getInstance().getWilderness());
|
|
|
|
factionList.remove(Factions.getInstance().getSafeZone());
|
|
|
|
factionList.remove(Factions.getInstance().getWarZone());
|
|
|
|
|
|
|
|
// remove exempt factions
|
2019-09-14 21:13:01 +02:00
|
|
|
if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) {
|
|
|
|
List<String> exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt");
|
2019-08-24 19:18:50 +02:00
|
|
|
|
|
|
|
factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by total followers first
|
2019-09-14 21:13:01 +02:00
|
|
|
factionList.sort((f1, f2) -> {
|
2019-08-24 19:18:50 +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;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Then sort by how many members are online now
|
|
|
|
factionList.sort((f1, 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<>();
|
|
|
|
|
|
|
|
factionList.add(0, Factions.getInstance().getWilderness());
|
|
|
|
|
|
|
|
final int pageheight = 9;
|
2019-09-14 21:13:01 +02:00
|
|
|
int pagenumber = context.argAsInt(0, 1);
|
2019-08-24 19:18:50 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-14 21:13:01 +02:00
|
|
|
String header = FactionsPlugin.getInstance().getConfig().getString("list.header", defaults[0]);
|
2019-08-24 19:18:50 +02:00
|
|
|
header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount));
|
2019-09-14 21:13:01 +02:00
|
|
|
lines.add(FactionsPlugin.getInstance().txt.parse(header));
|
2019-08-24 19:18:50 +02:00
|
|
|
|
|
|
|
for (Faction faction : factionList.subList(start, end)) {
|
|
|
|
if (faction.isWilderness()) {
|
2019-09-14 21:13:01 +02:00
|
|
|
lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, FactionsPlugin.getInstance().getConfig().getString("list.factionless", defaults[1]))));
|
2019-08-24 19:18:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, context.fPlayer, FactionsPlugin.getInstance().getConfig().getString("list.entry", defaults[2]))));
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
context.sendMessage(lines);
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_LIST_DESCRIPTION;
|
|
|
|
}
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|