Archived
0

Changed config naming rules, changed reload behaviour

This commit is contained in:
Pepich
2017-10-16 20:15:33 +02:00
parent c9cbefd3d7
commit 5201d2058d

View File

@@ -36,7 +36,7 @@ import com.redstoner.modules.Module;
@Commands(CommandHolderType.Stream) @Commands(CommandHolderType.Stream)
@AutoRegisterListener @AutoRegisterListener
@Version(major = 4, minor = 1, revision = 0, compatible = 4) @Version(major = 4, minor = 1, revision = 2, compatible = 4)
public final class DataManager implements CoreModule, Listener public final class DataManager implements CoreModule, Listener
{ {
protected final File dataFolder = new File(Main.plugin.getDataFolder(), "data"); protected final File dataFolder = new File(Main.plugin.getDataFolder(), "data");
@@ -45,6 +45,7 @@ public final class DataManager implements CoreModule, Listener
protected ArrayList<String> module_index; protected ArrayList<String> module_index;
int old_hash = 0; int old_hash = 0;
protected HashMap<String, HashMap<String, Boolean>> states = new HashMap<>(); protected HashMap<String, HashMap<String, Boolean>> states = new HashMap<>();
private DataManager previous_instance = null;
protected ArrayList<String> subcommands; protected ArrayList<String> subcommands;
@Override @Override
@@ -61,7 +62,13 @@ public final class DataManager implements CoreModule, Listener
subcommands.add("get"); subcommands.add("get");
subcommands.add("set"); subcommands.add("set");
subcommands.add("remove"); subcommands.add("remove");
if (previous_instance == null)
states.put(getID(Bukkit.getConsoleSender()), new HashMap<String, Boolean>()); states.put(getID(Bukkit.getConsoleSender()), new HashMap<String, Boolean>());
else
{
this.states = previous_instance.states;
previous_instance = null;
}
config_data = JsonManager.getObject(new File(dataFolder, "configs.json")); config_data = JsonManager.getObject(new File(dataFolder, "configs.json"));
if (config_data == null) if (config_data == null)
config_data = new JSONObject(); config_data = new JSONObject();
@@ -73,6 +80,7 @@ public final class DataManager implements CoreModule, Listener
@Override @Override
public void onDisable() public void onDisable()
{ {
previous_instance = this;
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers())
{ {
saveAndUnload(p); saveAndUnload(p);
@@ -652,8 +660,8 @@ public final class DataManager implements CoreModule, Listener
@EventHandler @EventHandler
public void onTabComplete(TabCompleteEvent event) public void onTabComplete(TabCompleteEvent event)
{ {
if (event.getBuffer().toLowerCase().matches("^settings? .*") if (event.getBuffer().toLowerCase().matches("^/?settings? .*")
|| event.getBuffer().toLowerCase().matches("^configs? .*")) || event.getBuffer().toLowerCase().matches("^/?configs? .*"))
{ {
boolean argument_complete = event.getBuffer().endsWith(" "); boolean argument_complete = event.getBuffer().endsWith(" ");
String[] arguments = event.getBuffer().split(" "); String[] arguments = event.getBuffer().split(" ");
@@ -812,6 +820,7 @@ public final class DataManager implements CoreModule, Listener
protected Object getConfigData_(String module, String key) protected Object getConfigData_(String module, String key)
{ {
module = module.toLowerCase();
Object o = config_data.get(module); Object o = config_data.get(module);
if (o == null) if (o == null)
return null; return null;
@@ -827,6 +836,7 @@ public final class DataManager implements CoreModule, Listener
protected ConfigEntry getConfigEntry_(String module, String key) protected ConfigEntry getConfigEntry_(String module, String key)
{ {
module = module.toLowerCase();
Object o = config_data.get(module); Object o = config_data.get(module);
if (o == null) if (o == null)
return null; return null;
@@ -865,6 +875,7 @@ public final class DataManager implements CoreModule, Listener
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected boolean setConfig_(String module, String key, String value) protected boolean setConfig_(String module, String key, String value)
{ {
module = module.toLowerCase();
ConfigEntry entry = getConfigEntry_(module, key); ConfigEntry entry = getConfigEntry_(module, key);
if (entry == null) if (entry == null)
entry = new ConfigEntry(value, null); entry = new ConfigEntry(value, null);
@@ -888,6 +899,7 @@ public final class DataManager implements CoreModule, Listener
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void setConfig_(String module, String key, String value, String[] complete_options) protected void setConfig_(String module, String key, String value, String[] complete_options)
{ {
module = module.toLowerCase();
ConfigEntry entry = new ConfigEntry(value, complete_options); ConfigEntry entry = new ConfigEntry(value, complete_options);
Object o = config_data.get(module); Object o = config_data.get(module);
JSONObject json; JSONObject json;
@@ -923,6 +935,7 @@ public final class DataManager implements CoreModule, Listener
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected boolean removeConfig_(String module, String key) protected boolean removeConfig_(String module, String key)
{ {
module = module.toLowerCase();
if (key == null) if (key == null)
return removeAllConfig_(module); return removeAllConfig_(module);
Object o = config_data.get(module); Object o = config_data.get(module);
@@ -942,6 +955,7 @@ public final class DataManager implements CoreModule, Listener
protected boolean removeAllConfig_(String module) protected boolean removeAllConfig_(String module)
{ {
module = module.toLowerCase();
if (config_data.remove(module) == null) if (config_data.remove(module) == null)
return false; return false;
updateIndex(); updateIndex();
@@ -1003,7 +1017,7 @@ class ConfigEntry
{ {
return "{\"value\":\"" + value + "\",\"complete_options\":" return "{\"value\":\"" + value + "\",\"complete_options\":"
+ (complete_options == null || complete_options.length == 0 ? "[]" + (complete_options == null || complete_options.length == 0 ? "[]"
: "[\"" + String.join("\",\"", complete_options + "\"]")) : "[\"" + String.join("\",\"", complete_options) + "\"]")
+ "}"; + "}";
} }
} }