Removing player index to reduce complexity since I doubt its required. Decouble and nullify faction descriptions.

This commit is contained in:
Olof Larsson 2013-04-17 08:49:43 +02:00
parent 6ef15bc2db
commit 1ccefc93b5
13 changed files with 187 additions and 173 deletions

View File

@ -71,9 +71,6 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public boolean hasFaction() { return this.factionId != null && ! factionId.equals(Const.FACTIONID_NONE); } public boolean hasFaction() { return this.factionId != null && ! factionId.equals(Const.FACTIONID_NONE); }
public void setFaction(Faction faction) public void setFaction(Faction faction)
{ {
Faction oldFaction = this.getFaction();
if (oldFaction != null) oldFaction.removeFPlayer(this);
faction.addFPlayer(this);
this.factionId = faction.getId(); this.factionId = faction.getId();
SpoutFeatures.updateTitle(this, null); SpoutFeatures.updateTitle(this, null);
SpoutFeatures.updateTitle(null, this); SpoutFeatures.updateTitle(null, this);
@ -157,15 +154,6 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public final void resetFactionData(boolean doSpoutUpdate) public final void resetFactionData(boolean doSpoutUpdate)
{ {
if (this.factionId != null && FactionColl.get().containsId(this.factionId)) // Avoid infinite loop! TODO: I think that this is needed is a sign we need to refactor.
{
Faction currentFaction = this.getFaction();
if (currentFaction != null)
{
currentFaction.removeFPlayer(this);
}
}
// TODO: Should we not rather use ConfServer.newPlayerStartingFactionID here? // TODO: Should we not rather use ConfServer.newPlayerStartingFactionID here?
this.factionId = Const.FACTIONID_NONE; // The default neutral faction this.factionId = Const.FACTIONID_NONE; // The default neutral faction
@ -476,7 +464,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
} }
Faction factionHere = BoardColl.get().getFactionAt(this.getCurrentChunk()); Faction factionHere = BoardColl.get().getFactionAt(this.getCurrentChunk());
String msg = Txt.parse("<i>")+" ~ "+factionHere.getTag(this); String msg = Txt.parse("<i>")+" ~ "+factionHere.getTag(this);
if (factionHere.getDescription().length() > 0) if (factionHere.hasDescription())
{ {
msg += " - "+factionHere.getDescription(); msg += " - "+factionHere.getDescription();
} }
@ -564,7 +552,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
PS ps = PS.valueOf(location); PS ps = PS.valueOf(location);
Faction myFaction = this.getFaction(); Faction myFaction = this.getFaction();
Faction currentFaction = BoardColl.get().getFactionAt(ps); Faction currentFaction = BoardColl.get().getFactionAt(ps);
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandCount();
if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location)) if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location))
{ {
@ -611,7 +599,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
( (
ConfServer.claimsMustBeConnected ConfServer.claimsMustBeConnected
&& ! this.isUsingAdminMode() && ! this.isUsingAdminMode()
&& myFaction.getLandRoundedInWorld(ps.getWorld()) > 0 && myFaction.getLandCountInWorld(ps.getWorld()) > 0
&& !BoardColl.get().isConnectedPs(ps, myFaction) && !BoardColl.get().isConnectedPs(ps, myFaction)
&& (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) && (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
) )
@ -649,7 +637,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
PS flocation = PS.valueOf(location).getChunk(true); PS flocation = PS.valueOf(location).getChunk(true);
Faction currentFaction = BoardColl.get().getFactionAt(flocation); Faction currentFaction = BoardColl.get().getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandCount();
if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false; if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false;
@ -662,7 +650,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
{ {
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorld()) > 0 && !BoardColl.get().isConnectedPs(flocation, forFaction)) if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(flocation.getWorld()) > 0 && !BoardColl.get().isConnectedPs(flocation, forFaction))
cost += ConfServer.econClaimUnconnectedFee; cost += ConfServer.econClaimUnconnectedFee;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction()) if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction())

View File

