2017-03-24 14:25:29 +01:00
|
|
|
package com.massivecraft.factions.comparator;
|
2015-01-25 00:13:19 +01:00
|
|
|
|
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2015-11-06 02:10:29 +01:00
|
|
|
import com.massivecraft.massivecore.Named;
|
2015-01-25 00:13:19 +01:00
|
|
|
|
2017-03-24 13:05:58 +01:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
2017-03-24 14:25:29 +01:00
|
|
|
public class ComparatorMPlayerInactivity implements Comparator<MPlayer>, Named
|
2015-01-25 00:13:19 +01:00
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// INSTANCE & CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2017-03-24 14:25:29 +01:00
|
|
|
private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity();
|
|
|
|
public static ComparatorMPlayerInactivity get() { return i; }
|
2015-01-25 00:13:19 +01:00
|
|
|
|
2015-11-06 02:10:29 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE: NAMED
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return "Time";
|
|
|
|
}
|
|
|
|
|
2015-01-25 00:13:19 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE: COMPARATOR
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(MPlayer m1, MPlayer m2)
|
|
|
|
{
|
|
|
|
// Null
|
|
|
|
if (m1 == null && m2 == null) return 0;
|
|
|
|
else if (m1 == null) return -1;
|
|
|
|
else if (m2 == null) return +1;
|
|
|
|
|
|
|
|
// Online
|
|
|
|
boolean o1 = m1.isOnline();
|
|
|
|
boolean o2 = m2.isOnline();
|
|
|
|
|
|
|
|
if (o1 && o2) return 0;
|
|
|
|
else if (o1) return -1;
|
|
|
|
else if (o2) return +1;
|
|
|
|
|
|
|
|
// Inactivity Time
|
|
|
|
long r1 = m1.getLastActivityMillis();
|
|
|
|
long r2 = m2.getLastActivityMillis();
|
|
|
|
|
|
|
|
return (int) (r1 - r2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|