use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CommandList method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command handling
*/
int selectedPage = 1;
if (commandData.getArgs().length == 2) {
try {
selectedPage = Integer.parseInt(commandData.getArgs()[1]);
} catch (NumberFormatException ex) {
pp.sendMessage(Messages.ADDCMD_LIST_WRONGCMD);
return;
}
}
/*
* Command starts
*/
// Get all parties
List<PartyEntity> parties = new ArrayList<PartyEntity>();
for (Party party : plugin.getDatabaseManager().getAllParties().join()) {
if (party != null) {
PartyEntity partyImpl = new PartyEntity(party, plugin);
partyImpl.reloadOnlinePlayers();
if (partyImpl.getNumberOnlinePlayers() >= ConfigParties.LIST_FILTERMIN)
parties.add(partyImpl);
}
}
// Order parties
switch(ConfigParties.LIST_ORDEREDBY.toLowerCase()) {
case "kills":
if (!ConfigParties.KILLS_ENABLE)
parties = orderName(parties);
else
parties = orderKills(parties);
break;
case "players":
parties = orderPlayers(parties);
break;
case "allplayers":
parties = orderAllPlayers(parties);
break;
default:
parties = orderName(parties);
}
// Group up parties
parties = limitList(parties);
int maxPages;
if (parties.size() == 0)
maxPages = 1;
else if (parties.size() % ConfigParties.LIST_PERPAGE == 0)
maxPages = parties.size() / ConfigParties.LIST_PERPAGE;
else
maxPages = (parties.size() / ConfigParties.LIST_PERPAGE) + 1;
if (selectedPage > maxPages)
selectedPage = maxPages;
else if (selectedPage < 1)
selectedPage = 1;
int currentPage = 0;
StringBuilder sb = new StringBuilder();
sb.append(Messages.ADDCMD_LIST_HEADER).append("\n");
for (PartyEntity party : parties) {
int currentChoosenPage = (selectedPage - 1) * ConfigParties.LIST_PERPAGE;
if (currentPage >= currentChoosenPage && currentPage < (currentChoosenPage + ConfigParties.LIST_PERPAGE)) {
sb.append(PartiesUtils.convertPartyPlaceholders(Messages.ADDCMD_LIST_FORMATPARTY, party)).append("\n");
}
currentPage++;
}
if (parties.size() == 0)
sb.append(Messages.ADDCMD_LIST_NOONE).append("\n");
sb.append(Messages.ADDCMD_LIST_FOOTER);
pp.sendMessage(sb.toString().replace("%number%", Integer.toString(parties.size())).replace("%page%", Integer.toString(selectedPage)).replace("%maxpages%", Integer.toString(maxPages)));
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_IGNORE_STOP.replace("{player}", pp.getName()), true);
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CommandList method orderPlayers.
private List<PartyEntity> orderPlayers(List<PartyEntity> list) {
int from;
for (int c = 0; c < list.size() - 1; c++) {
from = c;
for (int c2 = c + 1; c2 < list.size(); c2++) {
if (list.get(c2).getNumberOnlinePlayers() > list.get(from).getNumberOnlinePlayers()) {
from = c2;
}
}
if (from != c) {
PartyEntity temp = list.get(c);
list.set(c, list.get(from));
list.set(from, temp);
}
}
return list;
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CommandList method orderAllPlayers.
private List<PartyEntity> orderAllPlayers(List<PartyEntity> list) {
int from;
for (int c = 0; c < list.size() - 1; c++) {
from = c;
for (int c2 = c + 1; c2 < list.size(); c2++) {
if (list.get(c2).getMembers().size() > list.get(from).getMembers().size()) {
from = c2;
}
}
if (from != c) {
PartyEntity temp = list.get(c);
list.set(c, list.get(from));
list.set(from, temp);
}
}
return list;
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CommandList method orderName.
private List<PartyEntity> orderName(List<PartyEntity> list) {
int from;
for (int c = 0; c < list.size() - 1; c++) {
from = c;
for (int c2 = c + 1; c2 < list.size(); c2++) {
if (list.get(c2).getName().trim().compareTo(list.get(from).getName().trim()) < 0) {
from = c2;
}
}
if (from != c) {
PartyEntity temp = list.get(c);
list.set(c, list.get(from));
list.set(from, temp);
}
}
return list;
}
use of com.alessiodp.parties.parties.objects.PartyEntity in project Parties by AlessioDP.
the class CommandList method orderKills.
private List<PartyEntity> orderKills(List<PartyEntity> list) {
int from;
for (int c = 0; c < list.size() - 1; c++) {
from = c;
for (int c2 = c + 1; c2 < list.size(); c2++) {
if (list.get(c2).getKills() > list.get(from).getKills()) {
from = c2;
}
}
if (from != c) {
PartyEntity temp = list.get(c);
list.set(c, list.get(from));
list.set(from, temp);
}
}
return list;
}
Aggregations