@ -2,8 +2,10 @@ package com.massivecraft.factions;
import java.util.*; import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
@ -13,7 +15,7 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.xlib.gson.annotations.SerializedName; import com.massivecraft.mcore.xlib.gson.annotations.SerializedName;
@ -39,7 +41,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.invitedPlayerIds = that.invitedPlayerIds; this.invitedPlayerIds = that.invitedPlayerIds;
this.open = that.open; this.open = that.open;
this.tag = that.tag; this.tag = that.tag;
this.description = that.description; this.setDescription(that.description);
this.home = that.home; this.home = that.home;
this.cape = that.cape; this.cape = that.cape;
this.powerBoost = that.powerBoost; this.powerBoost = that.powerBoost;
@ -53,10 +55,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// FIELDS: RAW // FIELDS: RAW
// -------------------------------------------- // // -------------------------------------------- //
// speedy lookup of players in faction
private transient Set<FPlayer> fplayers = new HashSet<FPlayer>();
// TODO
private Map<String, Rel> relationWish; private Map<String, Rel> relationWish;
// TODO // TODO
@ -84,8 +82,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.invitedPlayerIds = target; this.invitedPlayerIds = target;
} }
// TODO: Add when we use a true mcore entity. this.changed();
// this.changed();
} }
private boolean open; private boolean open;
@ -116,10 +113,31 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// FIELD: description // FIELD: description
private String description; private String description;
public String getDescription() { return this.description; } public boolean hasDescription()
public void setDescription(String value) { this.description = value; } {
return this.description != null;
}
public String getDescription()
{
if (this.hasDescription()) return this.description;
return Lang.FACTION_NODESCRIPTION;
}
public void setDescription(String description)
{
if (description != null)
{
description = description.trim();
// This code should be kept for a while to clean out the previous default text that was actually stored in the database.
if (description.length() == 0 || description.equalsIgnoreCase("Default faction description :("))
{
description = null;
}
}
this.description = description;
}
// FIELD: home // FIELD: home
// TODO: Use a PS instead!
private LazyLocation home; private LazyLocation home;
public void setHome(Location home) { this.home = new LazyLocation(home); } public void setHome(Location home) { this.home = new LazyLocation(home); }
public boolean hasHome() { return this.getHome() != null; } public boolean hasHome() { return this.getHome() != null; }
@ -166,8 +184,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// FIELDS: Flag management // FIELDS: Flag management
// TODO: This will save... defaults if they where changed to... // TODO: This will save... defaults if they where changed to...
private Map<FFlag, Boolean> flagOverrides; // Contains the modifications to the default values private Map<FFlag, Boolean> flagOverrides; // Contains the modifications to the default values
public boolean getFlag(FFlag flag) public boolean getFlag(FFlag flag)
{ {
@ -245,15 +261,15 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// -------------------------------------------- // // -------------------------------------------- //
// Construct // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public Faction() public Faction()
{ {
this.relationWish = new HashMap<String, Rel>(); this.relationWish = new LinkedHashMap<String, Rel>();
this.open = ConfServer.newFactionsDefaultOpen; this.open = ConfServer.newFactionsDefaultOpen;
this.tag = "???"; this.tag = "???";
this.description = "Default faction description :("; this.description = null;
this.powerBoost = 0.0; this.powerBoost = 0.0;
this.flagOverrides = new LinkedHashMap<FFlag, Boolean>(); this.flagOverrides = new LinkedHashMap<FFlag, Boolean>();
this.permOverrides = new LinkedHashMap<FPerm, Set<Rel>>(); this.permOverrides = new LinkedHashMap<FPerm, Set<Rel>>();
@ -306,26 +322,23 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.removeInvitedPlayerId(fplayer.getId()); this.removeInvitedPlayerId(fplayer.getId());
} }
// ------------------------------- // -------------------------------------------- //
// Understand the types // NONE OR NORMAL?
// ------------------------------- // -------------------------------------------- //
// TODO: These should be gone after the refactoring...
public boolean isNormal()
{
//return ! (this.isNone() || this.isSafeZone() || this.isWarZone());
return ! this.isNone();
}
public boolean isNone() public boolean isNone()
{ {
return this.getId().equals(Const.FACTIONID_NONE); return this.getId().equals(Const.FACTIONID_NONE);
} }
// ------------------------------- public boolean isNormal()
// Relation and relation colors {
// ------------------------------- return ! this.isNone();
}
// -------------------------------------------- //
// RELATION AND COLORS
// -------------------------------------------- //
@Override @Override
public String describeTo(RelationParticipator observer, boolean ucfirst) public String describeTo(RelationParticipator observer, boolean ucfirst)
@ -402,8 +415,9 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// TODO: Implement a has enough feature. // TODO: Implement a has enough feature.
// -------------------------------------------- // // -------------------------------------------- //
// Power // POWER
// -------------------------------------------- // // -------------------------------------------- //
public double getPower() public double getPower()
{ {
if (this.getFlag(FFlag.INFPOWER)) if (this.getFlag(FFlag.INFPOWER))
@ -412,7 +426,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
} }
double ret = 0; double ret = 0;
for (FPlayer fplayer : fplayers) for (FPlayer fplayer : this.getFPlayers())
{ {
ret += fplayer.getPower(); ret += fplayer.getPower();
} }
@ -431,7 +445,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
} }
double ret = 0; double ret = 0;
for (FPlayer fplayer : fplayers) for (FPlayer fplayer : this.getFPlayers())
{ {
ret += fplayer.getPowerMax(); ret += fplayer.getPowerMax();
} }
@ -452,119 +466,91 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
return (int) Math.round(this.getPowerMax()); return (int) Math.round(this.getPowerMax());
} }
// TODO: Why "rounded"? Rename to getLandCount? or getChunkCount? public int getLandCount()
public int getLandRounded()
{ {
return BoardColl.get().getCount(this); return BoardColl.get().getCount(this);
} }
public int getLandRoundedInWorld(String worldName) public int getLandCountInWorld(String worldName)
{ {
return BoardColl.get().get(worldName).getCount(this); return BoardColl.get().get(worldName).getCount(this);
} }
public boolean hasLandInflation() public boolean hasLandInflation()
{ {
return this.getLandRounded() > this.getPowerRounded(); return this.getLandCount() > this.getPowerRounded();
} }
// -------------------------------------------- // // -------------------------------------------- //
// FPlayers // FPLAYERS
// -------------------------------------------- // // -------------------------------------------- //
// maintain the reference list of FPlayers in this faction public List<FPlayer> getFPlayers()
public void refreshFPlayers()
{ {
fplayers.clear(); List<FPlayer> ret = new ArrayList<FPlayer>();
if (this.isNone()) return;
for (FPlayer fplayer : FPlayerColl.get().getAll()) for (FPlayer fplayer : FPlayerColl.get().getAll())
{ {
if (fplayer.getFaction() == this) if (fplayer.getFaction() != this) continue;
{
fplayers.add(fplayer);
}
}
}
protected boolean addFPlayer(FPlayer fplayer)
{
if (this.isNone()) return false;
return fplayers.add(fplayer);
}
protected boolean removeFPlayer(FPlayer fplayer)
{
if (this.isNone()) return false;
return fplayers.remove(fplayer);
}
public Set<FPlayer> getFPlayers()
{
// return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers);
return ret;
}
public Set<FPlayer> getFPlayersWhereOnline(boolean online)
{
Set<FPlayer> ret = new HashSet<FPlayer>();
for (FPlayer fplayer : fplayers)
{
if (fplayer.isOnline() == online)
{
ret.add(fplayer); ret.add(fplayer);
} }
}
return ret; return ret;
} }
public FPlayer getFPlayerLeader() public List<FPlayer> getFPlayersWhereOnline(boolean online)
{ {
//if ( ! this.isNormal()) return null; List<FPlayer> ret = new ArrayList<FPlayer>();
for (FPlayer fplayer : FPlayerColl.get().getAll())
for (FPlayer fplayer : fplayers)
{ {
if (fplayer.getRole() == Rel.LEADER) if (fplayer.getFaction() != this) continue;
{ if (fplayer.isOnline() != online) continue;
return fplayer; ret.add(fplayer);
} }
return ret;
}
public List<FPlayer> getFPlayersWhereRole(Rel role)
{
List<FPlayer> ret = new ArrayList<FPlayer>();
for (FPlayer fplayer : FPlayerColl.get().getAll())
{
if (fplayer.getFaction() != this) continue;
if (fplayer.getRole() != role) continue;
ret.add(fplayer);
}
return ret;
}
public FPlayer getLeader()
{
for (FPlayer fplayer : FPlayerColl.get().getAll())
{
if (fplayer.getFaction() != this) continue;
if (fplayer.getRole() != Rel.LEADER) continue;
return fplayer;
} }
return null; return null;
} }
public ArrayList<FPlayer> getFPlayersWhereRole(Rel role) public List<CommandSender> getOnlineCommandSenders()
{ {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); List<CommandSender> ret = new ArrayList<CommandSender>();
//if ( ! this.isNormal()) return ret; for (CommandSender player : SenderUtil.getOnlineSenders())
for (FPlayer fplayer : fplayers)
{ {
if (fplayer.getRole() == role) FPlayer fplayer = FPlayerColl.get().get(player);
{ if (fplayer.getFaction() != this) continue;
ret.add(fplayer); ret.add(player);
} }
}
return ret; return ret;
} }
// TODO: Makes use of bukkit instead of mixin. Fix that? public List<Player> getOnlinePlayers()
public ArrayList<Player> getOnlinePlayers()
{ {
ArrayList<Player> ret = new ArrayList<Player>(); List<Player> ret = new ArrayList<Player>();
//if (this.isPlayerFreeType()) return ret; for (Player player : Bukkit.getOnlinePlayers())
for (Player player: Factions.get().getServer().getOnlinePlayers())
{ {
FPlayer fplayer = FPlayerColl.get().get(player); FPlayer fplayer = FPlayerColl.get().get(player);
if (fplayer.getFaction() == this) if (fplayer.getFaction() != this) continue;
{
ret.add(player); ret.add(player);
} }
}
return ret; return ret;
} }
@ -574,25 +560,31 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
if ( ! this.isNormal()) return; if ( ! this.isNormal()) return;
if (this.getFlag(FFlag.PERMANENT) && ConfServer.permanentFactionsDisableLeaderPromotion) return; if (this.getFlag(FFlag.PERMANENT) && ConfServer.permanentFactionsDisableLeaderPromotion) return;
FPlayer oldLeader = this.getFPlayerLeader(); FPlayer oldLeader = this.getLeader();
// get list of officers, or list of normal members if there are no officers // get list of officers, or list of normal members if there are no officers
ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Rel.OFFICER); List<FPlayer> replacements = this.getFPlayersWhereRole(Rel.OFFICER);
if (replacements == null || replacements.isEmpty()) if (replacements == null || replacements.isEmpty())
{
replacements = this.getFPlayersWhereRole(Rel.MEMBER); replacements = this.getFPlayersWhereRole(Rel.MEMBER);
}
if (replacements == null || replacements.isEmpty()) if (replacements == null || replacements.isEmpty())
{ // faction leader is the only member; one-man faction { // faction leader is the only member; one-man faction
if (this.getFlag(FFlag.PERMANENT)) if (this.getFlag(FFlag.PERMANENT))
{ {
if (oldLeader != null) if (oldLeader != null)
{
oldLeader.setRole(Rel.MEMBER); oldLeader.setRole(Rel.MEMBER);
}
return; return;
} }
// no members left and faction isn't permanent, so disband it // no members left and faction isn't permanent, so disband it
if (ConfServer.logFactionDisband) if (ConfServer.logFactionDisband)
{
Factions.get().log("The faction "+this.getTag()+" ("+this.getId()+") has been disbanded since it has no members left."); Factions.get().log("The faction "+this.getTag()+" ("+this.getId()+") has been disbanded since it has no members left.");
}
for (FPlayer fplayer : FPlayerColl.get().getAllOnline()) for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{ {
@ -604,7 +596,10 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
else else
{ // promote new faction leader { // promote new faction leader
if (oldLeader != null) if (oldLeader != null)
{
oldLeader.setRole(Rel.MEMBER); oldLeader.setRole(Rel.MEMBER);
}
replacements.get(0).setRole(Rel.LEADER); replacements.get(0).setRole(Rel.LEADER);
this.msg("<i>Faction leader <h>%s<i> has been removed. %s<i> has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName()); this.msg("<i>Faction leader <h>%s<i> has been removed. %s<i> has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
Factions.get().log("Faction "+this.getTag()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName()); Factions.get().log("Faction "+this.getTag()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName());
@ -612,37 +607,66 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
} }
// -------------------------------------------- // // -------------------------------------------- //
// Messages // MESSAGES
// -------------------------------------------- // // -------------------------------------------- //
// These methods are simply proxied in from the SenderEntity class using a for loop.
// TODO: Invalid code since Mixin introduction. Fix this. // CONVENIENCE SEND MESSAGE
public boolean msg(String message, Object... args)
public boolean sendMessage(String message)
{ {
message = Txt.parse(message, args); for (FPlayer fplayer : this.getFPlayers())
for (FPlayer fplayer : this.getFPlayersWhereOnline(true))
{ {
fplayer.sendMessage(message); fplayer.sendMessage(message);
} }
return true; return true;
} }
public void sendMessage(String message) public boolean sendMessage(String... messages)
{ {
for (FPlayer fplayer : this.getFPlayersWhereOnline(true)) for (FPlayer fplayer : this.getFPlayers())
{
fplayer.sendMessage(message);
}
}
public void sendMessage(List<String> messages)
{
for (FPlayer fplayer : this.getFPlayersWhereOnline(true))
{ {
fplayer.sendMessage(messages); fplayer.sendMessage(messages);
} }
return true;
} }
public boolean sendMessage(Collection<String> messages)
{
for (FPlayer fplayer : this.getFPlayers())
{
fplayer.sendMessage(messages);
}
return true;
}
// CONVENIENCE MSG
public boolean msg(String msg)
{
for (FPlayer fplayer : this.getFPlayers())
{
fplayer.msg(msg);
}
return true;
}
public boolean msg(String msg, Object... args)
{
for (FPlayer fplayer : this.getFPlayers())
{
fplayer.msg(msg, args);
}
return true;
}
public boolean msg(Collection<String> msgs)
{
for (FPlayer fplayer : this.getFPlayers())
{
fplayer.msg(msgs);
}
return true;
}
} }

View File

@ -41,14 +41,6 @@ public class FactionColl extends Coll<Faction>
this.migrate(); this.migrate();
this.createDefaultFactions(); this.createDefaultFactions();
// TODO: Refactor and fix with the member-index.
// populate all faction player lists
// or as you also could describe it: Reindex of Members
for (Faction faction : this.getAll())
{
faction.refreshFPlayers();
}
} }
public void migrate() public void migrate()
@ -194,10 +186,10 @@ public class FactionColl extends Coll<Faction>
Factions.get().log("Running econLandRewardRoutine..."); Factions.get().log("Running econLandRewardRoutine...");
for (Faction faction : this.getAll()) for (Faction faction : this.getAll())
{ {
int landCount = faction.getLandRounded(); int landCount = faction.getLandCount();
if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0) if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0)
{ {
Set<FPlayer> players = faction.getFPlayers(); List<FPlayer> players = faction.getFPlayers();
int playerCount = players.size(); int playerCount = players.size();
double reward = ConfServer.econLandReward * landCount / playerCount; double reward = ConfServer.econLandReward * landCount / playerCount;
for (FPlayer player : players) for (FPlayer player : players)

View File

@ -28,7 +28,7 @@ public class FactionListComparator implements Comparator<Faction>
if (f2 == null) ret = +1; if (f2 == null) ret = +1;
if (ret != 0) return ret; if (ret != 0) return ret;
// None // None a.k.a. Wilderness
if (f1.isNone() && f2.isNone()) ret = 0; if (f1.isNone() && f2.isNone()) ret = 0;
if (f1.isNone()) ret = -1; if (f1.isNone()) ret = -1;
if (f2.isNone()) ret = +1; if (f2.isNone()) ret = +1;

View File

@ -0,0 +1,8 @@
package com.massivecraft.factions;
import com.massivecraft.mcore.util.Txt;
public class Lang
{
public static final String FACTION_NODESCRIPTION = Txt.parse("<em><silver>no description set");
}

View File

@ -7,7 +7,6 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt;
public class CmdFactionsDescription extends FCommand public class CmdFactionsDescription extends FCommand
{ {
@ -28,22 +27,21 @@ public class CmdFactionsDescription extends FCommand
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(ConfServer.econCostDesc, "to change faction description", "for changing faction description")) return; if ( ! payForCommand(ConfServer.econCostDesc, "to change faction description", "for changing faction description")) return;
// TODO: This must be an invalid replace-approach. The call order is wrong somehow? if (ConfServer.broadcastDescriptionChanges)
myFaction.setDescription(Txt.implode(args, " ").replaceAll("(&([a-f0-9]))", "& $2")); // since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up
if ( ! ConfServer.broadcastDescriptionChanges)
{ {
fme.msg("You have changed the description for <h>%s<i> to:", myFaction.describeTo(fme));
fme.sendMessage(myFaction.getDescription());
return;
}
// Broadcast the description to everyone // Broadcast the description to everyone
for (FPlayer fplayer : FPlayerColl.get().getAllOnline()) for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{ {
fplayer.msg("<h>%s<i> changed their description to:", myFaction.describeTo(fplayer)); fplayer.msg("<h>%s<i> changed their description to:", myFaction.describeTo(fplayer));
fplayer.sendMessage(myFaction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description, thus exploitable (masquerade as server messages or whatever); by the way, &k is particularly interesting looking fplayer.sendMessage(myFaction.getDescription());
} }
} }
else
{
fme.msg("You have changed the description for <h>%s<i> to:", myFaction.describeTo(fme));
fme.sendMessage(myFaction.getDescription());
}
}
} }

