Some refactoring and better messages

This commit is contained in:
Olof Larsson 2011-10-24 11:07:06 +02:00
parent bb5a676430
commit 0c46809952
13 changed files with 111 additions and 131 deletions

View File

@ -171,10 +171,9 @@ public class Board
int width = halfWidth * 2 + 1;
int height = halfHeight * 2 + 1;
/*if (Conf.showMapFactionKey)
{
height--;
}*/
//Make room for the list of tags
height--;
Map<Faction, Character> fList = new HashMap<Faction, Character>();
int chrIdx = 0;
@ -194,33 +193,17 @@ public class Board
FLocation flocationHere = topLeft.getRelative(dx, dz);
Faction factionHere = getFactionAt(flocationHere);
//Rel relation = faction.getRelationTo(factionHere);
if (factionHere.isNone())
{
row += ChatColor.GRAY+"-";
}
else /*if
(
factionHere == faction
||
factionHere == factionLoc
||
relation.isAtLeast(Rel.ALLY)
||
(Conf.showNeutralFactionsOnMap && relation.equals(Rel.NEUTRAL))
||
(Conf.showEnemyFactionsOnMap && relation.equals(Rel.ENEMY))
)*/
else
{
if (!fList.containsKey(factionHere.getTag()))
if (!fList.containsKey(factionHere))
fList.put(factionHere, Conf.mapKeyChrs[chrIdx++]);
char tag = fList.get(factionHere);
row += factionHere.getColorTo(observer) + "" + tag;
char fchar = fList.get(factionHere);
row += factionHere.getColorTo(observer) + "" + fchar;
}
/*else
{
row += ChatColor.GRAY+"-";
}*/
}
ret.add(row);
}
@ -232,19 +215,14 @@ public class Board
ret.set(1, asciiCompass.get(0)+ret.get(1).substring(3*3));
ret.set(2, asciiCompass.get(1)+ret.get(2).substring(3*3));
ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3));
// Add the faction key
// TODO: relation color for them
//if (Conf.showMapFactionKey)
//{
String fRow = "";
for(Faction keyfaction : fList.keySet())
{
fRow += String.format("%s%s: %s ", keyfaction.getColorTo(observer), fList.get(keyfaction), keyfaction.getTag());
fRow += ""+keyfaction.getColorTo(observer) + fList.get(keyfaction) + ": " + keyfaction.getTag() + " ";
}
fRow = fRow.trim();
ret.add(fRow);
//}
return ret;
}

View File

@ -100,7 +100,8 @@ public class Conf
public static double homesTeleportAllowedEnemyDistance = 32.0;
public static boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
public static boolean disablePVPBetweenNeutralFactions = false;
public static Rel friendlyFireFromRel = Rel.TRUCE;
public static boolean disablePVPForFactionlessPlayers = false;
public static boolean enablePVPAgainstFactionlessInAttackersLand = false;
@ -165,7 +166,6 @@ public class Conf
public static double econClaimAdditionalMultiplier = 0.5;
public static double econClaimRefundMultiplier = 0.7;
public static double econCostCreate = 100.0;
public static double econCostOwner = 15.0;
public static double econCostSethome = 30.0;
public static double econCostJoin = 0.0;
public static double econCostLeave = 0.0;
@ -181,9 +181,9 @@ public class Conf
public static double econCostShow = 0.0;
public static double econCostOpen = 0.0;
public static double econCostAlly = 0.0;
public static double econCostEnemy = 0.0;
public static double econCostTruce = 0.0;
public static double econCostNeutral = 0.0;
public static double econCostNoBoom = 0.0;
public static double econCostEnemy = 0.0;
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them
public static boolean bankEnabled = true;

View File

