From fb0c77efc07c804c9dbd78a7e2ebd086c6f35b18 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Fri, 5 Jan 2018 00:25:50 -0800 Subject: [PATCH] Add truce to tag util --- .../factions/util/PlaceholderAPIManager.java | 8 +++++--- .../factions/zcore/util/TagReplacer.java | 10 ++++++++++ .../factions/zcore/util/TagUtil.java | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java b/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java index 40198303..21a4bfa3 100644 --- a/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java +++ b/src/main/java/com/massivecraft/factions/util/PlaceholderAPIManager.java @@ -50,15 +50,15 @@ public class PlaceholderAPIManager extends EZPlaceholderHook { return faction.getTag(); case "faction_power": return String.valueOf(faction.getPowerRounded()); - case "faction_description": - return faction.getDescription(); case "faction_powermax": return String.valueOf(faction.getPowerMaxRounded()); + case "faction_description": + return faction.getDescription(); case "faction_claims": return String.valueOf(faction.getAllClaims().size()); case "faction_founded": return String.valueOf(TL.sdf.format(faction.getFoundedDate())); - case "faction_joning": + case "faction_joining": return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString()); case "faction_peaceful": return faction.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : ""; @@ -91,6 +91,8 @@ public class PlaceholderAPIManager extends EZPlaceholderHook { return String.valueOf(faction.getRelationCount(Relation.ALLY)); case "faction_enemies": return String.valueOf(faction.getRelationCount(Relation.ENEMY)); + case "faction_truces": + return String.valueOf(faction.getRelationCount(Relation.TRUCE)); case "faction_online": return String.valueOf(faction.getOnlinePlayers().size()); case "faction_offline": diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java index 8b76ef6e..1fbdca43 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java @@ -23,6 +23,7 @@ public enum TagReplacer { ALLIES_LIST(TagType.FANCY, "{allies-list}"), ONLINE_LIST(TagType.FANCY, "{online-list}"), ENEMIES_LIST(TagType.FANCY, "{enemies-list}"), + TRUCES_LIST(TagType.FANCY, "{truces-list}"), OFFLINE_LIST(TagType.FANCY, "{offline-list}"), /** @@ -64,6 +65,7 @@ public enum TagReplacer { BANK_BALANCE(TagType.FACTION, "{faction-balance}"), ALLIES_COUNT(TagType.FACTION, "{allies}"), ENEMIES_COUNT(TagType.FACTION, "{enemies}"), + TRUCES_COUNT(TagType.FACTION, "{truces}"), ONLINE_COUNT(TagType.FACTION, "{online}"), OFFLINE_COUNT(TagType.FACTION, "{offline}"), FACTION_SIZE(TagType.FACTION, "{members}"), @@ -76,6 +78,7 @@ public enum TagReplacer { MAX_WARPS(TagType.GENERAL, "{max-warps}"), MAX_ALLIES(TagType.GENERAL, "{max-allies}"), MAX_ENEMIES(TagType.GENERAL, "{max-enemies}"), + MAX_TRUCES(TagType.GENERAL, "{max-truces}"), FACTIONLESS(TagType.GENERAL, "{factionless}"), TOTAL_ONLINE(TagType.GENERAL, "{total-online}"); @@ -117,6 +120,11 @@ public enum TagReplacer { return String.valueOf(P.p.getConfig().getInt("max-relations.enemy", 10)); } return TL.GENERIC_INFINITY.toString(); + case MAX_TRUCES: + if (P.p.getConfig().getBoolean("max-relations.enabled", true)) { + return String.valueOf(P.p.getConfig().getInt("max-relations.truce", 10)); + } + return TL.GENERIC_INFINITY.toString(); case MAX_WARPS: return String.valueOf(P.p.getConfig().getInt("max-warps", 5)); } @@ -213,6 +221,8 @@ public enum TagReplacer { return String.valueOf(fac.getRelationCount(Relation.ALLY)); case ENEMIES_COUNT: return String.valueOf(fac.getRelationCount(Relation.ENEMY)); + case TRUCES_COUNT: + return String.valueOf(fac.getRelationCount(Relation.TRUCE)); case ONLINE_COUNT: return String.valueOf(fac.getOnlinePlayers().size()); case OFFLINE_COUNT: diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java b/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java index c18e5ded..a0301d35 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java @@ -162,6 +162,26 @@ public class TagUtil { } fancyMessages.add(currentEnemies); return firstEnemy && minimal ? null : fancyMessages; // we must return here and not outside the switch + case TRUCES_LIST: + FancyMessage currentTruces = P.p.txt.parseFancy(prefix); + boolean firstTruce = true; + for (Faction otherFaction : Factions.getInstance().getAllFactions()) { + if (otherFaction == target) { + continue; + } + String s = otherFaction.getTag(fme); + if (otherFaction.getRelationTo(target).isTruce()) { + currentTruces.then(firstTruce ? s : ", " + s); + currentTruces.tooltip(tipFaction(otherFaction)).color(fme.getColorTo(otherFaction)); + firstTruce = false; + if (currentTruces.toJSONString().length() > ARBITRARY_LIMIT) { + fancyMessages.add(currentTruces); + currentTruces = new FancyMessage(""); + } + } + } + fancyMessages.add(currentTruces); + return firstTruce && minimal ? null : fancyMessages; // we must return here and not outside the switch case ONLINE_LIST: FancyMessage currentOnline = P.p.txt.parseFancy(prefix); boolean firstOnline = true;