Factions/src/com/massivecraft/factions/util/RelationUtil.java
Brettflan bc40f3b751 Server admins can now promote or demote any member of any faction to/from faction leader or officer using the existing /f leader and /f officer commands, with two new permissions added to allow that. A third permission is also added to allow server admins or moderators to join any faction without the need of /f bypass mode.
Also, a couple more minor bugfixes are included for /f home payment giving the wrong message, player/faction descriptions being wrong for console messages, and potential NPE in new faction leader promotion routine if faction was permanent with no current leader.

New permissions:
factions.leader.any - allows use of /f leader on any player in any faction
factions officer.any - allows use of /f officer on any player in any faction
factions.join.any - allows player to join any faction, bypassing invitation process for closed factions (the same as players with /f bypass enabled can do)
2012-01-18 06:01:50 -06:00

149 lines
3.6 KiB
Java

package com.massivecraft.factions.util;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.zcore.util.TextUtil;
public class RelationUtil
{
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
{
String ret = "";
if (that == null)
{
return "A server admin";
}
Faction thatFaction = getFaction(that);
if (thatFaction == null) return "ERROR"; // ERROR
Faction myFaction = getFaction(me);
// if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic name or tag
if (that instanceof Faction)
{
if (me instanceof FPlayer && myFaction == thatFaction)
{
ret = "your faction";
}
else
{
ret = thatFaction.getTag();
}
}
else if (that instanceof FPlayer)
{
FPlayer fplayerthat = (FPlayer) that;
if (that == me)
{
ret = "you";
}
else if (thatFaction == myFaction)
{
ret = fplayerthat.getNameAndTitle();
}
else
{
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 Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
{
return getRelationOfThatToMe(that, me, false);
}
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
{
Rel ret = null;
Faction myFaction = getFaction(me);
if (myFaction == null) return Rel.NEUTRAL; // ERROR
Faction thatFaction = getFaction(that);
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))
{
ret = Rel.MEMBER;
// Do officer and leader check
//P.p.log("getRelationOfThatToMe the factions are the same for "+that.getClass().getSimpleName()+" and observer "+me.getClass().getSimpleName());
if (that instanceof FPlayer)
{
ret = ((FPlayer)that).getRole();
//P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
}
}
else if (!ignorePeaceful && (thatFaction.getFlag(FFlag.PEACEFUL) || myFaction.getFlag(FFlag.PEACEFUL)))
{
ret = Rel.TRUCE;
}
return ret;
}
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)
{
Faction thatFaction = getFaction(that);
if (thatFaction != null && thatFaction != getFaction(me))
{
if (thatFaction.getFlag(FFlag.FRIENDLYFIRE) == true)
{
return Conf.colorFriendlyFire;
}
if (thatFaction.getFlag(FFlag.PVP) == false)
{
return Conf.colorNoPVP;
}
}
return getRelationOfThatToMe(that, me).getColor();
}
}