2013-04-16 12:04:12 +02:00
|
|
|
package com.massivecraft.factions;
|
|
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2014-06-04 14:02:23 +02:00
|
|
|
import com.massivecraft.massivecore.util.MUtil;
|
2013-04-16 12:04:12 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-04-16 13:17:42 +02:00
|
|
|
// Null
|
2013-04-16 12:04:12 +02:00
|
|
|
if (f1 == null && f2 == null) ret = 0;
|
|
|
|
if (f1 == null) ret = -1;
|
|
|
|
if (f2 == null) ret = +1;
|
|
|
|
if (ret != 0) return ret;
|
|
|
|
|
2013-04-17 08:49:43 +02:00
|
|
|
// None a.k.a. Wilderness
|
2013-04-16 12:04:12 +02:00
|
|
|
if (f1.isNone() && f2.isNone()) ret = 0;
|
2013-04-16 13:17:42 +02:00
|
|
|
if (f1.isNone()) ret = -1;
|
|
|
|
if (f2.isNone()) ret = +1;
|
2013-04-16 12:04:12 +02:00
|
|
|
if (ret != 0) return ret;
|
|
|
|
|
2013-04-16 13:17:42 +02:00
|
|
|
// Players Online
|
2014-09-17 13:29:58 +02:00
|
|
|
ret = f2.getMPlayersWhereOnline(true).size() - f1.getMPlayersWhereOnline(true).size();
|
2013-04-16 12:04:12 +02:00
|
|
|
if (ret != 0) return ret;
|
|
|
|
|
2013-04-16 13:17:42 +02:00
|
|
|
// Players Total
|
2014-09-17 13:29:58 +02:00
|
|
|
ret = f2.getMPlayers().size() - f1.getMPlayers().size();
|
2013-04-16 12:04:12 +02:00
|
|
|
if (ret != 0) return ret;
|
|
|
|
|
|
|
|
// Tie by Id
|
|
|
|
return MUtil.compare(f1.getId(), f2.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|