From f16907412db441c7efe69712ee8f3e109ce1af0f Mon Sep 17 00:00:00 2001 From: kukelekuuk00 Date: Tue, 12 Feb 2013 20:40:49 +0100 Subject: [PATCH] Add a method to write to the userdata to UserData.java and IUser.java. --- .../src/com/earth2me/essentials/IUser.java | 10 ++++ .../src/com/earth2me/essentials/UserData.java | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 972165a39..00c4f328f 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -1,6 +1,8 @@ package com.earth2me.essentials; import com.earth2me.essentials.commands.IEssentialsCommand; +import java.util.Map; +import java.util.Set; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -52,4 +54,12 @@ public interface IUser extends Player void setLogoutLocation(); Location getLogoutLocation(); + + void setConfigProperty(String node, Object object); + + Set getConfigKeys(); + + Map getConfigMap(); + + Map getConfigMap(String node); } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 023214a13..13a8a9eb5 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -867,6 +867,60 @@ public abstract class UserData extends PlayerExtension implements IConf config.save(); } + public void setConfigProperty(String node, Object object) + { + final String prefix = "info."; + node = prefix+node; + if (object instanceof Map) + { + config.setProperty(node, (Map) object); + } + else if (object instanceof List) + { + config.setProperty(node, (List) object); + } + else if (object instanceof Location) + { + config.setProperty(node, (Location) object); + } + else if (object instanceof ItemStack) + { + config.setProperty(node, (ItemStack) object); + } + else + { + config.setProperty(node, object); + } + config.save(); + } + + public Set getConfigKeys() + { + if (config.isConfigurationSection("info")) + { + return config.getConfigurationSection("info").getKeys(true); + } + return new HashSet(); + } + + public Map getConfigMap() + { + if (config.isConfigurationSection("info")) + { + return config.getConfigurationSection("info").getValues(true); + } + return new HashMap(); + } + + public Map getConfigMap(String node) + { + if (config.isConfigurationSection("info."+node)) + { + return config.getConfigurationSection("info."+node).getValues(true); + } + return new HashMap(); + } + public void save() { config.save();