Fixes POM, and moves things around
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorAbstract;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorComparable;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class ComparatorFactionList extends ComparatorAbstract<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
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareInner(Faction f1, Faction f2) {
|
||||
// None a.k.a. Wilderness
|
||||
if (f1.isNone() && f2.isNone()) {
|
||||
return 0;
|
||||
}
|
||||
if (f1.isNone()) {
|
||||
return -1;
|
||||
}
|
||||
if (f2.isNone()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Players Online
|
||||
int 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,48 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorAbstract;
|
||||
|
||||
public class ComparatorMPlayerInactivity extends ComparatorAbstract<MPlayer> implements Named {
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity();
|
||||
|
||||
public static ComparatorMPlayerInactivity get() {
|
||||
return i;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Time";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareInner(MPlayer m1, MPlayer m2) {
|
||||
// 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,39 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorAbstract;
|
||||
|
||||
public class ComparatorMPlayerPower extends ComparatorAbstract<MPlayer> implements Named {
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerPower i = new ComparatorMPlayerPower();
|
||||
|
||||
public static ComparatorMPlayerPower get() {
|
||||
return i;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Power";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareInner(MPlayer m1, MPlayer m2) {
|
||||
// Power
|
||||
int ret = m1.getPowerRounded() - m2.getPowerRounded();
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// MaxPower
|
||||
return m1.getPowerMaxRounded() - m2.getPowerMaxRounded();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorAbstract;
|
||||
|
||||
public class ComparatorMPlayerRole extends ComparatorAbstract<MPlayer> implements Named {
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ComparatorMPlayerRole i = new ComparatorMPlayerRole();
|
||||
|
||||
public static ComparatorMPlayerRole get() {
|
||||
return i;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Rank";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareInner(MPlayer m1, MPlayer m2) {
|
||||
// Rank
|
||||
if (m1.getFaction() != m2.getFaction()) {
|
||||
throw new IllegalArgumentException("Noncomparable players");
|
||||
}
|
||||
Rank r1 = m1.getRank();
|
||||
Rank r2 = m2.getRank();
|
||||
return r2.getPriority() - r1.getPriority();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user