Factions/src/com/massivecraft/factions/PlayerInactivityComparator.java

44 lines
1.1 KiB
Java
Raw Normal View History

2015-01-25 00:13:19 +01:00
package com.massivecraft.factions;
import java.util.Comparator;
import com.massivecraft.factions.entity.MPlayer;
public class PlayerInactivityComparator implements Comparator<MPlayer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PlayerInactivityComparator i = new PlayerInactivityComparator();
public static PlayerInactivityComparator get() { return i; }
// -------------------------------------------- //
// 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);
}
}