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

View File

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