Add max relation type. Adds HCF feature from #169.

If used, max relation should be set to -1 for the default relation.
This commit is contained in:
drtshock 2015-01-27 09:33:47 -06:00
parent 092d4b352c
commit 147a051fee
6 changed files with 80 additions and 20 deletions

View File

@ -134,6 +134,8 @@ public interface Faction extends EconomyParticipator {
public void setRelationWish(Faction otherFaction, Relation relation);
public int getRelationCount(Relation relation);
// ----------------------------------------------//
// Power
// ----------------------------------------------//

View File

@ -2,13 +2,13 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.event.FactionRelationEvent;
import com.massivecraft.factions.event.FactionRelationWishEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -52,6 +52,10 @@ public abstract class FRelationCommand extends FCommand {
return;
}
if (exceedsMaxRelations(targetRelation)) {
// We message them down there with the count.
return;
}
Relation oldRelation = myFaction.getRelationTo(them, true);
FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation);
Bukkit.getPluginManager().callEvent(wishEvent);
@ -98,6 +102,19 @@ public abstract class FRelationCommand extends FCommand {
FTeamWrapper.updatePrefixes(them);
}
private boolean exceedsMaxRelations(Relation targetRelation) {
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;
}
}
return false;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_RELATIONS_DESCRIPTION;

View File

@ -31,7 +31,7 @@ public enum Relation {
return MEMBER;
} else if (s.equalsIgnoreCase("ally")) {
return ALLY;
} else if(s.equalsIgnoreCase("truce")) {
} else if (s.equalsIgnoreCase("truce")) {
return TRUCE;
} else if (s.equalsIgnoreCase("enemy")) {
return ENEMY;
@ -42,7 +42,16 @@ public enum Relation {
public String getTranslation() {
for (TL t : TL.values()) {
if (t.name().equals("RELATION_" + name())) {
if (t.name().equalsIgnoreCase("RELATION_" + name())) {
return t.toString();
}
}
return toString();
}
public String getPluralTranslation() {
for (TL t : TL.values()) {
if (t.name().equalsIgnoreCase("RELATION_" + name() + "_PLURAL")) {
return t.toString();
}
}

View File

@ -365,6 +365,16 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
}
public int getRelationCount(Relation relation) {
int count = 0;
for (Faction faction : Factions.getInstance().getAllFactions()) {
if (faction.getRelationTo(this) == relation) {
count++;
}
}
return count;
}
// ----------------------------------------------//
// Power
// ----------------------------------------------//

View File

@ -383,6 +383,21 @@ public enum TL {
COMMAND_POWERBOOST_BOOSTLOG("%1$s has set the power bonus/penalty for %2$s to %3$d."),
COMMAND_POWERBOOST_DESCRIPTION("Apply permanent power bonus/penalty to specified player or faction"),
COMMAND_RELATIONS_ALLTHENOPE("<b>Nope! You can't."),
COMMAND_RELATIONS_MORENOPE("<b>Nope! You can't declare a relation to yourself :)"),
COMMAND_RELATIONS_ALREADYINRELATIONSHIP("<b>You already have that relation wish set with %1$s."),
COMMAND_RELATIONS_TOMARRY("to change a relation wish"),
COMMAND_RELATIONS_FORMARRY("for changing a relation wish"),
COMMAND_RELATIONS_MUTUAL("<i>Your faction is now %1$s<i> to %2$s"),
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_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_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_SENT("%1$s<i> were informed that you wish to be %2$s"),
COMMAND_RELOAD_TIME("<i>Reloaded <h>conf.json <i>from disk, took <h>%1$d ms<i>."),
COMMAND_RELOAD_DESCRIPTION("Reload data file(s) from disk"),
@ -484,20 +499,6 @@ public enum TL {
COMMAND_WARUNCLAIMALL_SUCCESS("<i>You unclaimed ALL war zone land."),
COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."),
COMMAND_RELATIONS_ALLTHENOPE("<b>Nope! You can't."),
COMMAND_RELATIONS_MORENOPE("<b>Nope! You can't declare a relation to yourself :)"),
COMMAND_RELATIONS_ALREADYINRELATIONSHIP("<b>You already have that relation wish set with %1$s."),
COMMAND_RELATIONS_TOMARRY("to change a relation wish"),
COMMAND_RELATIONS_FORMARRY("for changing a relation wish"),
COMMAND_RELATIONS_MUTUAL("<i>Your faction is now %1$s<i> to %2$s"),
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_DESCRIPTION("Set relation wish to another faction"),
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_SENT("%1$s<i> were informed that you wish to be %2$s"),
/**
* Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s
*/
@ -511,7 +512,7 @@ public enum TL {
LEAVE_DESCRIPTION("Leave your faction"),
/**
* Claiming - Same as above basically. No COMMAND_* because it's not in a command class, but...
* Claiming - Same as above basically. No COMMAND_* because it's not in a command class, but...
*/
CLAIM_PROTECTED("<b>This land is protected"),
CLAIM_DISABLED("<b>Sorry, this world has land claiming disabled."),
@ -583,10 +584,15 @@ public enum TL {
* Relations
*/
RELATION_MEMBER("member"),
RELATION_MEMBER_PURAL("members"),
RELATION_ALLY("ally"),
RELATION_ALLY_PURAL("allies"),
RELATION_TRUCE("truce"),
RELATION_TRUCE_PLURAL("truces"),
RELATION_NEUTRAL("neutral"),
RELATION_NEUTRAL_PURAL("neutrals"),
RELATION_ENEMY("enemy"),
RELATION_ENEMY_PLURAL("enemies"),
/**
* Roles
@ -657,8 +663,7 @@ public enum TL {
/**
* Warmups
*/
WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds.")
;
WARMUPS_NOTIFY_TELEPORT("&eYou will teleport to &d%1$s &ein &d%2$d &eseconds.");
private String path;
private String def;

View File

@ -149,3 +149,20 @@ warmups:
f-home: 0
# Delay for /f warp
f-warp: 0
# HCF Features
# These features were requested as part of Hardcore Factions or something.
# All of them are disabled by default.
# Max Relation Types
# Limits factions to having a max number of each relation.
# Setting to 0 means none allowed. -1 for disabled.
# This will have no effect on default or existing relations, only when relations are changed.
# It is advised that you set the default relation to -1 so they can always go back to that.
# Otherwise Factions could be stuck with not being able to unenemy other Factions.
max-relations:
enabled: false
ally: 10
truce: 10
neutral: -1
enemy: 10