Fix relation limit glitch

Hand merged from HCF. Fixes issue where factions could exceed the max
relation setting in config.
This commit is contained in:
Nick Porillo 2015-05-12 12:13:30 -04:00
parent cb0043600d
commit 362bb55a0f
2 changed files with 14 additions and 9 deletions

View File

@ -52,7 +52,7 @@ public abstract class FRelationCommand extends FCommand {
return; return;
} }
if (exceedsMaxRelations(targetRelation)) { if (hasMaxRelations(them, targetRelation)) {
// We message them down there with the count. // We message them down there with the count.
return; return;
} }
@ -102,14 +102,18 @@ public abstract class FRelationCommand extends FCommand {
FTeamWrapper.updatePrefixes(them); FTeamWrapper.updatePrefixes(them);
} }
private boolean exceedsMaxRelations(Relation targetRelation) { private boolean hasMaxRelations(Faction them, Relation targetRelation) {
int max = P.p.getConfig().getInt("max-relations." + targetRelation.toString(), -1);
if (P.p.getConfig().getBoolean("max-relations.enabled", false)) { if (P.p.getConfig().getBoolean("max-relations.enabled", false)) {
int max = P.p.getConfig().getInt("max-relations." + targetRelation.toString(), -1); if (max != -1) {
// -1 means don't care. if (myFaction.getRelationCount(targetRelation) >= max) {
if (max != -1 && myFaction.getRelationCount(targetRelation) >= max) { msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation());
// Message them now as long as we have the count. return true;
msg(TL.COMMAND_RELATIONS_EXCEEDS_MAX, max, targetRelation.getPluralTranslation()); }
return true; if (them.getRelationCount(targetRelation) > max) {
msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation());
return true;
}
} }
} }
return false; return false;

View File

@ -392,7 +392,8 @@ public enum TL {
COMMAND_RELATIONS_PEACEFUL("<i>This will have no effect while your faction is peaceful."), COMMAND_RELATIONS_PEACEFUL("<i>This will have no effect while your faction is peaceful."),
COMMAND_RELATIONS_PEACEFULOTHER("<i>This will have no effect while their faction is peaceful."), COMMAND_RELATIONS_PEACEFULOTHER("<i>This will have no effect while their faction is peaceful."),
COMMAND_RELATIONS_DESCRIPTION("Set relation wish to another faction"), COMMAND_RELATIONS_DESCRIPTION("Set relation wish to another faction"),
COMMAND_RELATIONS_EXCEEDS_MAX("<i>Failed to set relation wish. You can only have %1$d %2%s."), COMMAND_RELATIONS_EXCEEDS_ME("<i>Failed to set relation wish. You can only have %1$s %2$s."),
COMMAND_RELATIONS_EXCEEDS_THEY("<i>Failed to set relation wish. They can only have %1$s %2$s."),
COMMAND_RELATIONS_PROPOSAL_1("%1$s<i> wishes to be your %2$s"), COMMAND_RELATIONS_PROPOSAL_1("%1$s<i> wishes to be your %2$s"),
COMMAND_RELATIONS_PROPOSAL_2("<i>Type <c>/%1$s %2$s %3$s<i> to accept."), COMMAND_RELATIONS_PROPOSAL_2("<i>Type <c>/%1$s %2$s %3$s<i> to accept."),