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:
parent
092d4b352c
commit
147a051fee
@ -134,6 +134,8 @@ public interface Faction extends EconomyParticipator {
|
|||||||
|
|
||||||
public void setRelationWish(Faction otherFaction, Relation relation);
|
public void setRelationWish(Faction otherFaction, Relation relation);
|
||||||
|
|
||||||
|
public int getRelationCount(Relation relation);
|
||||||
|
|
||||||
// ----------------------------------------------//
|
// ----------------------------------------------//
|
||||||
// Power
|
// Power
|
||||||
// ----------------------------------------------//
|
// ----------------------------------------------//
|
||||||
|
@ -2,13 +2,13 @@ package com.massivecraft.factions.cmd;
|
|||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.P;
|
||||||
import com.massivecraft.factions.event.FactionRelationEvent;
|
import com.massivecraft.factions.event.FactionRelationEvent;
|
||||||
import com.massivecraft.factions.event.FactionRelationWishEvent;
|
import com.massivecraft.factions.event.FactionRelationWishEvent;
|
||||||
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
@ -52,6 +52,10 @@ public abstract class FRelationCommand extends FCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exceedsMaxRelations(targetRelation)) {
|
||||||
|
// We message them down there with the count.
|
||||||
|
return;
|
||||||
|
}
|
||||||
Relation oldRelation = myFaction.getRelationTo(them, true);
|
Relation oldRelation = myFaction.getRelationTo(them, true);
|
||||||
FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation);
|
FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation);
|
||||||
Bukkit.getPluginManager().callEvent(wishEvent);
|
Bukkit.getPluginManager().callEvent(wishEvent);
|
||||||
@ -98,6 +102,19 @@ public abstract class FRelationCommand extends FCommand {
|
|||||||
FTeamWrapper.updatePrefixes(them);
|
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
|
@Override
|
||||||
public TL getUsageTranslation() {
|
public TL getUsageTranslation() {
|
||||||
return TL.COMMAND_RELATIONS_DESCRIPTION;
|
return TL.COMMAND_RELATIONS_DESCRIPTION;
|
||||||
|
@ -42,7 +42,16 @@ public enum Relation {
|
|||||||
|
|
||||||
public String getTranslation() {
|
public String getTranslation() {
|
||||||
for (TL t : TL.values()) {
|
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();
|
return t.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
// Power
|
||||||
// ----------------------------------------------//
|
// ----------------------------------------------//
|
||||||
|
@ -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_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_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_TIME("<i>Reloaded <h>conf.json <i>from disk, took <h>%1$d ms<i>."),
|
||||||
COMMAND_RELOAD_DESCRIPTION("Reload data file(s) from disk"),
|
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_SUCCESS("<i>You unclaimed ALL war zone land."),
|
||||||
COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."),
|
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
|
* Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s
|
||||||
*/
|
*/
|
||||||
@ -583,10 +584,15 @@ public enum TL {
|
|||||||
* Relations
|
* Relations
|
||||||
*/
|
*/
|
||||||
RELATION_MEMBER("member"),
|
RELATION_MEMBER("member"),
|
||||||
|
RELATION_MEMBER_PURAL("members"),
|
||||||
RELATION_ALLY("ally"),
|
RELATION_ALLY("ally"),
|
||||||
|
RELATION_ALLY_PURAL("allies"),
|
||||||
RELATION_TRUCE("truce"),
|
RELATION_TRUCE("truce"),
|
||||||
|
RELATION_TRUCE_PLURAL("truces"),
|
||||||
RELATION_NEUTRAL("neutral"),
|
RELATION_NEUTRAL("neutral"),
|
||||||
|
RELATION_NEUTRAL_PURAL("neutrals"),
|
||||||
RELATION_ENEMY("enemy"),
|
RELATION_ENEMY("enemy"),
|
||||||
|
RELATION_ENEMY_PLURAL("enemies"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Roles
|
* Roles
|
||||||
@ -657,8 +663,7 @@ public enum TL {
|
|||||||
/**
|
/**
|
||||||
* Warmups
|
* 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 path;
|
||||||
private String def;
|
private String def;
|
||||||
|
@ -149,3 +149,20 @@ warmups:
|
|||||||
f-home: 0
|
f-home: 0
|
||||||
# Delay for /f warp
|
# Delay for /f warp
|
||||||
f-warp: 0
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user