View File

@ -35,7 +35,7 @@ public class CmdFactionsLeader extends FCommand
Faction targetFaction = this.arg(1, ARFaction.get(), myFaction); Faction targetFaction = this.arg(1, ARFaction.get(), myFaction);
if (targetFaction == null) return; if (targetFaction == null) return;
FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader(); FPlayer targetFactionCurrentLeader = targetFaction.getLeader();
// We now have fplayer and the target faction // We now have fplayer and the target faction
if (this.senderIsConsole || fme.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false)) if (this.senderIsConsole || fme.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false))

View File

@ -64,7 +64,7 @@ public class CmdFactionsList extends FCommand
faction.getTag(fme), faction.getTag(fme),
faction.getFPlayersWhereOnline(true).size(), faction.getFPlayersWhereOnline(true).size(),
faction.getFPlayers().size(), faction.getFPlayers().size(),
faction.getLandRounded(), faction.getLandCount(),
faction.getPowerRounded(), faction.getPowerRounded(),
faction.getPowerMaxRounded()) faction.getPowerMaxRounded())
); );

View File

@ -61,12 +61,12 @@ public class CmdFactionsShow extends FCommand
double powerBoost = faction.getPowerBoost(); double powerBoost = faction.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")";
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d %s", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); msg("<a>Land / Power / Maxpower: <i> %d/%d/%d %s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
// show the land value // show the land value
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed())
{ {
double value = Econ.calculateTotalLandValue(faction.getLandRounded()); double value = Econ.calculateTotalLandValue(faction.getLandCount());
double refund = value * ConfServer.econClaimRefundMultiplier; double refund = value * ConfServer.econClaimRefundMultiplier;
if (value > 0) if (value > 0)
{ {

View File

@ -40,7 +40,7 @@ public class CmdFactionsUnclaim extends FCommand
//String moneyBack = "<i>"; //String moneyBack = "<i>";
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed())
{ {
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded()); double refund = Econ.calculateClaimRefund(myFaction.getLandCount());
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts)
{ {

View File

@ -28,7 +28,7 @@ public class CmdFactionsUnclaimall extends FCommand
{ {
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed())
{ {
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded()); double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount());
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts) if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts)
{ {
if ( ! Econ.modifyMoney(myFaction, refund, "to unclaim all faction land", "for unclaiming all faction land")) return; if ( ! Econ.modifyMoney(myFaction, refund, "to unclaim all faction land", "for unclaiming all faction land")) return;

View File

@ -113,8 +113,10 @@ public class SpoutMainListener implements Listener
String msg = tag; String msg = tag;
if (ConfServer.spoutTerritoryDisplayShowDescription && !factionHere.getDescription().isEmpty()) if (ConfServer.spoutTerritoryDisplayShowDescription && factionHere.hasDescription())
{
msg += " - " + factionHere.getDescription(); msg += " - " + factionHere.getDescription();
}
label.setText(msg); label.setText(msg);
alignLabel(label, msg); alignLabel(label, msg);
@ -141,8 +143,10 @@ public class SpoutMainListener implements Listener
String msg = tag; String msg = tag;
if (ConfServer.spoutTerritoryNoticeShowDescription && !factionHere.getDescription().isEmpty()) if (ConfServer.spoutTerritoryNoticeShowDescription && factionHere.hasDescription())
{
msg += " - " + factionHere.getDescription(); msg += " - " + factionHere.getDescription();
}
label.setText(msg); label.setText(msg);
alignLabel(label, msg, 2); alignLabel(label, msg, 2);