mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-02 14:38:57 +00:00
Functional commented configuration now. Settings still not loaded from
new chatconfig.
This commit is contained in:
1 parent
aa8e816df7
commit
eac1803c8d
4 files changed
+156
-122
No files matched your search
@@ -39,8 +39,6 @@ import com.palmergames.bukkit.towny.Towny;
|
||||
*/
|
||||
|
||||
public class Chat extends JavaPlugin {
|
||||
|
||||
private String version = "2.0";
|
||||
|
||||
private TownyChatPlayerListener TownyPlayerListener;
|
||||
private ChannelsHolder channels;
|
||||
@@ -59,8 +57,6 @@ public class Chat extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
version = this.getDescription().getVersion();
|
||||
|
||||
pm = getServer().getPluginManager();
|
||||
configuration = new ConfigurationHandler(this);
|
||||
channels = new ChannelsHolder(this);
|
||||
@@ -270,13 +266,6 @@ public class Chat extends JavaPlugin {
|
||||
} else if (root.getRoot() == ChatConfigNodes.LAST_RUN_VERSION.getRoot())
|
||||
setNewProperty(root.getRoot(), getLastRunVersion(version));
|
||||
else {
|
||||
System.out.println("**** setDefaults() ***");
|
||||
System.out.println("* Loading: " + root.getRoot());
|
||||
if (chatConfig.get(root.getRoot().toLowerCase()) != null) {
|
||||
System.out.println("* Found: " + chatConfig.get(root.getRoot().toLowerCase()));
|
||||
} else {
|
||||
System.out.println("* Setting Default: " + root.getDefault());
|
||||
}
|
||||
setNewProperty(root.getRoot(), (chatConfig.get(root.getRoot().toLowerCase()) != null) ? chatConfig.get(root.getRoot().toLowerCase()) : root.getDefault());
|
||||
}
|
||||
|
||||
|
||||
@@ -10,72 +10,72 @@ public enum ChatConfigNodes {
|
||||
"version.last_run_version",
|
||||
"",
|
||||
"# This is for showing the changelog on updates. Please do not edit."),
|
||||
// CHATCONFIGCOMMENTS(
|
||||
// "chatconfigcomments",
|
||||
// "",
|
||||
// "",
|
||||
// "############################################################",
|
||||
// "# +------------------------------------------------------+ #",
|
||||
// "# | ChatConfig.yml | #",
|
||||
// "# +------------------------------------------------------+ #",
|
||||
// "############################################################",
|
||||
// "",
|
||||
// "# The formats below will specify the changes made to the player chat when talking.",
|
||||
// "",
|
||||
// "# {worldname} - Displays the world the player is currently in.",
|
||||
// "# {town} - Displays town name if a member of a town.",
|
||||
// "# {townformatted} - Displays town name (if a member of a town) using tag_format.town.",
|
||||
// "# {towntag} - Displays the formated town tag (if a member of a town) using modify_chat.tag_format.town.",
|
||||
// "# {towntagoverride} - Displays the formated town tag (if a member of a town and present) or falls back to the full name (using modify_chat.tag_format.town).",
|
||||
// "",
|
||||
// "# {nation} - Displays nation name if a member of a nation.",
|
||||
// "# {nationformatted} - Displays nation name (if a member of a nation) using tag_format.town.",
|
||||
// "# {nationtag} - Displays the formated nation tag (if a member of a nation) using modify_chat.tag_format.nation.",
|
||||
// "# {nationtagoverride} - Displays the formated nation tag (if a member of a nation and present) or falls back to the full name (using modify_chat.tag_format.nation).",
|
||||
// "",
|
||||
// "# {townytag} - Displays the formated town/nation tag as specified in modify_chat.tag_format.both.",
|
||||
// "# {townyformatted} - Displays the formated full town/nation names as specified in modify_chat.tag_format.both.",
|
||||
// "# {townytagoverride} - Displays the formated town/nation tag (if present) or falls back to the full names (using modify_chat.tag_format.both).",
|
||||
// "",
|
||||
// "# {title} - Towny resident Title.",
|
||||
// "# {surname} - Towny resident Surname.",
|
||||
// "# {townynameprefix} - Towny name prefix taken from the townLevel/nationLevels.",
|
||||
// "# {townynamepostfix} - Towny name postfix taken from the townLevel/nationLevels.",
|
||||
// "# {townyprefix} - Towny resident title, or townynameprefix if no title exists.",
|
||||
// "# {townypostfix} - Towny resident surname, or townynamepostfix if no surname exists",
|
||||
// "",
|
||||
// "# {townycolor} - Towny name colour for king/mayor/resident.",
|
||||
// "# {group} - Players group name pulled from your permissions plugin.",
|
||||
// "# {permuserprefix} - Permission user prefix.",
|
||||
// "# {permusersuffix} - Permission user suffix.",
|
||||
// "# {permgroupprefix} - Permission group prefix.",
|
||||
// "# {permgroupsuffix} - Permission group suffix.",
|
||||
// "# {permprefix} - Permission group and user prefix.",
|
||||
// "# {permsuffix} - Permission group and user suffix.",
|
||||
// "",
|
||||
// "# {playername} - Default player name.",
|
||||
// "# {modplayername} - Modified player name (use if Towny is over writing some other plugins changes).",
|
||||
// "# {msg} - The message sent.",
|
||||
// "",
|
||||
// "# {channelTag} - Defined in the channels entry in Channels.yml.",
|
||||
// "# {msgcolour} - Defined in the channels entry in Channels.yml.",
|
||||
// "",
|
||||
// "# Text colouring",
|
||||
// "# --------------",
|
||||
// "# Black = &0, Navy = &1, Green = &2, Blue = &3, Red = &4",
|
||||
// "# Purple = &5, Gold = &6, LightGray = &7, Gray = &8",
|
||||
// "# DarkPurple = &9, LightGreen = &a, LightBlue = &b",
|
||||
// "# Rose = &c, LightPurple = &d, Yellow = &e, White = &f",
|
||||
// "",
|
||||
// "# Text altering",
|
||||
// "# -------------",
|
||||
// "# Bold = &l, Italics = &o, Underlined = &n,",
|
||||
// "# Magic = &k, Strike = &m, Reset = &r"),
|
||||
// SPAM_TIME(
|
||||
// "spam_time",
|
||||
// "0.5",
|
||||
// "",
|
||||
// "# Spam_time set the minimum time between messages to be flagged as spam"),
|
||||
CHATCONFIGCOMMENTS(
|
||||
"chatconfigcomments",
|
||||
"",
|
||||
"",
|
||||
"############################################################",
|
||||
"# +------------------------------------------------------+ #",
|
||||
"# | ChatConfig.yml | #",
|
||||
"# +------------------------------------------------------+ #",
|
||||
"############################################################",
|
||||
"",
|
||||
"# The formats below will specify the changes made to the player chat when talking.",
|
||||
"",
|
||||
"# {worldname} - Displays the world the player is currently in.",
|
||||
"# {town} - Displays town name if a member of a town.",
|
||||
"# {townformatted} - Displays town name (if a member of a town) using tag_format.town.",
|
||||
"# {towntag} - Displays the formated town tag (if a member of a town) using modify_chat.tag_format.town.",
|
||||
"# {towntagoverride} - Displays the formated town tag (if a member of a town and present) or falls back to the full name (using modify_chat.tag_format.town).",
|
||||
"",
|
||||
"# {nation} - Displays nation name if a member of a nation.",
|
||||
"# {nationformatted} - Displays nation name (if a member of a nation) using tag_format.town.",
|
||||
"# {nationtag} - Displays the formated nation tag (if a member of a nation) using modify_chat.tag_format.nation.",
|
||||
"# {nationtagoverride} - Displays the formated nation tag (if a member of a nation and present) or falls back to the full name (using modify_chat.tag_format.nation).",
|
||||
"",
|
||||
"# {townytag} - Displays the formated town/nation tag as specified in modify_chat.tag_format.both.",
|
||||
"# {townyformatted} - Displays the formated full town/nation names as specified in modify_chat.tag_format.both.",
|
||||
"# {townytagoverride} - Displays the formated town/nation tag (if present) or falls back to the full names (using modify_chat.tag_format.both).",
|
||||
"",
|
||||
"# {title} - Towny resident Title.",
|
||||
"# {surname} - Towny resident Surname.",
|
||||
"# {townynameprefix} - Towny name prefix taken from the townLevel/nationLevels.",
|
||||
"# {townynamepostfix} - Towny name postfix taken from the townLevel/nationLevels.",
|
||||
"# {townyprefix} - Towny resident title, or townynameprefix if no title exists.",
|
||||
"# {townypostfix} - Towny resident surname, or townynamepostfix if no surname exists",
|
||||
"",
|
||||
"# {townycolor} - Towny name colour for king/mayor/resident.",
|
||||
"# {group} - Players group name pulled from your permissions plugin.",
|
||||
"# {permuserprefix} - Permission user prefix.",
|
||||
"# {permusersuffix} - Permission user suffix.",
|
||||
"# {permgroupprefix} - Permission group prefix.",
|
||||
"# {permgroupsuffix} - Permission group suffix.",
|
||||
"# {permprefix} - Permission group and user prefix.",
|
||||
"# {permsuffix} - Permission group and user suffix.",
|
||||
"",
|
||||
"# {playername} - Default player name.",
|
||||
"# {modplayername} - Modified player name (use if Towny is over writing some other plugins changes).",
|
||||
"# {msg} - The message sent.",
|
||||
"",
|
||||
"# {channelTag} - Defined in the channels entry in Channels.yml.",
|
||||
"# {msgcolour} - Defined in the channels entry in Channels.yml.",
|
||||
"",
|
||||
"# Text colouring",
|
||||
"# --------------",
|
||||
"# Black = &0, Navy = &1, Green = &2, Blue = &3, Red = &4",
|
||||
"# Purple = &5, Gold = &6, LightGray = &7, Gray = &8",
|
||||
"# DarkPurple = &9, LightGreen = &a, LightBlue = &b",
|
||||
"# Rose = &c, LightPurple = &d, Yellow = &e, White = &f",
|
||||
"",
|
||||
"# Text altering",
|
||||
"# -------------",
|
||||
"# Bold = &l, Italics = &o, Underlined = &n,",
|
||||
"# Magic = &k, Strike = &m, Reset = &r"),
|
||||
SPAM_TIME(
|
||||
"spam_time",
|
||||
"0.5",
|
||||
"",
|
||||
"# Spam_time set the minimum time between messages to be flagged as spam"),
|
||||
HEROIC_DEATH_TO_IRC("HeroicDeathToIRC",
|
||||
"",
|
||||
"",
|
||||
@@ -109,36 +109,36 @@ public enum ChatConfigNodes {
|
||||
"channel_formats.default",
|
||||
"{channelTag} {permprefix}{playername}{permsuffix}&f:{msgcolour} {msg}",
|
||||
"# DEFAULT channel types."),
|
||||
// TAG_FORMATS(
|
||||
// "tag_formats",
|
||||
// "",
|
||||
// ""),
|
||||
// TAG_FORMATS_WORLD(
|
||||
// "tag_formats.world",
|
||||
// "&f[&f%s&f] "),
|
||||
// TAG_FORMATS_TOWN(
|
||||
// "tag_formats.town",
|
||||
// "&f[&3%s&f] "),
|
||||
// TAG_FORMATS_NATION(
|
||||
// "tag_formats.nation",
|
||||
// "&f[&e%s&f] "),
|
||||
// TAG_FORMATS_BOTH(
|
||||
// "tag_formats.both",
|
||||
// "&f[&6%s&f|&3%s&f] ",
|
||||
// "# First %s is the nation tag, second is the town tag."),
|
||||
// COLOUR(
|
||||
// "colour",
|
||||
// "",
|
||||
// ""),
|
||||
// COLOUR_KING(
|
||||
// "colour.king",
|
||||
// "&6"),
|
||||
// COLOUR_MAYOR(
|
||||
// "colour.mayor",
|
||||
// "&b"),
|
||||
// COLOUR_RESIDENT(
|
||||
// "colour.resident",
|
||||
// "&f"),
|
||||
TAG_FORMATS(
|
||||
"tag_formats",
|
||||
"",
|
||||
""),
|
||||
TAG_FORMATS_WORLD(
|
||||
"tag_formats.world",
|
||||
"&f[&f%s&f] "),
|
||||
TAG_FORMATS_TOWN(
|
||||
"tag_formats.town",
|
||||
"&f[&3%s&f] "),
|
||||
TAG_FORMATS_NATION(
|
||||
"tag_formats.nation",
|
||||
"&f[&e%s&f] "),
|
||||
TAG_FORMATS_BOTH(
|
||||
"tag_formats.both",
|
||||
"&f[&6%s&f|&3%s&f] ",
|
||||
"# First %s is the nation tag, second is the town tag."),
|
||||
COLOUR(
|
||||
"colour",
|
||||
"",
|
||||
""),
|
||||
COLOUR_KING(
|
||||
"colour.king",
|
||||
"&6"),
|
||||
COLOUR_MAYOR(
|
||||
"colour.mayor",
|
||||
"&b"),
|
||||
COLOUR_RESIDENT(
|
||||
"colour.resident",
|
||||
"&f"),
|
||||
MODIFY_CHAT(
|
||||
"modify_chat",
|
||||
"",
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
package com.palmergames.bukkit.TownyChat.config;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
import org.bukkit.configuration.file.YamlRepresenter;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@@ -18,6 +30,10 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
private HashMap<String, String> comments;
|
||||
private File file;
|
||||
|
||||
private final DumperOptions yamlOptions = new DumperOptions();
|
||||
private final Representer yamlRepresenter = new YamlRepresenter();
|
||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
|
||||
public CommentedConfiguration(File file) {
|
||||
|
||||
super();
|
||||
@@ -49,7 +65,12 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
|
||||
// Save the config just like normal
|
||||
try {
|
||||
super.save(file);
|
||||
/*
|
||||
* Doing some saving of our own. We have found that the implementation of YAMLComfiguration used by Bukkit will attempt to
|
||||
* cap strings at 80 characters long, forming new lines in some of our longer strings (channel_formats.)
|
||||
*/
|
||||
this.save(file);
|
||||
|
||||
} catch (Exception e) {
|
||||
saved = false;
|
||||
}
|
||||
@@ -72,8 +93,6 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
|
||||
// Loop through the config lines
|
||||
for (String line : yamlContents) {
|
||||
System.out.println("**** A line of yamlContents: **");
|
||||
System.out.println("* Initial line: " + line);
|
||||
// If the line is a node (and not something like a list value)
|
||||
if (line.contains(": ") || (line.length() > 1 && line.charAt(line.length() - 1) == ':')) {
|
||||
|
||||
@@ -217,4 +236,41 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
}
|
||||
comments.put(path, commentstring.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void save(File file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
Files.createParentDirs(file);
|
||||
|
||||
String data = this.saveToString();
|
||||
|
||||
Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
|
||||
|
||||
try {
|
||||
writer.write(data);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
yamlOptions.setWidth(10000);
|
||||
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
|
||||
|
||||
String header = buildHeader();
|
||||
String dump = yaml.dump(getValues(false));
|
||||
|
||||
|
||||
if (dump.equals(BLANK_CONFIG)) {
|
||||
dump = "";
|
||||
}
|
||||
|
||||
return header + dump;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -161,9 +161,6 @@ public class FileMgmt {
|
||||
|
||||
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
|
||||
|
||||
// BufferedWriter out = new BufferedWriter(new
|
||||
// FileWriter(FileName));
|
||||
|
||||
source.replaceAll("\n", System.getProperty("line.separator"));
|
||||
|
||||
out.write(source);
|
||||
@@ -198,11 +195,6 @@ public class FileMgmt {
|
||||
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
int n;
|
||||
while ((n = reader.read(buffer)) != -1) {
|
||||
System.out.println("**** The outputs of FileMgmt's convertFileToString's 'while' **");
|
||||
System.out.println("* n = " + n);
|
||||
System.out.println("* reader.read(buffer) = " + reader.read(buffer));
|
||||
System.out.println("*");
|
||||
|
||||
writer.write(buffer, 0, n);
|
||||
}
|
||||
reader.close();
|
||||
@@ -216,9 +208,6 @@ public class FileMgmt {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("**** The final return of FileMgmt's convertFileToString before it is parsed into an array by the **");
|
||||
System.out.println("* writer.toString(): " + writer.toString());
|
||||
System.out.println("*");
|
||||
return writer.toString();
|
||||
} else {
|
||||
return "";
|
||||
|
||||
Reference in new issue
Block a user