50 lines
1.3 KiB
Java
50 lines
1.3 KiB
Java
package com.massivecraft.factions;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import com.massivecraft.mcore.util.MUtil;
|
|
|
|
public class FactionListComparator implements Comparator<Faction>
|
|
{
|
|
// -------------------------------------------- //
|
|
// INSTANCE & CONSTRUCT
|
|
// -------------------------------------------- //
|
|
|
|
private static FactionListComparator i = new FactionListComparator();
|
|
public static FactionListComparator get() { return i; }
|
|
|
|
// -------------------------------------------- //
|
|
// OVERRIDE: COMPARATOR
|
|
// -------------------------------------------- //
|
|
|
|
@Override
|
|
public int compare(Faction f1, Faction f2)
|
|
{
|
|
int ret = 0;
|
|
|
|
// Null
|
|
if (f1 == null && f2 == null) ret = 0;
|
|
if (f1 == null) ret = -1;
|
|
if (f2 == null) ret = +1;
|
|
if (ret != 0) return ret;
|
|
|
|
// None
|
|
if (f1.isNone() && f2.isNone()) ret = 0;
|
|
if (f1.isNone()) ret = -1;
|
|
if (f2.isNone()) ret = +1;
|
|
if (ret != 0) return ret;
|
|
|
|
// Players Online
|
|
ret = f2.getFPlayersWhereOnline(true).size() - f1.getFPlayersWhereOnline(true).size();
|
|
if (ret != 0) return ret;
|
|
|
|
// Players Total
|
|
ret = f2.getFPlayers().size() - f1.getFPlayers().size();
|
|
if (ret != 0) return ret;
|
|
|
|
// Tie by Id
|
|
return MUtil.compare(f1.getId(), f2.getId());
|
|
}
|
|
|
|
}
|