From ebfbbf45551697d38a21fab1d23d867e1c44980b Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 3 Oct 2014 08:07:12 +0200 Subject: [PATCH] Fixed LWC integration for servers not using LWC and automated dynmap flags. --- .../massivecraft/factions/entity/MConf.java | 4 +- .../integration/dynmap/EngineDynmap.java | 79 +++++++++++++++---- .../factions/integration/lwc/EngineLwc.java | 14 ++++ .../integration/lwc/IntegrationLwc.java | 6 -- 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java index dfac68c2..22afa230 100644 --- a/src/main/java/com/massivecraft/factions/entity/MConf.java +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -484,9 +484,7 @@ public class MConf extends Entity "Bank: %money%
\n" + "
\n" + "Flags:
\n" + - "%open.color% | %permanent.color% | %peaceful.color% | %infpower.color% | %powerloss.color%
\n" + - "%pvp.color% | %friendlyfire.color% | %monsters.color% | %explosions.color%
\n" + - "%offlineexplosions.color% | %firespread.color% | %endergrief.color%\n" + + "%flags.table3%\n" + ""; // Enable the %money% macro. Only do this if you know your economy manager is thread safe. diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java index 951204ee..1e25fc89 100644 --- a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java @@ -2,8 +2,10 @@ package com.massivecraft.factions.integration.dynmap; import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -758,44 +760,62 @@ public class EngineDynmap extends EngineAbstract ret = ret.replace("%money%", money); // Flags and Open - Map flags = new HashMap(); + Map flags = new LinkedHashMap(); for (MFlag mflag : MFlag.getAll()) { - flags.put(mflag.getName(), faction.getFlag(mflag)); + flags.put(mflag, faction.getFlag(mflag)); } - for (Entry entry : flags.entrySet()) + + List flagMapParts = new ArrayList(); + List flagTableParts = new ArrayList(); + + for (Entry entry : flags.entrySet()) { - String flag = entry.getKey(); + MFlag mflag = entry.getKey(); + String flag = mflag.getName(); boolean value = entry.getValue(); String bool = String.valueOf(value); String color = boolcolor(flag, value); String boolcolor = boolcolor(String.valueOf(value), value); - ret = ret.replace("%" + flag + ".bool%", bool); - ret = ret.replace("%" + flag + ".color%", color); - ret = ret.replace("%" + flag + ".boolcolor%", boolcolor); + ret = ret.replace("%" + flag + ".bool%", bool); // true + ret = ret.replace("%" + flag + ".color%", color); // monsters (red or green) + ret = ret.replace("%" + flag + ".boolcolor%", boolcolor); // true (red or green) + + if (!mflag.isVisible()) continue; + flagMapParts.add(flag + ": " + boolcolor); + flagTableParts.add(color); + } + + String flagMap = Txt.implode(flagMapParts, "
\n"); + ret = ret.replace("%flags.map%", flagMap); + + for (int cols = 1; cols <= 10; cols++) + { + String flagTable = getHtmlAsciTable(flagTableParts, cols); + ret = ret.replace("%flags.table" + cols + "%", flagTable); } // Players List playersList = faction.getMPlayers(); String playersCount = String.valueOf(playersList.size()); - String players = getPlayerString(playersList); + String players = getHtmlPlayerString(playersList); MPlayer playersLeaderObject = faction.getLeader(); - String playersLeader = getPlayerName(playersLeaderObject); + String playersLeader = getHtmlPlayerName(playersLeaderObject); List playersOfficersList = faction.getMPlayersWhereRole(Rel.OFFICER); String playersOfficersCount = String.valueOf(playersOfficersList.size()); - String playersOfficers = getPlayerString(playersOfficersList); + String playersOfficers = getHtmlPlayerString(playersOfficersList); List playersMembersList = faction.getMPlayersWhereRole(Rel.MEMBER); String playersMembersCount = String.valueOf(playersMembersList.size()); - String playersMembers = getPlayerString(playersMembersList); + String playersMembers = getHtmlPlayerString(playersMembersList); List playersRecruitsList = faction.getMPlayersWhereRole(Rel.RECRUIT); String playersRecruitsCount = String.valueOf(playersRecruitsList.size()); - String playersRecruits = getPlayerString(playersRecruitsList); + String playersRecruits = getHtmlPlayerString(playersRecruitsList); ret = ret.replace("%players%", players); @@ -811,18 +831,47 @@ public class EngineDynmap extends EngineAbstract return ret; } - public static String getPlayerString(List mplayers) + public static String getHtmlAsciTable(Collection strings, int cols) + { + StringBuilder ret = new StringBuilder(); + + int count = 0; + Iterator iter = strings.iterator(); + while (iter.hasNext()) + { + String string = iter.next(); + count++; + + ret.append(string); + if (iter.hasNext()) + { + if (count == cols) + { + ret.append("
\n"); + count = 0; + } + else + { + ret.append(" | "); + } + } + } + + return ret.toString(); + } + + public static String getHtmlPlayerString(List mplayers) { String ret = ""; for (MPlayer mplayer : mplayers) { if (ret.length() > 0) ret += ", "; - ret += getPlayerName(mplayer); + ret += getHtmlPlayerName(mplayer); } return ret; } - public static String getPlayerName(MPlayer mplayer) + public static String getHtmlPlayerName(MPlayer mplayer) { if (mplayer == null) return "none"; return escapeHtml(mplayer.getName()); diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java index f8ca9799..0564648b 100644 --- a/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java +++ b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java @@ -43,6 +43,20 @@ public class EngineLwc extends EngineAbstract return Factions.get(); } + @Override + public void activate() + { + super.activate(); + LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); + } + + @Override + public void deactivate() + { + super.deactivate(); + LWC.getInstance().getModuleLoader().removeModules(Factions.get()); + } + // -------------------------------------------- // // LISTENER // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java index a1723874..ac5764c5 100644 --- a/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java +++ b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.integration.lwc; -import com.griefcraft.lwc.LWC; -import com.massivecraft.factions.Factions; import com.massivecraft.massivecore.integration.IntegrationAbstract; public class IntegrationLwc extends IntegrationAbstract @@ -22,16 +20,12 @@ public class IntegrationLwc extends IntegrationAbstract public void activate() { EngineLwc.get().activate(); - - LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); } @Override public void deactivate() { EngineLwc.get().deactivate(); - - LWC.getInstance().getModuleLoader().removeModules(Factions.get()); } }