From 362bb55a0f387475859f88f7e19865482ccc50ed Mon Sep 17 00:00:00 2001 From: Nick Porillo Date: Tue, 12 May 2015 12:13:30 -0400 Subject: [PATCH] Fix relation limit glitch Hand merged from HCF. Fixes issue where factions could exceed the max relation setting in config. --- .../factions/cmd/FRelationCommand.java | 20 +++++++++++-------- .../massivecraft/factions/zcore/util/TL.java | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/FRelationCommand.java b/src/main/java/com/massivecraft/factions/cmd/FRelationCommand.java index 6bff7650..cb497d68 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FRelationCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FRelationCommand.java @@ -52,7 +52,7 @@ public abstract class FRelationCommand extends FCommand { return; } - if (exceedsMaxRelations(targetRelation)) { + if (hasMaxRelations(them, targetRelation)) { // We message them down there with the count. return; } @@ -102,14 +102,18 @@ public abstract class FRelationCommand extends FCommand { 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)) { - int max = P.p.getConfig().getInt("max-relations." + targetRelation.toString(), -1); - // -1 means don't care. - if (max != -1 && myFaction.getRelationCount(targetRelation) >= max) { - // Message them now as long as we have the count. - msg(TL.COMMAND_RELATIONS_EXCEEDS_MAX, max, targetRelation.getPluralTranslation()); - return true; + if (max != -1) { + if (myFaction.getRelationCount(targetRelation) >= max) { + msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation()); + return true; + } + if (them.getRelationCount(targetRelation) > max) { + msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation()); + return true; + } } } return false; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index c01e87b1..460d1734 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -392,7 +392,8 @@ public enum TL { COMMAND_RELATIONS_PEACEFUL("This will have no effect while your faction is peaceful."), COMMAND_RELATIONS_PEACEFULOTHER("This will have no effect while their faction is peaceful."), COMMAND_RELATIONS_DESCRIPTION("Set relation wish to another faction"), - COMMAND_RELATIONS_EXCEEDS_MAX("Failed to set relation wish. You can only have %1$d %2%s."), + COMMAND_RELATIONS_EXCEEDS_ME("Failed to set relation wish. You can only have %1$s %2$s."), + COMMAND_RELATIONS_EXCEEDS_THEY("Failed to set relation wish. They can only have %1$s %2$s."), COMMAND_RELATIONS_PROPOSAL_1("%1$s wishes to be your %2$s"), COMMAND_RELATIONS_PROPOSAL_2("Type /%1$s %2$s %3$s to accept."),