2011-10-12 17:25:01 +02:00
|
|
|
package com.massivecraft.factions.util;
|
|
|
|
|
2011-10-21 20:08:54 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
2011-10-12 17:25:01 +02:00
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.iface.RelationParticipator;
|
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2015-01-27 16:46:56 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2011-10-12 17:25:01 +02:00
|
|
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
2014-04-04 20:55:21 +02:00
|
|
|
import org.bukkit.ChatColor;
|
2011-10-12 17:25:01 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public class RelationUtil {
|
2014-08-05 17:17:27 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) {
|
|
|
|
String ret = "";
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction == null) {
|
2014-07-01 21:49:42 +02:00
|
|
|
return "ERROR"; // ERROR
|
|
|
|
}
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
Faction myFaction = getFaction(me);
|
2012-01-18 13:01:29 +01:00
|
|
|
// if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag
|
2011-10-12 18:48:47 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
if (that instanceof Faction) {
|
|
|
|
if (me instanceof FPlayer && myFaction == thatFaction) {
|
2015-01-27 16:46:56 +01:00
|
|
|
ret = TL.GENERIC_YOURFACTION.toString();
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
ret = thatFaction.getTag();
|
|
|
|
}
|
2014-07-01 21:52:40 +02:00
|
|
|
} else if (that instanceof FPlayer) {
|
2014-07-01 22:10:18 +02:00
|
|
|
FPlayer fplayerthat = (FPlayer) that;
|
|
|
|
if (that == me) {
|
2015-01-27 16:46:56 +01:00
|
|
|
ret = TL.GENERIC_YOU.toString();
|
2014-07-01 21:52:40 +02:00
|
|
|
} else if (thatFaction == myFaction) {
|
2014-04-04 20:55:21 +02:00
|
|
|
ret = fplayerthat.getNameAndTitle();
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
ret = fplayerthat.getNameAndTag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ucfirst) {
|
|
|
|
ret = TextUtil.upperCaseFirst(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "" + getColorOfThatToMe(that, me) + ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String describeThatToMe(RelationParticipator that, RelationParticipator me) {
|
|
|
|
return describeThatToMe(that, me, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that) {
|
|
|
|
return getRelationTo(that, me, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
|
2014-07-01 22:10:18 +02:00
|
|
|
Faction fthat = getFaction(that);
|
|
|
|
if (fthat == null) {
|
2014-07-01 21:49:42 +02:00
|
|
|
return Relation.NEUTRAL; // ERROR
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
Faction fme = getFaction(me);
|
|
|
|
if (fme == null) {
|
2014-07-01 21:49:42 +02:00
|
|
|
return Relation.NEUTRAL; // ERROR
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
if (!fthat.isNormal() || !fme.isNormal()) {
|
|
|
|
return Relation.NEUTRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fthat.equals(fme)) {
|
|
|
|
return Relation.MEMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ignorePeaceful && (fme.isPeaceful() || fthat.isPeaceful())) {
|
|
|
|
return Relation.NEUTRAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fme.getRelationWish(fthat).value >= fthat.getRelationWish(fme).value) {
|
|
|
|
return fthat.getRelationWish(fme);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fme.getRelationWish(fthat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Faction getFaction(RelationParticipator rp) {
|
|
|
|
if (rp instanceof Faction) {
|
|
|
|
return (Faction) rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rp instanceof FPlayer) {
|
|
|
|
return ((FPlayer) rp).getFaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ERROR
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
|
2014-07-01 22:10:18 +02:00
|
|
|
Faction thatFaction = getFaction(that);
|
|
|
|
if (thatFaction != null) {
|
2014-04-04 20:55:21 +02:00
|
|
|
if (thatFaction.isPeaceful() && thatFaction != getFaction(me)) {
|
|
|
|
return Conf.colorPeaceful;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thatFaction.isSafeZone() && thatFaction != getFaction(me)) {
|
|
|
|
return Conf.colorPeaceful;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thatFaction.isWarZone() && thatFaction != getFaction(me)) {
|
|
|
|
return Conf.colorWar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return getRelationTo(that, me).getColor();
|
|
|
|
}
|
2011-10-12 17:25:01 +02:00
|
|
|
}
|