@ -268,27 +268,27 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
// -------------------------------
@Override
public String describeTo(RelationParticipator that, boolean ucfirst)
public String describeTo(RelationParticipator observer, boolean ucfirst)
{
return RelationUtil.describeThatToMe(this, that, ucfirst);
return RelationUtil.describeThatToMe(this, observer, ucfirst);
}
@Override
public String describeTo(RelationParticipator that)
public String describeTo(RelationParticipator observer)
{
return RelationUtil.describeThatToMe(this, that);
return RelationUtil.describeThatToMe(this, observer);
}
@Override
public Rel getRelationTo(RelationParticipator rp)
public Rel getRelationTo(RelationParticipator observer)
{
return RelationUtil.getRelationTo(this, rp);
return RelationUtil.getRelationOfThatToMe(this, observer);
}
@Override
public Rel getRelationTo(RelationParticipator rp, boolean ignorePeaceful)
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
{
return RelationUtil.getRelationTo(this, rp, ignorePeaceful);
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
}
public Rel getRelationToLocation()
@ -297,9 +297,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
}
@Override
public ChatColor getColorTo(RelationParticipator rp)
public ChatColor getColorTo(RelationParticipator observer)
{
return RelationUtil.getColorOfThatToMe(this, rp);
return RelationUtil.getColorOfThatToMe(this, observer);
}
//----------------------------------------------//

View File

@ -186,33 +186,33 @@ public class Faction extends Entity implements EconomyParticipator
// -------------------------------
@Override
public String describeTo(RelationParticipator that, boolean ucfirst)
public String describeTo(RelationParticipator observer, boolean ucfirst)
{
return RelationUtil.describeThatToMe(this, that, ucfirst);
return RelationUtil.describeThatToMe(this, observer, ucfirst);
}
@Override
public String describeTo(RelationParticipator that)
public String describeTo(RelationParticipator observer)
{
return RelationUtil.describeThatToMe(this, that);
return RelationUtil.describeThatToMe(this, observer);
}
@Override
public Rel getRelationTo(RelationParticipator rp)
public Rel getRelationTo(RelationParticipator observer)
{
return RelationUtil.getRelationTo(this, rp);
return RelationUtil.getRelationOfThatToMe(this, observer);
}
@Override
public Rel getRelationTo(RelationParticipator rp, boolean ignorePeaceful)
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
{
return RelationUtil.getRelationTo(this, rp, ignorePeaceful);
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
}
@Override
public ChatColor getColorTo(RelationParticipator rp)
public ChatColor getColorTo(RelationParticipator observer)
{
return RelationUtil.getColorOfThatToMe(this, rp);
return RelationUtil.getColorOfThatToMe(this, observer);
}
public Rel getRelationWish(Faction otherFaction)

View File

@ -52,7 +52,7 @@ public class CmdKick extends FCommand
return;
}
if (you.getRole().value >= fme.getRole().value)
if (you.getRole().isAtLeast(fme.getRole()))
{
// TODO add more informative messages.
msg("<b>Your rank is too low to kick this player.");

View File

@ -138,7 +138,7 @@ public abstract class FCommand extends MCommand<P>
{
if (me == null) return true;
if (fme.getRole().value < role.value)
if (fme.getRole().isLessThan(role))
{
msg("<b>You <h>must be "+role+"<b> to "+this.getHelpShort()+".");
return false;
@ -356,7 +356,7 @@ public abstract class FCommand extends MCommand<P>
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Rel.LEADER) )
if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) )
{
return true;
}

View File

