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

55 lines
1.3 KiB
Java
Raw Normal View History

2015-01-25 00:13:19 +01:00
package com.massivecraft.factions;
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;
2015-11-06 02:10:29 +01:00
public class PlayerInactivityComparator implements Comparator<MPlayer>, Named
2015-01-25 00:13:19 +01:00
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PlayerInactivityComparator i = new PlayerInactivityComparator();
public static PlayerInactivityComparator get() { return i; }
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);
}
}