From ce77799ef14676c9846c129242cbeee1fb448d5c Mon Sep 17 00:00:00 2001 From: drtshock Date: Thu, 6 Aug 2015 16:59:54 -0500 Subject: [PATCH] Add minimal f show. --- .../massivecraft/factions/cmd/CmdShow.java | 5 ++++- .../factions/zcore/util/TagReplacer.java | 19 +++++++++++-------- .../factions/zcore/util/TagUtil.java | 17 ++++++++++++----- src/main/resources/config.yml | 3 +++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 2839de39..b6a2afca 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -78,6 +78,9 @@ public class CmdShow extends FCommand { for (String raw : show) { String parsed = TagUtil.parsePlain(faction, fme, raw); // use relations + if (parsed == null) { + continue; // Due to minimal f show. + } if (TagUtil.hasFancy(parsed)) { List fancy = TagUtil.parseFancy(faction, fme, parsed); if (fancy != null) { @@ -90,7 +93,7 @@ public class CmdShow extends FCommand { // replaces all variables with no home TL parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString(); } - if(parsed.contains("%")) { + if (parsed.contains("%")) { parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. } msg(p.txt.parse(parsed)); 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 59d4db0c..1608d2b0 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagReplacer.java @@ -135,6 +135,9 @@ public enum TagReplacer { if (this.type == TagType.GENERAL) { return getValue(); } + + boolean minimal = P.p.getConfig().getBoolean("minimal-show", false); + if (fp != null) { switch (this) { case HEADER: @@ -191,22 +194,22 @@ public enum TagReplacer { boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && fac.getLandRounded() >= fac.getPowerRounded(); return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString(); case HOME_WORLD: - return fac.hasHome() ? fac.getHome().getWorld().getName() : "{ig}"; + return fac.hasHome() ? fac.getHome().getWorld().getName() : minimal ? null : "{ig}"; case HOME_X: - return fac.hasHome() ? String.valueOf(fac.getHome().getBlockX()) : "{ig}"; + return fac.hasHome() ? String.valueOf(fac.getHome().getBlockX()) : minimal ? null : "{ig}"; case HOME_Y: - return fac.hasHome() ? String.valueOf(fac.getHome().getBlockY()) : "{ig}"; + return fac.hasHome() ? String.valueOf(fac.getHome().getBlockY()) : minimal ? null : "{ig}"; case HOME_Z: - return fac.hasHome() ? String.valueOf(fac.getHome().getBlockZ()) : "{ig}"; + return fac.hasHome() ? String.valueOf(fac.getHome().getBlockZ()) : minimal ? null : "{ig}"; case LAND_VALUE: - return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(fac.getLandRounded())) : TL.ECON_OFF.format("value"); + return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(fac.getLandRounded())) : minimal ? null : TL.ECON_OFF.format("value"); case LAND_REFUND: - return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(fac.getLandRounded())) : TL.ECON_OFF.format("refund"); + return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(fac.getLandRounded())) : minimal ? null : TL.ECON_OFF.format("refund"); case BANK_BALANCE: if (Econ.shouldBeUsed()) { - return Conf.bankEnabled ? Econ.moneyString(Econ.getBalance(fac.getAccountId())) : TL.ECON_OFF.format("balance"); + return Conf.bankEnabled ? Econ.moneyString(Econ.getBalance(fac.getAccountId())) : minimal ? null : TL.ECON_OFF.format("balance"); } - return TL.ECON_OFF.format("balance"); + return minimal ? null : TL.ECON_OFF.format("balance"); case ALLIES_COUNT: return String.valueOf(fac.getRelationCount(Relation.ALLY)); case ENEMIES_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 c0d30c1d..b89165d3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TagUtil.java @@ -68,7 +68,12 @@ public class TagUtil { public static String parsePlain(Faction faction, FPlayer fplayer, String line) { for (TagReplacer tagReplacer : TagReplacer.getByType(TagType.PLAYER)) { if (tagReplacer.contains(line)) { - line = tagReplacer.replace(line, tagReplacer.getValue(faction, fplayer)); + String value = tagReplacer.getValue(faction, fplayer); + if (value != null) { + line = tagReplacer.replace(line, value); + } else { + return null; // minimal show, entire line to be ignored + } } } return line; @@ -120,6 +125,8 @@ public class TagUtil { */ protected static List getFancy(Faction target, FPlayer fme, TagReplacer type, String prefix) { List fancyMessages = new ArrayList(); + boolean minimal = P.p.getConfig().getBoolean("minimal-show", false); + switch (type) { case ALLIES_LIST: FancyMessage currentAllies = P.p.txt.parseFancy(prefix); @@ -140,7 +147,7 @@ public class TagUtil { } } fancyMessages.add(currentAllies); - return fancyMessages; // we must return here and not outside the switch + return firstAlly && minimal ? null : fancyMessages; // we must return here and not outside the switch case ENEMIES_LIST: FancyMessage currentEnemies = P.p.txt.parseFancy(prefix); boolean firstEnemy = true; @@ -160,7 +167,7 @@ public class TagUtil { } } fancyMessages.add(currentEnemies); - return fancyMessages; // we must return here and not outside the switch + return firstEnemy && 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; @@ -175,7 +182,7 @@ public class TagUtil { } } fancyMessages.add(currentOnline); - return fancyMessages; // we must return here and not outside the switch + return firstOnline && minimal ? null : fancyMessages; // we must return here and not outside the switch case OFFLINE_LIST: FancyMessage currentOffline = P.p.txt.parseFancy(prefix); boolean firstOffline = true; @@ -192,7 +199,7 @@ public class TagUtil { } } fancyMessages.add(currentOffline); - return fancyMessages; // we must return here and not outside the switch + return firstOffline && minimal ? null : fancyMessages; // we must return here and not outside the switch } return null; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ed7e78ab..7e610493 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -242,6 +242,9 @@ show: - 'Online: ({online}/{members}): {online-list}' - 'Offline: ({offline}/{members}): {offline-list}' +# For a /f show that does not display fancy messages that are essentially empty, use minimal-show +minimal-show: false + ############################################################ # +------------------------------------------------------+ # # | Configurable /f list | #