mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-03 22:21:20 +00:00
First attempts at getting worlds section of chatconfig to populate
(hint: its not pretty)
This commit is contained in:
1 parent
970ef71242
commit
ab59a7e2cf
3 files changed
+110
-80
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -20,14 +19,12 @@ import com.palmergames.bukkit.TownyChat.Command.MuteListCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.UnmuteCommand;
|
||||
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatConfigNodes;
|
||||
import com.palmergames.bukkit.TownyChat.config.CommentedConfiguration;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
|
||||
import com.palmergames.bukkit.TownyChat.listener.HeroicDeathForwarder;
|
||||
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
||||
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
||||
import com.palmergames.bukkit.TownyChat.util.FileMgmt;
|
||||
import com.palmergames.bukkit.config.ConfigNodes;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
|
||||
/**
|
||||
@@ -43,8 +40,7 @@ public class Chat extends JavaPlugin {
|
||||
private TownyChatPlayerListener TownyPlayerListener;
|
||||
private ChannelsHolder channels;
|
||||
private ConfigurationHandler channelsConfig;
|
||||
private static CommentedConfiguration chatConfig, newChatConfig;
|
||||
|
||||
|
||||
protected PluginManager pm;
|
||||
private Towny towny = null;
|
||||
private CraftIRC craftIRC = null;
|
||||
@@ -64,7 +60,7 @@ public class Chat extends JavaPlugin {
|
||||
checkPlugins();
|
||||
|
||||
try {
|
||||
loadNewConfig(getTowny().getDataFolder().getPath() + FileMgmt.fileSeparator() + "settings" + FileMgmt.fileSeparator() + "ChatConfig2.yml", this.getDescription().getVersion());
|
||||
ChatSettings.loadNewConfig(getTowny().getDataFolder().getPath() + FileMgmt.fileSeparator() + "settings" + FileMgmt.fileSeparator() + "ChatConfig2.yml", this.getDescription().getVersion());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -98,21 +94,7 @@ public class Chat extends JavaPlugin {
|
||||
return channelsConfig.loadChannels(getChannelsPath(), "Channels.yml");
|
||||
}
|
||||
|
||||
public static void loadNewConfig(String filepath, String version) throws IOException {
|
||||
|
||||
File file = FileMgmt.CheckYMLExists(new File(filepath));
|
||||
if (file != null) {
|
||||
|
||||
// read the config.yml into memory
|
||||
chatConfig = new CommentedConfiguration(file);
|
||||
if (!chatConfig.load())
|
||||
System.out.print("Failed to load ChatConfig!");
|
||||
|
||||
setDefaults(version, file);
|
||||
|
||||
chatConfig.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
@@ -248,60 +230,5 @@ public class Chat extends JavaPlugin {
|
||||
return heroicDeathListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new chatconfig reading old chatconfig data.
|
||||
*/
|
||||
private static void setDefaults(String version, File file) {
|
||||
|
||||
newChatConfig = new CommentedConfiguration(file);
|
||||
newChatConfig.load();
|
||||
|
||||
for (ChatConfigNodes root : ChatConfigNodes.values()) {
|
||||
if (root.getComments().length > 0)
|
||||
addComment(root.getRoot(), root.getComments());
|
||||
|
||||
if (root.getRoot() == ChatConfigNodes.VERSION.getRoot()) {
|
||||
setNewProperty(root.getRoot(), version);
|
||||
} else if (root.getRoot() == ChatConfigNodes.LAST_RUN_VERSION.getRoot())
|
||||
setNewProperty(root.getRoot(), getLastRunVersion(version));
|
||||
else {
|
||||
setNewProperty(root.getRoot(), (chatConfig.get(root.getRoot().toLowerCase()) != null) ? chatConfig.get(root.getRoot().toLowerCase()) : root.getDefault());
|
||||
}
|
||||
}
|
||||
chatConfig = newChatConfig;
|
||||
newChatConfig = null;
|
||||
}
|
||||
|
||||
public static void addComment(String root, String... comments) {
|
||||
|
||||
newChatConfig.addComment(root.toLowerCase(), comments);
|
||||
}
|
||||
|
||||
private static void setNewProperty(String root, Object value) {
|
||||
|
||||
if (value == null) {
|
||||
value = "";
|
||||
}
|
||||
newChatConfig.set(root.toLowerCase(), value.toString());
|
||||
}
|
||||
|
||||
public static String getLastRunVersion(String currentVersion) {
|
||||
|
||||
return getString(ConfigNodes.LAST_RUN_VERSION.getRoot(), currentVersion);
|
||||
}
|
||||
|
||||
public static String getString(String root, String def) {
|
||||
|
||||
String data = chatConfig.getString(root.toLowerCase(), def);
|
||||
if (data == null) {
|
||||
sendError(root.toLowerCase() + " from ChatConfig.yml");
|
||||
return "";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static void sendError(String msg) {
|
||||
|
||||
System.out.println("[TownyChat] Error could not read " + msg);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user