From b0871b0ee6063a49d41ded005582356ad71b4c52 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 22 Apr 2013 09:51:19 +0200 Subject: [PATCH] Moving prefixes and chat from ConfServer to MConf --- src/com/massivecraft/factions/ConfServer.java | 50 ------------------- src/com/massivecraft/factions/Factions.java | 2 + src/com/massivecraft/factions/Rel.java | 8 +-- .../massivecraft/factions/entity/FPlayer.java | 32 ------------ .../massivecraft/factions/entity/MConf.java | 48 ++++++++++++++++++ .../integration/herochat/AlliesChannel.java | 38 +++++++------- .../integration/herochat/FactionChannel.java | 38 +++++++------- .../integration/herochat/HerochatEngine.java | 4 +- .../listeners/FactionsListenerChat.java | 12 ++--- 9 files changed, 100 insertions(+), 132 deletions(-) diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 67be8905..64deab28 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -2,9 +2,6 @@ package com.massivecraft.factions; import java.util.*; -import org.bukkit.*; -import org.bukkit.event.EventPriority; - import com.massivecraft.mcore.SimpleConfig; import com.massivecraft.mcore.util.MUtil; @@ -25,8 +22,6 @@ public class ConfServer extends SimpleConfig public static List baseCommandAliases = MUtil.list("f"); public static String dburi = "default"; - - // -------------------------------------------- // // DOUBTFULLY CONFIGURABLE DEFAULTS (TODO) // -------------------------------------------- // @@ -62,15 +57,6 @@ public class ConfServer extends SimpleConfig public static double powerFactionMax = 0.0; // if greater than 0, the cap on how much power a faction can have (additional power from players beyond that will act as a "buffer" of sorts) - // -------------------------------------------- // - // PREFIXES - // -------------------------------------------- // - - public static String prefixLeader = "**"; - public static String prefixOfficer = "*"; - public static String prefixMember = "+"; - public static String prefixRecruit = "-"; - // -------------------------------------------- // // CORE // -------------------------------------------- // @@ -90,43 +76,7 @@ public class ConfServer extends SimpleConfig // Disallow joining/leaving/kicking while power is negative public static boolean canLeaveWithNegativePower = true; - // -------------------------------------------- // - // CHAT - // -------------------------------------------- // - // We offer a simple standard way to set the format - public static boolean chatSetFormat = false; - public static EventPriority chatSetFormatAt = EventPriority.LOWEST; - public static String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_tag|rp}§f%1$s> %2$s"; - - // We offer a simple standard way to parse the chat tags - public static boolean chatParseTags = true; - public static EventPriority chatParseTagsAt = EventPriority.LOW; - - // TODO: What is this line and can I get rid of it? - public static String chatTagFormat = "%s"+ChatColor.WHITE; // This one is almost deprecated now right? or is it? - - // HeroChat: The Faction Channel - public static String herochatFactionName = "Faction"; - public static String herochatFactionNick = "F"; - public static String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{factions_roleprefix}&r{color}{factions_title|rp}{sender}{color}] &f{msg}"; - public static ChatColor herochatFactionColor = ChatColor.GREEN; - public static int herochatFactionDistance = 0; - public static boolean herochatFactionIsShortcutAllowed = false; - public static boolean herochatFactionCrossWorld = true; - public static boolean herochatFactionMuted = false; - public static Set herochatFactionWorlds = new HashSet(); - - // HeroChat: The Allies Channel - public static String herochatAlliesName = "Allies"; - public static String herochatAlliesNick = "A"; - public static String herochatAlliesFormat = "{color}[&l{nick}&r&f {factions_relcolor}&l{factions_roleprefix}&r{factions_relcolor}{factions_tag|rp}{sender}{color}] &f{msg}"; - public static ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE; - public static int herochatAlliesDistance = 0; - public static boolean herochatAlliesIsShortcutAllowed = false; - public static boolean herochatAlliesCrossWorld = true; - public static boolean herochatAlliesMuted = false; - public static Set herochatAlliesWorlds = new HashSet(); // -------------------------------------------- // // AUTO LEAVE diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index eb667d8f..87f982c1 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -23,6 +23,7 @@ import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.FPlayerColl; import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConfColl; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.Worldguard; @@ -79,6 +80,7 @@ public class Factions extends MPlugin MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get()); // Initialize Collections + MConfColl.get().init(); FPlayerColl.get().init(); FactionColl.get().init(); BoardColl.get().init(); diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java index 9f353cde..ce595e8e 100644 --- a/src/com/massivecraft/factions/Rel.java +++ b/src/com/massivecraft/factions/Rel.java @@ -136,22 +136,22 @@ public enum Rel { if (this == LEADER) { - return ConfServer.prefixLeader; + return MConf.get().prefixLeader; } if (this == OFFICER) { - return ConfServer.prefixOfficer; + return MConf.get().prefixOfficer; } if (this == MEMBER) { - return ConfServer.prefixMember; + return MConf.get().prefixMember; } if (this == RECRUIT) { - return ConfServer.prefixRecruit; + return MConf.get().prefixRecruit; } return ""; diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index 56f15ca8..fc8bf28d 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -565,38 +565,6 @@ public class FPlayer extends SenderEntity implements EconomyParticipato return this.getColorTo(fplayer)+this.getNameAndTitle(); } - // Chat Tag: - // These are injected into the format of global chat messages. - - public String getChatTag() - { - if ( ! this.hasFaction()) { - return ""; - } - - return String.format(ConfServer.chatTagFormat, this.role.getPrefix()+this.getTag()); - } - - // Colored Chat Tag - public String getChatTag(Faction faction) - { - if ( ! this.hasFaction()) { - return ""; - } - - return this.getRelationTo(faction).getColor()+getChatTag(); - } - - public String getChatTag(FPlayer fplayer) - { - if ( ! this.hasFaction()) - { - return ""; - } - - return this.getColorTo(fplayer)+getChatTag(); - } - // -------------------------------------------- // // RELATION AND RELATION COLORS // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index e6bd0a67..54bbc754 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -1,6 +1,10 @@ package com.massivecraft.factions.entity; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.ChatColor; +import org.bukkit.event.EventPriority; import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.store.Entity; @@ -30,5 +34,49 @@ public class MConf extends Entity public ChatColor colorFriendlyFire = ChatColor.DARK_RED; //public ChatColor colorWilderness = ChatColor.DARK_GREEN; + // -------------------------------------------- // + // PREFIXES + // -------------------------------------------- // + + public String prefixLeader = "**"; + public String prefixOfficer = "*"; + public String prefixMember = "+"; + public String prefixRecruit = "-"; + + // -------------------------------------------- // + // CHAT + // -------------------------------------------- // + + // We offer a simple standard way to set the format + public boolean chatSetFormat = false; + public EventPriority chatSetFormatAt = EventPriority.LOWEST; + public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_tag|rp}§f%1$s> %2$s"; + + // We offer a simple standard way to parse the chat tags + public boolean chatParseTags = true; + public EventPriority chatParseTagsAt = EventPriority.LOW; + + // HeroChat: The Faction Channel + public String herochatFactionName = "Faction"; + public String herochatFactionNick = "F"; + public String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{factions_roleprefix}&r{color}{factions_title|rp}{sender}{color}] &f{msg}"; + public ChatColor herochatFactionColor = ChatColor.GREEN; + public int herochatFactionDistance = 0; + public boolean herochatFactionIsShortcutAllowed = false; + public boolean herochatFactionCrossWorld = true; + public boolean herochatFactionMuted = false; + public Set herochatFactionWorlds = new HashSet(); + + // HeroChat: The Allies Channel + public String herochatAlliesName = "Allies"; + public String herochatAlliesNick = "A"; + public String herochatAlliesFormat = "{color}[&l{nick}&r&f {factions_relcolor}&l{factions_roleprefix}&r{factions_relcolor}{factions_tag|rp}{sender}{color}] &f{msg}"; + public ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE; + public int herochatAlliesDistance = 0; + public boolean herochatAlliesIsShortcutAllowed = false; + public boolean herochatAlliesCrossWorld = true; + public boolean herochatAlliesMuted = false; + public Set herochatAlliesWorlds = new HashSet(); + } \ No newline at end of file diff --git a/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java b/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java index 000e72c7..a5ef80e3 100644 --- a/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java +++ b/src/com/massivecraft/factions/integration/herochat/AlliesChannel.java @@ -5,38 +5,38 @@ import java.util.Set; import org.bukkit.ChatColor; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.MConf; public class AlliesChannel extends FactionsChannelAbstract { public static final Set targetRelations = EnumSet.of(Rel.MEMBER, Rel.ALLY); @Override public Set getTargetRelations() { return targetRelations; } - @Override public String getName() { return ConfServer.herochatAlliesName; } + @Override public String getName() { return MConf.get().herochatAlliesName; } - @Override public String getNick() { return ConfServer.herochatAlliesNick; } - @Override public void setNick(String nick) { ConfServer.herochatAlliesNick = nick; } + @Override public String getNick() { return MConf.get().herochatAlliesNick; } + @Override public void setNick(String nick) { MConf.get().herochatAlliesNick = nick; } - @Override public String getFormat() { return ConfServer.herochatAlliesFormat; } - @Override public void setFormat(String format) { ConfServer.herochatAlliesFormat = format; } + @Override public String getFormat() { return MConf.get().herochatAlliesFormat; } + @Override public void setFormat(String format) { MConf.get().herochatAlliesFormat = format; } - @Override public ChatColor getColor() { return ConfServer.herochatAlliesColor; } - @Override public void setColor(ChatColor color) { ConfServer.herochatAlliesColor = color; } + @Override public ChatColor getColor() { return MConf.get().herochatAlliesColor; } + @Override public void setColor(ChatColor color) { MConf.get().herochatAlliesColor = color; } - @Override public int getDistance() { return ConfServer.herochatAlliesDistance; } - @Override public void setDistance(int distance) { ConfServer.herochatAlliesDistance = distance; } + @Override public int getDistance() { return MConf.get().herochatAlliesDistance; } + @Override public void setDistance(int distance) { MConf.get().herochatAlliesDistance = distance; } - @Override public void addWorld(String world) { ConfServer.herochatAlliesWorlds.add(world); } - @Override public Set getWorlds() { return ConfServer.herochatAlliesWorlds; } - @Override public void setWorlds(Set worlds) { ConfServer.herochatAlliesWorlds = worlds; } + @Override public void addWorld(String world) { MConf.get().herochatAlliesWorlds.add(world); } + @Override public Set getWorlds() { return MConf.get().herochatAlliesWorlds; } + @Override public void setWorlds(Set worlds) { MConf.get().herochatAlliesWorlds = worlds; } - @Override public boolean isShortcutAllowed() { return ConfServer.herochatAlliesIsShortcutAllowed; } - @Override public void setShortcutAllowed(boolean shortcutAllowed) { ConfServer.herochatAlliesIsShortcutAllowed = shortcutAllowed; } + @Override public boolean isShortcutAllowed() { return MConf.get().herochatAlliesIsShortcutAllowed; } + @Override public void setShortcutAllowed(boolean shortcutAllowed) { MConf.get().herochatAlliesIsShortcutAllowed = shortcutAllowed; } - @Override public boolean isCrossWorld() { return ConfServer.herochatAlliesCrossWorld; } - @Override public void setCrossWorld(boolean crossWorld) { ConfServer.herochatAlliesCrossWorld = crossWorld; } + @Override public boolean isCrossWorld() { return MConf.get().herochatAlliesCrossWorld; } + @Override public void setCrossWorld(boolean crossWorld) { MConf.get().herochatAlliesCrossWorld = crossWorld; } - @Override public boolean isMuted() { return ConfServer.herochatAlliesMuted; } - @Override public void setMuted(boolean value) { ConfServer.herochatAlliesMuted = value; } + @Override public boolean isMuted() { return MConf.get().herochatAlliesMuted; } + @Override public void setMuted(boolean value) { MConf.get().herochatAlliesMuted = value; } } diff --git a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java index d74dcc6b..2b237195 100644 --- a/src/com/massivecraft/factions/integration/herochat/FactionChannel.java +++ b/src/com/massivecraft/factions/integration/herochat/FactionChannel.java @@ -6,38 +6,38 @@ import java.util.Set; import org.bukkit.ChatColor; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.MConf; public class FactionChannel extends FactionsChannelAbstract { public static final Set targetRelations = EnumSet.of(Rel.MEMBER); @Override public Set getTargetRelations() { return targetRelations; } - @Override public String getName() { return ConfServer.herochatFactionName; } + @Override public String getName() { return MConf.get().herochatFactionName; } - @Override public String getNick() { return ConfServer.herochatFactionNick; } - @Override public void setNick(String nick) { ConfServer.herochatFactionNick = nick; } + @Override public String getNick() { return MConf.get().herochatFactionNick; } + @Override public void setNick(String nick) { MConf.get().herochatFactionNick = nick; } - @Override public String getFormat() { return ConfServer.herochatFactionFormat; } - @Override public void setFormat(String format) { ConfServer.herochatFactionFormat = format; } + @Override public String getFormat() { return MConf.get().herochatFactionFormat; } + @Override public void setFormat(String format) { MConf.get().herochatFactionFormat = format; } - @Override public ChatColor getColor() { return ConfServer.herochatFactionColor; } - @Override public void setColor(ChatColor color) { ConfServer.herochatFactionColor = color; } + @Override public ChatColor getColor() { return MConf.get().herochatFactionColor; } + @Override public void setColor(ChatColor color) { MConf.get().herochatFactionColor = color; } - @Override public int getDistance() { return ConfServer.herochatFactionDistance; } - @Override public void setDistance(int distance) { ConfServer.herochatFactionDistance = distance; } + @Override public int getDistance() { return MConf.get().herochatFactionDistance; } + @Override public void setDistance(int distance) { MConf.get().herochatFactionDistance = distance; } - @Override public void addWorld(String world) { ConfServer.herochatFactionWorlds.add(world); } - @Override public Set getWorlds() { return new HashSet(ConfServer.herochatFactionWorlds); } - @Override public void setWorlds(Set worlds) { ConfServer.herochatFactionWorlds = worlds; } + @Override public void addWorld(String world) { MConf.get().herochatFactionWorlds.add(world); } + @Override public Set getWorlds() { return new HashSet(MConf.get().herochatFactionWorlds); } + @Override public void setWorlds(Set worlds) { MConf.get().herochatFactionWorlds = worlds; } - @Override public boolean isShortcutAllowed() { return ConfServer.herochatFactionIsShortcutAllowed; } - @Override public void setShortcutAllowed(boolean shortcutAllowed) { ConfServer.herochatFactionIsShortcutAllowed = shortcutAllowed; } + @Override public boolean isShortcutAllowed() { return MConf.get().herochatFactionIsShortcutAllowed; } + @Override public void setShortcutAllowed(boolean shortcutAllowed) { MConf.get().herochatFactionIsShortcutAllowed = shortcutAllowed; } - @Override public boolean isCrossWorld() { return ConfServer.herochatFactionCrossWorld; } - @Override public void setCrossWorld(boolean crossWorld) { ConfServer.herochatFactionCrossWorld = crossWorld; } + @Override public boolean isCrossWorld() { return MConf.get().herochatFactionCrossWorld; } + @Override public void setCrossWorld(boolean crossWorld) { MConf.get().herochatFactionCrossWorld = crossWorld; } - @Override public boolean isMuted() { return ConfServer.herochatFactionMuted; } - @Override public void setMuted(boolean value) { ConfServer.herochatFactionMuted = value; } + @Override public boolean isMuted() { return MConf.get().herochatFactionMuted; } + @Override public void setMuted(boolean value) { MConf.get().herochatFactionMuted = value; } } diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java b/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java index 34ab8b2f..13d41f31 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatEngine.java @@ -8,9 +8,9 @@ import org.bukkit.event.Listener; import com.dthielke.herochat.ChannelChatEvent; import com.dthielke.herochat.Herochat; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.chat.ChatFormatter; +import com.massivecraft.factions.entity.MConf; public class HerochatEngine implements Listener @@ -48,7 +48,7 @@ public class HerochatEngine implements Listener public void onChannelChatEvent(ChannelChatEvent event) { // Should we even parse? - if ( ! ConfServer.chatParseTags) return; + if ( ! MConf.get().chatParseTags) return; String format = event.getFormat(); format = format.replaceAll("&r", "§r"); diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerChat.java b/src/com/massivecraft/factions/listeners/FactionsListenerChat.java index 3a8089a9..8fd23887 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerChat.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerChat.java @@ -6,9 +6,9 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.chat.ChatFormatter; +import com.massivecraft.factions.entity.MConf; import com.massivecraft.mcore.util.SenderUtil; public class FactionsListenerChat implements Listener @@ -36,13 +36,13 @@ public class FactionsListenerChat implements Listener public static void setFormat(AsyncPlayerChatEvent event, EventPriority currentPriority) { // If we are setting the chat format ... - if (!ConfServer.chatSetFormat) return; + if (!MConf.get().chatSetFormat) return; // ... and this is the right priority ... - if (currentPriority != ConfServer.chatSetFormatAt) return; + if (currentPriority != MConf.get().chatSetFormatAt) return; // ... then set the format. - event.setFormat(ConfServer.chatSetFormatTo); + event.setFormat(MConf.get().chatSetFormatTo); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @@ -88,10 +88,10 @@ public class FactionsListenerChat implements Listener public static void parseTags(AsyncPlayerChatEvent event, EventPriority currentPriority) { // If we are setting the chat format ... - if (!ConfServer.chatParseTags) return; + if (!MConf.get().chatParseTags) return; // ... and this is the right priority ... - if (currentPriority != ConfServer.chatParseTagsAt) return; + if (currentPriority != MConf.get().chatParseTagsAt) return; // ... then parse tags a.k.a. "format the format". String format = event.getFormat();