2011-10-12 17:25:01 +02:00
|
|
|
package com.massivecraft.factions.util;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.RelationParticipator;
|
2014-10-02 11:45:06 +02:00
|
|
|
import com.massivecraft.factions.entity.MFlag;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2013-04-22 09:41:48 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2014-06-04 14:02:23 +02:00
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
2011-10-12 17:25:01 +02:00
|
|
|
|
|
|
|
public class RelationUtil
|
|
|
|
{
|
|
|
|
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
|
|
|
|
{
|
|
|
|
String ret = "";
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-23 20:50:49 +02:00
|
|
|
if (that == null)
|
|
|
|
{
|
|
|
|
return "A server admin";
|
|
|
|
}
|
|
|
|
|
2011-10-12 18:48:47 +02:00
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction == null) return "ERROR"; // ERROR
|
|
|
|
|
|
|
|
Faction myFaction = getFaction(me);
|
2012-01-18 13:01:50 +01:00
|
|
|
// if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic name or tag
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (that instanceof Faction)
|
|
|
|
{
|
2014-09-18 13:41:20 +02:00
|
|
|
if (thatFaction.isNone())
|
|
|
|
{
|
|
|
|
ret = thatFaction.getName();
|
|
|
|
}
|
2014-09-17 13:17:33 +02:00
|
|
|
if (me instanceof MPlayer && myFaction == thatFaction)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
ret = "your faction";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-24 19:01:17 +02:00
|
|
|
ret = thatFaction.getName();
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-17 13:17:33 +02:00
|
|
|
else if (that instanceof MPlayer)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
MPlayer mplayerthat = (MPlayer) that;
|
2011-10-12 17:25:01 +02:00
|
|
|
if (that == me)
|
|
|
|
{
|
|
|
|
ret = "you";
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
else if (thatFaction == myFaction)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
ret = mplayerthat.getNameAndTitle(myFaction);
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
ret = mplayerthat.getNameAndFactionName();
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (ucfirst)
|
|
|
|
{
|
2013-04-10 10:45:47 +02:00
|
|
|
ret = Txt.upperCaseFirst(ret);
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-21 20:08:54 +02:00
|
|
|
return "" + getColorOfThatToMe(that, me) + ret;
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-13 22:49:41 +02:00
|
|
|
public static String describeThatToMe(RelationParticipator that, RelationParticipator me)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return describeThatToMe(that, me, false);
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-24 11:07:06 +02:00
|
|
|
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 13:02:48 +02:00
|
|
|
return getRelationOfThatToMe(that, me, false);
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-24 11:07:06 +02:00
|
|
|
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
Rel ret = null;
|
|
|
|
|
2011-10-24 13:02:48 +02:00
|
|
|
Faction myFaction = getFaction(me);
|
|
|
|
if (myFaction == null) return Rel.NEUTRAL; // ERROR
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-24 13:02:48 +02:00
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction == null) return Rel.NEUTRAL; // ERROR
|
2011-10-24 11:07:06 +02:00
|
|
|
|
|
|
|
// The faction with the lowest wish "wins"
|
2011-10-24 13:02:48 +02:00
|
|
|
if (thatFaction.getRelationWish(myFaction).isLessThan(myFaction.getRelationWish(thatFaction)))
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 13:02:48 +02:00
|
|
|
ret = thatFaction.getRelationWish(myFaction);
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-24 11:07:06 +02:00
|
|
|
else
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 13:02:48 +02:00
|
|
|
ret = myFaction.getRelationWish(thatFaction);
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-24 13:02:48 +02:00
|
|
|
if (myFaction.equals(thatFaction))
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
ret = Rel.MEMBER;
|
|
|
|
// Do officer and leader check
|
2011-10-24 13:02:48 +02:00
|
|
|
//P.p.log("getRelationOfThatToMe the factions are the same for "+that.getClass().getSimpleName()+" and observer "+me.getClass().getSimpleName());
|
2014-09-17 13:17:33 +02:00
|
|
|
if (that instanceof MPlayer)
|
2011-10-24 11:07:06 +02:00
|
|
|
{
|
2014-09-17 13:17:33 +02:00
|
|
|
ret = ((MPlayer)that).getRole();
|
2011-10-24 13:02:48 +02:00
|
|
|
//P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
|
2011-10-24 11:07:06 +02:00
|
|
|
}
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2014-10-02 11:45:06 +02:00
|
|
|
else if (!ignorePeaceful && (thatFaction.getFlag(MFlag.getPeaceful()) || myFaction.getFlag(MFlag.getPeaceful())))
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 11:07:06 +02:00
|
|
|
ret = Rel.TRUCE;
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-24 11:07:06 +02:00
|
|
|
return ret;
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
public static Faction getFaction(RelationParticipator rp)
|
|
|
|
{
|
|
|
|
if (rp instanceof Faction)
|
|
|
|
{
|
2011-10-12 18:48:47 +02:00
|
|
|
return (Faction) rp;
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
if (rp instanceof MPlayer)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2014-09-17 13:17:33 +02:00
|
|
|
return ((MPlayer) rp).getFaction();
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
// ERROR
|
|
|
|
return null;
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-21 20:08:54 +02:00
|
|
|
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-24 09:28:08 +02:00
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction != null && thatFaction != getFaction(me))
|
2011-10-21 20:08:54 +02:00
|
|
|
{
|
2014-10-02 11:45:06 +02:00
|
|
|
if (thatFaction.getFlag(MFlag.getFriendlyire()) == true)
|
2011-10-22 17:03:49 +02:00
|
|
|
{
|
2013-04-22 09:41:48 +02:00
|
|
|
return MConf.get().colorFriendlyFire;
|
2011-10-22 17:03:49 +02:00
|
|
|
}
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
if (thatFaction.getFlag(MFlag.getPvp()) == false)
|
2011-10-22 17:03:49 +02:00
|
|
|
{
|
2013-04-22 09:41:48 +02:00
|
|
|
return MConf.get().colorNoPVP;
|
2011-10-22 17:03:49 +02:00
|
|
|
}
|
2011-10-24 09:28:08 +02:00
|
|
|
}
|
2011-10-24 11:07:06 +02:00
|
|
|
return getRelationOfThatToMe(that, me).getColor();
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
|
|
|
}
|