Rename and relocate Comparators and Predicates
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorComparable;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorFactionList implements Comparator<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final WeakReference<CommandSender> watcher;
|
||||
public CommandSender getWatcher() { return this.watcher.get(); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); }
|
||||
public ComparatorFactionList(Object watcherObject)
|
||||
{
|
||||
this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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 a.k.a. Wilderness
|
||||
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.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size();
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Players Total
|
||||
ret = f2.getMPlayers().size() - f1.getMPlayers().size();
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// Tie by Id
|
||||
return ComparatorComparable.get().compare(f1.getId(), f2.getId());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorMPlayerInactivity implements Comparator<MPlayer>, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity();
|
||||
public static ComparatorMPlayerInactivity get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: NAMED
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Time";
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorMPlayerPower implements Comparator<MPlayer>, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerPower i = new ComparatorMPlayerPower();
|
||||
public static ComparatorMPlayerPower get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: NAMED
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Power";
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COMPARATOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compare(MPlayer m1, MPlayer m2)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
// Null
|
||||
if (m1 == null && m2 == null) return 0;
|
||||
else if (m1 == null) return -1;
|
||||
else if (m2 == null) return +1;
|
||||
|
||||
// Power
|
||||
int p1 = m1.getPowerRounded();
|
||||
int p2 = m2.getPowerRounded();
|
||||
ret = p1 - p2;
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// MaxPower
|
||||
int max1 = m1.getPowerMaxRounded();
|
||||
int max2 = m2.getPowerMaxRounded();
|
||||
ret = max1 - max2;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorMPlayerRole implements Comparator<MPlayer>, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerRole i = new ComparatorMPlayerRole();
|
||||
public static ComparatorMPlayerRole get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: NAMED
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Rank";
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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;
|
||||
|
||||
// Rank
|
||||
Rel r1 = m1.getRole();
|
||||
Rel r2 = m2.getRole();
|
||||
return r2.getValue() - r1.getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user