Permalink
Browse files

Updated to 4.8.0. Added cross-world-chat option. Separated user data …

…into multiple files. Added the /ignore alias back in.
  • Loading branch information...
1 parent 8ad84c9 commit 5f2836a44b04ca77ef3e767e2b448ce14dfd1185 @DThielke DThielke committed Mar 27, 2011
View
@@ -1,5 +1,5 @@
name: HeroChat
-version: 4.7.6
+version: 4.8.0
main: com.herocraftonline.dthielke.herochat.HeroChat
description: Provides fully configurable chat channels.
commands:
@@ -24,3 +24,6 @@ commands:
tell:
description: Starts or ends a private conversation
usage: /<command> player
+ ignore:
+ description: Ignores a player
+ usage: /<command> player
@@ -142,6 +142,8 @@ public void onEnable() {
loadPermissions();
loadCraftIRC();
+ checkConflict("iChat");
+ checkConflict("EssentialsChat");
}
@Override
@@ -219,6 +221,19 @@ public void loadCraftIRC() {
}
}
}
+
+ private void checkConflict(String pluginName) {
+ Plugin plugin = this.getServer().getPluginManager().getPlugin(pluginName);
+ if (plugin != null) {
+ if (plugin.isEnabled()) {
+ issueConflictWarning(plugin);
+ }
+ }
+ }
+
+ public void issueConflictWarning(Plugin conflict) {
+ log(Level.WARNING, "Conflicting plugin detected: " + conflict.getDescription().getName() + ". If you experience issues, please try disabling this plugin.");
+ }
public void log(Level level, String msg) {
log.log(level, "[HeroChat] " + msg.replaceAll("§[0-9a-f]", ""));
@@ -89,6 +89,7 @@ public void onPlayerQuit(PlayerEvent event) {
String quitterName = quitter.getName();
plugin.getConfigManager().savePlayer(quitterName);
plugin.getChannelManager().removeFromAll(quitterName);
+ plugin.getChannelManager().setActiveChannel(quitterName, null);
ConversationManager convos = plugin.getConversationManager();
if (convos.hasActive(quitter)) {
@@ -20,6 +20,10 @@ public void onPluginEnabled(PluginEvent event) {
this.plugin.loadPermissions();
} else if (name.equals("CraftIRC")) {
this.plugin.loadCraftIRC();
+ } else if (name.equals("iChat")) {
+ this.plugin.issueConflictWarning(plugin);
+ } else if (name.equals("EssentialsChat")) {
+ this.plugin.issueConflictWarning(plugin);
}
}
@@ -1,9 +0,0 @@
-package com.herocraftonline.dthielke.herochat;
-
-public class HeroChatTest {
-
- public static void main(String[] args) {
-
- }
-
-}
@@ -40,6 +40,7 @@
protected boolean forced;
protected boolean autoJoined;
protected boolean quickMessagable;
+ protected boolean crossWorld;
protected List<String> players;
protected List<String> moderators;
@@ -64,6 +65,7 @@ public Channel(HeroChat plugin) {
forced = false;
autoJoined = false;
quickMessagable = false;
+ crossWorld = true;
players = new ArrayList<String>();
moderators = new ArrayList<String>();
@@ -135,7 +137,9 @@ protected void sendUncheckedMessage(String source, String msg, String format, bo
if (receiver != null) {
if (includeSender || !receiver.getName().equals(source)) {
if (worlds.isEmpty() || worlds.contains(receiver.getWorld().getName())) {
- receiver.sendMessage(formattedMsg);
+ if (crossWorld || !sentByPlayer || (plugin.getServer().getPlayer(source).getWorld().getName().equals(receiver.getWorld().getName()))) {
+ receiver.sendMessage(formattedMsg);
+ }
}
}
}
@@ -339,4 +343,12 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
+ public boolean isCrossWorld() {
+ return crossWorld;
+ }
+
+ public void setCrossWorld(boolean crossWorld) {
+ this.crossWorld = crossWorld;
+ }
+
}
@@ -82,7 +82,11 @@ public Channel getActiveChannel(String name) {
}
public void setActiveChannel(String player, String channel) {
- activeChannels.put(player, channel);
+ if (channel != null) {
+ activeChannels.put(player, channel);
+ } else {
+ activeChannels.remove(player);
+ }
}
public boolean isIgnoring(String ignorer, String ignoree) {
@@ -23,10 +23,11 @@ public IgnoreCommand(HeroChat plugin) {
super(plugin);
name = "Ignore";
description = "Ignores all messages from a player";
- usage = "§e/ch ignore §8[player]";
+ usage = "§e/ch ignore §8[player] §eOR /ignore §8[player]";
minArgs = 0;
maxArgs = 1;
identifiers.add("ch ignore");
+ identifiers.add("ignore");
}
@Override
@@ -14,8 +14,8 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Level;
+import org.bukkit.entity.Player;
import org.bukkit.util.config.Configuration;
import com.herocraftonline.dthielke.herochat.HeroChat;
@@ -27,32 +27,29 @@
public class ConfigManager {
protected HeroChat plugin;
protected File primaryConfigFile;
- protected File usersConfigFile;
- protected Configuration usersConfig;
+ protected File usersConfigFolder;
public ConfigManager(HeroChat plugin) {
this.plugin = plugin;
this.primaryConfigFile = new File(plugin.getDataFolder(), "config.yml");
- this.usersConfigFile = new File(plugin.getDataFolder(), "users.yml");
- this.usersConfig = new Configuration(usersConfigFile);
+ this.usersConfigFolder = new File(plugin.getDataFolder(), "users/");
+ usersConfigFolder.mkdirs();
}
public void reload() throws Exception {
load();
}
public void load() throws Exception {
- checkForConfig();
+ checkConfig();
Configuration config = new Configuration(primaryConfigFile);
config.load();
loadChannels(config);
loadGlobals(config);
-
- usersConfig.load();
}
- private void checkForConfig() {
+ private void checkConfig() {
if (!primaryConfigFile.exists()) {
try {
primaryConfigFile.getParentFile().mkdir();
@@ -131,6 +128,7 @@ private void loadChannels(Configuration config) {
c.setHidden(config.getBoolean(options + "hidden", false));
c.setAutoJoined(config.getBoolean(options + "auto-join", false));
c.setForced(config.getBoolean(options + "forced", false));
+ c.setCrossWorld(config.getBoolean(options + "cross-world-chat", true));
String lists = root + "lists.";
c.setBlacklist(config.getStringList(lists + "bans", null));
@@ -145,48 +143,40 @@ private void loadChannels(Configuration config) {
plugin.getChannelManager().setChannels(list);
}
- @SuppressWarnings("unused")
- private void loadPlayers() {
- Configuration config = new Configuration(usersConfigFile);
- config.load();
- try {
- for (String name : config.getKeys("users")) {
- loadPlayer(name, config);
- }
- } catch (Exception e) {}
- }
-
- public void loadPlayer(String name) throws Exception {
- loadPlayer(name, usersConfig);
- }
-
- private void loadPlayer(String name, Configuration config) throws Exception {
- ChannelManager cm = plugin.getChannelManager();
+ public void loadPlayer(String name) {
+ File userConfigFile = new File(usersConfigFolder, name + ".yml");
try {
- String activeChannel = config.getString("users." + name + ".active-channel", cm.getDefaultChannel().getName());
- Channel a = cm.getChannel(activeChannel);
- if (a != null) {
- cm.setActiveChannel(name, activeChannel);
- } else {
- cm.setActiveChannel(name, cm.getDefaultChannel().getName());
- }
+ Configuration config = new Configuration(userConfigFile);
+ config.load();
+ ChannelManager channelManager = plugin.getChannelManager();
+ try {
+ String activeChannelName = config.getString("active-channel", channelManager.getDefaultChannel().getName());
+ Channel activeChannel = channelManager.getChannel(activeChannelName);
+ if (activeChannel != null) {
+ channelManager.setActiveChannel(name, activeChannelName);
+ } else {
+ channelManager.setActiveChannel(name, channelManager.getDefaultChannel().getName());
+ }
- List<String> joinedChannels = config.getStringList("users." + name + ".joined-channels", null);
- if (joinedChannels.isEmpty()) {
- cm.joinAutoChannels(name);
- } else {
- for (String s : joinedChannels) {
- Channel c = cm.getChannel(s);
- if (c != null) {
- if (!c.getBlacklist().contains(name)) {
- c.addPlayer(name);
+ List<String> joinedChannels = config.getStringList("joined-channels", null);
+ if (joinedChannels.isEmpty()) {
+ channelManager.joinAutoChannels(name);
+ } else {
+ for (String s : joinedChannels) {
+ Channel c = channelManager.getChannel(s);
+ if (c != null) {
+ if (!c.getBlacklist().contains(name)) {
+ c.addPlayer(name);
+ }
}
}
}
+ } catch (Exception e) {
+ channelManager.setActiveChannel(name, channelManager.getDefaultChannel().getName());
+ channelManager.joinAutoChannels(name);
}
} catch (Exception e) {
- cm.setActiveChannel(name, cm.getDefaultChannel().getName());
- cm.joinAutoChannels(name);
+ e.printStackTrace();
}
}
@@ -195,8 +185,10 @@ public void save() throws Exception {
saveGlobals(config);
saveChannels(config);
config.save();
-
- usersConfig.save();
+
+ for (Player player : plugin.getServer().getOnlinePlayers()) {
+ savePlayer(player.getName());
+ }
}
private void saveGlobals(Configuration config) throws Exception {
@@ -231,6 +223,7 @@ private void saveChannels(Configuration config) throws Exception {
config.setProperty(options + "auto-join", c.isAutoJoined());
config.setProperty(options + "local", c instanceof LocalChannel);
config.setProperty(options + "forced", c.isForced());
+ config.setProperty(options + "cross-world-chat", c.isCrossWorld());
String lists = root + "lists.";
config.setProperty(lists + "bans", c.getBlacklist());
@@ -242,32 +235,22 @@ private void saveChannels(Configuration config) throws Exception {
}
}
- @SuppressWarnings("unused")
- private void savePlayers() {
- for (String name : plugin.getChannelManager().getPlayerList()) {
- savePlayer(name, usersConfig);
- }
- usersConfig.save();
- }
-
public void savePlayer(String name) {
- savePlayer(name, usersConfig);
- }
-
- private void savePlayer(String name, Configuration config) {
+ File userConfigFile = new File(usersConfigFolder, name + ".yml");
try {
- ChannelManager cm = plugin.getChannelManager();
- Channel active = cm.getActiveChannel(name);
- List<Channel> joined = cm.getJoinedChannels(name);
- List<String> names = new ArrayList<String>();
- for (Channel c : joined) {
- names.add(c.getName());
+ Configuration config = new Configuration(userConfigFile);
+ ChannelManager configManager = plugin.getChannelManager();
+ Channel active = configManager.getActiveChannel(name);
+ List<Channel> joinedChannels = configManager.getJoinedChannels(name);
+ List<String> joinedChannelNames = new ArrayList<String>();
+ for (Channel channel : joinedChannels) {
+ joinedChannelNames.add(channel.getName());
}
- config.setProperty("users." + name + ".active-channel", active.getName());
- config.setProperty("users." + name + ".joined-channels", names);
+ config.setProperty("active-channel", active.getName());
+ config.setProperty("joined-channels", joinedChannelNames);
+ config.save();
} catch (Exception e) {
e.printStackTrace();
- plugin.log(Level.WARNING, "Error saving player data. Delete your users.yml");
}
}
}

0 comments on commit 5f2836a

Please sign in to comment.