@ -1,7 +1,5 @@
package com.massivecraft.factions.cmd;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.SpoutFeatures;
@ -51,26 +49,26 @@ public abstract class FRelationCommand extends FCommand
myFaction.setRelationWish(them, targetRelation);
Rel currentRelation = myFaction.getRelationTo(them, true);
ChatColor currentRelationColor = currentRelation.getColor();
if (targetRelation.value == currentRelation.value)
if (targetRelation == currentRelation)
{
them.msg("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+myFaction.getTag());
myFaction.msg("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+them.getTag());
them.msg("%s<i> is now %s.", myFaction.describeTo(them, true), targetRelation.getDescFactionOne());
myFaction.msg("%s<i> is now %s.", them.describeTo(myFaction, true), targetRelation.getDescFactionOne());
}
else
{
them.msg(currentRelationColor+myFaction.getTag()+"<i> wishes to be your "+targetRelation.getColor()+targetRelation.toString());
them.msg("%s<i> wishes to be %s.", myFaction.describeTo(them, true), targetRelation.getColor()+targetRelation.getDescFactionOne());
them.msg("<i>Type <c>/"+Conf.baseCommandAliases.get(0)+" "+targetRelation+" "+myFaction.getTag()+"<i> to accept.");
myFaction.msg(currentRelationColor+them.getTag()+"<i> were informed that you wish to be "+targetRelation.getColor()+targetRelation);
myFaction.msg("%s<i> were informed that you wish to be %s<i>.", them.describeTo(myFaction, true), targetRelation.getColor()+targetRelation.getDescFactionOne());
}
if ( targetRelation != Rel.NEUTRAL && them.getFlag(FFlag.PEACEFUL))
// TODO: The ally case should work!!
if ( targetRelation != Rel.TRUCE && them.getFlag(FFlag.PEACEFUL))
{
them.msg("<i>This will have no effect while your faction is peaceful.");
myFaction.msg("<i>This will have no effect while their faction is peaceful.");
}
if ( targetRelation != Rel.NEUTRAL && myFaction.getFlag(FFlag.PEACEFUL))
if ( targetRelation != Rel.TRUCE && myFaction.getFlag(FFlag.PEACEFUL))
{
them.msg("<i>This will have no effect while their faction is peaceful.");
myFaction.msg("<i>This will have no effect while your faction is peaceful.");

View File

@ -5,11 +5,11 @@ import com.massivecraft.factions.struct.Rel;
public interface RelationParticipator
{
public String describeTo(RelationParticipator that);
public String describeTo(RelationParticipator that, boolean ucfirst);
public String describeTo(RelationParticipator observer);
public String describeTo(RelationParticipator observer, boolean ucfirst);
public Rel getRelationTo(RelationParticipator that);
public Rel getRelationTo(RelationParticipator that, boolean ignorePeaceful);
public Rel getRelationTo(RelationParticipator observer);
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful);
public ChatColor getColorTo(RelationParticipator to);
public ChatColor getColorTo(RelationParticipator observer);
}

View File

@ -81,7 +81,7 @@ public class PluginCapiListener extends CapiListener
for (Player somePlayer : Bukkit.getServer().getOnlinePlayers())
{
FPlayer someFPlayer = FPlayers.i.get(somePlayer);
if (someFPlayer.getRelationTo(fme).value >= Rel.ALLY.value)
if (someFPlayer.getRelationTo(fme).isAtLeast(Rel.ALLY))
{
event.getThem().add(somePlayer);
}

View File

@ -115,10 +115,7 @@ public class FactionsEntityListener extends EntityListener
Entity damagee = sub.getEntity();
int damage = sub.getDamage();
if ( ! (damagee instanceof Player))
{
return true;
}
if ( ! (damagee instanceof Player)) return true;
FPlayer defender = FPlayers.i.get((Player)damagee);
@ -206,23 +203,10 @@ public class FactionsEntityListener extends EntityListener
Rel relation = defendFaction.getRelationTo(attackFaction);
// You can not hurt neutral factions
if (Conf.disablePVPBetweenNeutralFactions && relation == Rel.NEUTRAL)
// Check the relation
if (relation.isAtLeast(Conf.friendlyFireFromRel))
{
attacker.msg("<i>You can't hurt neutral factions. Declare them as an enemy.");
return false;
}
// Players without faction may be hurt anywhere
if (!defender.hasFaction())
{
return true;
}
// You can never hurt faction members or allies
if (relation == Rel.MEMBER || relation == Rel.ALLY)
{
attacker.msg("<i>You can't hurt %s<i>.", defender.describeTo(attacker));
attacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
return false;
}

View File

@ -79,7 +79,7 @@ public enum FPerm
List<String> rels = new ArrayList<String>();
for (Rel rel : value)
{
rels.add("<p>"+rel.nicename);
rels.add("<p>"+rel);
}
if (rels.size() > 0)
{

View File

@ -6,22 +6,35 @@ import com.massivecraft.factions.Conf;
public enum Rel
{
LEADER (70, "leader"),
OFFICER (60, "officer"),
MEMBER (50, "member"),
ALLY (40, "ally"),
TRUCE (30, "truce"),
NEUTRAL (20, "neutral"),
ENEMY (10, "enemy"),
LEADER (70, "your faction leader", "your faction leader", "", ""),
OFFICER (60, "an officer in your faction", "officers in your faction", "", ""),
MEMBER (50, "a member in your faction", "members in your faction", "your faction", "your factions"),
ALLY (40, "an ally", "allies", "an allied faction", "allied factions"),
TRUCE (30, "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce"),
NEUTRAL (20, "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions"),
ENEMY (10, "an enemy", "enemies", "an enemy faction", "enemy factions"),
;
public final int value;
public final String nicename;
private final int value;
private final String descPlayerOne;
public String getDescPlayerOne() { return this.descPlayerOne; }
private Rel(final int value, final String nicename)
private final String descPlayerMany;
public String getDescPlayerMany() { return this.descPlayerMany; }
private final String descFactionOne;
public String getDescFactionOne() { return this.descFactionOne; }
private final String descFactionMany;
public String getDescFactionMany() { return this.descFactionMany; }
private Rel(final int value, final String descPlayerOne, final String descPlayerMany, final String descFactionOne, final String descFactionMany)
{
this.value = value;
this.nicename = nicename;
this.descPlayerOne = descPlayerOne;
this.descPlayerMany = descPlayerMany;
this.descFactionOne = descFactionOne;
this.descFactionMany = descFactionMany;
}
public static Rel parse(String str)
@ -58,12 +71,6 @@ public enum Rel
return null;
}
@Override
public String toString()
{
return this.nicename;
}
public boolean isAtLeast(Rel rel)
{
return this.value >= rel.value;
@ -79,6 +86,11 @@ public enum Rel
return this.value < rel.value;
}
public boolean isMoreThan(Rel rel)
{
return this.value > rel.value;
}
public ChatColor getColor()
{
if (this == MEMBER)
@ -116,6 +128,8 @@ public enum Rel
return Conf.econCostEnemy;
else if (this == ALLY)
return Conf.econCostAlly;
else if (this == TRUCE)
return Conf.econCostTruce;
else
return Conf.econCostNeutral;
}

View File

@ -68,40 +68,46 @@ public class RelationUtil
return describeThatToMe(that, me, false);
}
public static Rel getRelationTo(RelationParticipator me, RelationParticipator that)
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
{
return getRelationTo(that, me, false);
return getRelationOfThatToMe(me, that, false);
}
public static Rel getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful)
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
{
Faction fthat = getFaction(that);
Rel ret = null;
Faction fthat = getFaction(me);
if (fthat == null) return Rel.NEUTRAL; // ERROR
Faction fme = getFaction(me);
Faction fme = getFaction(that);
if (fme == null) return Rel.NEUTRAL; // ERROR
if (!fthat.isNormal() || !fme.isNormal())
// The faction with the lowest wish "wins"
if (fme.getRelationWish(fthat).isLessThan(fthat.getRelationWish(fme)))
{
return Rel.NEUTRAL;
ret = fme.getRelationWish(fthat);
}
else
{
ret = fthat.getRelationWish(fme);
}
if (fthat.equals(fme))
{
return Rel.MEMBER;
ret = Rel.MEMBER;
// Do officer and leader check
if (that instanceof FPlayer)
{
ret = ((FPlayer)that).getRole();
}
}
if (!ignorePeaceful && (fme.getFlag(FFlag.PEACEFUL) || fthat.getFlag(FFlag.PEACEFUL)))
else if (!ignorePeaceful && (fme.getFlag(FFlag.PEACEFUL) || fthat.getFlag(FFlag.PEACEFUL)))
{
return Rel.TRUCE;
ret = Rel.TRUCE;
}
if (fme.getRelationWish(fthat).value >= fthat.getRelationWish(fme).value)
{
return fthat.getRelationWish(fme);
}
return fme.getRelationWish(fthat);
return ret;
}
public static Faction getFaction(RelationParticipator rp)
@ -135,6 +141,6 @@ public class RelationUtil
return Conf.colorNoPVP;
}
}
return getRelationTo(that, me).getColor();
return getRelationOfThatToMe(that, me).getColor();
}
}