2011-10-12 17:25:01 +02:00
|
|
|
package com.massivecraft.factions.util;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.iface.RelationParticipator;
|
|
|
|
import com.massivecraft.factions.struct.Relation;
|
|
|
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
|
|
|
|
|
|
|
public class RelationUtil
|
|
|
|
{
|
|
|
|
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
|
|
|
|
{
|
|
|
|
String ret = "";
|
2011-10-12 18:48:47 +02:00
|
|
|
|
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction == null) return "ERROR"; // ERROR
|
|
|
|
|
|
|
|
Faction myFaction = getFaction(me);
|
|
|
|
if (myFaction == null) return "ERROR"; // ERROR
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (that instanceof Faction)
|
|
|
|
{
|
2011-10-12 18:48:47 +02:00
|
|
|
if (me instanceof FPlayer && myFaction == thatFaction)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
ret = "your faction";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-12 18:48:47 +02:00
|
|
|
ret = "the faction " + thatFaction.getTag();
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
else if (that instanceof FPlayer)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
2011-10-12 18:48:47 +02:00
|
|
|
FPlayer fplayerthat = (FPlayer) 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
|
|
|
{
|
|
|
|
ret = fplayerthat.getNameAndTitle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = fplayerthat.getNameAndTag();
|
|
|
|
}
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (ucfirst)
|
|
|
|
{
|
|
|
|
ret = TextUtil.upperCaseFirst(ret);
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
|
|
|
return "" + getRelationColor(me, that) + 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-13 22:49:41 +02:00
|
|
|
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return getRelationTo(that, me, false);
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-13 22:49:41 +02:00
|
|
|
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
Faction fthat = getFaction(that);
|
|
|
|
if (fthat == null) return Relation.NEUTRAL; // ERROR
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
Faction fme = getFaction(me);
|
|
|
|
if (fme == null) return Relation.NEUTRAL; // ERROR
|
2011-10-12 18:48:47 +02:00
|
|
|
|
|
|
|
if (!fthat.isNormal() || !fme.isNormal())
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return Relation.NEUTRAL;
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (fthat.equals(fme))
|
|
|
|
{
|
|
|
|
return Relation.MEMBER;
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
|
|
|
if (!ignorePeaceful && (fme.isPeaceful() || fthat.isPeaceful()))
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return Relation.NEUTRAL;
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
|
|
|
if (fme.getRelationWish(fthat).value >= fthat.getRelationWish(fme).value)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return fthat.getRelationWish(fme);
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
return fme.getRelationWish(fthat);
|
|
|
|
}
|
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
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
if (rp instanceof FPlayer)
|
|
|
|
{
|
2011-10-12 18:48:47 +02:00
|
|
|
return ((FPlayer) 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
|
|
|
|
|
|
|
public static ChatColor getRelationColor(RelationParticipator me,
|
|
|
|
RelationParticipator that)
|
2011-10-12 17:25:01 +02:00
|
|
|
{
|
|
|
|
return getRelationTo(that, me).getColor();
|
|
|
|
}
|
|
|
|
}
|