Rename and relocate Comparators and Predicates

This commit is contained in:
Olof Larsson 2017-03-24 14:25:29 +01:00
parent 2dfce5ea3a
commit 83b12fddc8
11 changed files with 46 additions and 44 deletions

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionListComparator; import com.massivecraft.factions.comparator.ComparatorFactionList;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
@ -71,7 +71,7 @@ public class CmdFactionsList extends FactionsCommand
public void run() public void run()
{ {
// Pager Items // Pager Items
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get(sender)); final List<Faction> factions = FactionColl.get().getAll(ComparatorFactionList.get(sender));
pager.setItems(factions); pager.setItems(factions);
// Pager Message // Pager Message

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.PlayerInactivityComparator; import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity;
import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeSortMPlayer; import com.massivecraft.factions.cmd.type.TypeSortMPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
@ -43,7 +43,7 @@ public class CmdFactionsStatus extends FactionsCommand
// Args // Args
int page = this.readArg(); int page = this.readArg();
Faction faction = this.readArg(msenderFaction); Faction faction = this.readArg(msenderFaction);
Comparator<MPlayer> sortedBy = this.readArg(PlayerInactivityComparator.get()); Comparator<MPlayer> sortedBy = this.readArg(ComparatorMPlayerInactivity.get());
// MPerm // MPerm
if ( ! MPerm.getPermStatus().has(msender, faction, true)) return; if ( ! MPerm.getPermStatus().has(msender, faction, true)) return;

View File

@ -1,8 +1,8 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.PlayerInactivityComparator; import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity;
import com.massivecraft.factions.PlayerPowerComparator; import com.massivecraft.factions.comparator.ComparatorMPlayerPower;
import com.massivecraft.factions.PlayerRoleComparator; import com.massivecraft.factions.comparator.ComparatorMPlayerRole;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.command.type.TypeAbstractChoice; import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
@ -20,9 +20,9 @@ public class TypeSortMPlayer extends TypeAbstractChoice<Comparator<MPlayer>>
{ {
super(Comparator.class); super(Comparator.class);
this.setAll( this.setAll(
PlayerRoleComparator.get(), ComparatorMPlayerRole.get(),
PlayerPowerComparator.get(), ComparatorMPlayerPower.get(),
PlayerInactivityComparator.get() ComparatorMPlayerInactivity.get()
); );
} }

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.comparator.ComparatorComparable; import com.massivecraft.massivecore.comparator.ComparatorComparable;
@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Comparator; import java.util.Comparator;
public class FactionListComparator implements Comparator<Faction> public class ComparatorFactionList implements Comparator<Faction>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -21,8 +21,8 @@ public class FactionListComparator implements Comparator<Faction>
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static FactionListComparator get(Object watcherObject) { return new FactionListComparator(watcherObject); } public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); }
public FactionListComparator(Object watcherObject) public ComparatorFactionList(Object watcherObject)
{ {
this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject));
} }

View File

@ -1,18 +1,18 @@
package com.massivecraft.factions; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import java.util.Comparator; import java.util.Comparator;
public class PlayerInactivityComparator implements Comparator<MPlayer>, Named public class ComparatorMPlayerInactivity implements Comparator<MPlayer>, Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static PlayerInactivityComparator i = new PlayerInactivityComparator(); private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity();
public static PlayerInactivityComparator get() { return i; } public static ComparatorMPlayerInactivity get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: NAMED // OVERRIDE: NAMED

View File

@ -1,18 +1,18 @@
package com.massivecraft.factions; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import java.util.Comparator; import java.util.Comparator;
public class PlayerPowerComparator implements Comparator<MPlayer>, Named public class ComparatorMPlayerPower implements Comparator<MPlayer>, Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static PlayerPowerComparator i = new PlayerPowerComparator(); private static ComparatorMPlayerPower i = new ComparatorMPlayerPower();
public static PlayerPowerComparator get() { return i; } public static ComparatorMPlayerPower get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: NAMED // OVERRIDE: NAMED

View File

