diff --git a/pom.xml b/pom.xml index 13ccc7f..9f6a986 100644 --- a/pom.xml +++ b/pom.xml @@ -1,66 +1,66 @@ - - 4.0.0 - com.extendedclip.papi.expansion.javascript - javascript-expansion - 1.4.2 - PAPI-Expansion-Javascript - PlaceholderAPI expansion for javascript placeholders - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - placeholderapi - http://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - - org.spigotmc - spigot-api - 1.12.2-R0.1-SNAPSHOT - provided - - - me.clip - placeholderapi - LATEST - provided - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - ${name} - - - true - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - UTF-8 - false - - - - - - - + + 4.0.0 + com.extendedclip.papi.expansion.javascript + javascript-expansion + 1.5.0 + PAPI-Expansion-Javascript + PlaceholderAPI expansion for javascript placeholders + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + + org.spigotmc + spigot-api + 1.14.1-R0.1-SNAPSHOT + provided + + + me.clip + placeholderapi + 2.10.2 + provided + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + ${name} + + + true + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + UTF-8 + false + + + + + + + diff --git a/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptExpansion.java b/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptExpansion.java index 43743e8..6eb747b 100644 --- a/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptExpansion.java @@ -1,237 +1,262 @@ -/* - * - * Javascript-Expansion - * Copyright (C) 2018 Ryan McCarthy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - */ -package com.extendedclip.papi.expansion.javascript; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; - -import me.clip.placeholderapi.expansion.Cacheable; -import me.clip.placeholderapi.expansion.Configurable; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.clip.placeholderapi.util.Msg; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class JavascriptExpansion extends PlaceholderExpansion implements Cacheable, Configurable, Listener { - - private ScriptEngine globalEngine = null; - - private JavascriptPlaceholdersConfig config; - - private final Set scripts = new HashSet<>(); - - private final String VERSION = getClass().getPackage().getImplementationVersion(); - - private static JavascriptExpansion instance; - - public JavascriptExpansion() { - instance = this; - } - - /* - * I am just testing the waters here because there is no command system for expansions... - */ - @EventHandler - public void onCmdExecute(PlayerCommandPreprocessEvent event) { - - String msg = event.getMessage(); - - if (!msg.startsWith("/papijsp")) { - return; - } - - if (!event.getPlayer().hasPermission("placeholderapi.admin")) { - return; - } - - event.setCancelled(true); - - Player p = event.getPlayer(); - - // default command - if (!msg.contains(" ")) { - Msg.msg(p, "&7Javascript expansion v: &f" + getVersion()); - Msg.msg(p, "&7Created by: &f" + getAuthor()); - Msg.msg(p, "&fWiki: &ahttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki"); - Msg.msg(p, "&r"); - Msg.msg(p, "&7/papijsp reload &7- &fReload your javascripts without reloading PlaceholderAPI"); - Msg.msg(p, "&7/papijsp list &7- &fList loaded script identifiers."); - return; - } - - if (msg.equals("/papijsp reload")) { - Msg.msg(p, "&aReloading..."); - int l = this.reloadScripts(); - Msg.msg(p, l + " &7script" + (l == 1 ? "" : "s")+ " loaded"); - return; - } - - if (msg.equals("/papijsp list")) { - List loaded = this.getLoadedIdentifiers(); - Msg.msg(p, loaded.size() + " &7script" + (loaded.size() == 1 ? "" : "s")+ " loaded"); - Msg.msg(p, String.join(", ", loaded)); - return; - } - - event.getPlayer().sendMessage("&cIncorrect usage &7- &f/papijsp"); - } - - @Override - public String getAuthor() { - return "clip"; - } - - @Override - public String getIdentifier() { - return "javascript"; - } - - @Override - public String getPlugin() { - return null; - } - - @Override - public String getVersion() { - return VERSION; - } - - @Override - public boolean register() { - if (globalEngine == null) { - try { - globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "javascript")); - } catch (NullPointerException ex) { - getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'javascript'"); - globalEngine = new ScriptEngineManager().getEngineByName("javascript"); - } - } - - config = new JavascriptPlaceholdersConfig(this); - config.loadPlaceholders(); - return super.register(); - } - - @Override - public void clear() { - scripts.forEach(s -> { - s.saveData(); - s.cleanup(); - }); - scripts.clear(); - globalEngine = null; - instance = null; - } - - @Override - public String onPlaceholderRequest(Player p, String identifier) { - if (p == null) { - return ""; - } - - if (scripts.isEmpty()) { - return null; - } - - for (JavascriptPlaceholder script : scripts) { - if (identifier.startsWith(script.getIdentifier() + "_")) { - identifier = identifier.replace(script.getIdentifier() + "_", ""); - return !identifier.contains(",") ? script.evaluate(p, identifier) : script.evaluate(p, identifier.split(",")); - } else if (identifier.equalsIgnoreCase(script.getIdentifier())) { - return script.evaluate(p); - } - } - return null; - } - - public boolean addJSPlaceholder(JavascriptPlaceholder p) { - if (p == null) { - return false; - } - - if (scripts.isEmpty()) { - scripts.add(p); - return true; - } - - if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier())).findFirst().orElse(null) != null) { - return false; - } - - scripts.add(p); - return true; - } - - public Set getJSPlaceholders() { - return scripts; - } - - public List getLoadedIdentifiers() { - List l = new ArrayList<>(); - scripts.forEach(s -> { - l.add(s.getIdentifier()); - }); - return l; - } - - public JavascriptPlaceholder getJSPlaceholder(String identifier) { - return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst().orElse(null); - } - - public int getAmountLoaded() { - return scripts.size(); - } - - public ScriptEngine getGlobalEngine() { - return globalEngine; - } - - @Override - public Map getDefaults() { - Map def = new HashMap(); - def.put("engine", "javascript"); - return def; - } - - private int reloadScripts() { - scripts.forEach(s -> { - s.saveData(); - s.cleanup(); - }); - scripts.clear(); - config.reload(); - return config.loadPlaceholders(); - } - - public static JavascriptExpansion getInstance() { - return instance; - } -} +/* + * + * Javascript-Expansion + * Copyright (C) 2018 Ryan McCarthy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + */ +package com.extendedclip.papi.expansion.javascript; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; + +import me.clip.placeholderapi.expansion.Cacheable; +import me.clip.placeholderapi.expansion.Configurable; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; + +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class JavascriptExpansion extends PlaceholderExpansion implements Cacheable, Configurable, Listener { + + private ScriptEngine globalEngine = null; + + private JavascriptPlaceholdersConfig config; + + private final Set scripts = new HashSet<>(); + + private final String VERSION = getClass().getPackage().getImplementationVersion(); + + private static JavascriptExpansion instance; + + public JavascriptExpansion() { + instance = this; + } + + private boolean debug = false; + + /* + * I am just testing the waters here because there is no command system for expansions... + */ + @EventHandler + public void onCmdExecute(PlayerCommandPreprocessEvent event) { + + String msg = event.getMessage(); + + if (!msg.startsWith("/papijsp")) { + return; + } + + if (!event.getPlayer().hasPermission("placeholderapi.admin")) { + return; + } + + event.setCancelled(true); + + Player p = event.getPlayer(); + + // default command + if (!msg.contains(" ")) { + msg(p, "&7Javascript expansion v: &f" + getVersion()); + msg(p, "&7Created by: &f" + getAuthor()); + msg(p, "&fWiki: &ahttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki"); + msg(p, "&r"); + msg(p, "&7/papijsp reload &7- &fReload your javascripts without reloading PlaceholderAPI"); + msg(p, "&7/papijsp list &7- &fList loaded script identifiers."); + return; + } + + if (msg.equals("/papijsp reload")) { + msg(p, "&aReloading..."); + int l = this.reloadScripts(); + msg(p, l + " &7script" + (l == 1 ? "" : "s")+ " loaded"); + return; + } + + if (msg.equals("/papijsp list")) { + List loaded = this.getLoadedIdentifiers(); + msg(p, loaded.size() + " &7script" + (loaded.size() == 1 ? "" : "s")+ " loaded"); + msg(p, String.join(", ", loaded)); + return; + } + + event.getPlayer().sendMessage("&cIncorrect usage &7- &f/papijsp"); + } + + public void msg(Player p, String text) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', text)); + } + + @Override + public String getAuthor() { + return "clip"; + } + + @Override + public String getIdentifier() { + return "javascript"; + } + + @Override + public String getPlugin() { + return null; + } + + @Override + public String getVersion() { + return VERSION; + } + + @Override + public boolean register() { + if (globalEngine == null) { + try { + globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "nashorn")); + } catch (NullPointerException ex) { + getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'nashorn'"); + globalEngine = new ScriptEngineManager().getEngineByName("nashorn"); + } + } + debug = (boolean) get("debug", false); + config = new JavascriptPlaceholdersConfig(this); + config.loadPlaceholders(); + if (debug) { + System.out.println("Java version: " + System.getProperty("java.version")); + + ScriptEngineManager manager = new ScriptEngineManager(); + List factories = manager.getEngineFactories(); + System.out.println("displaying all script engine factories:"); + for (ScriptEngineFactory factory : factories) { + System.out.println("Engine name: " + factory.getEngineName()); + System.out.println("version: " + factory.getEngineVersion()); + System.out.println("lang name: " + factory.getLanguageName()); + System.out.println("lang version: " + factory.getLanguageVersion()); + System.out.println("extensions: " + factory.getExtensions()); + System.out.println("mime types: " + factory.getMimeTypes()); + System.out.println("names: " + factory.getNames()); + } + } + return super.register(); + } + + @Override + public void clear() { + scripts.forEach(s -> { + s.saveData(); + s.cleanup(); + }); + scripts.clear(); + globalEngine = null; + instance = null; + } + + @Override + public String onRequest( OfflinePlayer p, String identifier) { + if (p == null) { + return ""; + } + + if (scripts.isEmpty()) { + return null; + } + + for (JavascriptPlaceholder script : scripts) { + if (identifier.startsWith(script.getIdentifier() + "_")) { + identifier = identifier.replace(script.getIdentifier() + "_", ""); + return !identifier.contains(",") ? script.evaluate(p, identifier) : script.evaluate(p, identifier.split(",")); + } else if (identifier.equalsIgnoreCase(script.getIdentifier())) { + return script.evaluate(p); + } + } + return null; + } + + public boolean addJSPlaceholder(JavascriptPlaceholder p) { + if (p == null) { + return false; + } + + if (scripts.isEmpty()) { + scripts.add(p); + return true; + } + + if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier())).findFirst().orElse(null) != null) { + return false; + } + + scripts.add(p); + return true; + } + + public Set getJSPlaceholders() { + return scripts; + } + + public List getLoadedIdentifiers() { + List l = new ArrayList<>(); + scripts.forEach(s -> { + l.add(s.getIdentifier()); + }); + return l; + } + + public JavascriptPlaceholder getJSPlaceholder(String identifier) { + return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst().orElse(null); + } + + public int getAmountLoaded() { + return scripts.size(); + } + + public ScriptEngine getGlobalEngine() { + return globalEngine; + } + + @Override + public Map getDefaults() { + Map def = new HashMap(); + def.put("engine", "javascript"); + def.put("debug", false); + return def; + } + + private int reloadScripts() { + scripts.forEach(s -> { + s.saveData(); + s.cleanup(); + }); + scripts.clear(); + config.reload(); + return config.loadPlaceholders(); + } + + public static JavascriptExpansion getInstance() { + return instance; + } +} diff --git a/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptPlaceholder.java b/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptPlaceholder.java index 26f16ac..01a7952 100644 --- a/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptPlaceholder.java +++ b/src/main/java/com/extendedclip/papi/expansion/javascript/JavascriptPlaceholder.java @@ -1,205 +1,197 @@ -/* - * - * Javascript-Expansion - * Copyright (C) 2018 Ryan McCarthy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - */ -package com.extendedclip.papi.expansion.javascript; - -import java.io.File; -import java.io.IOException; -import java.util.Set; - -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.PlaceholderAPIPlugin; - -public class JavascriptPlaceholder { - - private ScriptEngine engine = null; - - private String identifier; - - private String script; - - private ScriptData data = null; - - private File dataFile; - - private FileConfiguration cfg; - - private final String FILEDIR = PlaceholderAPIPlugin.getInstance().getDataFolder() + File.separator + "javascripts" + File.separator + "javascript_data"; - - public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script) { - Validate.notNull(engine, "ScriptEngine can not be null"); - Validate.notNull(identifier, "Identifier can not be null"); - Validate.notNull(script, "script can not be null"); - this.engine = engine; - this.identifier = identifier; - this.script = script; - File dir = new File(FILEDIR); - - try { - if (!dir.exists()) { - dir.mkdirs(); - } - } catch (SecurityException e) { - e.printStackTrace(); - } - data = new ScriptData(); - dataFile = new File(FILEDIR, identifier + "_data.yml"); - engine.put("Data", data); - engine.put("BukkitServer", Bukkit.getServer()); - engine.put("Expansion", JavascriptExpansion.getInstance()); - engine.put("Placeholder", this); - } - - public String getIdentifier() { - return identifier; - } - - public String getScript() { - return script; - } - - public String evaluate(Player p, String... args) { - String exp = PlaceholderAPI.setPlaceholders(p, script); - - try { - String[] c = null; - - if (args != null && args.length > 0) { - for (int i = 0 ; i < args.length ; i++) { - if (args[i] == null || args[i].isEmpty()) { - continue; - } - - String s = PlaceholderAPI.setBracketPlaceholders(p, args[i]); - - if (c == null) { - c = new String[args.length]; - } - - c[i] = s; - } - } - - if (c == null) { - c = new String[]{}; - } - - engine.put("args", c); - engine.put("BukkitPlayer", p); - Object result = engine.eval(exp); - return result != null ? PlaceholderAPI.setBracketPlaceholders(p, result.toString()) : ""; - - } catch (ScriptException ex) { - ex.printStackTrace(); - } - return "Script error"; - } - - public ScriptData getData() { - // this should never be null but just in case setData(null) is called - if (data == null) { - data = new ScriptData(); - } - return data; - } - - public void setData(ScriptData data) { - this.data = data; - } - - public boolean loadData() { - - cfg = new YamlConfiguration(); - - if (!dataFile.exists()) { - return false; - } - try { - cfg.load(dataFile); - } catch (IOException e) { - e.printStackTrace(); - return false; - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - return false; - } - - final Set keys = cfg.getKeys(true); - - if (keys == null || keys.isEmpty()) { - return false; - } - - if (data == null) { - data = new ScriptData(); - } else { - data.clear(); - } - - keys.stream().forEach(k -> { - data.set(k, cfg.get(k)); - }); - - if (!data.isEmpty()) { - this.setData(data); - return true; - } - return false; - } - - public boolean saveData() { - if (data == null || data.isEmpty()) { - return false; - } - - if (cfg == null) { - return false; - } - - data.getData().entrySet().forEach(e -> { - cfg.set(e.getKey(), e.getValue()); - }); - - try { - cfg.save(dataFile); - return true; - } catch (IOException e) { - return false; - } - } - - public void cleanup() { - if (this.data != null) { - this.data.clear(); - this.data = null; - } - this.cfg = null; - } -} +/* + * + * Javascript-Expansion + * Copyright (C) 2018 Ryan McCarthy + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + */ +package com.extendedclip.papi.expansion.javascript; + +import java.io.File; +import java.io.IOException; +import java.util.Set; +import javax.script.ScriptEngine; +import javax.script.ScriptException; +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +public class JavascriptPlaceholder { + + private ScriptEngine engine = null; + private String identifier; + private String script; + private ScriptData data = null; + private File dataFile; + private FileConfiguration cfg; + + private final String FILEDIR = PlaceholderAPIPlugin.getInstance().getDataFolder() + File.separator + "javascripts"+ File.separator + "javascript_data"; + + public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script) { + Validate.notNull(engine, "ScriptEngine can not be null"); + Validate.notNull(identifier, "Identifier can not be null"); + Validate.notNull(script, "script can not be null"); + this.engine = engine; + this.identifier = identifier; + this.script = script; + File dir = new File(FILEDIR); + + try { + if (!dir.exists()) { + dir.mkdirs(); + } + } catch (SecurityException e) { + e.printStackTrace(); + } + data = new ScriptData(); + dataFile = new File(FILEDIR, identifier + "_data.yml"); + engine.put("Data", data); + engine.put("BukkitServer", Bukkit.getServer()); + engine.put("Expansion", JavascriptExpansion.getInstance()); + engine.put("Placeholder", this); + } + + public String getIdentifier() { + return identifier; + } + + public String getScript() { + return script; + } + + public String evaluate(OfflinePlayer p, String... args) { + String exp = PlaceholderAPI.setPlaceholders(p, script); + + try { + String[] c = null; + + if (args != null && args.length > 0) { + for (int i = 0; i < args.length; i++) { + if (args[i] == null || args[i].isEmpty()) { + continue; + } + + String s = PlaceholderAPI.setBracketPlaceholders(p, args[i]); + + if (c == null) { + c = new String[args.length]; + } + + c[i] = s; + } + } + + if (c == null) { + c = new String[]{}; + } + + engine.put("args", c); + engine.put("BukkitPlayer", p != null && p.isOnline() ? p.getPlayer() : null); + engine.put("OfflinePlayer", p); + Object result = engine.eval(exp); + return result != null ? PlaceholderAPI.setBracketPlaceholders(p, result.toString()) : ""; + } catch (ScriptException ex) { + ex.printStackTrace(); + } + return "Script error"; + } + + public ScriptData getData() { + // this should never be null but just in case setData(null) is called + if (data == null) { + data = new ScriptData(); + } + return data; + } + + public void setData(ScriptData data) { + this.data = data; + } + + public boolean loadData() { + + cfg = new YamlConfiguration(); + + if (!dataFile.exists()) { + return false; + } + try { + cfg.load(dataFile); + } catch (IOException e) { + e.printStackTrace(); + return false; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + return false; + } + + final Set keys = cfg.getKeys(true); + + if (keys == null || keys.isEmpty()) { + return false; + } + + if (data == null) { + data = new ScriptData(); + } else { + data.clear(); + } + + keys.stream().forEach(k -> { + data.set(k, cfg.get(k)); + }); + + if (!data.isEmpty()) { + this.setData(data); + return true; + } + return false; + } + + public boolean saveData() { + if (data == null || data.isEmpty()) { + return false; + } + + if (cfg == null) { + return false; + } + + data.getData().entrySet().forEach(e -> { + cfg.set(e.getKey(), e.getValue()); + }); + + try { + cfg.save(dataFile); + return true; + } catch (IOException e) { + return false; + } + } + + public void cleanup() { + if (this.data != null) { + this.data.clear(); + this.data = null; + } + this.cfg = null; + } +}