Clean up RelationUtil

This commit is contained in:
TheComputerGeek2 2017-03-08 10:43:39 -08:00
parent 52023a31ff
commit 7076ffbc5d

View File

@ -12,34 +12,46 @@ import com.massivecraft.massivecore.util.Txt;
public class RelationUtil public class RelationUtil
{ {
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
private static final String UNKNOWN_RELATION_OTHER = "A server admin";
private static final String UNDEFINED_FACTION_OTHER = "ERROR";
private static final String OWN_FACTION = "your faction";
private static final String SELF = "you";
// -------------------------------------------- //
// DESCRIBE
// -------------------------------------------- //
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
{ {
String ret = ""; String ret = "";
if (that == null) if (that == null) return UNKNOWN_RELATION_OTHER;
{
return "A server admin";
}
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction == null) return "ERROR"; // ERROR if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
// if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic name or tag
boolean isSameFaction = thatFaction == myFaction;
if (that instanceof Faction) if (that instanceof Faction)
{ {
String thatFactionName = thatFaction.getName();
if (thatFaction.isNone()) if (thatFaction.isNone())
{ {
ret = thatFaction.getName(); ret = thatFactionName;
} }
else if (me instanceof MPlayer && myFaction == thatFaction) else if (me instanceof MPlayer && isSameFaction)
{ {
ret = "your faction"; ret = OWN_FACTION;
} }
else else
{ {
ret = thatFaction.getName(); ret = thatFactionName;
} }
} }
else if (that instanceof MPlayer) else if (that instanceof MPlayer)
@ -47,9 +59,9 @@ public class RelationUtil
MPlayer mplayerthat = (MPlayer) that; MPlayer mplayerthat = (MPlayer) that;
if (that == me) if (that == me)
{ {
ret = "you"; ret = SELF;
} }
else if (thatFaction == myFaction) else if (isSameFaction)
{ {
ret = mplayerthat.getNameAndTitle(myFaction); ret = mplayerthat.getNameAndTitle(myFaction);
} }
@ -59,12 +71,9 @@ public class RelationUtil
} }
} }
if (ucfirst) if (ucfirst) ret = Txt.upperCaseFirst(ret);
{
ret = Txt.upperCaseFirst(ret);
}
return "" + getColorOfThatToMe(that, me) + ret; return getColorOfThatToMe(that, me).toString() + ret;
} }
public static String describeThatToMe(RelationParticipator that, RelationParticipator me) public static String describeThatToMe(RelationParticipator that, RelationParticipator me)
@ -72,6 +81,10 @@ public class RelationUtil
return describeThatToMe(that, me, false); return describeThatToMe(that, me, false);
} }
// -------------------------------------------- //
// RELATION
// -------------------------------------------- //
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
{ {
return getRelationOfThatToMe(that, me, false); return getRelationOfThatToMe(that, me, false);
@ -79,74 +92,55 @@ public class RelationUtil
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
{ {
Rel ret = null;
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
if (myFaction == null) return Rel.NEUTRAL; // ERROR if (myFaction == null) return Rel.NEUTRAL; // ERROR
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction == null) return Rel.NEUTRAL; // ERROR if (thatFaction == null) return Rel.NEUTRAL; // ERROR
// The faction with the lowest wish "wins"
if (thatFaction.getRelationWish(myFaction).isLessThan(myFaction.getRelationWish(thatFaction)))
{
ret = thatFaction.getRelationWish(myFaction);
}
else
{
ret = myFaction.getRelationWish(thatFaction);
}
if (myFaction.equals(thatFaction)) if (myFaction.equals(thatFaction))
{ {
ret = Rel.MEMBER; if (that instanceof MPlayer) return ((MPlayer) that).getRole();
// Do officer and leader check return Rel.MEMBER;
//P.p.log("getRelationOfThatToMe the factions are the same for "+that.getClass().getSimpleName()+" and observer "+me.getClass().getSimpleName());
if (that instanceof MPlayer)
{
ret = ((MPlayer)that).getRole();
//P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
}
}
else if (!ignorePeaceful && (thatFaction.getFlag(MFlag.getFlagPeaceful()) || myFaction.getFlag(MFlag.getFlagPeaceful())))
{
ret = Rel.TRUCE;
} }
return ret; MFlag flagPeaceful = MFlag.getFlagPeaceful();
if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE;
// The faction with the lowest wish "wins"
Rel theirWish = thatFaction.getRelationWish(myFaction);
Rel myWish = myFaction.getRelationWish(thatFaction);
return theirWish.isLessThan(myWish) ? theirWish : myWish;
} }
// -------------------------------------------- //
// FACTION
// -------------------------------------------- //
public static Faction getFaction(RelationParticipator rp) public static Faction getFaction(RelationParticipator rp)
{ {
if (rp instanceof Faction) if (rp instanceof Faction) return (Faction) rp;
{
return (Faction) rp;
}
if (rp instanceof MPlayer) if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction();
{
return ((MPlayer) rp).getFaction();
}
// ERROR // ERROR
return null; return null;
} }
// -------------------------------------------- //
// COLOR
// -------------------------------------------- //
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
{ {
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction != null && thatFaction != getFaction(me)) if (thatFaction != null && thatFaction != getFaction(me))
{ {
if (thatFaction.getFlag(MFlag.getFlagFriendlyire()) == true) if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire;
{
return MConf.get().colorFriendlyFire;
}
if (thatFaction.getFlag(MFlag.getFlagPvp()) == false) if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP;
{
return MConf.get().colorNoPVP;
}
} }
return getRelationOfThatToMe(that, me).getColor(); return getRelationOfThatToMe(that, me).getColor();
} }
} }