@ -1,18 +1,19 @@
package com.massivecraft.factions; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import java.util.Comparator; import java.util.Comparator;
public class PlayerRoleComparator implements Comparator<MPlayer>, Named public class ComparatorMPlayerRole implements Comparator<MPlayer>, Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static PlayerRoleComparator i = new PlayerRoleComparator(); private static ComparatorMPlayerRole i = new ComparatorMPlayerRole();
public static PlayerRoleComparator get() { return i; } public static ComparatorMPlayerRole get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: NAMED // OVERRIDE: NAMED

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.engine; package com.massivecraft.factions.engine;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.PlayerRoleComparator; import com.massivecraft.factions.comparator.ComparatorMPlayerRole;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
@ -143,7 +143,7 @@ public class EngineShow extends Engine
List<String> followerNamesOffline = new ArrayList<>(); List<String> followerNamesOffline = new ArrayList<>();
List<MPlayer> followers = faction.getMPlayers(); List<MPlayer> followers = faction.getMPlayers();
Collections.sort(followers, PlayerRoleComparator.get()); Collections.sort(followers, ComparatorMPlayerRole.get());
for (MPlayer follower : followers) for (MPlayer follower : followers)
{ {
if (follower.isOnline(sender)) if (follower.isOnline(sender))

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.factions.FactionEqualsPredicate; import com.massivecraft.factions.predicate.PredicateCommandSenderFaction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsParticipator; import com.massivecraft.factions.FactionsParticipator;
import com.massivecraft.factions.Lang; import com.massivecraft.factions.Lang;
import com.massivecraft.factions.PredicateRole; import com.massivecraft.factions.predicate.PredicateMPlayerRole;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
@ -1070,7 +1070,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
public List<MPlayer> getMPlayersWhereRole(Rel role) public List<MPlayer> getMPlayersWhereRole(Rel role)
{ {
return this.getMPlayersWhere(PredicateRole.get(role)); return this.getMPlayersWhere(PredicateMPlayerRole.get(role));
} }
public MPlayer getLeader() public MPlayer getLeader()
@ -1221,34 +1221,34 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
public boolean sendMessage(Object message) public boolean sendMessage(Object message)
{ {
return MixinMessage.get().messagePredicate(new FactionEqualsPredicate(this), message); return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), message);
} }
public boolean sendMessage(Object... messages) public boolean sendMessage(Object... messages)
{ {
return MixinMessage.get().messagePredicate(new FactionEqualsPredicate(this), messages); return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages);
} }
public boolean sendMessage(Collection<Object> messages) public boolean sendMessage(Collection<Object> messages)
{ {
return MixinMessage.get().messagePredicate(new FactionEqualsPredicate(this), messages); return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages);
} }
// CONVENIENCE MSG // CONVENIENCE MSG
public boolean msg(String msg) public boolean msg(String msg)
{ {
return MixinMessage.get().msgPredicate(new FactionEqualsPredicate(this), msg); return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg);
} }
public boolean msg(String msg, Object... args) public boolean msg(String msg, Object... args)
{ {
return MixinMessage.get().msgPredicate(new FactionEqualsPredicate(this), msg, args); return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg, args);
} }
public boolean msg(Collection<String> msgs) public boolean msg(Collection<String> msgs)
{ {
return MixinMessage.get().msgPredicate(new FactionEqualsPredicate(this), msgs); return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msgs);
} }
} }

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions; package com.massivecraft.factions.predicate;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
import java.io.Serializable; import java.io.Serializable;
public class FactionEqualsPredicate implements Predicate<CommandSender>, Serializable public class PredicateCommandSenderFaction implements Predicate<CommandSender>, Serializable
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -23,7 +23,7 @@ public class FactionEqualsPredicate implements Predicate<CommandSender>, Seriali
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FactionEqualsPredicate(Faction faction) public PredicateCommandSenderFaction(Faction faction)
{ {
this.factionId = faction.getId(); this.factionId = faction.getId();
} }

View File

@ -1,9 +1,10 @@
package com.massivecraft.factions; package com.massivecraft.factions.predicate;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.predicate.Predicate;
public class PredicateRole implements Predicate<MPlayer> public class PredicateMPlayerRole implements Predicate<MPlayer>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -16,8 +17,8 @@ public class PredicateRole implements Predicate<MPlayer>
// INSTANCE AND CONTRUCT // INSTANCE AND CONTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static PredicateRole get(Rel role) { return new PredicateRole(role); } public static PredicateMPlayerRole get(Rel role) { return new PredicateMPlayerRole(role); }
public PredicateRole(Rel role) public PredicateMPlayerRole(Rel role)
{ {
this.role = role; this.role = role;
} }