More sorting cleanup & lambda functions in F Top Command.

This commit is contained in:
ProSavage 2019-02-12 07:51:59 -04:00
parent c2a90e857f
commit 25ac8f026e
1 changed files with 63 additions and 83 deletions

View File

@ -9,8 +9,6 @@ import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class CmdTop extends FCommand { public class CmdTop extends FCommand {
@ -47,97 +45,79 @@ public class CmdTop extends FCommand {
// TODO: Better way to sort? // TODO: Better way to sort?
if (criteria.equalsIgnoreCase("members")) { if (criteria.equalsIgnoreCase("members")) {
factionList.sort(new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override int f1Size = f1.getFPlayers().size();
public int compare(Faction f1, Faction f2) { int f2Size = f2.getFPlayers().size();
int f1Size = f1.getFPlayers().size(); if (f1Size < f2Size) {
int f2Size = f2.getFPlayers().size(); return 1;
if (f1Size < f2Size) { } else if (f1Size > f2Size) {
return 1; return -1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
} }
}); return 0;
});
} else if (criteria.equalsIgnoreCase("start")) { } else if (criteria.equalsIgnoreCase("start")) {
Collections.sort(factionList, new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override long f1start = f1.getFoundedDate();
public int compare(Faction f1, Faction f2) { long f2start = f2.getFoundedDate();
long f1start = f1.getFoundedDate(); // flip signs because a smaller date is farther in the past
long f2start = f2.getFoundedDate(); if (f1start > f2start) {
// flip signs because a smaller date is farther in the past return 1;
if (f1start > f2start) { } else if (f1start < f2start) {
return 1; return -1;
} else if (f1start < f2start) { }
return -1; return 0;
}
return 0;
}
}); });
} else if (criteria.equalsIgnoreCase("power")) { } else if (criteria.equalsIgnoreCase("power")) {
Collections.sort(factionList, new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override int f1Size = f1.getPowerRounded();
public int compare(Faction f1, Faction f2) { int f2Size = f2.getPowerRounded();
int f1Size = f1.getPowerRounded(); if (f1Size < f2Size) {
int f2Size = f2.getPowerRounded(); return 1;
if (f1Size < f2Size) { } else if (f1Size > f2Size) {
return 1; return -1;
} else if (f1Size > f2Size) { }
return -1; return 0;
}
return 0;
}
}); });
} else if (criteria.equalsIgnoreCase("land")) { } else if (criteria.equalsIgnoreCase("land")) {
Collections.sort(factionList, new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override int f1Size = f1.getLandRounded();
public int compare(Faction f1, Faction f2) { int f2Size = f2.getLandRounded();
int f1Size = f1.getLandRounded(); if (f1Size < f2Size) {
int f2Size = f2.getLandRounded(); return 1;
if (f1Size < f2Size) { } else if (f1Size > f2Size) {
return 1; return -1;
} else if (f1Size > f2Size) { }
return -1; return 0;
}
return 0;
}
}); });
} else if (criteria.equalsIgnoreCase("online")) { } else if (criteria.equalsIgnoreCase("online")) {
factionList.sort(new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override int f1Size = f1.getFPlayersWhereOnline(true).size();
public int compare(Faction f1, Faction f2) { int f2Size = f2.getFPlayersWhereOnline(true).size();
int f1Size = f1.getFPlayersWhereOnline(true).size(); if (f1Size < f2Size) {
int f2Size = f2.getFPlayersWhereOnline(true).size(); return 1;
if (f1Size < f2Size) { } else if (f1Size > f2Size) {
return 1; return -1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
} }
}); return 0;
});
} else if (criteria.equalsIgnoreCase("money") || criteria.equalsIgnoreCase("balance") || criteria.equalsIgnoreCase("bal")) { } else if (criteria.equalsIgnoreCase("money") || criteria.equalsIgnoreCase("balance") || criteria.equalsIgnoreCase("bal")) {
factionList.sort(new Comparator<Faction>() { factionList.sort((f1, f2) -> {
@Override double f1Size = Econ.getBalance(f1.getAccountId());
public int compare(Faction f1, Faction f2) { // Lets get the balance of /all/ the players in the Faction.
double f1Size = Econ.getBalance(f1.getAccountId()); for (FPlayer fp : f1.getFPlayers()) {
// Lets get the balance of /all/ the players in the Faction. f1Size = f1Size + Econ.getBalance(fp.getAccountId());
for (FPlayer fp : f1.getFPlayers()) { }
f1Size = f1Size + Econ.getBalance(fp.getAccountId()); double f2Size = Econ.getBalance(f2.getAccountId());
} for (FPlayer fp : f2.getFPlayers()) {
double f2Size = Econ.getBalance(f2.getAccountId()); f2Size = f2Size + Econ.getBalance(fp.getAccountId());
for (FPlayer fp : f2.getFPlayers()) { }
f2Size = f2Size + Econ.getBalance(fp.getAccountId()); if (f1Size < f2Size) {
} return 1;
if (f1Size < f2Size) { } else if (f1Size > f2Size) {
return 1; return -1;
} else if (f1Size > f2Size) { }
return -1; return 0;
} });
return 0;
}
});
} else { } else {
msg(TL.COMMAND_TOP_INVALID, criteria); msg(TL.COMMAND_TOP_INVALID, criteria);
} }