From f9c1ae6422988ba0231f0dfc510d034471302834 Mon Sep 17 00:00:00 2001 From: TheGamersCave Date: Thu, 28 Jan 2016 23:03:19 -0330 Subject: [PATCH 1/5] Add support for both YML and XML based configuration files using a generic Configuration interface. A data-option.txt file is generated based on (previous) configuration if they have it, or created when a new instance of Commons is initialized. Conversion between the two types of data should be handled with ease on startup. Automatic type convertors for ItemStacks, Enchantments, Inventories, Sounds, Titles, Potions, Locations, ParticleEffects, Entities, and so forth will follow in the soon future. --- .../java/com/caved_in/commons/Commons.java | 752 +++++++++++++++++- .../command/commands/UnsilenceCommand.java | 5 +- .../commons/config/CommandConfiguration.java | 8 + .../config/CommonsXmlConfiguration.java | 529 ++++++++++++ .../config/CommonsYamlConfiguration.java | 702 ++++++++++++++++ .../commons/config/Configuration.java | 289 ++++--- .../caved_in/commons/config/DebugConfig.java | 12 + .../commons/config/PremiumConfiguration.java | 90 ++- .../commons/config/SqlConfiguration.java | 27 +- .../caved_in/commons/config/WarpConfig.java | 6 +- .../commons/config/WorldConfiguration.java | 521 +++++++----- .../listeners/BlockBreakPlaceListener.java | 76 +- .../commons/listeners/BlockFormListener.java | 4 +- .../commons/listeners/ChatListener.java | 4 +- .../listeners/CommandPreProcessListener.java | 9 +- .../listeners/EntityDamageListener.java | 20 +- .../listeners/EntityExplodeListener.java | 38 +- .../commons/listeners/FoodChangeListener.java | 27 +- .../commons/listeners/InventoryListener.java | 3 +- .../commons/listeners/ItemDropListener.java | 17 +- .../commons/listeners/PlayerJoinListener.java | 75 +- .../commons/listeners/PlayerKickListener.java | 12 +- .../listeners/PlayerLoginListener.java | 58 +- .../commons/listeners/PlayerQuitListener.java | 8 +- .../commons/listeners/ServerPingListener.java | 22 +- .../configmenu/items/HasSqlBackendItem.java | 4 +- .../items/RegisterCommandsItem.java | 4 +- .../com/caved_in/commons/player/Players.java | 4 +- .../commons/sql/DatabaseConnector.java | 1 - .../com/caved_in/commons/world/Worlds.java | 2 +- .../commons/yml/converter/Config.java | 78 +- src/main/resources/plugin.yml | 4 + 32 files changed, 2779 insertions(+), 632 deletions(-) create mode 100644 src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java create mode 100644 src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java diff --git a/src/main/java/com/caved_in/commons/Commons.java b/src/main/java/com/caved_in/commons/Commons.java index 0c15e72..fa288ff 100644 --- a/src/main/java/com/caved_in/commons/Commons.java +++ b/src/main/java/com/caved_in/commons/Commons.java @@ -3,9 +3,10 @@ import com.caved_in.commons.chat.Chat; import com.caved_in.commons.chat.PrivateMessageManager; import com.caved_in.commons.command.RegisterCommandMethodException; +import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.CommonsYamlConfiguration; import com.caved_in.commons.config.Configuration; import com.caved_in.commons.config.SqlConfiguration; -import com.caved_in.commons.config.WorldConfiguration; import com.caved_in.commons.file.TextFile; import com.caved_in.commons.item.ItemSetManager; import com.caved_in.commons.item.SavedItemManager; @@ -19,6 +20,7 @@ import com.caved_in.commons.sql.ServerDatabaseConnector; import com.caved_in.commons.warp.Warps; import com.caved_in.commons.world.Worlds; +import com.caved_in.commons.yml.InvalidConfigurationException; import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; @@ -30,10 +32,7 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; +import java.util.*; public class Commons extends BukkitPlugin { private static Commons plugin; @@ -45,9 +44,9 @@ public class Commons extends BukkitPlugin { public static final String ITEM_SET_DATA_FOLDER = "plugins/Commons/ItemSets/"; public static final String RULES_LOCATION = "plugins/Commons/rules.txt"; public static final String TELEPORT_MENU_DISABLED_LOCATION = "plugins/Commons/disabled-teleport-menus.txt"; + public static final String DATA_OPTION_FILE = "plugins/Commons/data-option.txt"; - - private static Configuration globalConfig = new Configuration(); + private static Configuration globalConfig = null; /* A(n) instance of the worlds class @@ -130,7 +129,14 @@ public void startup() { //If the SQL Backend is enabled, then register all the database interfaces if (globalConfig.hasSqlBackend()) { - SqlConfiguration sqlConfig = globalConfig.getSqlConfig(); + SqlConfiguration sqlConfig = new SqlConfiguration( + globalConfig.getMysqlHost(), + globalConfig.getMysqlPort(), + globalConfig.getMysqlDatabaseName(), + globalConfig.getMysqlUsername(), + globalConfig.getMysqlPassword(), + globalConfig.trackOnlinePlayerStatus() + ); //Create the database connection database = new ServerDatabaseConnector(sqlConfig); @@ -197,9 +203,14 @@ public String getAuthor() { public void initConfig() { Serializer configSerializer = new Persister(); + File dataOptionFile = new File(DATA_OPTION_FILE); + + File xmlConfigFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); + File ymlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.yml"); + /* - Check if the warps folder exists, and if not + Check if the warps folder exists, and if not then create it! */ File warpsFolder = new File(WARP_DATA_FOLDER); @@ -208,7 +219,7 @@ public void initConfig() { } /* - Create the items folder, where + Create the items folder, where serializable items are stored */ File itemsFolder = new File(ITEM_DATA_FOLDER); @@ -217,7 +228,7 @@ public void initConfig() { } /* - Create the sets folder for the item manager; used to save and load- track and update item sets. + Create the sets folder for the item manager; used to save and load- track and update item sets. */ File itemSetsFolder = new File(ITEM_SET_DATA_FOLDER); if (!itemSetsFolder.exists()) { @@ -253,32 +264,704 @@ public void initConfig() { } /* - Check if the debug data folder exists, and if not then create it! + Check if the debug data folder exists, and if not then create it! */ File debugFolder = new File(DEBUG_DATA_FOLDER); if (!debugFolder.exists()) { debugFolder.mkdirs(); } - try { - File configFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); - if (!configFile.exists()) { - configSerializer.write(new Configuration(), configFile); - } - globalConfig = configSerializer.read(Configuration.class, configFile); - } catch (Exception Ex) { - Ex.printStackTrace(); - } - /* - Initialize the rules class! + Initialize the rules class! */ Rules.init(new File(RULES_LOCATION)); /* - Initialize the Teleport Menu Settings + Initialize the Teleport Menu Settings */ TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); + + boolean freshCommonsInstall = false; + + boolean ymlConfig = false; + + boolean xmlConfig = false; + + boolean convertFromXmlToYml = false; + boolean convertFromYmlToXml = false; + + if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { + freshCommonsInstall = true; + ymlConfig = true; + + Chat.messageConsole( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + Chat.debug("Initialized the config.yml Commons configuration file"); + ymlConfig = true; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + Chat.debug("Unable to initialize the Commons config.yml file"); + } + } + + if (!dataOptionFile.exists()) { + /* + This usually happens when servers are upgrading from a previous + Commons version, to version 1.8.8-3 + + If they have an XML Configuration file and no data option file, + then we're going to make their default the XML Config (that they had previously) + though at the same time inform them of how to convert, and so forth. + */ + if (xmlConfigFile.exists()) { + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=xml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + Chat.messageConsole( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| It seems you've used commons |", + "| before, and have an existing |", + "| configuration file available |", + "| so we'll continue using that. |", + "| |", + "| To Convert to YML config, you |", + "| must change 'data-option.txt' |", + "| inside Commons plugin folder. |", + "| |", + "| Supported options are |", + "| 'commons-data-format=yml' and |", + "| 'commons-data-format=xml' |", + "| which signal your format. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + //They've got an XML File for config. + try { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + } + Chat.debug("Loaded XML based configuration for Commons from Config.xml"); + xmlConfig = true; + return; + } + + /* + If there's no data option file present, and there's a YML file present + then it's likely someone deleted their data-option.txt + + We'll send a nice notice to the console, and inform them of the issues caused + by doing this. Hopefully warning them to not do it again! + + It's also a fail-safe to prevent loading a different configuration file / type + when it's not required. + */ + if (ymlConfigFile.exists()) { + Chat.messageConsole( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you have config.yml |", + "| as your config file, though |", + "| you have no data-option.txt |", + "| |", + "| To properly config and data |", + "| throughout commons we require |", + "| this file be present. It will |", + "| be re-created, though please |", + "| don't remove this file again. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + Chat.debug("Commons configuration has been loaded from config.yml!"); + ymlConfig = true; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + Chat.debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------"); + Plugins.disablePlugin(this); + return; + } + } else { + /* + No data-option.txt and no config file, then we're going to want to + create the config.yml file by default. + + Give them a notice of this functionality, and also explain + that an XML based configuration file is also + available if they choose! + */ + + Chat.messageConsole( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + Chat.debug("Commons has been initialized, and created a 'config.yml' file for managing its configuration!"); + ymlConfig = true; + } catch (InvalidConfigurationException e) { + //INVALID INITIAL CONFIG? + e.printStackTrace(); + } + } + + } else { + /* + In this case they actually have a data-option.txt file present, + so we're going to parse their file for type of chosen configuration + and see if they're converting, or simply loading the previous choice they had made. + + If they're converting, they'll have (for example) commons-data-format=yml + in their data-option.txt and a 'Config.xml' file present in their + plugin data folder (Or vice versa) + */ + String dataFileContents = null; + try { + dataFileContents = FileUtils.readFileToString(dataOptionFile); + } catch (IOException e) { + e.printStackTrace(); + } + + /* + If there's an error while attempting to load their data-option file + then we're going to give them a nice message warning about this, + and then disable commons from loading to prevent any further Errors from happening! + */ + if (dataFileContents == null) { + Chat.messageConsole( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| It appears you have an error |", + "| or invalid format in the file |", + "| 'data-option.txt' inside of |", + "| Commons plugin folder. |", + "| |", + "| Please fix this error/syntax |", + "| or delete it and then restart |", + "| your server to regenerate it. |", + "| |", + "| This file is essential to the |", + "| method Commons uses to convert |", + "|between xml and yml based files |", + "| |", + "| ........ |", + "| Meaning something, or someone |", + "|along the way broke a key part |", + "|of Commons functionality! Oops! |", + "| ........ |", + "| |", + "| No big deal. Follow the steps |", + "| above and everything should go |", + "| back to normal in no time! :) |", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + Plugins.disablePlugin(this); + + return; + } + /* + Though if it makes it this far then we're going to continue with parsing + their chosen config format, and perhaps performing a Conversion! + */ + + String[] option = dataFileContents.split("commons-data-format="); + if (option[1].equalsIgnoreCase("xml")) { + /* + They've chosen to use XMl as the configuration option. + We check if they have a YML based configuration file available + and if they do perform a conversion! + + If they don't have a YML based file, and they have an XML file then they're + simply loading the configuration they had previously. + */ + + if (ymlConfigFile.exists()) { + CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); + Chat.debug("Attempting to convert from YML Config to XML Configuration"); + try { + yamlConfig.load(ymlConfigFile); + Chat.debug("Loaded the previous config.yml file used to configure Commons!"); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + Chat.debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from yml to XML", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } + + CommonsXmlConfiguration cxmlConfig = new CommonsXmlConfiguration(); + + /* + Attempting to move all the values from the previous config.yml + to the new Config.xml file! + + Then after that, we delete the config.yml! (So there's no further confusion :) + */ + alternateCommonsConfig(yamlConfig, cxmlConfig); + globalConfig = cxmlConfig; + + /* + Delete the previous config.yml file to avoid issues! + */ + try { + FileUtils.forceDelete(ymlConfigFile); + Chat.debug("Deleted your previous config.yml file to avoid future issues on startup and confusion."); + } catch (IOException e) { + e.printStackTrace(); + Chat.debug("HUUUUGE MISTAKE! THERE'S AN ERROR DELETING config.yml!"); + } + Chat.debug("Successfully converted your previous config.yml file to an XML based Document (Config.xml)"); + + } else { + /* + In this case, they've chosen XML as their configuration, and don't have + a previous config.yml file to convert from! + + If they have an existing Config.xml file we'll load that bad boy up + and use that as configuration (Meaning they already chose xml as the option before) + though if not, they must have DELETED their configuration file in a previous attempt.... + */ + + if (xmlConfigFile.exists()) { + try { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + Chat.debug("Error loading existing Config.xml file! Pleasure assure your config file is valid, and restart your server to try again!"); + Plugins.disablePlugin(this); + return; + } + + /* + Just to be sure we caught all the errors along the way! + */ + if (globalConfig == null) { + Chat.debug("Error loading existing Config.xml file! Pleasure assure your config file is valid, and restart your server to try again!"); + Plugins.disablePlugin(this); + return; + } + } else { + //todo send notice about not deleting configuration + /* + In this case, they've chosen XMl as their config type, and don't (or no longer) + have their Config.xml file! This is an issue, so we'll sort this out! + */ + globalConfig = new CommonsXmlConfiguration(); + + try { + configSerializer.write(globalConfig, xmlConfigFile); + Chat.debug("Wrote new instance of Config.xml! Did your previous version get deleted?"); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + Chat.debug("Loaded XML based configuration for Commons from Config.xml"); + } else if (option[1].equalsIgnoreCase("yml")) { + + /* + This means they're converting from a previous configuration file + and wish to use YML instead! + + Begin the process! + */ + if (xmlConfigFile.exists()) { + CommonsXmlConfiguration xmlConfiguration = null; + + + try { + xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + Chat.debug( + "====================================================", + "There was an error while processing your Config.xml", + "File inside of plugins/Commons/Config.xml", + "To prevent this from happening again you need", + "To assure the format and syntax of Config.xml", + "Is correct (in accordance to standard XML Documents", + "", + "COMMONS HAS BEEN DISABLED UNTIL THIS ISSUE IS CORRECTED", + "", + "RESTART YOUR SERVER ONCE FIXED TO CONTINUE AS DESIRED!", + "====================================================" + ); + Plugins.disablePlugin(this); + return; + } + + /* + If a yml file already exists and so does an XML then delete the previous + yml file to avoid issues with instancing a new version! (Such as path changes, and such) + */ + if (ymlConfigFile.exists()) { + try { + FileUtils.forceDelete(ymlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + Chat.debug("Transferring content from Config.xml to config.yml"); + alternateCommonsConfig(xmlConfiguration, yamlConfiguration); + Chat.debug("Content transferred from previous Config.xml file!"); + globalConfig = yamlConfiguration; + Chat.debug("Assigned the Commons configuration from the converted Config.xml file!"); + try { + Chat.debug("Attempting to save yaml configuration!"); + yamlConfiguration.init(ymlConfigFile); + Chat.debug("Saved yaml configuration file; Converted from Config.xml"); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + + Chat.debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from XML to yml", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.xml/config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } + + try { + FileUtils.forceDelete(xmlConfigFile); + Chat.debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", + "Your Commons config is now based out of config.yml"); + } catch (IOException e) { + e.printStackTrace(); + Chat.debug("Failed to delete the previous Config.xml from your Commons plugin folder."); + } + + return; + } + + /* + They've previously chosen to use YML as a configuration style and have an existing config file + their plugins/Commons/ folder; Loading this file for configuration. + */ + if (ymlConfigFile.exists()) { + Chat.debug("Beginning to load config.yml"); + + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.load(ymlConfigFile); + globalConfig = yamlConfiguration; + Chat.debug("Loaded the previous instance of config.yml"); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } else { + /* + They've chosen to use yml as their config file, though don't currently have a config.yml file! + Send them a notice saying they've likely deleted their previous version of configuration + and create a new one for them! + */ + Chat.messageConsole( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you no config.yml in |", + "| your Commons plugin folder |", + "| but have yml as your chosen |", + "| data type in data-option.txt |", + "| |", + "| A new config.yml file will be |", + "| generated for you to use, and |", + "| configure accordingly to your |", + "| likings, and servers desire. |", + "| |", + "| To prevent this issue from |", + "| happening again, please don't |", + "| delete your config.yml file! |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + } + + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + //Error initializing initial configutration!? SHOULD NEVER HAPPEN + } + } + + } + } + + private void alternateCommonsConfig(Configuration currentConfig, Configuration targetConfig) { + /* + Configure all the database options! + */ + targetConfig.setMysqlBackend(currentConfig.hasSqlBackend()); + targetConfig.setMysqlHost(currentConfig.getMysqlHost()); + targetConfig.setMysqlPort(currentConfig.getMysqlPort()); + targetConfig.setMysqlDatabaseName(currentConfig.getMysqlDatabaseName()); + targetConfig.setMysqlUsername(currentConfig.getMysqlUsername()); + targetConfig.setMysqlPassword(currentConfig.getMysqlPassword()); + targetConfig.setTrackOnlinePlayerStatus(currentConfig.trackOnlinePlayerStatus()); + targetConfig.setServerName(currentConfig.getServerName()); + + /* + Commands configuration! + */ + targetConfig.registerCommands(currentConfig.registerCommands()); + targetConfig.enableBukkitCommands(currentConfig.enableBukkitCommands()); + targetConfig.enablePluginsCommand(currentConfig.enablePluginsCommand()); + + /* + Server-specific configuration! + */ + targetConfig.enableJoinMessages(currentConfig.enableJoinMessages()); + targetConfig.enableLeaveMessages(currentConfig.enableLeaveMessages()); + targetConfig.enableKickMessages(currentConfig.enableKickMessages()); + targetConfig.externalChatPlugin(currentConfig.hasExternalChatPlugin()); + targetConfig.silenceChat(currentConfig.isChatSilenced()); + + /* + Premium Only mode configuration! + */ + targetConfig.setPremiumOnlyMode(currentConfig.isPremiumOnlyMode()); + targetConfig.setPremiumUserPermission(currentConfig.getPremiumUserPermission()); + targetConfig.premiumOnlyModeKickMessage(currentConfig.getPremiumOnlyModeKickMessage()); + targetConfig.kickNonPremiumPlayerWhenFull(currentConfig.kickNonPremiumPlayerWhenFull()); + targetConfig.setKickNonPremiumMessage(currentConfig.kickNonPremiumMessage()); + + /* + World configuration! + */ + targetConfig.teleportToSpawnOnJoin(currentConfig.teleportToSpawnOnJoin()); + targetConfig.disableWeather(currentConfig.disableWeather()); + targetConfig.disableLightning(currentConfig.disableLightning()); + targetConfig.disableThunder(currentConfig.disableThunder()); + targetConfig.disableIceAccumulation(currentConfig.disableIceAccumulation()); + targetConfig.disableSnowAccumulation(currentConfig.disableSnowAccumulation()); + targetConfig.disableMyceliumSpread(currentConfig.disableMyceliumSpread()); + targetConfig.disableFireSpread(currentConfig.disableFireSpread()); + targetConfig.launchpadPressurePlates(currentConfig.hasLaunchpadPressurePlates()); + targetConfig.enableBlockBreak(currentConfig.enableBlockBreak()); + targetConfig.enableItemDrop(currentConfig.enableItemDrop()); + targetConfig.enableItemPickup(currentConfig.enableItemPickup()); + targetConfig.enableFoodChange(currentConfig.enableFoodChange()); + targetConfig.explosionFireworks(currentConfig.hasExplosionFireworks()); + targetConfig.enableFallDamage(currentConfig.enableFallDamage()); + + /* + Maintenance mode configuration! + */ + targetConfig.setMaintenanceMode(currentConfig.isMaintenanceModeEnabled()); + targetConfig.maintenanceModeKickMessage(currentConfig.maintenanceModeKickMessage()); + targetConfig.maintenanceModeMotd(currentConfig.maintenanceModeMotd()); + + /* + Debug configuration! + */ + targetConfig.enableStackTraceEvent(currentConfig.enableStackTraceEvent()); + targetConfig.enableStackTraceBook(currentConfig.enableStackTraceBook()); + targetConfig.enableStackTraceChat(currentConfig.enableStackTraceChat()); + + /* + Warps Configuration! + */ + targetConfig.enableWarpsMenu(currentConfig.enableWarpsMenu()); } public static class TeleportMenuSettings { @@ -352,7 +1035,7 @@ protected Rules(File f) { file = f; /* - If the rules file doesn't exist, then create it! + If the rules file doesn't exist, then create it! */ if (!file.exists()) { @@ -403,52 +1086,51 @@ private void prepForCustomEnchantments() { } private void registerListeners() { - WorldConfiguration worldConfig = globalConfig.getWorldConfig(); registerListeners(new ChatListener()); debug("&aCreated the Chat Listener"); - if (worldConfig.hasLaunchpadPressurePlates()) { + if (globalConfig.hasLaunchpadPressurePlates()) { registerListeners(new LauncherListener()); // Register fire pad listener if its enabled debug("&aRegistered the fire pad listener"); } - if (worldConfig.isIceSpreadDisabled() || worldConfig.isSnowSpreadDisabled()) { + if (globalConfig.disableIceAccumulation() || globalConfig.disableSnowAccumulation()) { registerListeners(new BlockFormListener()); debug("&aRegistered the block spread listener"); } - if (worldConfig.isMyceliumSpreadDisabled()) { + if (globalConfig.disableMyceliumSpread()) { registerListeners(new BlockSpreadListener()); debug("&aRegistered the mycelium spread listener"); } - if (worldConfig.isThunderDisabled()) { + if (globalConfig.disableThunder()) { registerListeners(new ThungerChangeListener()); debug("&aRegistered the thunder listener"); } - if (worldConfig.isWeatherDisabled()) { + if (globalConfig.disableWeather()) { registerListeners(new WeatherChangeListener()); debug("&aRegistered the Weather-Change listener"); } - if (worldConfig.isLightningDisabled()) { + if (globalConfig.disableLightning()) { registerListeners(new LightningStrikeListener()); debug("&aRegistered the lightning listener"); } - if (worldConfig.isFireSpreadDisabled()) { + if (globalConfig.disableFireSpread()) { registerListeners(new FireSpreadListener()); debug("&aRegistered the fire-spread listener"); } - if (!worldConfig.isItemPickupEnabled()) { + if (!globalConfig.enableItemPickup()) { registerListeners(new ItemPickupListener()); debug("&aRegistered the item-pickup listener"); } - if (!worldConfig.isFoodChangeEnabled()) { + if (!globalConfig.enableFoodChange()) { registerListeners(new FoodChangeListener()); debug("&aRegistered the food change listener"); } diff --git a/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java b/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java index d47e544..6f66e28 100644 --- a/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java +++ b/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java @@ -4,14 +4,13 @@ import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; import com.caved_in.commons.command.Command; -import com.caved_in.commons.config.Configuration; +import com.caved_in.commons.config.CommonsXmlConfiguration; import com.caved_in.commons.permission.Perms; -import com.caved_in.commons.player.Players; import org.bukkit.command.CommandSender; public class UnsilenceCommand { - private static Configuration config = Commons.getInstance().getConfiguration(); + private static CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); public UnsilenceCommand() { diff --git a/src/main/java/com/caved_in/commons/config/CommandConfiguration.java b/src/main/java/com/caved_in/commons/config/CommandConfiguration.java index d99343d..90e5a30 100644 --- a/src/main/java/com/caved_in/commons/config/CommandConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/CommandConfiguration.java @@ -30,4 +30,12 @@ public boolean disableBukkitCommands() { public boolean disablePluginsCommand() { return disablePluginsCommand; } + + public void setDisableBukkitCommands(boolean disableBukkitCommands) { + this.disableBukkitCommands = disableBukkitCommands; + } + + public void setDisablePluginsCommand(boolean disablePluginsCommand) { + this.disablePluginsCommand = disablePluginsCommand; + } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java new file mode 100644 index 0000000..11d91b0 --- /dev/null +++ b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java @@ -0,0 +1,529 @@ +package com.caved_in.commons.config; + +import org.simpleframework.xml.Element; + +/** + * Commons configuration. + */ +public class CommonsXmlConfiguration implements Configuration { + + @Element(name = "mysql-backend") + private boolean sqlBackend = false; + + @Element(name = "database-config", type = SqlConfiguration.class) + private SqlConfiguration sqlConfig; + + @Element(name = "register-commands") + private boolean registerCommands = true; + + @Element(name = "command-config", type = CommandConfiguration.class) + private CommandConfiguration commandConfig; + + @Element(name = "premium-config", type = PremiumConfiguration.class) + private PremiumConfiguration premiumConfig; + + @Element(name = "world-config", type = WorldConfiguration.class) + private WorldConfiguration worldConfig; + + @Element(name = "maintenance-config", type = MaintenanceConfiguration.class) + private MaintenanceConfiguration maintenanceConfig; + + @Element(name = "debug-config", type = DebugConfig.class) + private DebugConfig debugConfig; + + @Element(name = "warp-config", type = WarpConfig.class) + private WarpConfig warpConfig; + + @Element(name = "server-name") + private String serverName = "EDIT THIS"; + + public CommonsXmlConfiguration(@Element(name = "world-config", type = WorldConfiguration.class) WorldConfiguration worldConfig, + @Element(name = "database-config", type = SqlConfiguration.class) SqlConfiguration sqlConfig, + @Element(name = "maintenance-config", type = MaintenanceConfiguration.class) MaintenanceConfiguration maintenanceConfig, + @Element(name = "server-name") String serverName, + @Element(name = "premium-config", type = PremiumConfiguration.class) PremiumConfiguration premiumConfig, + @Element(name = "mysql-backend") boolean sqlBackend, + @Element(name = "register-commands") boolean registerCommands, + @Element(name = "debug-config", type = DebugConfig.class) DebugConfig debugConfig, + @Element(name = "warp-config", type = WarpConfig.class) WarpConfig warpConfig, + @Element(name = "command-config", type = CommandConfiguration.class) CommandConfiguration commandConfig) { + this.worldConfig = worldConfig; + this.sqlConfig = sqlConfig; + this.maintenanceConfig = maintenanceConfig; + this.serverName = serverName; + this.premiumConfig = premiumConfig; + this.sqlBackend = sqlBackend; + this.registerCommands = registerCommands; + this.debugConfig = debugConfig; + this.warpConfig = warpConfig; + this.commandConfig = commandConfig; + } + + public CommonsXmlConfiguration() { + this.worldConfig = new WorldConfiguration(); + this.sqlConfig = new SqlConfiguration(); + this.maintenanceConfig = new MaintenanceConfiguration(); + this.premiumConfig = new PremiumConfiguration(); + this.debugConfig = new DebugConfig(); + this.warpConfig = new WarpConfig(); + this.commandConfig = new CommandConfiguration(); + } + + public MaintenanceConfiguration getMaintenanceConfig() { + return maintenanceConfig; + } + + public WorldConfiguration getWorldConfig() { + return worldConfig; + } + + public SqlConfiguration getSqlConfig() { + return sqlConfig; + } + + @Override + public String getServerName() { + return serverName; + } + + @Override + public void setServerName(String name) { + serverName = name; + } + + public PremiumConfiguration getPremiumConfig() { + return premiumConfig; + } + + @Override + public boolean hasSqlBackend() { + return sqlBackend; + } + + @Override + public void setMysqlBackend(boolean val) { + sqlBackend = val; + } + + @Override + public String getMysqlHost() { + return sqlConfig.getHost(); + } + + @Override + public void setMysqlHost(String host) { + sqlConfig.setMySqlHost(host); + } + + @Override + public String getMysqlDatabaseName() { + return sqlConfig.getDatabase(); + } + + @Override + public void setMysqlDatabaseName(String name) { + sqlConfig.setMySqlDatabaseName(name); + } + + @Override + public String getMysqlPort() { + return sqlConfig.getPort(); + } + + @Override + public void setMysqlPort(String port) { + sqlConfig.setMySqlPort(port); + } + + @Override + public String getMysqlUsername() { + return sqlConfig.getUsername(); + } + + @Override + public void setMysqlUsername(String username) { + sqlConfig.setMySqlUsername(username); + } + + @Override + public String getMysqlPassword() { + return sqlConfig.getPassword(); + } + + @Override + public void setMysqlPassword(String password) { + sqlConfig.getPassword(); + } + + @Override + public boolean trackOnlinePlayerStatus() { + return sqlConfig.trackPlayerOnlineStatus(); + } + + @Override + public void setTrackOnlinePlayerStatus(boolean val) { + sqlConfig.setTrackPlayerOnlineStatus(val); + } + + @Override + public boolean registerCommands() { + return registerCommands; + } + + @Override + public void registerCommands(boolean val) { + registerCommands = val; + } + + @Override + public boolean enableBukkitCommands() { + return !commandConfig.disableBukkitCommands(); + } + + @Override + public void enableBukkitCommands(boolean val) { + commandConfig.setDisableBukkitCommands(!val); + } + + @Override + public boolean enablePluginsCommand() { + return !commandConfig.disablePluginsCommand(); + } + + @Override + public void enablePluginsCommand(boolean val) { + commandConfig.setDisablePluginsCommand(!val); + } + + @Override + public boolean enableJoinMessages() { + return worldConfig.hasJoinMessages(); + } + + @Override + public void enableJoinMessages(boolean val) { + worldConfig.setEnableJoinMessages(val); + } + + @Override + public boolean enableLeaveMessages() { + return worldConfig.hasLeaveMessages(); + } + + @Override + public void enableLeaveMessages(boolean val) { + worldConfig.setEnableLeaveMessages(val); + } + + @Override + public boolean enableKickMessages() { + return worldConfig.isEnableKickMessages(); + } + + @Override + public void enableKickMessages(boolean val) { + worldConfig.setEnableKickMessages(val); + } + + @Override + public boolean hasExternalChatPlugin() { + return worldConfig.hasExternalChatHandler(); + } + + @Override + public void externalChatPlugin(boolean val) { + worldConfig.setExternalChatHandler(val); + } + + @Override + public boolean isChatSilenced() { + return worldConfig.isChatSilenced(); + } + + @Override + public void silenceChat(boolean val) { + worldConfig.setChatSilenced(val); + } + + @Override + public boolean isPremiumOnlyMode() { + return premiumConfig.isPremiumMode(); + } + + @Override + public void setPremiumOnlyMode(boolean val) { + premiumConfig.setPremiumMode(val); + } + + @Override + public String getPremiumUserPermission() { + return premiumConfig.getPremiumOnlyPermission(); + } + + @Override + public void setPremiumUserPermission(String perm) { + premiumConfig.setPremiumOnlyPermission(perm); + } + + @Override + public String getPremiumOnlyModeKickMessage() { + return premiumConfig.getKickMessage(); + } + + @Override + public void premiumOnlyModeKickMessage(String msg) { + premiumConfig.setKickMessage(msg); + } + + @Override + public boolean kickNonPremiumPlayerWhenFull() { + return premiumConfig.isKickNonPremiumPlayerWhenFull(); + } + + @Override + public void kickNonPremiumPlayerWhenFull(boolean val) { + premiumConfig.setKickNonPremiumPlayerWhenFull(val); + } + + @Override + public String kickNonPremiumMessage() { + return premiumConfig.getKickNonPremiumMessage(); + } + + @Override + public void setKickNonPremiumMessage(String msg) { + premiumConfig.setKickNonPremiumMessage(msg); + } + + @Override + public boolean teleportToSpawnOnJoin() { + return worldConfig.isTeleportToSpawnOnJoin(); + } + + @Override + public void teleportToSpawnOnJoin(boolean val) { + worldConfig.setTeleportToSpawnOnJoin(val); + } + + @Override + public boolean disableWeather() { + return worldConfig.isWeatherDisabled(); + } + + @Override + public void disableWeather(boolean val) { + worldConfig.setDisableWeather(val); + } + + @Override + public boolean disableLightning() { + return worldConfig.isLightningDisabled(); + } + + @Override + public void disableLightning(boolean val) { + worldConfig.setDisableLightning(val); + } + + @Override + public boolean disableThunder() { + return worldConfig.isThunderDisabled(); + } + + @Override + public void disableThunder(boolean val) { + worldConfig.setDisableThunder(val); + } + + @Override + public boolean disableIceAccumulation() { + return worldConfig.isIceSpreadDisabled(); + } + + @Override + public void disableIceAccumulation(boolean val) { + worldConfig.setDisableIceAccumulation(val); + } + + @Override + public boolean disableSnowAccumulation() { + return worldConfig.isSnowSpreadDisabled(); + } + + @Override + public void disableSnowAccumulation(boolean val) { + worldConfig.isSnowSpreadDisabled(); + } + + @Override + public boolean disableMyceliumSpread() { + return worldConfig.isMyceliumSpreadDisabled(); + } + + @Override + public void disableMyceliumSpread(boolean val) { + worldConfig.setDisableMyceliumSpread(val); + } + + @Override + public boolean disableFireSpread() { + return worldConfig.isFireSpreadDisabled(); + } + + @Override + public void disableFireSpread(boolean val) { + worldConfig.setDisableFireSpread(val); + } + + @Override + public boolean hasLaunchpadPressurePlates() { + return worldConfig.hasLaunchpadPressurePlates(); + } + + @Override + public void launchpadPressurePlates(boolean val) { + worldConfig.setLaunchpadPressurePlates(val); + } + + @Override + public boolean enableBlockBreak() { + return worldConfig.isBlockBreakEnabled(); + } + + @Override + public void enableBlockBreak(boolean val) { + worldConfig.setEnableBlockBreak(val); + } + + @Override + public boolean enableItemPickup() { + return worldConfig.isItemPickupEnabled(); + } + + @Override + public void enableItemPickup(boolean val) { + worldConfig.setEnableItemPickup(val); + } + + @Override + public boolean enableItemDrop() { + return worldConfig.isItemDropEnabled(); + } + + @Override + public void enableItemDrop(boolean val) { + worldConfig.isItemDropEnabled(); + } + + @Override + public boolean enableFoodChange() { + return worldConfig.isFoodChangeEnabled(); + } + + @Override + public void enableFoodChange(boolean val) { + worldConfig.setEnableFoodChange(val); + } + + @Override + public boolean hasExplosionFireworks() { + return worldConfig.hasExplosionFireworks(); + } + + @Override + public void explosionFireworks(boolean val) { + worldConfig.setExplosionFireworks(val); + } + + @Override + public boolean enableFallDamage() { + return worldConfig.hasFallDamage(); + } + + @Override + public void enableFallDamage(boolean val) { + worldConfig.setFallDamage(val); + } + + @Override + public boolean isMaintenanceModeEnabled() { + return maintenanceConfig.isMaintenanceMode(); + } + + @Override + public void setMaintenanceMode(boolean val) { + maintenanceConfig.setMaintenanceMode(val); + } + + @Override + public String maintenanceModeKickMessage() { + return maintenanceConfig.getKickMessage(); + } + + @Override + public void maintenanceModeKickMessage(String msg) { + maintenanceConfig.setKickMessage(msg); + } + + @Override + public String maintenanceModeMotd() { + return maintenanceConfig.getMotd(); + } + + @Override + public void maintenanceModeMotd(String msg) { + maintenanceConfig.setMotd(msg); + } + + @Override + public boolean enableStackTraceEvent() { + return debugConfig.isStackTraceEvent(); + } + + @Override + public void enableStackTraceEvent(boolean val) { + debugConfig.setStackTraceEvent(val); + } + + @Override + public boolean enableStackTraceBook() { + return debugConfig.isStackTraceBooks(); + } + + @Override + public void enableStackTraceBook(boolean val) { + debugConfig.setStackTraceBooks(val); + } + + @Override + public boolean enableStackTraceChat() { + return debugConfig.isStackTraceChat(); + } + + @Override + public void enableStackTraceChat(boolean val) { + debugConfig.setStackTraceChat(val); + } + + @Override + public boolean enableWarpsMenu() { + return warpConfig.isWarpsMenuEnabled(); + } + + @Override + public void enableWarpsMenu(boolean val) { + warpConfig.setWarpsMenuEnabled(val); + } + + public DebugConfig getDebugConfig() { + return debugConfig; + } + + public WarpConfig getWarpConfig() { + return warpConfig; + } + + public CommandConfiguration getCommandConfig() { + return commandConfig; + } +} diff --git a/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java b/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java new file mode 100644 index 0000000..5b68ae2 --- /dev/null +++ b/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java @@ -0,0 +1,702 @@ +package com.caved_in.commons.config; + +import com.caved_in.commons.yml.*; + +@SerializeOptions( + configHeader = { + "Any concerns regarding the purpose of configuration nodes", + "What they affect, or how they change aspects of the API", + "are described under the Wiki on Commons GitHub page." + }, + configMode = ConfigMode.DEFAULT +) + +public class CommonsYamlConfiguration extends YamlConfig implements Configuration { + @Path("Database.Mysql.enable") + private boolean sqlBackend = false; + + @Path("Database.Mysql.host") + private String mysqlHost = "localhost"; + + @Path("Database.Mysql.port") + private String mysqlPort = "3306"; + + @Path("Database.Mysql.database-name") + private String mysqlDatabaseName = "minecraft"; + + @Path("Database.Mysql.username") + private String mysqlUsername = "username"; + + @Path("Database.Mysql.password") + private String mysqlPassword; + + @Path("Database.track-online-status") + //todo implement optional var in config. If its not present it's ok. + private boolean trackOnlinePlayerStatus = false; + + @Path("Database.server-name") + @Comments({ + "Used in the chosen database implementation", + "to identify the server.", + }) + private String serverName = "EDIT THIS"; + + @Path("Commands.register-commands") + @Comments({ + "By default Commons includes a plethora of commands", + "Designed to aid you in your server ventures!", + "Though if you're not requiring use of these commands, and", + "Wish to use Commons for only its API Features, then change this value to", + "False" + }) + private boolean registerCommands = true; + + @Path("Commands.enable-bukkit-commands") + @Comments({ + "Allows usage of 'Bukkit:' prefixed commands", + "Changing this value to false disable these commands", + "from being used on your server." + }) + private boolean bukkitCommands = true; + + @Path("Commands.enable-plugins-command") + @Comments({ + "Changing the value of this option to false", + "Stops players from using '/plugins' on your server." + }) + private boolean pluginsCommand = true; + + @Path("Server.enable-join-message") + @Comments({ + "Whether or not to enable join messages", + "in chat when a player joins the server" + }) + private boolean enableJoinMessages = true; + + @Path("Server.enable-leave-messages") + @Comments({ + "Whether or not to enable leave messages", + "in chat when a player leaves the server" + }) + private boolean enableLeaveMessages = true; + + @Path("Server.enable-kick-messages") + @Comments({ + "Whether or not to show 'player was kicked'", + "messages in chat, when a player is kicked." + }) + private boolean enableKickMessages = true; + + @Path("Server.external-chat-plugin") + @Comments({ + "Determines whether or not Commons should", + "handle chat formatting (in a very basic manner)", + "or to hand it off to another plugin" + }) + private boolean externalChatPlugin = true; + + @Path("Server.silence-chat") + @Comments({ + "When enabled, only players with 'commons.silence.bypass'", + "in their permissions will be able to talk" + }) + private boolean silenceChat = false; + + @Path("Server.Premium.kick-when-full") + @Comments({ + "Determines whether or not to kick a non-premium player", + "when a premium user joins the server, and the server", + "is currently full.", + "Premium users are determined by the 'premium-user-permission'", + "node below." + }) + private boolean kickNonPremiumPlayerWhenFull = false; + + @Path("Server.Premium.kick-when-full-message") + @Comments({ + "Message to display to non-premium users after being", + "kicked to make room for a premium user." + }) + private String kickNonPremiumMessage = "&eYou were kicked to make room for a Premium User. Sorry."; + + + @Path("Server.Premium.premium-only-mode") + @Comments({ + "When enabled, only users with premium (defined by a permission below)", + "will be able to join your server.", + "Those without premium will be displayed a configurable message" + }) + private boolean premiumOnlyMode = false; + + @Path("Server.Premium.premium-only-mode-kick-message") + @Comment("This message will be shown to non-premium users who join during premium-only mode.") + private String premiumOnlyModeKickMessage = "&cThis server is currently in premium mode"; + + @Path("Server.Premium.premium-user-permission") + @Comments({ + "Used to restrict access during premium only mode", + "To players who have this permission" + }) + private String premiumModePermission = "commons.premiumuser"; + + @Path("Server.Worlds.disable-weather") + @Comments({ + "All the options beneath this are used to control", + "various aspects of the worlds across all", + "the enabled worlds on your server.", + "", + "If you have another plugin enabled that also", + "Modifies any of these values, there's no guarantee", + "that they will function as expected." + }) + private boolean disableWeather = false; + + @Path("Server.Worlds.teleport-to-spawn-on-join") + @Comment("When enabled, players will be teleported to their world spawn when joining the server") + private boolean teleportToSpawnOnJoin = false; + + + @Path("Server.Worlds.disable-lightning") + @Comment("Changes whether or not lightning will strike during a storm") + private boolean disableLightning = false; + + @Path("Server.Worlds.disable-thunder") + @Comment("Changes whether or not thunder will rumble during a storm") + private boolean disableThunder = false; + + @Path("Server.Worlds.disable-ice-accumulation") + @Comment("Changes whether or not ice will spread and accumulate") + private boolean disableIceAccumulation = false; + + @Path("Server.Worlds.disable-snow-accumulation") + @Comment("Changes whether or not snow will accumulate while snowing") + private boolean disableSnowAccumulation = false; + + @Path("Server.Worlds.disable-mycelium-spread") + @Comment("Changes whether or not mycelium will infect blocks around it, and spread") + private boolean disableMyceliumSpread = false; + + @Path("Server.Worlds.disable-fire-spread") + @Comment("Changes whether or not fire will spread") + private boolean disableFireSpread = false; + + @Path("Server.Worlds.launchpad-pressure-plates") + @Comment("When enabled it changes pressure plates into launch pads, like many server hubs have") + private boolean launchpadPressurePlates = false; + + @Path("Server.Worlds.enable-block-break") + @Comment("Changes whether or not blocks can be broken outside of creative") + private boolean enableBlockBreak = true; + + @Path("Server.Worlds.enable-item-pickup") + @Comment("Changes if players are able to pick up items that are dropped") + private boolean enableItemPickup = true; + + @Path("Server.Worlds.enable-item-drop") + @Comment("Changes if players are able to drop their items") + private boolean enableItemDrop = true; + + @Path("Server.Worlds.enable-food-change") + @Comments("Changes whether or not players lose their hunger while playing") + private boolean enableFoodChange = true; + + @Path("Server.Worlds.fireworks-on-explosion") + @Comment("When enabled, fireworks will launch and explode whenever a regular explosion happens") + private boolean explosionFireworks = false; + + @Path("Server.Worlds.enable-fall-damage") + @Comment("Changes whether or not players take fall damage") + private boolean enableFallDamage = true; + + @Path("Server.Maintenance-Mode.enabled") + @Comments({ + "Maintenance mode enables admins, operators, and users", + "with the 'commons.maintenance.join' permission", + "to join while the server is undergoing maintenance.", + "At the same time, it keeps all players not permitted, out, until", + "maintenance is complete!", + "", + "Customizable MOTD (Server list message)", + "and kick message are available to notify users of", + "maintenance!" + }) + private boolean maintenanceMode = false; + + @Path("Server.Maintenance-Mode.kick-message") + private String maintenanceModeKickMessage = "&cThis server is currently undergoing maintenance; Sorry for the inconvenience"; + + @Path("Server.Maintenance-Mode.motd") + private String maintenanceModeMotd = "&aThis server is currently undergoing maintenance"; + + @Path("Debug.stack-trace-event") + @Comments({ + "Debug options are very useful to developers!", + "Providing a StackTraceEvent, and various output options", + "which enable in-game players in debug mode", + "and developers hooking the event to", + "track, handle, change, and work with the headaches of bug fixing", + "in an easy and fun manner!" + }) + private boolean stackTraceEvent = true; + + @Path("Debug.stack-trace-book") + @Comments({ + "When enabled in conjunction with stack-trace-event", + "users in debug mode will receive a Book in-game outlining", + "The error which happened, and it's stack trace written in the books", + "pages!" + }) + private boolean stackTraceBook = false; + + @Path("Debug.stack-trace-chat") + @Comments({ + "When enabled in conjunction with stack-trace-event,", + "users in debug mode will receive the stack trace in their chat;", + "so eyes don't have to stray from game, to console, to code.", + "", + "Note: Can quickly and painfully spam your chat if to many", + "errors occur" + }) + private boolean stackTraceChat = true; + + @Path("Warps.enable-gui") + @Comments({ + "When enabled, it provides an interactive GUI", + "of which players can use to teleport and interact", + "with warps.", + "", + "If it's disabled, and a player does /warps, they'll receive", + "a chat based menu with pages detailing the available warps." + }) + private boolean enableWarpsMenu = true; + + @Override + public boolean hasSqlBackend() { + return sqlBackend; + } + + @Override + public void setMysqlBackend(boolean val) { + sqlBackend = val; + } + + @Override + public String getMysqlHost() { + return mysqlHost; + } + + @Override + public void setMysqlHost(String host) { + mysqlHost = host; + } + + @Override + public String getMysqlDatabaseName() { + return mysqlDatabaseName; + } + + @Override + public void setMysqlDatabaseName(String name) { + mysqlDatabaseName = name; + } + + @Override + public String getMysqlPort() { + return mysqlPort; + } + + @Override + public void setMysqlPort(String port) { + mysqlPort = port; + } + + @Override + public String getMysqlUsername() { + return mysqlUsername; + } + + @Override + public void setMysqlUsername(String username) { + mysqlUsername = username; + } + + @Override + public String getMysqlPassword() { + return mysqlPassword; + } + + @Override + public void setMysqlPassword(String password) { + mysqlPassword = password; + } + + @Override + public boolean trackOnlinePlayerStatus() { + return trackOnlinePlayerStatus; + } + + @Override + public void setTrackOnlinePlayerStatus(boolean val) { + trackOnlinePlayerStatus = val; + } + + @Override + public String getServerName() { + return serverName; + } + + @Override + public void setServerName(String name) { + serverName = name; + } + + @Override + public boolean registerCommands() { + return registerCommands; + } + + @Override + public void registerCommands(boolean val) { + registerCommands = val; + } + + @Override + public boolean enableBukkitCommands() { + return bukkitCommands; + } + + @Override + public void enableBukkitCommands(boolean val) { + bukkitCommands = val; + } + + @Override + public boolean enablePluginsCommand() { + return pluginsCommand; + } + + @Override + public void enablePluginsCommand(boolean val) { + pluginsCommand = val; + } + + @Override + public boolean enableJoinMessages() { + return enableJoinMessages; + } + + @Override + public void enableJoinMessages(boolean val) { + enableJoinMessages = val; + } + + @Override + public boolean enableLeaveMessages() { + return enableLeaveMessages; + } + + @Override + public void enableLeaveMessages(boolean val) { + enableLeaveMessages = val; + } + + @Override + public boolean enableKickMessages() { + return enableKickMessages; + } + + @Override + public void enableKickMessages(boolean val) { + enableKickMessages = val; + } + + @Override + public boolean hasExternalChatPlugin() { + return externalChatPlugin; + } + + @Override + public void externalChatPlugin(boolean val) { + externalChatPlugin = val; + } + + @Override + public boolean isChatSilenced() { + return silenceChat; + } + + @Override + public void silenceChat(boolean val) { + silenceChat = val; + } + + @Override + public boolean isPremiumOnlyMode() { + return premiumOnlyMode; + } + + @Override + public void setPremiumOnlyMode(boolean val) { + premiumOnlyMode = val; + } + + @Override + public String getPremiumUserPermission() { + return premiumModePermission; + } + + @Override + public void setPremiumUserPermission(String perm) { + premiumModePermission = perm; + } + + @Override + public String getPremiumOnlyModeKickMessage() { + return premiumOnlyModeKickMessage; + } + + @Override + public void premiumOnlyModeKickMessage(String msg) { + premiumOnlyModeKickMessage = msg; + } + + @Override + public boolean kickNonPremiumPlayerWhenFull() { + return kickNonPremiumPlayerWhenFull; + } + + @Override + public void kickNonPremiumPlayerWhenFull(boolean val) { + kickNonPremiumPlayerWhenFull = val; + } + + @Override + public String kickNonPremiumMessage() { + return kickNonPremiumMessage; + } + + @Override + public void setKickNonPremiumMessage(String msg) { + kickNonPremiumMessage = msg; + } + + @Override + public boolean teleportToSpawnOnJoin() { + return teleportToSpawnOnJoin; + } + + @Override + public void teleportToSpawnOnJoin(boolean val) { + teleportToSpawnOnJoin = val; + } + + @Override + public boolean disableWeather() { + return disableWeather; + } + + @Override + public void disableWeather(boolean val) { + disableWeather = val; + } + + @Override + public boolean disableLightning() { + return disableLightning; + } + + @Override + public void disableLightning(boolean val) { + disableLightning = val; + } + + @Override + public boolean disableThunder() { + return disableThunder; + } + + @Override + public void disableThunder(boolean val) { + disableThunder = val; + } + + @Override + public boolean disableIceAccumulation() { + return disableIceAccumulation; + } + + @Override + public void disableIceAccumulation(boolean val) { + disableIceAccumulation = val; + } + + @Override + public boolean disableSnowAccumulation() { + return disableSnowAccumulation; + } + + @Override + public void disableSnowAccumulation(boolean val) { + disableSnowAccumulation = val; + } + + @Override + public boolean disableMyceliumSpread() { + return disableMyceliumSpread; + } + + @Override + public void disableMyceliumSpread(boolean val) { + disableMyceliumSpread = val; + } + + @Override + public boolean disableFireSpread() { + return disableFireSpread; + } + + @Override + public void disableFireSpread(boolean val) { + disableFireSpread = val; + } + + @Override + public boolean hasLaunchpadPressurePlates() { + return launchpadPressurePlates; + } + + @Override + public void launchpadPressurePlates(boolean val) { + launchpadPressurePlates = val; + } + + @Override + public boolean enableBlockBreak() { + return enableBlockBreak; + } + + @Override + public void enableBlockBreak(boolean val) { + enableBlockBreak = val; + } + + @Override + public boolean enableItemPickup() { + return enableItemPickup; + } + + @Override + public void enableItemPickup(boolean val) { + enableItemPickup = val; + } + + @Override + public boolean enableItemDrop() { + return enableItemDrop; + } + + @Override + public void enableItemDrop(boolean val) { + enableItemDrop = val; + } + + @Override + public boolean enableFoodChange() { + return enableFoodChange; + } + + @Override + public void enableFoodChange(boolean val) { + enableFoodChange = val; + } + + @Override + public boolean hasExplosionFireworks() { + return explosionFireworks; + } + + @Override + public void explosionFireworks(boolean val) { + explosionFireworks = val; + } + + @Override + public boolean enableFallDamage() { + return enableFallDamage; + } + + @Override + public void enableFallDamage(boolean val) { + enableFallDamage = val; + } + + @Override + public boolean isMaintenanceModeEnabled() { + return maintenanceMode; + } + + @Override + public void setMaintenanceMode(boolean val) { + maintenanceMode = val; + } + + @Override + public String maintenanceModeKickMessage() { + return maintenanceModeKickMessage; + } + + @Override + public void maintenanceModeKickMessage(String msg) { + maintenanceModeKickMessage = msg; + } + + @Override + public String maintenanceModeMotd() { + return maintenanceModeMotd; + } + + @Override + public void maintenanceModeMotd(String msg) { + maintenanceModeMotd = msg; + } + + @Override + public boolean enableStackTraceEvent() { + return stackTraceEvent; + } + + @Override + public void enableStackTraceEvent(boolean val) { + stackTraceEvent = val; + } + + @Override + public boolean enableStackTraceBook() { + return stackTraceBook; + } + + @Override + public void enableStackTraceBook(boolean val) { + stackTraceBook = val; + } + + @Override + public boolean enableStackTraceChat() { + return stackTraceChat; + } + + @Override + public void enableStackTraceChat(boolean val) { + stackTraceChat = val; + } + + @Override + public boolean enableWarpsMenu() { + return enableWarpsMenu; + } + + @Override + public void enableWarpsMenu(boolean val) { + enableWarpsMenu = val; + } +} diff --git a/src/main/java/com/caved_in/commons/config/Configuration.java b/src/main/java/com/caved_in/commons/config/Configuration.java index c7e3163..3f70fa7 100644 --- a/src/main/java/com/caved_in/commons/config/Configuration.java +++ b/src/main/java/com/caved_in/commons/config/Configuration.java @@ -1,119 +1,176 @@ package com.caved_in.commons.config; -import org.simpleframework.xml.Element; - -/** - * Commons configuration. - */ -public class Configuration { - - @Element(name = "mysql-backend") - private boolean sqlBackend = false; - - @Element(name = "database-config", type = SqlConfiguration.class) - private SqlConfiguration sqlConfig; - - @Element(name = "register-commands") - private boolean registerCommands = true; - - @Element(name = "command-config", type = CommandConfiguration.class) - private CommandConfiguration commandConfig; - - @Element(name = "premium-config", type = PremiumConfiguration.class) - private PremiumConfiguration premiumConfig; - - @Element(name = "world-config", type = WorldConfiguration.class) - private WorldConfiguration worldConfig; - - @Element(name = "maintenance-config", type = MaintenanceConfiguration.class) - private MaintenanceConfiguration maintenanceConfig; - - @Element(name = "debug-config", type = DebugConfig.class) - private DebugConfig debugConfig; - - @Element(name = "warp-config", type = WarpConfig.class) - private WarpConfig warpConfig; - - @Element(name = "server-name") - private String serverName = "EDIT THIS"; - - public Configuration(@Element(name = "world-config", type = WorldConfiguration.class) WorldConfiguration worldConfig, - @Element(name = "database-config", type = SqlConfiguration.class) SqlConfiguration sqlConfig, - @Element(name = "maintenance-config", type = MaintenanceConfiguration.class) MaintenanceConfiguration maintenanceConfig, - @Element(name = "server-name") String serverName, - @Element(name = "premium-config", type = PremiumConfiguration.class) PremiumConfiguration premiumConfig, - @Element(name = "mysql-backend") boolean sqlBackend, - @Element(name = "register-commands") boolean registerCommands, - @Element(name = "debug-config", type = DebugConfig.class) DebugConfig debugConfig, - @Element(name = "warp-config", type = WarpConfig.class) WarpConfig warpConfig, - @Element(name = "command-config", type = CommandConfiguration.class) CommandConfiguration commandConfig) { - this.worldConfig = worldConfig; - this.sqlConfig = sqlConfig; - this.maintenanceConfig = maintenanceConfig; - this.serverName = serverName; - this.premiumConfig = premiumConfig; - this.sqlBackend = sqlBackend; - this.registerCommands = registerCommands; - this.debugConfig = debugConfig; - this.warpConfig = warpConfig; - this.commandConfig = commandConfig; - } - - public Configuration() { - this.worldConfig = new WorldConfiguration(); - this.sqlConfig = new SqlConfiguration(); - this.maintenanceConfig = new MaintenanceConfiguration(); - this.premiumConfig = new PremiumConfiguration(); - this.debugConfig = new DebugConfig(); - this.warpConfig = new WarpConfig(); - this.commandConfig = new CommandConfiguration(); - } - - public MaintenanceConfiguration getMaintenanceConfig() { - return maintenanceConfig; - } - - public WorldConfiguration getWorldConfig() { - return worldConfig; - } - - public SqlConfiguration getSqlConfig() { - return sqlConfig; - } - - public String getServerName() { - return serverName; - } - - public PremiumConfiguration getPremiumConfig() { - return premiumConfig; - } - - public boolean hasSqlBackend() { - return sqlBackend; - } - - public boolean registerCommands() { - return registerCommands; - } - - public DebugConfig getDebugConfig() { - return debugConfig; - } - - public WarpConfig getWarpConfig() { - return warpConfig; - } - - public void setSqlBackend(boolean sqlBackend) { - this.sqlBackend = sqlBackend; - } - - public void setRegisterCommands(boolean registerCommands) { - this.registerCommands = registerCommands; - } - - public CommandConfiguration getCommandConfig() { - return commandConfig; - } +public interface Configuration { + + public boolean hasSqlBackend(); + + public void setMysqlBackend(boolean val); + + public String getMysqlHost(); + + public void setMysqlHost(String host); + + public String getMysqlDatabaseName(); + + public void setMysqlDatabaseName(String name); + + public String getMysqlPort(); + + public void setMysqlPort(String port); + + public String getMysqlUsername(); + + public void setMysqlUsername(String username); + + public String getMysqlPassword(); + + public void setMysqlPassword(String password); + + public boolean trackOnlinePlayerStatus(); + + public void setTrackOnlinePlayerStatus(boolean val); + + public String getServerName(); + + public void setServerName(String name); + + public boolean registerCommands(); + + public void registerCommands(boolean val); + + public boolean enableBukkitCommands(); + + public void enableBukkitCommands(boolean val); + + public boolean enablePluginsCommand(); + + public void enablePluginsCommand(boolean val); + + public boolean enableJoinMessages(); + + public void enableJoinMessages(boolean val); + + public boolean enableLeaveMessages(); + + public void enableLeaveMessages(boolean val); + + public boolean enableKickMessages(); + + public void enableKickMessages(boolean val); + + public boolean hasExternalChatPlugin(); + + public void externalChatPlugin(boolean val); + + public boolean isChatSilenced(); + + public void silenceChat(boolean val); + + public boolean isPremiumOnlyMode(); + + public void setPremiumOnlyMode(boolean val); + + public String getPremiumUserPermission(); + + public void setPremiumUserPermission(String perm); + + public String getPremiumOnlyModeKickMessage(); + + public void premiumOnlyModeKickMessage(String msg); + + public boolean kickNonPremiumPlayerWhenFull(); + + public void kickNonPremiumPlayerWhenFull(boolean val); + + public String kickNonPremiumMessage(); + + public void setKickNonPremiumMessage(String msg); + + public boolean teleportToSpawnOnJoin(); + + public void teleportToSpawnOnJoin(boolean val); + + public boolean disableWeather(); + + public void disableWeather(boolean val); + + public boolean disableLightning(); + + public void disableLightning(boolean val); + + public boolean disableThunder(); + + public void disableThunder(boolean val); + + public boolean disableIceAccumulation(); + + public void disableIceAccumulation(boolean val); + + public boolean disableSnowAccumulation(); + + public void disableSnowAccumulation(boolean val); + + public boolean disableMyceliumSpread(); + + public void disableMyceliumSpread(boolean val); + + public boolean disableFireSpread(); + + public void disableFireSpread(boolean val); + + public boolean hasLaunchpadPressurePlates(); + + public void launchpadPressurePlates(boolean val); + + public boolean enableBlockBreak(); + + public void enableBlockBreak(boolean val); + + public boolean enableItemPickup(); + + public void enableItemPickup(boolean val); + + public boolean enableItemDrop(); + + public void enableItemDrop(boolean val); + + public boolean enableFoodChange(); + + public void enableFoodChange(boolean val); + + public boolean hasExplosionFireworks(); + + public void explosionFireworks(boolean val); + + public boolean enableFallDamage(); + + public void enableFallDamage(boolean val); + + public boolean isMaintenanceModeEnabled(); + + public void setMaintenanceMode(boolean val); + + public String maintenanceModeKickMessage(); + + public void maintenanceModeKickMessage(String msg); + + public String maintenanceModeMotd(); + + public void maintenanceModeMotd(String msg); + + public boolean enableStackTraceEvent(); + + public void enableStackTraceEvent(boolean val); + + public boolean enableStackTraceBook(); + + public void enableStackTraceBook(boolean val); + + public boolean enableStackTraceChat(); + + public void enableStackTraceChat(boolean val); + + public boolean enableWarpsMenu(); + + public void enableWarpsMenu(boolean val); } diff --git a/src/main/java/com/caved_in/commons/config/DebugConfig.java b/src/main/java/com/caved_in/commons/config/DebugConfig.java index 569d254..df89048 100644 --- a/src/main/java/com/caved_in/commons/config/DebugConfig.java +++ b/src/main/java/com/caved_in/commons/config/DebugConfig.java @@ -33,4 +33,16 @@ public boolean isStackTraceBooks() { public boolean isStackTraceEvent() { return stackTraceEvent; } + + public void setStackTraceEvent(boolean stackTraceEvent) { + this.stackTraceEvent = stackTraceEvent; + } + + public void setStackTraceBooks(boolean stackTraceBooks) { + this.stackTraceBooks = stackTraceBooks; + } + + public void setStackTraceChat(boolean stackTraceChat) { + this.stackTraceChat = stackTraceChat; + } } diff --git a/src/main/java/com/caved_in/commons/config/PremiumConfiguration.java b/src/main/java/com/caved_in/commons/config/PremiumConfiguration.java index 5fbf030..e514fd4 100644 --- a/src/main/java/com/caved_in/commons/config/PremiumConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/PremiumConfiguration.java @@ -4,40 +4,80 @@ import org.simpleframework.xml.Element; public class PremiumConfiguration { + @Element(name = "premium_enable") + private boolean premiumMode = false; - @Element(name = "premium_kick_message") - private String premiumKickMessage = "&cThis server is currently in premium mode; Donate to join the server"; + @Element(name = "premium_kick_message") + private String premiumKickMessage = "&cThis server is currently in premium mode; Donate to join the server"; - @Element(name = "premium_enable") - private boolean premiumMode = false; + @Element(name = "premium_only_permission", required = false) + private String premiumOnlyPermission = "commons.premiumuser"; - public PremiumConfiguration(@Element(name = "premium_kick_message") String premiumKickMessage, @Element(name = "premium_enable") boolean premiumEnable) { - this.premiumKickMessage = premiumKickMessage; - this.premiumMode = premiumEnable; - } + @Element(name = "kick_non_premium_player_when_full", required = false) + private boolean kickNonPremiumPlayerWhenFull = false; - public PremiumConfiguration() { + @Element(name = "kick_non_premium_message", required = false) + private String kickNonPremiumMessage = "&eYou were kicked to make room for a Premium User. Sorry."; - } + public PremiumConfiguration( + @Element(name = "premium_kick_message") String premiumKickMessage, + @Element(name = "premium_enable") boolean premiumEnable, + @Element(name = "premium_only_permission", required = false) String premiumOnlyPermission, + @Element(name = "kick_non_premium_player_when_full", required = false) boolean kickNonPremiumPlayerWhenFull, + @Element(name = "kick_non_premium_message", required = false) String kickNonPremiumMessage + ) { + this.premiumKickMessage = premiumKickMessage; + this.premiumMode = premiumEnable; + this.premiumOnlyPermission = premiumOnlyPermission; + this.kickNonPremiumPlayerWhenFull = kickNonPremiumPlayerWhenFull; + this.kickNonPremiumMessage = kickNonPremiumMessage; + } - public boolean isPremiumMode() { - return this.premiumMode; - } + public PremiumConfiguration() { - public void setPremiumMode(boolean premium) { - this.premiumMode = premium; - } + } - public void togglePremiumMode() { - this.premiumMode = !this.premiumMode; - } + public boolean isPremiumMode() { + return this.premiumMode; + } - public String getKickMessage() { - return StringUtil.formatColorCodes(this.premiumKickMessage); - } + public void setPremiumMode(boolean premium) { + this.premiumMode = premium; + } - public void setKickMessage(String message) { - this.premiumKickMessage = message; - } + public void togglePremiumMode() { + this.premiumMode = !this.premiumMode; + } + public String getKickMessage() { + return StringUtil.formatColorCodes(this.premiumKickMessage); + } + + public void setKickMessage(String message) { + this.premiumKickMessage = message; + } + + public String getPremiumOnlyPermission() { + return premiumOnlyPermission; + } + + public void setPremiumOnlyPermission(String premiumOnlyPermission) { + this.premiumOnlyPermission = premiumOnlyPermission; + } + + public boolean isKickNonPremiumPlayerWhenFull() { + return kickNonPremiumPlayerWhenFull; + } + + public void setKickNonPremiumPlayerWhenFull(boolean kickNonPremiumPlayerWhenFull) { + this.kickNonPremiumPlayerWhenFull = kickNonPremiumPlayerWhenFull; + } + + public String getKickNonPremiumMessage() { + return kickNonPremiumMessage; + } + + public void setKickNonPremiumMessage(String kickNonPremiumMessage) { + this.kickNonPremiumMessage = kickNonPremiumMessage; + } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/config/SqlConfiguration.java b/src/main/java/com/caved_in/commons/config/SqlConfiguration.java index 58d976a..0695dae 100644 --- a/src/main/java/com/caved_in/commons/config/SqlConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/SqlConfiguration.java @@ -1,10 +1,11 @@ package com.caved_in.commons.config; +import com.caved_in.commons.yml.YamlConfig; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root -public class SqlConfiguration { +public class SqlConfiguration extends YamlConfig { @Element(name = "MySqlHost") private String mySqlHost = "localhost"; @@ -59,4 +60,28 @@ public String getPassword() { public boolean trackPlayerOnlineStatus() { return trackPlayerOnlineStatus; } + + public void setMySqlHost(String mySqlHost) { + this.mySqlHost = mySqlHost; + } + + public void setMySqlPort(String mySqlPort) { + this.mySqlPort = mySqlPort; + } + + public void setMySqlDatabaseName(String mySqlDatabaseName) { + this.mySqlDatabaseName = mySqlDatabaseName; + } + + public void setMySqlUsername(String mySqlUsername) { + this.mySqlUsername = mySqlUsername; + } + + public void setMySqlPassword(String mySqlPassword) { + this.mySqlPassword = mySqlPassword; + } + + public void setTrackPlayerOnlineStatus(boolean trackPlayerOnlineStatus) { + this.trackPlayerOnlineStatus = trackPlayerOnlineStatus; + } } diff --git a/src/main/java/com/caved_in/commons/config/WarpConfig.java b/src/main/java/com/caved_in/commons/config/WarpConfig.java index cb7a7e6..2ed9984 100644 --- a/src/main/java/com/caved_in/commons/config/WarpConfig.java +++ b/src/main/java/com/caved_in/commons/config/WarpConfig.java @@ -1,15 +1,17 @@ package com.caved_in.commons.config; +import com.caved_in.commons.yml.Path; +import com.caved_in.commons.yml.YamlConfig; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root(name = "warp-config") -public class WarpConfig { +public class WarpConfig extends YamlConfig { @Element(name = "enable-warps-menu") + @Path("enable-warps-menu") private boolean warpsMenu = true; public WarpConfig() { - } public WarpConfig(@Element(name = "enable-warps-menu") boolean warpsMenu) { diff --git a/src/main/java/com/caved_in/commons/config/WorldConfiguration.java b/src/main/java/com/caved_in/commons/config/WorldConfiguration.java index 8cb4f24..f75d464 100644 --- a/src/main/java/com/caved_in/commons/config/WorldConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/WorldConfiguration.java @@ -5,217 +5,312 @@ @Root(name = "world-config") public class WorldConfiguration { - @Element(name = "disable-weather") - private boolean disableWeather = true; - - @Element(name = "disable-lightning") - private boolean disableLightning = true; - - @Element(name = "disable-thunder") - private boolean disableThunder = true; - - @Element(name = "disable-ice-accumulation") - private boolean disableIceAccumulation = true; - - @Element(name = "disable-snow-accumulation") - private boolean disableSnowAccumulation = true; - - @Element(name = "disable-mycelium-spread") - private boolean disableMyceliumSpread = true; - - @Element(name = "disable-fire-spread") - private boolean disableFireSpread = true; - - @Element(name = "launchpad-pressure-plates") - private boolean launchpadPressurePlates = false; - - @Element(name = "enable-join-messages") - private boolean enableJoinMessages = true; - - @Element(name = "enable-leave-messages") - private boolean enableLeaveMessages = true; - - @Element(name = "enable-block-break") - private boolean enableBlockBreak = true; - - @Element(name = "enable-item-pickup") - private boolean enableItemPickup = true; - - @Element(name = "enable-item-drop") - private boolean enableItemDrop = true; - - @Element(name = "enable-food-change") - private boolean enableFoodChange = true; - - @Element(name = "external-chat-plugin") - private boolean externalChatHandler = true; - - @Element(name = "explosion-fireworks") - private boolean explosionFireworks = true; - - @Element(name = "enable-fall-damage") - private boolean fallDamage = true; - - private boolean silenceChat = false; - - public WorldConfiguration(@Element(name = "disable-weather") boolean disableWeather, - @Element(name = "disable-lightning") boolean disableLightning, - @Element(name = "disable-thunder") boolean disableThunder, - @Element(name = "disable-ice-accumulation") boolean disableIceAccumulation, - @Element(name = "disable-snow-accumulation") boolean disableSnowAccumulation, - @Element(name = "disable-mycelium-spread") boolean disableMyceliumSpread, - @Element(name = "launchpad-pressure-plates") boolean launchpadPressurePlates, - @Element(name = "enable-join-messages") boolean enableJoinMessages, - @Element(name = "enable-leave-messages") boolean enableLeaveMessages, - @Element(name = "external-chat-plugin") boolean externalChatHandler, - @Element(name = "enable-block-break") boolean enableBlockBreak, - @Element(name = "enable-item-pickup") boolean enableItemPickup, - @Element(name = "enable-item-drop") boolean enableItemDrop, - @Element(name = "enable-food-change") boolean enableFoodChange, - @Element(name = "disable-fire-spread") boolean disableFireSpread, - @Element(name = "explosion-fireworks") boolean explosionFireworks, - @Element(name = "enable-fall-damage") boolean fallDamage - ) { - this.disableIceAccumulation = disableIceAccumulation; - this.disableWeather = disableWeather; - this.disableLightning = disableLightning; - this.disableMyceliumSpread = disableMyceliumSpread; - this.disableSnowAccumulation = disableSnowAccumulation; - this.disableThunder = disableThunder; - this.launchpadPressurePlates = launchpadPressurePlates; - this.enableJoinMessages = enableJoinMessages; - this.enableLeaveMessages = enableLeaveMessages; - this.externalChatHandler = externalChatHandler; - this.enableBlockBreak = enableBlockBreak; - this.enableItemDrop = enableItemDrop; - this.enableItemPickup = enableItemPickup; - this.enableFoodChange = enableFoodChange; - this.disableFireSpread = disableFireSpread; - this.explosionFireworks = explosionFireworks; - this.fallDamage = fallDamage; - } - - public WorldConfiguration() { - } - - public boolean isWeatherDisabled() { - return this.disableWeather; - } - - public boolean isChatSilenced() { - return this.silenceChat; - } - - public void setChatSilenced(boolean silenced) { - this.silenceChat = silenced; - } - - public boolean isLightningDisabled() { - return this.disableLightning; - } - - public boolean isThunderDisabled() { - return this.disableThunder; - } - - /** - * @return true if ice spread is disabled, false otherwise - */ - public boolean isIceSpreadDisabled() { - return this.disableIceAccumulation; - } - - /** - * @return true if snow spread is disabled, false otherwise - */ - public boolean isSnowSpreadDisabled() { - return this.disableSnowAccumulation; - } - - /** - * @return true if mycelium spread is disabled, false otherwise - */ - public boolean isMyceliumSpreadDisabled() { - return this.disableMyceliumSpread; - } - - /** - * Whether or not this server has "fire-pad" pressure plates - * - * @return true if pressure plates are fire-pads, false otherwise - */ - public boolean hasLaunchpadPressurePlates() { - return this.launchpadPressurePlates; - } - - /** - * @return true if join messages are enabled, false otherwise - */ - public boolean hasJoinMessages() { - return enableJoinMessages; - } - - /** - * Whether or not leave messages are enabled - * - * @return - */ - public boolean hasLeaveMessages() { - return enableLeaveMessages; - } - - /** - * @return true if there's an external plugin for chat handling, false if commons is handling - */ - public boolean hasExternalChatHandler() { - return this.externalChatHandler; - } - - /** - * @return true if players can break blocks, false otherwise - */ - public boolean isBlockBreakEnabled() { - return this.enableBlockBreak; - } - - /** - * @return true if players can drop items, false otherwise - */ - public boolean isItemDropEnabled() { - return enableItemDrop; - } - - /** - * @return true if players can pick up items, false otherwise - */ - public boolean isItemPickupEnabled() { - return enableItemPickup; - } - - /** - * @return true if food-change is enabled, false otherwise - */ - public boolean isFoodChangeEnabled() { - return enableFoodChange; - } - - /** - * @return true if firespread is disabled, false otherwise - */ - public boolean isFireSpreadDisabled() { - return disableFireSpread; - } - - /** - * Whether or not creepers should display fireworks when they die. - * - * @return - */ - public boolean hasExplosionFireworks() { - return explosionFireworks; - } - - public boolean hasFallDamage() { - return fallDamage; - } + @Element(name = "teleport-to-spawn-on-join", required = false) + private boolean teleportToSpawnOnJoin = false; + + @Element(name = "disable-weather") + private boolean disableWeather = true; + + @Element(name = "disable-lightning") + private boolean disableLightning = true; + + @Element(name = "disable-thunder") + private boolean disableThunder = true; + + @Element(name = "disable-ice-accumulation") + private boolean disableIceAccumulation = true; + + @Element(name = "disable-snow-accumulation") + private boolean disableSnowAccumulation = true; + + @Element(name = "disable-mycelium-spread") + private boolean disableMyceliumSpread = true; + + @Element(name = "disable-fire-spread") + private boolean disableFireSpread = true; + + @Element(name = "launchpad-pressure-plates") + private boolean launchpadPressurePlates = false; + + @Element(name = "enable-join-messages") + private boolean enableJoinMessages = true; + + @Element(name = "enable-leave-messages") + private boolean enableLeaveMessages = true; + + @Element(name = "enable-kick-messages", required = false) + private boolean enableKickMessages = true; + + @Element(name = "enable-block-break") + private boolean enableBlockBreak = true; + + @Element(name = "enable-item-pickup") + private boolean enableItemPickup = true; + + @Element(name = "enable-item-drop") + private boolean enableItemDrop = true; + + @Element(name = "enable-food-change") + private boolean enableFoodChange = true; + + @Element(name = "external-chat-plugin") + private boolean externalChatHandler = true; + + @Element(name = "explosion-fireworks") + private boolean explosionFireworks = true; + + @Element(name = "enable-fall-damage") + private boolean fallDamage = true; + + private boolean silenceChat = false; + + public WorldConfiguration( + @Element(name = "teleport-to-spawn-on-join", required = false) boolean teleportToSpawnOnJoin, + @Element(name = "disable-weather") boolean disableWeather, + @Element(name = "disable-lightning") boolean disableLightning, + @Element(name = "disable-thunder") boolean disableThunder, + @Element(name = "disable-ice-accumulation") boolean disableIceAccumulation, + @Element(name = "disable-snow-accumulation") boolean disableSnowAccumulation, + @Element(name = "disable-mycelium-spread") boolean disableMyceliumSpread, + @Element(name = "launchpad-pressure-plates") boolean launchpadPressurePlates, + @Element(name = "enable-join-messages") boolean enableJoinMessages, + @Element(name = "enable-leave-messages") boolean enableLeaveMessages, + @Element(name = "enable-kick-messages", required = false) boolean enableKickMessages, + @Element(name = "external-chat-plugin") boolean externalChatHandler, + @Element(name = "enable-block-break") boolean enableBlockBreak, + @Element(name = "enable-item-pickup") boolean enableItemPickup, + @Element(name = "enable-item-drop") boolean enableItemDrop, + @Element(name = "enable-food-change") boolean enableFoodChange, + @Element(name = "disable-fire-spread") boolean disableFireSpread, + @Element(name = "explosion-fireworks") boolean explosionFireworks, + @Element(name = "enable-fall-damage") boolean fallDamage + ) { + this.teleportToSpawnOnJoin = teleportToSpawnOnJoin; + this.disableIceAccumulation = disableIceAccumulation; + this.disableWeather = disableWeather; + this.disableLightning = disableLightning; + this.disableMyceliumSpread = disableMyceliumSpread; + this.disableSnowAccumulation = disableSnowAccumulation; + this.disableThunder = disableThunder; + this.launchpadPressurePlates = launchpadPressurePlates; + this.enableJoinMessages = enableJoinMessages; + this.enableLeaveMessages = enableLeaveMessages; + this.enableKickMessages = enableKickMessages; + this.externalChatHandler = externalChatHandler; + this.enableBlockBreak = enableBlockBreak; + this.enableItemDrop = enableItemDrop; + this.enableItemPickup = enableItemPickup; + this.enableFoodChange = enableFoodChange; + this.disableFireSpread = disableFireSpread; + this.explosionFireworks = explosionFireworks; + this.fallDamage = fallDamage; + } + + public WorldConfiguration() { + } + + public boolean isTeleportToSpawnOnJoin() { + return teleportToSpawnOnJoin; + } + + public void setTeleportToSpawnOnJoin(boolean teleportToSpawnOnJoin) { + this.teleportToSpawnOnJoin = teleportToSpawnOnJoin; + } + + public boolean isWeatherDisabled() { + return this.disableWeather; + } + + public boolean isChatSilenced() { + return this.silenceChat; + } + + public void setChatSilenced(boolean silenced) { + this.silenceChat = silenced; + } + + public boolean isLightningDisabled() { + return this.disableLightning; + } + + public boolean isThunderDisabled() { + return this.disableThunder; + } + + /** + * @return true if ice spread is disabled, false otherwise + */ + public boolean isIceSpreadDisabled() { + return this.disableIceAccumulation; + } + + /** + * @return true if snow spread is disabled, false otherwise + */ + public boolean isSnowSpreadDisabled() { + return this.disableSnowAccumulation; + } + + /** + * @return true if mycelium spread is disabled, false otherwise + */ + public boolean isMyceliumSpreadDisabled() { + return this.disableMyceliumSpread; + } + + /** + * Whether or not this server has "fire-pad" pressure plates + * + * @return true if pressure plates are fire-pads, false otherwise + */ + public boolean hasLaunchpadPressurePlates() { + return this.launchpadPressurePlates; + } + + /** + * @return true if join messages are enabled, false otherwise + */ + public boolean hasJoinMessages() { + return enableJoinMessages; + } + + /** + * Whether or not leave messages are enabled + * + * @return + */ + public boolean hasLeaveMessages() { + return enableLeaveMessages; + } + + /** + * @return true if there's an external plugin for chat handling, false if commons is handling + */ + public boolean hasExternalChatHandler() { + return this.externalChatHandler; + } + + /** + * @return true if players can break blocks, false otherwise + */ + public boolean isBlockBreakEnabled() { + return this.enableBlockBreak; + } + + /** + * @return true if players can drop items, false otherwise + */ + public boolean isItemDropEnabled() { + return enableItemDrop; + } + + /** + * @return true if players can pick up items, false otherwise + */ + public boolean isItemPickupEnabled() { + return enableItemPickup; + } + + /** + * @return true if food-change is enabled, false otherwise + */ + public boolean isFoodChangeEnabled() { + return enableFoodChange; + } + + /** + * @return true if firespread is disabled, false otherwise + */ + public boolean isFireSpreadDisabled() { + return disableFireSpread; + } + + /** + * Whether or not creepers should display fireworks when they die. + * + * @return + */ + public boolean hasExplosionFireworks() { + return explosionFireworks; + } + + public boolean hasFallDamage() { + return fallDamage; + } + + public void setDisableWeather(boolean disableWeather) { + this.disableWeather = disableWeather; + } + + public void setDisableLightning(boolean disableLightning) { + this.disableLightning = disableLightning; + } + + public void setDisableThunder(boolean disableThunder) { + this.disableThunder = disableThunder; + } + + public void setDisableIceAccumulation(boolean disableIceAccumulation) { + this.disableIceAccumulation = disableIceAccumulation; + } + + public void setDisableSnowAccumulation(boolean disableSnowAccumulation) { + this.disableSnowAccumulation = disableSnowAccumulation; + } + + public void setDisableMyceliumSpread(boolean disableMyceliumSpread) { + this.disableMyceliumSpread = disableMyceliumSpread; + } + + public void setDisableFireSpread(boolean disableFireSpread) { + this.disableFireSpread = disableFireSpread; + } + + public void setLaunchpadPressurePlates(boolean launchpadPressurePlates) { + this.launchpadPressurePlates = launchpadPressurePlates; + } + + public void setEnableJoinMessages(boolean enableJoinMessages) { + this.enableJoinMessages = enableJoinMessages; + } + + public void setEnableLeaveMessages(boolean enableLeaveMessages) { + this.enableLeaveMessages = enableLeaveMessages; + } + + public void setEnableBlockBreak(boolean enableBlockBreak) { + this.enableBlockBreak = enableBlockBreak; + } + + public void setEnableItemPickup(boolean enableItemPickup) { + this.enableItemPickup = enableItemPickup; + } + + public void setEnableItemDrop(boolean enableItemDrop) { + this.enableItemDrop = enableItemDrop; + } + + public void setEnableFoodChange(boolean enableFoodChange) { + this.enableFoodChange = enableFoodChange; + } + + public void setExternalChatHandler(boolean externalChatHandler) { + this.externalChatHandler = externalChatHandler; + } + + public void setExplosionFireworks(boolean explosionFireworks) { + this.explosionFireworks = explosionFireworks; + } + + public void setFallDamage(boolean fallDamage) { + this.fallDamage = fallDamage; + } + + public boolean isEnableKickMessages() { + return enableKickMessages; + } + + public void setEnableKickMessages(boolean enableKickMessages) { + this.enableKickMessages = enableKickMessages; + } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/listeners/BlockBreakPlaceListener.java b/src/main/java/com/caved_in/commons/listeners/BlockBreakPlaceListener.java index a1eb653..f04de21 100644 --- a/src/main/java/com/caved_in/commons/listeners/BlockBreakPlaceListener.java +++ b/src/main/java/com/caved_in/commons/listeners/BlockBreakPlaceListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.debug.Debugger; import com.caved_in.commons.permission.Perms; import com.caved_in.commons.player.MinecraftPlayer; @@ -15,50 +15,50 @@ public class BlockBreakPlaceListener implements Listener { - private static Commons commons = Commons.getInstance(); - private static WorldConfiguration config; + private static Commons commons = Commons.getInstance(); + private static Configuration config; - public BlockBreakPlaceListener() { - config = Commons.getInstance().getConfiguration().getWorldConfig(); - } + public BlockBreakPlaceListener() { + config = commons.getConfiguration(); + } - @EventHandler - public void onBlockBreak(BlockBreakEvent event) { - if (config.isBlockBreakEnabled()) { - return; - } + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + if (config.enableBlockBreak()) { + return; + } - Player player = event.getPlayer(); - MinecraftPlayer minecraftPlayer = commons.getPlayerHandler().getData(player); - //If block breaking is disabled - //If the player doesn't have the permission to break blocks, disable it - if (!Players.hasPermission(player, Perms.BLOCK_BREAK)) { - event.setCancelled(true); - } - //If the player's in debug mode, then send them debug info - if (minecraftPlayer.isInDebugMode()) { - Debugger.debugBlockBreakEvent(player, event); - } - } + Player player = event.getPlayer(); + MinecraftPlayer minecraftPlayer = commons.getPlayerHandler().getData(player); + //If block breaking is disabled + //If the player doesn't have the permission to break blocks, disable it + if (!Players.hasPermission(player, Perms.BLOCK_BREAK)) { + event.setCancelled(true); + } + //If the player's in debug mode, then send them debug info + if (minecraftPlayer.isInDebugMode()) { + Debugger.debugBlockBreakEvent(player, event); + } + } - @EventHandler - public void onBlockPlace(BlockPlaceEvent event) { - if (event.isCancelled()) { - return; - } + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + if (event.isCancelled()) { + return; + } - Player player = event.getPlayer(); - if (config.isBlockBreakEnabled()) { - return; - } + Player player = event.getPlayer(); + if (config.enableBlockBreak()) { + return; + } - if (!Players.hasPermission(player, Perms.BLOCK_PLACE)) { - if (player.getGameMode() != GameMode.CREATIVE) { - event.setCancelled(true); - } - } + if (!Players.hasPermission(player, Perms.BLOCK_PLACE)) { + if (player.getGameMode() != GameMode.CREATIVE) { + event.setCancelled(true); + } + } - } + } } diff --git a/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java b/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java index 516faef..8870029 100644 --- a/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java +++ b/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.Configuration; +import com.caved_in.commons.config.CommonsXmlConfiguration; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -9,7 +9,7 @@ public class BlockFormListener implements Listener { - private Configuration config; + private CommonsXmlConfiguration config; public BlockFormListener() { config = Commons.getInstance().getConfiguration(); diff --git a/src/main/java/com/caved_in/commons/listeners/ChatListener.java b/src/main/java/com/caved_in/commons/listeners/ChatListener.java index ccb0c47..39f5598 100644 --- a/src/main/java/com/caved_in/commons/listeners/ChatListener.java +++ b/src/main/java/com/caved_in/commons/listeners/ChatListener.java @@ -3,7 +3,7 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; -import com.caved_in.commons.config.Configuration; +import com.caved_in.commons.config.CommonsXmlConfiguration; import com.caved_in.commons.player.MinecraftPlayer; import com.caved_in.commons.player.Players; import com.caved_in.commons.utilities.StringUtil; @@ -17,7 +17,7 @@ public class ChatListener implements Listener { private static Commons commons = Commons.getInstance(); - private Configuration config; + private CommonsXmlConfiguration config; public ChatListener() { config = commons.getConfiguration(); diff --git a/src/main/java/com/caved_in/commons/listeners/CommandPreProcessListener.java b/src/main/java/com/caved_in/commons/listeners/CommandPreProcessListener.java index e6ebc63..001f1e7 100644 --- a/src/main/java/com/caved_in/commons/listeners/CommandPreProcessListener.java +++ b/src/main/java/com/caved_in/commons/listeners/CommandPreProcessListener.java @@ -3,7 +3,7 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; -import com.caved_in.commons.config.CommandConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.debug.Debugger; import com.caved_in.commons.player.MinecraftPlayer; import com.caved_in.commons.utilities.StringUtil; @@ -18,10 +18,9 @@ public class CommandPreProcessListener implements Listener { private static Commons commons = Commons.getInstance(); - private static CommandConfiguration commandConfig = Commons.getInstance().getConfiguration().getCommandConfig(); + private static Configuration config = commons.getConfiguration(); public CommandPreProcessListener() { - } @EventHandler(priority = EventPriority.HIGHEST) @@ -31,7 +30,7 @@ public void onCommandPreProcess(PlayerCommandPreprocessEvent e) { String command = e.getMessage(); //Check if they're using a bukkit command, and bukkit commands are disabled. - if (StringUtil.startsWithIgnoreCase(command, "/bukkit:") && commandConfig.disableBukkitCommands()) { + if (StringUtil.startsWithIgnoreCase(command, "/bukkit:") && !config.enableBukkitCommands()) { e.setCancelled(true); Chat.message(player, Messages.COMMAND_DISABLED); return; @@ -42,7 +41,7 @@ public void onCommandPreProcess(PlayerCommandPreprocessEvent e) { case "/pl": case "/plugins": case "/plugin": - if (commandConfig.disablePluginsCommand()) { + if (!config.enablePluginsCommand() && !player.isOp()) { e.setCancelled(true); Chat.message(player, Messages.COMMAND_DISABLED); return; diff --git a/src/main/java/com/caved_in/commons/listeners/EntityDamageListener.java b/src/main/java/com/caved_in/commons/listeners/EntityDamageListener.java index eb400b0..97c3f92 100644 --- a/src/main/java/com/caved_in/commons/listeners/EntityDamageListener.java +++ b/src/main/java/com/caved_in/commons/listeners/EntityDamageListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.player.MinecraftPlayer; import com.caved_in.commons.player.Players; import org.bukkit.entity.Entity; @@ -13,12 +13,12 @@ public class EntityDamageListener implements Listener { - private WorldConfiguration worldConfig; + private Configuration config; private Players playerHandler; public EntityDamageListener() { - worldConfig = Commons.getInstance().getConfiguration().getWorldConfig(); + config = Commons.getInstance().getConfiguration(); playerHandler = Commons.getInstance().getPlayerHandler(); } @@ -27,9 +27,14 @@ public EntityDamageListener() { public void onEntityDamageEvent(EntityDamageEvent e) { EntityDamageEvent.DamageCause cause = e.getCause(); - if (!worldConfig.hasFallDamage()) { + Entity damaged = e.getEntity(); + if (!(damaged instanceof Player)) { + return; + } + + if (!config.enableFallDamage()) { /* - As this listener is only registered when fall damage is disabled, we're only + As this listener is only registered when fall damage is disabled, we're only going to cancel the event when an entity is damaged via falling. */ if (cause == EntityDamageEvent.DamageCause.FALL) { @@ -37,11 +42,6 @@ public void onEntityDamageEvent(EntityDamageEvent e) { } } - Entity damaged = e.getEntity(); - if (!(damaged instanceof Player)) { - return; - } - Player damagedPlayer = (Player) damaged; MinecraftPlayer mcPlayer = playerHandler.getData(damagedPlayer); diff --git a/src/main/java/com/caved_in/commons/listeners/EntityExplodeListener.java b/src/main/java/com/caved_in/commons/listeners/EntityExplodeListener.java index 9a66fae..af8dede 100644 --- a/src/main/java/com/caved_in/commons/listeners/EntityExplodeListener.java +++ b/src/main/java/com/caved_in/commons/listeners/EntityExplodeListener.java @@ -1,33 +1,33 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.fireworks.Fireworks; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; public class EntityExplodeListener implements Listener { - private WorldConfiguration worldConfig; + private Configuration config; - public EntityExplodeListener() { - worldConfig = Commons.getInstance().getConfiguration().getWorldConfig(); - } + public EntityExplodeListener() { + config = Commons.getInstance().getConfiguration(); + } - @EventHandler - public void onEntityExplode(EntityExplodeEvent event) { - if (event.isCancelled()) { - return; - } + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + if (event.isCancelled()) { + return; + } - if (worldConfig.hasExplosionFireworks()) { - Fireworks.playRandomFirework(event.getLocation()); - } + if (config.hasExplosionFireworks()) { + Fireworks.playRandomFirework(event.getLocation()); + } - if (worldConfig.isBlockBreakEnabled()) { - return; - } - //Clear all the blocks from the block list to assure they're not removed when exploding - event.blockList().clear(); - } + if (config.enableBlockBreak()) { + return; + } + //Clear all the blocks from the block list to assure they're not removed when exploding + event.blockList().clear(); + } } diff --git a/src/main/java/com/caved_in/commons/listeners/FoodChangeListener.java b/src/main/java/com/caved_in/commons/listeners/FoodChangeListener.java index 9c548d9..f55527f 100644 --- a/src/main/java/com/caved_in/commons/listeners/FoodChangeListener.java +++ b/src/main/java/com/caved_in/commons/listeners/FoodChangeListener.java @@ -1,28 +1,25 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.FoodLevelChangeEvent; public class FoodChangeListener implements Listener { - private WorldConfiguration worldConfig; + public FoodChangeListener() { + } - public FoodChangeListener() { - worldConfig = Commons.getInstance().getConfiguration().getWorldConfig(); - } + @EventHandler + public void onFoodChange(FoodLevelChangeEvent event) { + if (event.isCancelled()) { + return; + } - @EventHandler - public void onFoodChange(FoodLevelChangeEvent event) { - if (event.isCancelled()) { - return; - } + if (Commons.getInstance().getConfiguration().enableFoodChange()) { + return; + } - if (worldConfig.isFoodChangeEnabled()) { - return; - } - event.setCancelled(true); - } + event.setCancelled(true); + } } diff --git a/src/main/java/com/caved_in/commons/listeners/InventoryListener.java b/src/main/java/com/caved_in/commons/listeners/InventoryListener.java index ae53e79..0668baf 100644 --- a/src/main/java/com/caved_in/commons/listeners/InventoryListener.java +++ b/src/main/java/com/caved_in/commons/listeners/InventoryListener.java @@ -50,8 +50,6 @@ public void onMenuClick(InventoryClickEvent event) { int index = event.getRawSlot(); //if the players selecting within bounds of the inventory, then act accordingly if (index < inventory.getSize()) { - //todo optionally pass the way the icon was clicked! - //todo Example: RIGHT_CLICK_ITEM, MIDDLE_CLICK_ITEM,SHIFT_CLICK,LEFT_CLICK menu.selectMenuItem(player, index, event.getClick()); } else { //If they're gonna mess with their inventory, they don't need a menu open. @@ -89,6 +87,7 @@ public void onInventoryClick(InventoryClickEvent event) { } if (minecraftPlayer.isInDebugMode()) { + //todo implement option to filter debug messages Debugger.debugInventoryClickEvent(player, event); } } diff --git a/src/main/java/com/caved_in/commons/listeners/ItemDropListener.java b/src/main/java/com/caved_in/commons/listeners/ItemDropListener.java index 691db03..3ec16f5 100644 --- a/src/main/java/com/caved_in/commons/listeners/ItemDropListener.java +++ b/src/main/java/com/caved_in/commons/listeners/ItemDropListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.game.gadget.Gadget; import com.caved_in.commons.game.gadget.Gadgets; import org.bukkit.event.EventHandler; @@ -10,27 +10,24 @@ import org.bukkit.inventory.ItemStack; public class ItemDropListener implements Listener { - private WorldConfiguration config; + private Configuration config; public ItemDropListener() { - config = Commons.getInstance().getConfiguration().getWorldConfig(); + config = Commons.getInstance().getConfiguration(); } @EventHandler public void onItemDrop(PlayerDropItemEvent event) { //todo check if player is in creative and has option for creative drops off, then don't drop items- Just remove them when they're dropped - if (!config.isItemDropEnabled()) { - event.setCancelled(true); - return; - } - ItemStack item = event.getItemDrop().getItemStack(); //If we're not dealing with gadgets if (!Gadgets.isGadget(item)) { - event.setCancelled(!config.isItemDropEnabled()); - return; + if (!config.enableItemDrop()) { + event.setCancelled(true); + return; + } } Gadget gadget = Gadgets.getGadget(item); diff --git a/src/main/java/com/caved_in/commons/listeners/PlayerJoinListener.java b/src/main/java/com/caved_in/commons/listeners/PlayerJoinListener.java index b5c07fd..1894ae2 100644 --- a/src/main/java/com/caved_in/commons/listeners/PlayerJoinListener.java +++ b/src/main/java/com/caved_in/commons/listeners/PlayerJoinListener.java @@ -2,10 +2,10 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.config.Configuration; -import com.caved_in.commons.config.WorldConfiguration; import com.caved_in.commons.player.MinecraftPlayer; import com.caved_in.commons.player.Players; import com.caved_in.commons.threading.tasks.UpdateOnlineStatusThread; +import com.caved_in.commons.utilities.StringUtil; import com.caved_in.commons.world.Worlds; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -15,53 +15,52 @@ import org.bukkit.event.player.PlayerTeleportEvent; public class PlayerJoinListener implements Listener { - private Configuration config; - boolean trackOnline = false; + private Configuration config; + boolean trackOnline = false; - private static Commons commons = Commons.getInstance(); + private static Commons commons = Commons.getInstance(); - public PlayerJoinListener() { - config = Commons.getInstance().getConfiguration(); - trackOnline = config.getSqlConfig().trackPlayerOnlineStatus(); - } + public PlayerJoinListener() { + config = Commons.getInstance().getConfiguration(); + trackOnline = config.trackOnlinePlayerStatus() && config.hasSqlBackend(); + } - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); - //Reset the players walk and fly speeds - player.setFlySpeed((float) MinecraftPlayer.DEFAULT_FLY_SPEED); - player.setWalkSpeed((float) MinecraftPlayer.DEFAULT_WALK_SPEED); - WorldConfiguration worldConfig = config.getWorldConfig(); + //Reset the players walk and fly speeds + player.setFlySpeed((float) MinecraftPlayer.DEFAULT_FLY_SPEED); + player.setWalkSpeed((float) MinecraftPlayer.DEFAULT_WALK_SPEED); - if (!worldConfig.hasJoinMessages()) { - event.setJoinMessage(null); - } + if (!config.enableJoinMessages()) { + event.setJoinMessage(null); + } - //Initialize the wrapped player data - commons.getPlayerHandler().addData(player); + //Initialize the wrapped player data + commons.getPlayerHandler().addData(player); - //Update the player's online status in our data-base! + //Update the player's online status in our data-base! - if (trackOnline) { - commons.getThreadManager().runTaskAsync(new UpdateOnlineStatusThread(player.getUniqueId(), true)); - } + if (trackOnline) { + commons.getThreadManager().runTaskAsync(new UpdateOnlineStatusThread(player.getUniqueId(), true)); + } - //If the players in the lobby, teleport them to the spawn when they join - if (config.getServerName().equalsIgnoreCase("lobby")) { - player.teleport(Worlds.getSpawn(player), PlayerTeleportEvent.TeleportCause.PLUGIN); - } + //If the players in the lobby, teleport them to the spawn when they join + if (config.teleportToSpawnOnJoin()) { + player.teleport(Worlds.getSpawn(player), PlayerTeleportEvent.TeleportCause.PLUGIN); + } - MinecraftPlayer mcPlayer = commons.getPlayerHandler().getData(player); + MinecraftPlayer mcPlayer = commons.getPlayerHandler().getData(player); - if (commons.isServerFull() && mcPlayer.isPremium()) { - Players.kick(Players.getRandomNonPremiumPlayer(), "&eYou were moved to hub to make room for a premium player"); - } + if (commons.isServerFull() && mcPlayer.isPremium()) { + Players.kick(Players.getRandomNonPremiumPlayer(), StringUtil.colorize(config.kickNonPremiumMessage())); + } - if (commons.hasDatabaseBackend()) { - commons.getThreadManager().runTaskAsync(() -> { - commons.getServerDatabase().updatePlayerCount(); - }); - } - } + if (commons.hasDatabaseBackend()) { + commons.getThreadManager().runTaskAsync(() -> { + commons.getServerDatabase().updatePlayerCount(); + }); + } + } } diff --git a/src/main/java/com/caved_in/commons/listeners/PlayerKickListener.java b/src/main/java/com/caved_in/commons/listeners/PlayerKickListener.java index 2064d4a..c1f732c 100644 --- a/src/main/java/com/caved_in/commons/listeners/PlayerKickListener.java +++ b/src/main/java/com/caved_in/commons/listeners/PlayerKickListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.permission.Perms; import com.caved_in.commons.player.Players; import com.caved_in.commons.threading.tasks.UpdateOnlineStatusThread; @@ -14,15 +14,15 @@ public class PlayerKickListener implements Listener { - private WorldConfiguration config; + private Configuration config; public PlayerKickListener() { - config = Commons.getInstance().getConfiguration().getWorldConfig(); + config = Commons.getInstance().getConfiguration(); } @EventHandler public void onPlayerKicked(PlayerKickEvent event) { - if (!config.hasJoinMessages()) { + if (!config.enableKickMessages()) { event.setLeaveMessage(null); } @@ -37,7 +37,9 @@ public void onPlayerKicked(PlayerKickEvent event) { UUID playerId = player.getUniqueId(); //Update the player's online status in the database - Commons.getInstance().getThreadManager().runTaskAsync(new UpdateOnlineStatusThread(playerId, false)); + if (config.hasSqlBackend() && config.trackOnlinePlayerStatus()) { + Commons.getInstance().getThreadManager().runTaskAsync(new UpdateOnlineStatusThread(playerId, false)); + } Players.removeData(playerId); // if (Commons.hasSqlBackend()) { diff --git a/src/main/java/com/caved_in/commons/listeners/PlayerLoginListener.java b/src/main/java/com/caved_in/commons/listeners/PlayerLoginListener.java index 60c9c73..b20663a 100644 --- a/src/main/java/com/caved_in/commons/listeners/PlayerLoginListener.java +++ b/src/main/java/com/caved_in/commons/listeners/PlayerLoginListener.java @@ -2,8 +2,6 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.config.Configuration; -import com.caved_in.commons.config.MaintenanceConfiguration; -import com.caved_in.commons.config.PremiumConfiguration; import com.caved_in.commons.permission.Perms; import com.caved_in.commons.player.Players; import org.bukkit.entity.Player; @@ -13,38 +11,38 @@ public class PlayerLoginListener implements Listener { - private Configuration config; + private Configuration config; - public PlayerLoginListener() { - config = Commons.getInstance().getConfiguration(); - } + public PlayerLoginListener() { + config = Commons.getInstance().getConfiguration(); + } - @EventHandler - public void onPlayerLogin(PlayerLoginEvent event) { - Player player = event.getPlayer(); - MaintenanceConfiguration maintenanceConfiguration = config.getMaintenanceConfig(); - //If maintenance mode is enabled, kick the player if they don't have permissions - if (maintenanceConfiguration.isMaintenanceMode()) { - if (!Players.hasPermission(player, Perms.MAINTENANCE_WHITELIST)) { - event.setKickMessage(maintenanceConfiguration.getKickMessage()); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); - } - } + @EventHandler + public void onPlayerLogin(PlayerLoginEvent event) { + Player player = event.getPlayer(); + //If maintenance mode is enabled, kick the player if they don't have permissions + if (config.isMaintenanceModeEnabled()) { + if (!Players.hasPermission(player, Perms.MAINTENANCE_WHITELIST)) { + event.setKickMessage(config.maintenanceModeKickMessage()); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } + } - if (!config.hasSqlBackend()) { - return; - } - /* + if (!config.hasSqlBackend()) { + return; + } + /* If the server is in premium-only mode check if the player is premium and if not kick them */ - PremiumConfiguration premiumConfiguration = config.getPremiumConfig(); - if (!premiumConfiguration.isPremiumMode()) { - return; - } - if (!Commons.getInstance().getServerDatabase().getPlayerWrapper(player.getUniqueId()).isPremium()) { - event.setKickMessage(premiumConfiguration.getKickMessage()); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); - } - } + if (!config.isPremiumOnlyMode()) { + return; + } + + //TODO Hook Vault / Permissions to see if player has permission to join while in premium. + if (!Commons.getInstance().getServerDatabase().getPlayerWrapper(player.getUniqueId()).isPremium()) { + event.setKickMessage(config.getPremiumOnlyModeKickMessage()); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); + } + } } diff --git a/src/main/java/com/caved_in/commons/listeners/PlayerQuitListener.java b/src/main/java/com/caved_in/commons/listeners/PlayerQuitListener.java index 8476070..710a6ea 100644 --- a/src/main/java/com/caved_in/commons/listeners/PlayerQuitListener.java +++ b/src/main/java/com/caved_in/commons/listeners/PlayerQuitListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.WorldConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.player.Players; import com.caved_in.commons.threading.tasks.UpdateOnlineStatusThread; import org.bukkit.event.EventHandler; @@ -11,12 +11,12 @@ import java.util.UUID; public class PlayerQuitListener implements Listener { - private WorldConfiguration config; + private Configuration config; private static Commons commons = Commons.getInstance(); public PlayerQuitListener() { - config = Commons.getInstance().getConfiguration().getWorldConfig(); + config = commons.getConfiguration(); } @EventHandler @@ -24,7 +24,7 @@ public void onPlayerQuit(PlayerQuitEvent event) { UUID playerId = event.getPlayer().getUniqueId(); //If there's no leave/join messages, then remove the message! - if (!config.hasJoinMessages()) { + if (!config.enableJoinMessages()) { event.setQuitMessage(null); } diff --git a/src/main/java/com/caved_in/commons/listeners/ServerPingListener.java b/src/main/java/com/caved_in/commons/listeners/ServerPingListener.java index c0a8950..16af228 100644 --- a/src/main/java/com/caved_in/commons/listeners/ServerPingListener.java +++ b/src/main/java/com/caved_in/commons/listeners/ServerPingListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.MaintenanceConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.utilities.StringUtil; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -9,16 +9,16 @@ public class ServerPingListener implements Listener { - private MaintenanceConfiguration config; + private Configuration config; - public ServerPingListener() { - config = Commons.getInstance().getConfiguration().getMaintenanceConfig(); - } + public ServerPingListener() { + config = Commons.getInstance().getConfiguration(); + } - @EventHandler - public void onServerPing(ServerListPingEvent event) { - if (config.isMaintenanceMode()) { - event.setMotd(StringUtil.formatColorCodes(config.getMotd())); - } - } + @EventHandler + public void onServerPing(ServerListPingEvent event) { + if (config.isMaintenanceModeEnabled()) { + event.setMotd(StringUtil.formatColorCodes(config.maintenanceModeMotd())); + } + } } diff --git a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java index 604fba7..b07f86e 100644 --- a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java +++ b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java @@ -1,7 +1,7 @@ package com.caved_in.commons.menu.menus.configmenu.items; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.Configuration; +import com.caved_in.commons.config.CommonsXmlConfiguration; import com.caved_in.commons.item.Wool; import com.caved_in.commons.menu.MenuItem; import org.bukkit.entity.Player; @@ -9,7 +9,7 @@ public class HasSqlBackendItem extends MenuItem { - private Configuration config = Commons.getInstance().getConfiguration(); + private CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); public HasSqlBackendItem() { super(); diff --git a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java index b2135d2..737cfe6 100644 --- a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java +++ b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java @@ -1,7 +1,7 @@ package com.caved_in.commons.menu.menus.configmenu.items; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.Configuration; +import com.caved_in.commons.config.CommonsXmlConfiguration; import com.caved_in.commons.item.Wool; import com.caved_in.commons.menu.MenuItem; import org.bukkit.entity.Player; @@ -30,7 +30,7 @@ private void init() { @Override public void onClick(Player player, ClickType type) { - Configuration config = Commons.getInstance().getConfiguration(); + CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); boolean registerCommands = !config.registerCommands(); config.setRegisterCommands(registerCommands); init(); diff --git a/src/main/java/com/caved_in/commons/player/Players.java b/src/main/java/com/caved_in/commons/player/Players.java index 7a71e47..fbce5f0 100644 --- a/src/main/java/com/caved_in/commons/player/Players.java +++ b/src/main/java/com/caved_in/commons/player/Players.java @@ -1094,11 +1094,13 @@ public static Player getRandomPlayer() { } public static Player getRandomNonPremiumPlayer() { + //todo move to matching against predicate for player if (!Players.isOnline(1)) { return null; } - List nonPremiums = allPlayerWrappers().stream().filter(p -> !p.isPremium()).collect(Collectors.toList()); + String premiumPermission = Commons.getInstance().getConfiguration().getPremiumUserPermission(); + List nonPremiums = stream().filter(player -> !hasPermission(player, premiumPermission)).collect(Collectors.toList()); return ListUtils.getRandom(nonPremiums).getPlayer(); } diff --git a/src/main/java/com/caved_in/commons/sql/DatabaseConnector.java b/src/main/java/com/caved_in/commons/sql/DatabaseConnector.java index a74d220..f8ec8d7 100644 --- a/src/main/java/com/caved_in/commons/sql/DatabaseConnector.java +++ b/src/main/java/com/caved_in/commons/sql/DatabaseConnector.java @@ -14,7 +14,6 @@ public abstract class DatabaseConnector implements TableConnector { public DatabaseConnector(SqlConfiguration sqlConfiguration) { this.config = sqlConfiguration; initConnection(); - } private void initConnection() { diff --git a/src/main/java/com/caved_in/commons/world/Worlds.java b/src/main/java/com/caved_in/commons/world/Worlds.java index 3975a18..773c3bc 100644 --- a/src/main/java/com/caved_in/commons/world/Worlds.java +++ b/src/main/java/com/caved_in/commons/world/Worlds.java @@ -26,7 +26,7 @@ public class Worlds { private static Commons commons = Commons.getInstance(); public void handleWeather(World World) { - if (World.hasStorm() && commons.getConfiguration().getWorldConfig().isWeatherDisabled()) { + if (World.hasStorm() && commons.getConfiguration().disableWeather()) { World.setStorm(false); World.setThundering(false); } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Config.java b/src/main/java/com/caved_in/commons/yml/converter/Config.java index b1f9abf..a47999f 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Config.java +++ b/src/main/java/com/caved_in/commons/yml/converter/Config.java @@ -12,43 +12,43 @@ * @author geNAZt (fabian.fassbender42@googlemail.com) */ public class Config implements Converter { - private InternalConverter internalConverter; - - public Config(InternalConverter internalConverter) { - this.internalConverter = internalConverter; - } - - @Override - public Object toConfig(Class type, Object obj, ParameterizedType parameterizedType) throws Exception { - return (obj instanceof Map) ? obj : ((YamlConfig) obj).saveToMap(obj.getClass()); - } - - @Override - public Object fromConfig(Class type, Object section, ParameterizedType genericType) throws Exception { - YamlConfig obj = (YamlConfig) newInstance(type); - - // Inject converter stack into subconfig - for (Class aClass : internalConverter.getCustomConverters()) { - obj.addConverter(aClass); - } - - obj.loadFromMap((section instanceof Map) ? (Map) section : ((ConfigSection) section).getRawMap(), type); - return obj; - } - - // recursively handles enclosed classes - public Object newInstance(Class type) throws Exception { - Class enclosingClass = type.getEnclosingClass(); - if (enclosingClass != null) { - Object instanceOfEnclosingClass = newInstance(enclosingClass); - return type.getConstructor(enclosingClass).newInstance(instanceOfEnclosingClass); - } else { - return type.newInstance(); - } - } - - @Override - public boolean supports(Class type) { - return YamlConfig.class.isAssignableFrom(type); - } + private InternalConverter internalConverter; + + public Config(InternalConverter internalConverter) { + this.internalConverter = internalConverter; + } + + @Override + public Object toConfig(Class type, Object obj, ParameterizedType parameterizedType) throws Exception { + return (obj instanceof Map) ? obj : ((YamlConfig) obj).saveToMap(obj.getClass()); + } + + @Override + public Object fromConfig(Class type, Object section, ParameterizedType genericType) throws Exception { + YamlConfig obj = (YamlConfig) newInstance(type); + + // Inject converter stack into subconfig + for (Class aClass : internalConverter.getCustomConverters()) { + obj.addConverter(aClass); + } + + obj.loadFromMap((section instanceof Map) ? (Map) section : ((ConfigSection) section).getRawMap(), type); + return obj; + } + + // recursively handles enclosed classes + public Object newInstance(Class type) throws Exception { + Class enclosingClass = type.getEnclosingClass(); + if (enclosingClass != null) { + Object instanceOfEnclosingClass = newInstance(enclosingClass); + return type.getConstructor(enclosingClass).newInstance(instanceOfEnclosingClass); + } else { + return type.newInstance(); + } + } + + @Override + public boolean supports(Class type) { + return YamlConfig.class.isAssignableFrom(type); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8e37b7f..3f27a36 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -204,6 +204,7 @@ permissions: commons.command.*: true commons.admin.antikick: true commons.armor.*: true + commons.silence.bypass: true commons.armor.*: description: Gives players access to spawning all the armor sets! default: op @@ -359,4 +360,7 @@ permissions: default: op commons.command.removepremium: description: Allows players to use the removepremium command + default: op + commons.silence.bypass: + description: Allows a player to bypass the silenced chat mode default: op \ No newline at end of file From 83978b450d9b69e047b1d2d242896d60042a6c26 Mon Sep 17 00:00:00 2001 From: TheGamersCave Date: Fri, 29 Jan 2016 00:47:16 -0330 Subject: [PATCH 2/5] Finished feature of Yaml to Xml to Yaml conversion for Config.xml and config.yml file. Will merge into master branch as a part of the 1.8.8-3 release very soon! --- pom.xml | 2 +- .../java/com/caved_in/commons/Commons.java | 192 +++++++++--------- .../command/commands/MaintenanceCommand.java | 14 +- .../command/commands/SilenceCommand.java | 3 +- .../command/commands/UnsilenceCommand.java | 6 +- .../command/commands/WarpsCommand.java | 34 ++-- .../commons/config/SqlConfiguration.java | 4 +- .../caved_in/commons/config/WarpConfig.java | 41 ++-- .../commons/event/StackTraceEvent.java | 9 +- .../commons/listeners/BlockFormListener.java | 8 +- .../commons/listeners/ChatListener.java | 8 +- .../configmenu/items/HasSqlBackendItem.java | 6 +- .../items/RegisterCommandsItem.java | 6 +- .../commons/yml/InternalConverter.java | 12 +- .../{Array.java => ArrayYamlConverter.java} | 4 +- .../{List.java => ListYamlConverter.java} | 4 +- .../{Map.java => MapYamlConverter.java} | 4 +- ...itive.java => PrimitiveYamlConverter.java} | 4 +- .../{Set.java => SetYamlConverter.java} | 4 +- .../{Config.java => YamlConfigConverter.java} | 4 +- 20 files changed, 185 insertions(+), 184 deletions(-) rename src/main/java/com/caved_in/commons/yml/converter/{Array.java => ArrayYamlConverter.java} (93%) rename src/main/java/com/caved_in/commons/yml/converter/{List.java => ListYamlConverter.java} (93%) rename src/main/java/com/caved_in/commons/yml/converter/{Map.java => MapYamlConverter.java} (96%) rename src/main/java/com/caved_in/commons/yml/converter/{Primitive.java => PrimitiveYamlConverter.java} (91%) rename src/main/java/com/caved_in/commons/yml/converter/{Set.java => SetYamlConverter.java} (93%) rename src/main/java/com/caved_in/commons/yml/converter/{Config.java => YamlConfigConverter.java} (93%) diff --git a/pom.xml b/pom.xml index eec54d6..aaa889b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.caved_in commons - 1.8.8-2 + 1.8.8-3 1.6.1 diff --git a/src/main/java/com/caved_in/commons/Commons.java b/src/main/java/com/caved_in/commons/Commons.java index fa288ff..50acb01 100644 --- a/src/main/java/com/caved_in/commons/Commons.java +++ b/src/main/java/com/caved_in/commons/Commons.java @@ -281,20 +281,12 @@ public void initConfig() { */ TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); - boolean freshCommonsInstall = false; - - boolean ymlConfig = false; - - boolean xmlConfig = false; - - boolean convertFromXmlToYml = false; - boolean convertFromYmlToXml = false; - + /* + This is a fresh install of commons! + */ if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { - freshCommonsInstall = true; - ymlConfig = true; - Chat.messageConsole( + debug( "[===============================]", "| COMMONS NOTICE |", "|-------------------------------|", @@ -347,11 +339,8 @@ public void initConfig() { try { ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - Chat.debug("Initialized the config.yml Commons configuration file"); - ymlConfig = true; } catch (InvalidConfigurationException e) { e.printStackTrace(); - Chat.debug("Unable to initialize the Commons config.yml file"); } } @@ -373,7 +362,7 @@ public void initConfig() { e.printStackTrace(); } - Chat.messageConsole( + debug( "[===============================]", "| COMMONS NOTICE |", "|-------------------------------|", @@ -424,8 +413,6 @@ public void initConfig() { } catch (Exception e) { e.printStackTrace(); } - Chat.debug("Loaded XML based configuration for Commons from Config.xml"); - xmlConfig = true; return; } @@ -440,7 +427,7 @@ public void initConfig() { when it's not required. */ if (ymlConfigFile.exists()) { - Chat.messageConsole( + debug( "[===============================]", "| COMMONS NOTICE |", "|-------------------------------|", @@ -476,11 +463,9 @@ public void initConfig() { globalConfig = new CommonsYamlConfiguration(); try { ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - Chat.debug("Commons configuration has been loaded from config.yml!"); - ymlConfig = true; } catch (InvalidConfigurationException e) { e.printStackTrace(); - Chat.debug( + debug( "Commons 'plugin.yml' is invalid, and will cause", "the plugin to malfunction without valid", "configuration available....", @@ -503,7 +488,7 @@ public void initConfig() { available if they choose! */ - Chat.messageConsole( + debug( "[===============================]", "| COMMONS NOTICE |", "|-------------------------------|", @@ -554,8 +539,6 @@ public void initConfig() { globalConfig = new CommonsYamlConfiguration(); try { ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - Chat.debug("Commons has been initialized, and created a 'config.yml' file for managing its configuration!"); - ymlConfig = true; } catch (InvalidConfigurationException e) { //INVALID INITIAL CONFIG? e.printStackTrace(); @@ -585,7 +568,7 @@ plugin data folder (Or vice versa) and then disable commons from loading to prevent any further Errors from happening! */ if (dataFileContents == null) { - Chat.messageConsole( + debug( "[================================]", "| COMMONS NOTICE |", "|--------------------------------|", @@ -627,8 +610,9 @@ plugin data folder (Or vice versa) their chosen config format, and perhaps performing a Conversion! */ - String[] option = dataFileContents.split("commons-data-format="); - if (option[1].equalsIgnoreCase("xml")) { + String[] options = dataFileContents.split("="); + String option = options[1].trim().replace("\n", "").replace("\r", ""); + if (option.equalsIgnoreCase("xml")) { /* They've chosen to use XMl as the configuration option. We check if they have a YML based configuration file available @@ -640,13 +624,11 @@ plugin data folder (Or vice versa) if (ymlConfigFile.exists()) { CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); - Chat.debug("Attempting to convert from YML Config to XML Configuration"); try { yamlConfig.load(ymlConfigFile); - Chat.debug("Loaded the previous config.yml file used to configure Commons!"); } catch (InvalidConfigurationException e) { e.printStackTrace(); - Chat.debug( + debug( "Commons 'plugin.yml' is invalid, and will cause", "the plugin to malfunction without valid", "configuration available....", @@ -676,19 +658,37 @@ plugin data folder (Or vice versa) */ alternateCommonsConfig(yamlConfig, cxmlConfig); globalConfig = cxmlConfig; - /* Delete the previous config.yml file to avoid issues! */ try { FileUtils.forceDelete(ymlConfigFile); - Chat.debug("Deleted your previous config.yml file to avoid future issues on startup and confusion."); } catch (IOException e) { e.printStackTrace(); - Chat.debug("HUUUUGE MISTAKE! THERE'S AN ERROR DELETING config.yml!"); } - Chat.debug("Successfully converted your previous config.yml file to an XML based Document (Config.xml)"); + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| yml based config file to using |", + "| an xml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to yml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); } else { /* In this case, they've chosen XML as their configuration, and don't have @@ -702,18 +702,11 @@ and use that as configuration (Meaning they already chose xml as the option befo if (xmlConfigFile.exists()) { try { globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + if (globalConfig == null) { + } else { + } } catch (Exception e) { e.printStackTrace(); - Chat.debug("Error loading existing Config.xml file! Pleasure assure your config file is valid, and restart your server to try again!"); - Plugins.disablePlugin(this); - return; - } - - /* - Just to be sure we caught all the errors along the way! - */ - if (globalConfig == null) { - Chat.debug("Error loading existing Config.xml file! Pleasure assure your config file is valid, and restart your server to try again!"); Plugins.disablePlugin(this); return; } @@ -727,14 +720,12 @@ and use that as configuration (Meaning they already chose xml as the option befo try { configSerializer.write(globalConfig, xmlConfigFile); - Chat.debug("Wrote new instance of Config.xml! Did your previous version get deleted?"); } catch (Exception e) { e.printStackTrace(); } } } - Chat.debug("Loaded XML based configuration for Commons from Config.xml"); - } else if (option[1].equalsIgnoreCase("yml")) { + } else if (option.equalsIgnoreCase("yml")) { /* This means they're converting from a previous configuration file @@ -744,13 +735,11 @@ and use that as configuration (Meaning they already chose xml as the option befo */ if (xmlConfigFile.exists()) { CommonsXmlConfiguration xmlConfiguration = null; - - try { xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); } catch (Exception e) { e.printStackTrace(); - Chat.debug( + debug( "====================================================", "There was an error while processing your Config.xml", "File inside of plugins/Commons/Config.xml", @@ -780,19 +769,14 @@ and use that as configuration (Meaning they already chose xml as the option befo } CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - Chat.debug("Transferring content from Config.xml to config.yml"); alternateCommonsConfig(xmlConfiguration, yamlConfiguration); - Chat.debug("Content transferred from previous Config.xml file!"); globalConfig = yamlConfiguration; - Chat.debug("Assigned the Commons configuration from the converted Config.xml file!"); try { - Chat.debug("Attempting to save yaml configuration!"); yamlConfiguration.init(ymlConfigFile); - Chat.debug("Saved yaml configuration file; Converted from Config.xml"); } catch (InvalidConfigurationException e) { e.printStackTrace(); - Chat.debug( + debug( "Commons 'plugin.yml' is invalid, and will cause", "the plugin to malfunction without valid", "configuration available....", @@ -814,13 +798,37 @@ and use that as configuration (Meaning they already chose xml as the option befo try { FileUtils.forceDelete(xmlConfigFile); - Chat.debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", + debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", "Your Commons config is now based out of config.yml"); } catch (IOException e) { e.printStackTrace(); - Chat.debug("Failed to delete the previous Config.xml from your Commons plugin folder."); + debug("Failed to delete the previous Config.xml from your Commons plugin folder."); } + + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| xml based config file to using |", + "| an yml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to xml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + return; } @@ -829,59 +837,59 @@ and use that as configuration (Meaning they already chose xml as the option befo their plugins/Commons/ folder; Loading this file for configuration. */ if (ymlConfigFile.exists()) { - Chat.debug("Beginning to load config.yml"); CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); try { yamlConfiguration.load(ymlConfigFile); globalConfig = yamlConfiguration; - Chat.debug("Loaded the previous instance of config.yml"); } catch (InvalidConfigurationException e) { e.printStackTrace(); } - } else { - /* + } + + /* They've chosen to use yml as their config file, though don't currently have a config.yml file! Send them a notice saying they've likely deleted their previous version of configuration and create a new one for them! */ - Chat.messageConsole( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| It seems you no config.yml in |", - "| your Commons plugin folder |", - "| but have yml as your chosen |", - "| data type in data-option.txt |", - "| |", - "| A new config.yml file will be |", - "| generated for you to use, and |", - "| configure accordingly to your |", - "| likings, and servers desire. |", - "| |", - "| To prevent this issue from |", - "| happening again, please don't |", - "| delete your config.yml file! |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - } + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you no config.yml in |", + "| your Commons plugin folder |", + "| but have yml as your chosen |", + "| data type in data-option.txt |", + "| |", + "| A new config.yml file will be |", + "| generated for you to use, and |", + "| configure accordingly to your |", + "| likings, and servers desire. |", + "| |", + "| To prevent this issue from |", + "| happening again, please don't |", + "| delete your config.yml file! |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); try { yamlConfiguration.init(ymlConfigFile); + globalConfig = yamlConfiguration; } catch (InvalidConfigurationException e) { e.printStackTrace(); //Error initializing initial configutration!? SHOULD NEVER HAPPEN } + } else { } } diff --git a/src/main/java/com/caved_in/commons/command/commands/MaintenanceCommand.java b/src/main/java/com/caved_in/commons/command/commands/MaintenanceCommand.java index 497f9a3..592ea3a 100644 --- a/src/main/java/com/caved_in/commons/command/commands/MaintenanceCommand.java +++ b/src/main/java/com/caved_in/commons/command/commands/MaintenanceCommand.java @@ -5,13 +5,13 @@ import com.caved_in.commons.chat.Chat; import com.caved_in.commons.command.Arg; import com.caved_in.commons.command.Command; -import com.caved_in.commons.config.MaintenanceConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.permission.Perms; import com.caved_in.commons.player.Players; import org.bukkit.command.CommandSender; public class MaintenanceCommand { - private static MaintenanceConfiguration config = Commons.getInstance().getConfiguration().getMaintenanceConfig(); + private static Configuration config = Commons.getInstance().getConfiguration(); public MaintenanceCommand() { @@ -19,12 +19,10 @@ public MaintenanceCommand() { @Command(identifier = "maintenance", permissions = {Perms.MAINTENANCE_TOGGLE}, onlyPlayers = false) public void onMaintenanceCommand(CommandSender sender, @Arg(name = "action", def = "toggle") String mode) { - MaintenanceConfiguration config = Commons.getInstance().getConfiguration().getMaintenanceConfig(); - switch (mode.toLowerCase()) { case "on": config.setMaintenanceMode(true); - Players.kickAllWithoutPermission(Perms.MAINTENANCE_WHITELIST, config.getKickMessage()); + Players.kickAllWithoutPermission(Perms.MAINTENANCE_WHITELIST, config.maintenanceModeKickMessage()); Chat.message(sender, Messages.MAINTENANCE_MODE_ENABLED); break; case "off": @@ -32,9 +30,9 @@ public void onMaintenanceCommand(CommandSender sender, @Arg(name = "action", def Chat.message(sender, Messages.MAINTENANCE_MODE_DISABLED); break; case "toggle": - config.toggleMaintenance(); - if (config.isMaintenanceMode()) { - Players.kickAllWithoutPermission(Perms.MAINTENANCE_WHITELIST, config.getKickMessage()); + config.setMaintenanceMode(!config.isMaintenanceModeEnabled()); + if (config.isMaintenanceModeEnabled()) { + Players.kickAllWithoutPermission(Perms.MAINTENANCE_WHITELIST, config.maintenanceModeKickMessage()); Chat.message(sender, Messages.MAINTENANCE_MODE_ENABLED); } else { Chat.message(sender, Messages.MAINTENANCE_MODE_DISABLED); diff --git a/src/main/java/com/caved_in/commons/command/commands/SilenceCommand.java b/src/main/java/com/caved_in/commons/command/commands/SilenceCommand.java index bd70811..a4df718 100644 --- a/src/main/java/com/caved_in/commons/command/commands/SilenceCommand.java +++ b/src/main/java/com/caved_in/commons/command/commands/SilenceCommand.java @@ -5,13 +5,12 @@ import com.caved_in.commons.chat.Chat; import com.caved_in.commons.command.Command; import com.caved_in.commons.permission.Perms; -import com.caved_in.commons.player.Players; import org.bukkit.command.CommandSender; public class SilenceCommand { @Command(identifier = "silence", permissions = Perms.COMMAND_SILENCE, onlyPlayers = false) public void onSilenceCommand(CommandSender sender) { - Commons.getInstance().getConfiguration().getWorldConfig().setChatSilenced(true); + Commons.getInstance().getConfiguration().silenceChat(true); Chat.messageAll(Messages.CHAT_SILENCED); } } diff --git a/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java b/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java index 6f66e28..a20db53 100644 --- a/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java +++ b/src/main/java/com/caved_in/commons/command/commands/UnsilenceCommand.java @@ -4,13 +4,13 @@ import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; import com.caved_in.commons.command.Command; -import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.permission.Perms; import org.bukkit.command.CommandSender; public class UnsilenceCommand { - private static CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); + private static Configuration config = Commons.getInstance().getConfiguration(); public UnsilenceCommand() { @@ -18,7 +18,7 @@ public UnsilenceCommand() { @Command(identifier = "unsilence", permissions = Perms.COMMAND_SILENCE, onlyPlayers = false) public void unsilenceLobbyCommand(CommandSender sender) { - config.getWorldConfig().setChatSilenced(false); + config.silenceChat(false); Chat.messageAll(Messages.CHAT_UNSILENCED); } } diff --git a/src/main/java/com/caved_in/commons/command/commands/WarpsCommand.java b/src/main/java/com/caved_in/commons/command/commands/WarpsCommand.java index 501eecb..67a6951 100644 --- a/src/main/java/com/caved_in/commons/command/commands/WarpsCommand.java +++ b/src/main/java/com/caved_in/commons/command/commands/WarpsCommand.java @@ -3,7 +3,7 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.command.Arg; import com.caved_in.commons.command.Command; -import com.caved_in.commons.config.WarpConfig; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.menu.HelpScreen; import com.caved_in.commons.menu.ItemFormat; import com.caved_in.commons.menu.Menus; @@ -15,22 +15,22 @@ import org.bukkit.entity.Player; public class WarpsCommand { - private WarpConfig warpConfig; + private Configuration config; - public WarpsCommand() { - warpConfig = Commons.getInstance().getConfiguration().getWarpConfig(); - } + public WarpsCommand() { + config = Commons.getInstance().getConfiguration(); + } - @Command(identifier = "warps", permissions = Perms.COMMAND_WARPS) - public void onWarpsCommand(Player player, @Arg(name = "page", def = "1") int page) { - if (warpConfig.isWarpsMenuEnabled()) { - WarpSelectionMenu.getMenu(page).openMenu(player); - } else { - HelpScreen warpsMenu = Menus.generateHelpScreen("Warps / Waypoints", PageDisplay.DEFAULT, ItemFormat.NO_DESCRIPTION, ChatColor.GREEN, ChatColor.DARK_GREEN); - for (String warp : Warps.getWarpNames()) { - warpsMenu.setEntry(warp, ""); - } - warpsMenu.sendTo(player, page, 7); - } - } + @Command(identifier = "warps", permissions = Perms.COMMAND_WARPS) + public void onWarpsCommand(Player player, @Arg(name = "page", def = "1") int page) { + if (config.enableWarpsMenu()) { + WarpSelectionMenu.getMenu(page).openMenu(player); + } else { + HelpScreen warpsMenu = Menus.generateHelpScreen("Warps / Waypoints", PageDisplay.DEFAULT, ItemFormat.NO_DESCRIPTION, ChatColor.GREEN, ChatColor.DARK_GREEN); + for (String warp : Warps.getWarpNames()) { + warpsMenu.setEntry(warp, ""); + } + warpsMenu.sendTo(player, page, 7); + } + } } diff --git a/src/main/java/com/caved_in/commons/config/SqlConfiguration.java b/src/main/java/com/caved_in/commons/config/SqlConfiguration.java index 0695dae..6cfa0c2 100644 --- a/src/main/java/com/caved_in/commons/config/SqlConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/SqlConfiguration.java @@ -1,11 +1,10 @@ package com.caved_in.commons.config; -import com.caved_in.commons.yml.YamlConfig; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root -public class SqlConfiguration extends YamlConfig { +public class SqlConfiguration { @Element(name = "MySqlHost") private String mySqlHost = "localhost"; @@ -35,6 +34,7 @@ public SqlConfiguration(@Element(name = "MySqlHost") String mySqlHost, @Element( } public SqlConfiguration() { + } public String getHost() { diff --git a/src/main/java/com/caved_in/commons/config/WarpConfig.java b/src/main/java/com/caved_in/commons/config/WarpConfig.java index 2ed9984..627180f 100644 --- a/src/main/java/com/caved_in/commons/config/WarpConfig.java +++ b/src/main/java/com/caved_in/commons/config/WarpConfig.java @@ -1,33 +1,30 @@ package com.caved_in.commons.config; -import com.caved_in.commons.yml.Path; -import com.caved_in.commons.yml.YamlConfig; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root(name = "warp-config") -public class WarpConfig extends YamlConfig { - @Element(name = "enable-warps-menu") - @Path("enable-warps-menu") - private boolean warpsMenu = true; +public class WarpConfig { + @Element(name = "enable-warps-menu") + private boolean warpsMenu = true; - public WarpConfig() { - } + public WarpConfig() { + } - public WarpConfig(@Element(name = "enable-warps-menu") boolean warpsMenu) { - this.warpsMenu = warpsMenu; - } + public WarpConfig(@Element(name = "enable-warps-menu") boolean warpsMenu) { + this.warpsMenu = warpsMenu; + } - public boolean isWarpsMenuEnabled() { - return warpsMenu; - } + public boolean isWarpsMenuEnabled() { + return warpsMenu; + } - /** - * Change whether or not the warps menu is enabled. - * - * @param status if true, the warps menu will be enabled, if false, it won't. - */ - public void setWarpsMenuEnabled(boolean status) { - this.warpsMenu = status; - } + /** + * Change whether or not the warps menu is enabled. + * + * @param status if true, the warps menu will be enabled, if false, it won't. + */ + public void setWarpsMenuEnabled(boolean status) { + this.warpsMenu = status; + } } diff --git a/src/main/java/com/caved_in/commons/event/StackTraceEvent.java b/src/main/java/com/caved_in/commons/event/StackTraceEvent.java index 7163212..7ddcc0d 100644 --- a/src/main/java/com/caved_in/commons/event/StackTraceEvent.java +++ b/src/main/java/com/caved_in/commons/event/StackTraceEvent.java @@ -3,7 +3,7 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; -import com.caved_in.commons.config.DebugConfig; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.debug.Debugger; import com.caved_in.commons.player.Players; import com.caved_in.commons.plugin.Plugins; @@ -49,18 +49,17 @@ public static void call(Throwable throwable) { } public static void handle(StackTraceEvent e) { - DebugConfig debugConfig = Commons.getInstance().getConfiguration().getDebugConfig(); - + Configuration config = Commons.getInstance().getConfiguration(); Set debuggingPlayers = Players.getAllDebugging(); Throwable eventException = e.getException(); //If the books for stack-tracing are enabled, then give one to all the debugging players - if (debugConfig.isStackTraceBooks()) { + if (config.enableStackTraceBook()) { ItemStack exceptionBook = Debugger.createExceptionBook(eventException); debuggingPlayers.forEach(p -> Players.giveItem(p, exceptionBook)); } //If the stack trace messages are to be sent in chat, send em! - if (debugConfig.isStackTraceChat()) { + if (config.enableStackTraceChat()) { String[] exceptionMessages = Messages.exceptionInfo(eventException); //For every player that's debugging, send them the exception-info message debuggingPlayers.forEach(p -> Chat.message(p.getPlayer(), exceptionMessages)); diff --git a/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java b/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java index 8870029..06b4c9f 100644 --- a/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java +++ b/src/main/java/com/caved_in/commons/listeners/BlockFormListener.java @@ -1,7 +1,7 @@ package com.caved_in.commons.listeners; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.Configuration; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -9,7 +9,7 @@ public class BlockFormListener implements Listener { - private CommonsXmlConfiguration config; + private Configuration config; public BlockFormListener() { config = Commons.getInstance().getConfiguration(); @@ -20,12 +20,12 @@ public void onBlockForm(BlockFormEvent event) { Material blockType = event.getNewState().getType(); switch (blockType) { case SNOW: - if (config.getWorldConfig().isSnowSpreadDisabled()) { + if (config.disableSnowAccumulation()) { event.setCancelled(true); } break; case ICE: - if (config.getWorldConfig().isIceSpreadDisabled()) { + if (config.disableIceAccumulation()) { event.setCancelled(true); } break; diff --git a/src/main/java/com/caved_in/commons/listeners/ChatListener.java b/src/main/java/com/caved_in/commons/listeners/ChatListener.java index 39f5598..8b85901 100644 --- a/src/main/java/com/caved_in/commons/listeners/ChatListener.java +++ b/src/main/java/com/caved_in/commons/listeners/ChatListener.java @@ -3,7 +3,7 @@ import com.caved_in.commons.Commons; import com.caved_in.commons.Messages; import com.caved_in.commons.chat.Chat; -import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.player.MinecraftPlayer; import com.caved_in.commons.player.Players; import com.caved_in.commons.utilities.StringUtil; @@ -17,7 +17,7 @@ public class ChatListener implements Listener { private static Commons commons = Commons.getInstance(); - private CommonsXmlConfiguration config; + private Configuration config; public ChatListener() { config = commons.getConfiguration(); @@ -27,7 +27,7 @@ public ChatListener() { public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); //Check if the chat is silenced - if (config.getWorldConfig().isChatSilenced()) { + if (config.isChatSilenced()) { if (!Players.canChatWhileSilenced(player)) { //Send the player a message saying the chat's silenced Chat.message(player, Messages.CHAT_SILENCED); @@ -45,7 +45,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) { // return; // } - if (config.getWorldConfig().hasExternalChatHandler()) { + if (config.hasExternalChatPlugin()) { return; } diff --git a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java index b07f86e..b96cc44 100644 --- a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java +++ b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/HasSqlBackendItem.java @@ -1,7 +1,7 @@ package com.caved_in.commons.menu.menus.configmenu.items; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.item.Wool; import com.caved_in.commons.menu.MenuItem; import org.bukkit.entity.Player; @@ -9,7 +9,7 @@ public class HasSqlBackendItem extends MenuItem { - private CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); + private Configuration config = Commons.getInstance().getConfiguration(); public HasSqlBackendItem() { super(); @@ -32,7 +32,7 @@ private void init() { @Override public void onClick(Player player, ClickType type) { boolean hasSqlBackend = !config.hasSqlBackend(); - config.setSqlBackend(hasSqlBackend); + config.setMysqlBackend(hasSqlBackend); init(); getMenu().updateMenu(); } diff --git a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java index 737cfe6..fa6c37b 100644 --- a/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java +++ b/src/main/java/com/caved_in/commons/menu/menus/configmenu/items/RegisterCommandsItem.java @@ -1,7 +1,7 @@ package com.caved_in.commons.menu.menus.configmenu.items; import com.caved_in.commons.Commons; -import com.caved_in.commons.config.CommonsXmlConfiguration; +import com.caved_in.commons.config.Configuration; import com.caved_in.commons.item.Wool; import com.caved_in.commons.menu.MenuItem; import org.bukkit.entity.Player; @@ -30,9 +30,9 @@ private void init() { @Override public void onClick(Player player, ClickType type) { - CommonsXmlConfiguration config = Commons.getInstance().getConfiguration(); + Configuration config = Commons.getInstance().getConfiguration(); boolean registerCommands = !config.registerCommands(); - config.setRegisterCommands(registerCommands); + config.registerCommands(registerCommands); init(); getMenu().updateMenu(); } diff --git a/src/main/java/com/caved_in/commons/yml/InternalConverter.java b/src/main/java/com/caved_in/commons/yml/InternalConverter.java index e10df66..40312af 100644 --- a/src/main/java/com/caved_in/commons/yml/InternalConverter.java +++ b/src/main/java/com/caved_in/commons/yml/InternalConverter.java @@ -20,12 +20,12 @@ public class InternalConverter { public InternalConverter() { try { - addConverter(Primitive.class); - addConverter(Config.class); - addConverter(List.class); - addConverter(Map.class); - addConverter(Array.class); - addConverter(Set.class); + addConverter(PrimitiveYamlConverter.class); + addConverter(YamlConfigConverter.class); + addConverter(ListYamlConverter.class); + addConverter(MapYamlConverter.class); + addConverter(ArrayYamlConverter.class); + addConverter(SetYamlConverter.class); } catch (InvalidConverterException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Array.java b/src/main/java/com/caved_in/commons/yml/converter/ArrayYamlConverter.java similarity index 93% rename from src/main/java/com/caved_in/commons/yml/converter/Array.java rename to src/main/java/com/caved_in/commons/yml/converter/ArrayYamlConverter.java index 2cf5c74..162c283 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Array.java +++ b/src/main/java/com/caved_in/commons/yml/converter/ArrayYamlConverter.java @@ -11,10 +11,10 @@ * @author geNAZt (fabian.fassbender42@googlemail.com) * @author bibo38 */ -public class Array implements Converter { +public class ArrayYamlConverter implements Converter { private InternalConverter internalConverter; - public Array(InternalConverter internalConverter) { + public ArrayYamlConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } diff --git a/src/main/java/com/caved_in/commons/yml/converter/List.java b/src/main/java/com/caved_in/commons/yml/converter/ListYamlConverter.java similarity index 93% rename from src/main/java/com/caved_in/commons/yml/converter/List.java rename to src/main/java/com/caved_in/commons/yml/converter/ListYamlConverter.java index 7c89ef1..0ebfaf3 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/List.java +++ b/src/main/java/com/caved_in/commons/yml/converter/ListYamlConverter.java @@ -9,10 +9,10 @@ /** * @author geNAZt (fabian.fassbender42@googlemail.com) */ -public class List implements Converter { +public class ListYamlConverter implements Converter { private InternalConverter internalConverter; - public List(InternalConverter internalConverter) { + public ListYamlConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Map.java b/src/main/java/com/caved_in/commons/yml/converter/MapYamlConverter.java similarity index 96% rename from src/main/java/com/caved_in/commons/yml/converter/Map.java rename to src/main/java/com/caved_in/commons/yml/converter/MapYamlConverter.java index be9b46a..088d7bc 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Map.java +++ b/src/main/java/com/caved_in/commons/yml/converter/MapYamlConverter.java @@ -10,10 +10,10 @@ /** * @author geNAZt (fabian.fassbender42@googlemail.com) */ -public class Map implements Converter { +public class MapYamlConverter implements Converter { private InternalConverter internalConverter; - public Map(InternalConverter internalConverter) { + public MapYamlConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Primitive.java b/src/main/java/com/caved_in/commons/yml/converter/PrimitiveYamlConverter.java similarity index 91% rename from src/main/java/com/caved_in/commons/yml/converter/Primitive.java rename to src/main/java/com/caved_in/commons/yml/converter/PrimitiveYamlConverter.java index 59e2b8e..160945d 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Primitive.java +++ b/src/main/java/com/caved_in/commons/yml/converter/PrimitiveYamlConverter.java @@ -9,7 +9,7 @@ /** * @author geNAZt (fabian.fassbender42@googlemail.com) */ -public class Primitive implements Converter { +public class PrimitiveYamlConverter implements Converter { private HashSet types = new HashSet() {{ add("boolean"); add("char"); @@ -23,7 +23,7 @@ public class Primitive implements Converter { private InternalConverter internalConverter; - public Primitive(InternalConverter internalConverter) { + public PrimitiveYamlConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Set.java b/src/main/java/com/caved_in/commons/yml/converter/SetYamlConverter.java similarity index 93% rename from src/main/java/com/caved_in/commons/yml/converter/Set.java rename to src/main/java/com/caved_in/commons/yml/converter/SetYamlConverter.java index 7cc6c6f..c609787 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Set.java +++ b/src/main/java/com/caved_in/commons/yml/converter/SetYamlConverter.java @@ -8,10 +8,10 @@ import java.util.HashSet; import java.util.Iterator; -public class Set implements Converter { +public class SetYamlConverter implements Converter { private InternalConverter internalConverter; - public Set(InternalConverter internalConverter) { + public SetYamlConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } diff --git a/src/main/java/com/caved_in/commons/yml/converter/Config.java b/src/main/java/com/caved_in/commons/yml/converter/YamlConfigConverter.java similarity index 93% rename from src/main/java/com/caved_in/commons/yml/converter/Config.java rename to src/main/java/com/caved_in/commons/yml/converter/YamlConfigConverter.java index a47999f..29b27be 100644 --- a/src/main/java/com/caved_in/commons/yml/converter/Config.java +++ b/src/main/java/com/caved_in/commons/yml/converter/YamlConfigConverter.java @@ -11,10 +11,10 @@ /** * @author geNAZt (fabian.fassbender42@googlemail.com) */ -public class Config implements Converter { +public class YamlConfigConverter implements Converter { private InternalConverter internalConverter; - public Config(InternalConverter internalConverter) { + public YamlConfigConverter(InternalConverter internalConverter) { this.internalConverter = internalConverter; } From f2eb0e367e40c0bddaa327cba5759a4f2ea34d27 Mon Sep 17 00:00:00 2001 From: TheGamersCave Date: Fri, 29 Jan 2016 15:32:49 -0330 Subject: [PATCH 3/5] Implemented LeavesDecayListener Updated implementations of each config. --- .../java/com/caved_in/commons/Commons.java | 1763 +++++++++-------- .../config/CommonsXmlConfiguration.java | 10 + .../config/CommonsYamlConfiguration.java | 15 +- .../commons/config/Configuration.java | 4 + .../commons/config/WorldConfiguration.java | 34 +- .../listeners/LeavesDecayListener.java | 24 + .../caved_in/commons/yml/ConfigMapper.java | 19 +- 7 files changed, 978 insertions(+), 891 deletions(-) create mode 100644 src/main/java/com/caved_in/commons/listeners/LeavesDecayListener.java diff --git a/src/main/java/com/caved_in/commons/Commons.java b/src/main/java/com/caved_in/commons/Commons.java index 50acb01..22d91e1 100644 --- a/src/main/java/com/caved_in/commons/Commons.java +++ b/src/main/java/com/caved_in/commons/Commons.java @@ -199,659 +199,499 @@ public String getAuthor() { return "Brandon Curtis"; } - @Override - public void initConfig() { - Serializer configSerializer = new Persister(); + public static class TeleportMenuSettings { + private List disabledUuids = new ArrayList<>(); - File dataOptionFile = new File(DATA_OPTION_FILE); + private static TeleportMenuSettings instance; - File xmlConfigFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); - File ymlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.yml"); + private TextFile textFile; + public static TeleportMenuSettings getInstance() { + return instance; + } - /* - Check if the warps folder exists, and if not - then create it! - */ - File warpsFolder = new File(WARP_DATA_FOLDER); - if (!warpsFolder.exists()) { - warpsFolder.mkdirs(); + public static void init(String path) { + instance = new TeleportMenuSettings(path); } - /* - Create the items folder, where - serializable items are stored - */ - File itemsFolder = new File(ITEM_DATA_FOLDER); - if (!itemsFolder.exists()) { - itemsFolder.mkdirs(); + protected TeleportMenuSettings(String filePath) { + textFile = new TextFile(filePath); } - /* - Create the sets folder for the item manager; used to save and load- track and update item sets. - */ - File itemSetsFolder = new File(ITEM_SET_DATA_FOLDER); - if (!itemSetsFolder.exists()) { - itemSetsFolder.mkdirs(); + public boolean hasMenuDisabled(UUID id) { + return disabledUuids.contains(id.toString()); } - Collection itemSetFiles = FileUtils.listFiles(itemSetsFolder, null, false); - if (itemSetFiles.size() > 0) { - /* Load all the files in the item folder, into the item set manager */ - for (File file : itemSetFiles) { - try { - ItemSetManager.ItemSet set = configSerializer.read(ItemSetManager.ItemSet.class, file); + public void disableMenu(UUID id) { + disabledUuids.add(id.toString()); + save(); + } - if (set == null) { - continue; - } + public void enableMenu(UUID id) { + disabledUuids.remove(id.toString()); + save(); + } - itemSetManager.addSet(set); - debug(String.format("Loaded itemset '%s' into the ItemSet Manager", set.getName())); - } catch (Exception e) { - e.printStackTrace(); - } - } + private void save() { + textFile.overwriteFile(disabledUuids); } + } - Collection itemFiles = FileUtils.listFiles(itemsFolder, null, false); + public static class Rules { + private static List rules = Lists.newArrayList( + "1. You may not use vulgar or abusive language.", + "2. You musn't be racist.", + "3. You musn't use hacks or (unnapproved) mods that give you an unfair advantage", + "4. You may not spam", + "5. You may not advertise", + "6. You musn't use excessive caps", + "7. You may not advertise any links that are not Tunnels related", + "8. You musn't abuse glitches or game exploits", + "9. You may not troll any of the members, or ellicit ill behaviour in any way.", + "10. You must be respectful to players", + "11. Do not abuse glitches, and report them if found", + "12. Do not steal, nor cheat the server or players", + "13. AFK Machines are forbidden." + ); - if (itemFiles.size() > 0) { - /* Load all the files in the item folder, into the saved item manager */ - for (File file : itemFiles) { - SavedItemManager.loadItem(file); - } + private static File file; + + private static Rules instance; + + public static void init(File file) { + instance = new Rules(file); } - /* - Check if the debug data folder exists, and if not then create it! - */ - File debugFolder = new File(DEBUG_DATA_FOLDER); - if (!debugFolder.exists()) { - debugFolder.mkdirs(); + public static Rules getInstance() { + return instance; } - /* - Initialize the rules class! - */ - Rules.init(new File(RULES_LOCATION)); + protected Rules(File f) { + file = f; - /* - Initialize the Teleport Menu Settings - */ - TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); + /* + If the rules file doesn't exist, then create it! - /* - This is a fresh install of commons! - */ - if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { + */ + if (!file.exists()) { + + //todo implement option for players who have their swear filter off, to things like "don't be a dick" + try { + FileUtils.writeLines(file, rules); + } catch (IOException e) { + e.printStackTrace(); + } + return; + } - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| This may be the first time |", - "| you've ever used Commons, or |", - "| simply the first time you've |", - "| used it since release 1.8.8-3 |", - "| but either way, please assure |", - "| you've chosen your data type |", - "| in the 'data-option.txt' file |", - "| inside 'Commons' plugin-data |", - "| folder. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| (Conversion is automatic) |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); + load(); + } + + public static void load() { try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); + rules = FileUtils.readLines(file); } catch (IOException e) { e.printStackTrace(); } + } - globalConfig = new CommonsYamlConfiguration(); - + public static void add(String rule) { + rules.add(String.format("%s. %s", rules.size() + 1, rule)); try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - } catch (InvalidConfigurationException e) { + FileUtils.writeLines(file, rules, false); + } catch (IOException e) { + //unable to add rules. e.printStackTrace(); } } - if (!dataOptionFile.exists()) { - /* - This usually happens when servers are upgrading from a previous - Commons version, to version 1.8.8-3 + public static List getRules() { + return rules; + } - If they have an XML Configuration file and no data option file, - then we're going to make their default the XML Config (that they had previously) - though at the same time inform them of how to convert, and so forth. - */ - if (xmlConfigFile.exists()) { - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=xml" - )); - } catch (IOException e) { - e.printStackTrace(); - } + } - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| It seems you've used commons |", - "| before, and have an existing |", - "| configuration file available |", - "| so we'll continue using that. |", - "| |", - "| To Convert to YML config, you |", - "| must change 'data-option.txt' |", - "| inside Commons plugin folder. |", - "| |", - "| Supported options are |", - "| 'commons-data-format=yml' and |", - "| 'commons-data-format=xml' |", - "| which signal your format. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| (Conversion is automatic) |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); + public static int getServerId() { + return 0; + } - //They've got an XML File for config. - try { - globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - } - return; - } + private void prepForCustomEnchantments() { + ReflectionUtilities.setField(Enchantment.class, "acceptingNew", null, true); + } - /* - If there's no data option file present, and there's a YML file present - then it's likely someone deleted their data-option.txt + private void registerListeners() { - We'll send a nice notice to the console, and inform them of the issues caused - by doing this. Hopefully warning them to not do it again! + registerListeners(new ChatListener()); + debug("&aCreated the Chat Listener"); - It's also a fail-safe to prevent loading a different configuration file / type - when it's not required. - */ - if (ymlConfigFile.exists()) { - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| It seems you have config.yml |", - "| as your config file, though |", - "| you have no data-option.txt |", - "| |", - "| To properly config and data |", - "| throughout commons we require |", - "| this file be present. It will |", - "| be re-created, though please |", - "| don't remove this file again. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); + if (globalConfig.hasLaunchpadPressurePlates()) { + registerListeners(new LauncherListener()); // Register fire pad listener if its enabled + debug("&aRegistered the fire pad listener"); + } - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); - } catch (IOException e) { - e.printStackTrace(); - } + if (globalConfig.disableIceAccumulation() || globalConfig.disableSnowAccumulation()) { + registerListeners(new BlockFormListener()); + debug("&aRegistered the block spread listener"); + } - globalConfig = new CommonsYamlConfiguration(); - try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------"); - Plugins.disablePlugin(this); - return; - } - } else { - /* - No data-option.txt and no config file, then we're going to want to - create the config.yml file by default. + if (globalConfig.disableMyceliumSpread()) { + registerListeners(new BlockSpreadListener()); + debug("&aRegistered the mycelium spread listener"); + } - Give them a notice of this functionality, and also explain - that an XML based configuration file is also - available if they choose! - */ + if (globalConfig.disableThunder()) { + registerListeners(new ThungerChangeListener()); + debug("&aRegistered the thunder listener"); + } - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| This may be the first time |", - "| you've ever used Commons, or |", - "| simply the first time you've |", - "| used it since release 1.8.8-3 |", - "| but either way, please assure |", - "| you've chosen your data type |", - "| in the 'data-option.txt' file |", - "| inside 'Commons' plugin-data |", - "| folder. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); + if (globalConfig.disableWeather()) { + registerListeners(new WeatherChangeListener()); + debug("&aRegistered the Weather-Change listener"); + } - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); - } catch (IOException e) { - e.printStackTrace(); - } + if (globalConfig.disableLightning()) { + registerListeners(new LightningStrikeListener()); + debug("&aRegistered the lightning listener"); + } - globalConfig = new CommonsYamlConfiguration(); - try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - //INVALID INITIAL CONFIG? - e.printStackTrace(); - } - } + if (globalConfig.disableFireSpread()) { + registerListeners(new FireSpreadListener()); + debug("&aRegistered the fire-spread listener"); + } - } else { - /* - In this case they actually have a data-option.txt file present, - so we're going to parse their file for type of chosen configuration - and see if they're converting, or simply loading the previous choice they had made. + if (!globalConfig.enableItemPickup()) { + registerListeners(new ItemPickupListener()); + debug("&aRegistered the item-pickup listener"); + } - If they're converting, they'll have (for example) commons-data-format=yml - in their data-option.txt and a 'Config.xml' file present in their - plugin data folder (Or vice versa) - */ - String dataFileContents = null; - try { - dataFileContents = FileUtils.readFileToString(dataOptionFile); - } catch (IOException e) { - e.printStackTrace(); - } + if (!globalConfig.enableFoodChange()) { + registerListeners(new FoodChangeListener()); + debug("&aRegistered the food change listener"); + } - /* - If there's an error while attempting to load their data-option file - then we're going to give them a nice message warning about this, - and then disable commons from loading to prevent any further Errors from happening! - */ - if (dataFileContents == null) { - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| It appears you have an error |", - "| or invalid format in the file |", - "| 'data-option.txt' inside of |", - "| Commons plugin folder. |", - "| |", - "| Please fix this error/syntax |", - "| or delete it and then restart |", - "| your server to regenerate it. |", - "| |", - "| This file is essential to the |", - "| method Commons uses to convert |", - "|between xml and yml based files |", - "| |", - "| ........ |", - "| Meaning something, or someone |", - "|along the way broke a key part |", - "|of Commons functionality! Oops! |", - "| ........ |", - "| |", - "| No big deal. Follow the steps |", - "| above and everything should go |", - "| back to normal in no time! :) |", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); - Plugins.disablePlugin(this); + //If the server is backed by SQL, then push the specific listeners + if (globalConfig.hasSqlBackend()) { + //Used to handle kicking of banned / temp-banned players + registerListeners(new PrePlayerLoginListener()); + debug("&aRegistered the player pre-login listener"); + } - return; - } - /* - Though if it makes it this far then we're going to continue with parsing - their chosen config format, and perhaps performing a Conversion! - */ + registerListeners( + //Used for gadgets, interaction restriction, etc. + new PlayerInteractListener(), + new BlockBreakPlaceListener(), + new EntityExplodeListener(), + new WorldLoadedListener(), + new ServerPingListener(), + new PlayerLoginListener(), + new PlayerJoinListener(), + new PlayerKickListener(), + new InventoryListener(), + new PlayerTeleportListener(), + new PlayerQuitListener(), + //Listen to the command pre-process event so we can spit params at debuggers, and drop disabled commands + new CommandPreProcessListener(), + //Listen to when a player dies so we can get the return location, incase they use /back + new PlayerDeathListener(), + //Used to handle the dropping of weapons. and items in general. + new ItemDropListener(), + //Used with the Weapons API. + new EntityDamageEntityListener(), + new ItemBreakListener(), + new ItemDamageListener(), + new EntityDamageListener(), + new SignEditListener(), + new LeavesDecayListener() + ); + } - String[] options = dataFileContents.split("="); - String option = options[1].trim().replace("\n", "").replace("\r", ""); - if (option.equalsIgnoreCase("xml")) { - /* - They've chosen to use XMl as the configuration option. - We check if they have a YML based configuration file available - and if they do perform a conversion! + public boolean hasDatabaseBackend() { + return Commons.getInstance().getConfiguration().hasSqlBackend(); + } - If they don't have a YML based file, and they have an XML file then they're - simply loading the configuration they had previously. - */ + public void reloadConfiguration() { + getInstance().initConfig(); + } - if (ymlConfigFile.exists()) { - CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); - try { - yamlConfig.load(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Before continueing with the conversion from yml to XML", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "", - "Choosing to regenerate your config file, and deleting config.yml", - "Will render you a fresh configuration!", - "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------" - ); - Plugins.disablePlugin(this); - return; - } + public Configuration getConfiguration() { + return globalConfig; + } - CommonsXmlConfiguration cxmlConfig = new CommonsXmlConfiguration(); + public static boolean bukkitVersionMatches(String versionNumber) { + return Plugins.getBukkitVersion().contains(versionNumber); + } - /* - Attempting to move all the values from the previous config.yml - to the new Config.xml file! + public ItemSetManager getItemSetManager() { + return itemSetManager; + } - Then after that, we delete the config.yml! (So there's no further confusion :) - */ - alternateCommonsConfig(yamlConfig, cxmlConfig); - globalConfig = cxmlConfig; - /* - Delete the previous config.yml file to avoid issues! - */ - try { - FileUtils.forceDelete(ymlConfigFile); - } catch (IOException e) { - e.printStackTrace(); - } + public ServerDatabaseConnector getServerDatabase() { + return database; + } - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| ~~~ITS A SUCCESS~~~ |", - "| |", - "| You've converted from using a |", - "| yml based config file to using |", - "| an xml based configuration file|", - "| |", - "| To convert back simply change |", - "| the option to yml in your |", - "| data-option.txt file and then |", - "| restart your server to start |", - "|the automatic conversion process|", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); - } else { - /* - In this case, they've chosen XML as their configuration, and don't have - a previous config.yml file to convert from! + public Players getPlayerHandler() { + return players; + } + + public PrivateMessageManager getPrivateMessageManager() { + return privateMessageManager; + } + + public Worlds getWorldHandler() { + return worlds; + } + + public boolean isServerFull() { + return Players.getOnlineCount() >= Bukkit.getMaxPlayers(); + } + + public ChatMenuCommandListener getChatMenuListener() { + return chatMenuListener; + } + + + private void alternateCommonsConfig(Configuration currentConfig, Configuration targetConfig) { + /* + Configure all the database options! + */ + targetConfig.setMysqlBackend(currentConfig.hasSqlBackend()); + targetConfig.setMysqlHost(currentConfig.getMysqlHost()); + targetConfig.setMysqlPort(currentConfig.getMysqlPort()); + targetConfig.setMysqlDatabaseName(currentConfig.getMysqlDatabaseName()); + targetConfig.setMysqlUsername(currentConfig.getMysqlUsername()); + targetConfig.setMysqlPassword(currentConfig.getMysqlPassword()); + targetConfig.setTrackOnlinePlayerStatus(currentConfig.trackOnlinePlayerStatus()); + targetConfig.setServerName(currentConfig.getServerName()); + + /* + Commands configuration! + */ + targetConfig.registerCommands(currentConfig.registerCommands()); + targetConfig.enableBukkitCommands(currentConfig.enableBukkitCommands()); + targetConfig.enablePluginsCommand(currentConfig.enablePluginsCommand()); + + /* + Server-specific configuration! + */ + targetConfig.enableJoinMessages(currentConfig.enableJoinMessages()); + targetConfig.enableLeaveMessages(currentConfig.enableLeaveMessages()); + targetConfig.enableKickMessages(currentConfig.enableKickMessages()); + targetConfig.externalChatPlugin(currentConfig.hasExternalChatPlugin()); + targetConfig.silenceChat(currentConfig.isChatSilenced()); + + /* + Premium Only mode configuration! + */ + targetConfig.setPremiumOnlyMode(currentConfig.isPremiumOnlyMode()); + targetConfig.setPremiumUserPermission(currentConfig.getPremiumUserPermission()); + targetConfig.premiumOnlyModeKickMessage(currentConfig.getPremiumOnlyModeKickMessage()); + targetConfig.kickNonPremiumPlayerWhenFull(currentConfig.kickNonPremiumPlayerWhenFull()); + targetConfig.setKickNonPremiumMessage(currentConfig.kickNonPremiumMessage()); + + /* + World configuration! + */ + targetConfig.teleportToSpawnOnJoin(currentConfig.teleportToSpawnOnJoin()); + targetConfig.disableWeather(currentConfig.disableWeather()); + targetConfig.disableLightning(currentConfig.disableLightning()); + targetConfig.disableThunder(currentConfig.disableThunder()); + targetConfig.disableIceAccumulation(currentConfig.disableIceAccumulation()); + targetConfig.disableSnowAccumulation(currentConfig.disableSnowAccumulation()); + targetConfig.disableMyceliumSpread(currentConfig.disableMyceliumSpread()); + targetConfig.disableFireSpread(currentConfig.disableFireSpread()); + targetConfig.launchpadPressurePlates(currentConfig.hasLaunchpadPressurePlates()); + targetConfig.enableBlockBreak(currentConfig.enableBlockBreak()); + targetConfig.enableItemDrop(currentConfig.enableItemDrop()); + targetConfig.enableItemPickup(currentConfig.enableItemPickup()); + targetConfig.enableFoodChange(currentConfig.enableFoodChange()); + targetConfig.explosionFireworks(currentConfig.hasExplosionFireworks()); + targetConfig.enableFallDamage(currentConfig.enableFallDamage()); + targetConfig.disableLeavesDecay(currentConfig.disableLeavesDecay()); + + /* + Maintenance mode configuration! + */ + targetConfig.setMaintenanceMode(currentConfig.isMaintenanceModeEnabled()); + targetConfig.maintenanceModeKickMessage(currentConfig.maintenanceModeKickMessage()); + targetConfig.maintenanceModeMotd(currentConfig.maintenanceModeMotd()); + + /* + Debug configuration! + */ + targetConfig.enableStackTraceEvent(currentConfig.enableStackTraceEvent()); + targetConfig.enableStackTraceBook(currentConfig.enableStackTraceBook()); + targetConfig.enableStackTraceChat(currentConfig.enableStackTraceChat()); + + /* + Warps Configuration! + */ + targetConfig.enableWarpsMenu(currentConfig.enableWarpsMenu()); + } + + @Override + public void initConfig() { + Serializer configSerializer = new Persister(); + + File dataOptionFile = new File(DATA_OPTION_FILE); + + File xmlConfigFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); + File ymlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.yml"); + + + /* + Check if the warps folder exists, and if not + then create it! + */ + File warpsFolder = new File(WARP_DATA_FOLDER); + if (!warpsFolder.exists()) { + warpsFolder.mkdirs(); + } + + /* + Create the items folder, where + serializable items are stored + */ + File itemsFolder = new File(ITEM_DATA_FOLDER); + if (!itemsFolder.exists()) { + itemsFolder.mkdirs(); + } - If they have an existing Config.xml file we'll load that bad boy up - and use that as configuration (Meaning they already chose xml as the option before) - though if not, they must have DELETED their configuration file in a previous attempt.... - */ + /* + Create the sets folder for the item manager; used to save and load- track and update item sets. + */ + File itemSetsFolder = new File(ITEM_SET_DATA_FOLDER); + if (!itemSetsFolder.exists()) { + itemSetsFolder.mkdirs(); + } - if (xmlConfigFile.exists()) { - try { - globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - if (globalConfig == null) { - } else { - } - } catch (Exception e) { - e.printStackTrace(); - Plugins.disablePlugin(this); - return; - } - } else { - //todo send notice about not deleting configuration - /* - In this case, they've chosen XMl as their config type, and don't (or no longer) - have their Config.xml file! This is an issue, so we'll sort this out! - */ - globalConfig = new CommonsXmlConfiguration(); + Collection itemSetFiles = FileUtils.listFiles(itemSetsFolder, null, false); + if (itemSetFiles.size() > 0) { + /* Load all the files in the item folder, into the item set manager */ + for (File file : itemSetFiles) { + try { + ItemSetManager.ItemSet set = configSerializer.read(ItemSetManager.ItemSet.class, file); - try { - configSerializer.write(globalConfig, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - } + if (set == null) { + continue; } + + itemSetManager.addSet(set); + debug(String.format("Loaded itemset '%s' into the ItemSet Manager", set.getName())); + } catch (Exception e) { + e.printStackTrace(); } - } else if (option.equalsIgnoreCase("yml")) { + } + } - /* - This means they're converting from a previous configuration file - and wish to use YML instead! + Collection itemFiles = FileUtils.listFiles(itemsFolder, null, false); - Begin the process! - */ - if (xmlConfigFile.exists()) { - CommonsXmlConfiguration xmlConfiguration = null; - try { - xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - debug( - "====================================================", - "There was an error while processing your Config.xml", - "File inside of plugins/Commons/Config.xml", - "To prevent this from happening again you need", - "To assure the format and syntax of Config.xml", - "Is correct (in accordance to standard XML Documents", - "", - "COMMONS HAS BEEN DISABLED UNTIL THIS ISSUE IS CORRECTED", - "", - "RESTART YOUR SERVER ONCE FIXED TO CONTINUE AS DESIRED!", - "====================================================" - ); - Plugins.disablePlugin(this); - return; - } + if (itemFiles.size() > 0) { + /* Load all the files in the item folder, into the saved item manager */ + for (File file : itemFiles) { + SavedItemManager.loadItem(file); + } + } - /* - If a yml file already exists and so does an XML then delete the previous - yml file to avoid issues with instancing a new version! (Such as path changes, and such) - */ - if (ymlConfigFile.exists()) { - try { - FileUtils.forceDelete(ymlConfigFile); - } catch (IOException e) { - e.printStackTrace(); - } - } + /* + Check if the debug data folder exists, and if not then create it! + */ + File debugFolder = new File(DEBUG_DATA_FOLDER); + if (!debugFolder.exists()) { + debugFolder.mkdirs(); + } - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - alternateCommonsConfig(xmlConfiguration, yamlConfiguration); - globalConfig = yamlConfiguration; - try { - yamlConfiguration.init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); + /* + Initialize the rules class! + */ + Rules.init(new File(RULES_LOCATION)); - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Before continueing with the conversion from XML to yml", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "", - "Choosing to regenerate your config file, and deleting config.xml/config.yml", - "Will render you a fresh configuration!", - "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------" - ); - Plugins.disablePlugin(this); - return; - } + /* + Initialize the Teleport Menu Settings + */ + TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); - try { - FileUtils.forceDelete(xmlConfigFile); - debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", - "Your Commons config is now based out of config.yml"); - } catch (IOException e) { - e.printStackTrace(); - debug("Failed to delete the previous Config.xml from your Commons plugin folder."); - } + /* + This is a fresh install of commons! + */ + if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| ~~~ITS A SUCCESS~~~ |", - "| |", - "| You've converted from using a |", - "| xml based config file to using |", - "| an yml based configuration file|", - "| |", - "| To convert back simply change |", - "| the option to xml in your |", - "| data-option.txt file and then |", - "| restart your server to start |", - "|the automatic conversion process|", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } - return; - } + globalConfig = new CommonsYamlConfiguration(); - /* - They've previously chosen to use YML as a configuration style and have an existing config file - their plugins/Commons/ folder; Loading this file for configuration. - */ - if (ymlConfigFile.exists()) { + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - try { - yamlConfiguration.load(ymlConfigFile); - globalConfig = yamlConfiguration; - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } + if (!dataOptionFile.exists()) { + /* + This usually happens when servers are upgrading from a previous + Commons version, to version 1.8.8-3 + + If they have an XML Configuration file and no data option file, + then we're going to make their default the XML Config (that they had previously) + though at the same time inform them of how to convert, and so forth. + */ + if (xmlConfigFile.exists()) { + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=xml" + )); + } catch (IOException e) { + e.printStackTrace(); } - /* - They've chosen to use yml as their config file, though don't currently have a config.yml file! - Send them a notice saying they've likely deleted their previous version of configuration - and create a new one for them! - */ debug( "[===============================]", "| COMMONS NOTICE |", @@ -861,19 +701,35 @@ and use that as configuration (Meaning they already chose xml as the option befo "| XML and YAML (YML) Config |", "| as of release 1.8.8-3. |", "| |", - "| It seems you no config.yml in |", - "| your Commons plugin folder |", - "| but have yml as your chosen |", - "| data type in data-option.txt |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", "| |", - "| A new config.yml file will be |", - "| generated for you to use, and |", - "| configure accordingly to your |", - "| likings, and servers desire. |", + "| It seems you've used commons |", + "| before, and have an existing |", + "| configuration file available |", + "| so we'll continue using that. |", "| |", - "| To prevent this issue from |", - "| happening again, please don't |", - "| delete your config.yml file! |", + "| To Convert to YML config, you |", + "| must change 'data-option.txt' |", + "| inside Commons plugin folder. |", + "| |", + "| Supported options are |", + "| 'commons-data-format=yml' and |", + "| 'commons-data-format=xml' |", + "| which signal your format. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", "| |", "|-------------------------------|", "| |", @@ -881,344 +737,491 @@ and use that as configuration (Meaning they already chose xml as the option befo "[===============================]" ); - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + //They've got an XML File for config. try { - yamlConfiguration.init(ymlConfigFile); - globalConfig = yamlConfiguration; - } catch (InvalidConfigurationException e) { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { e.printStackTrace(); - //Error initializing initial configutration!? SHOULD NEVER HAPPEN } - } else { + return; } - } - } - - private void alternateCommonsConfig(Configuration currentConfig, Configuration targetConfig) { - /* - Configure all the database options! - */ - targetConfig.setMysqlBackend(currentConfig.hasSqlBackend()); - targetConfig.setMysqlHost(currentConfig.getMysqlHost()); - targetConfig.setMysqlPort(currentConfig.getMysqlPort()); - targetConfig.setMysqlDatabaseName(currentConfig.getMysqlDatabaseName()); - targetConfig.setMysqlUsername(currentConfig.getMysqlUsername()); - targetConfig.setMysqlPassword(currentConfig.getMysqlPassword()); - targetConfig.setTrackOnlinePlayerStatus(currentConfig.trackOnlinePlayerStatus()); - targetConfig.setServerName(currentConfig.getServerName()); - - /* - Commands configuration! - */ - targetConfig.registerCommands(currentConfig.registerCommands()); - targetConfig.enableBukkitCommands(currentConfig.enableBukkitCommands()); - targetConfig.enablePluginsCommand(currentConfig.enablePluginsCommand()); - - /* - Server-specific configuration! - */ - targetConfig.enableJoinMessages(currentConfig.enableJoinMessages()); - targetConfig.enableLeaveMessages(currentConfig.enableLeaveMessages()); - targetConfig.enableKickMessages(currentConfig.enableKickMessages()); - targetConfig.externalChatPlugin(currentConfig.hasExternalChatPlugin()); - targetConfig.silenceChat(currentConfig.isChatSilenced()); - - /* - Premium Only mode configuration! - */ - targetConfig.setPremiumOnlyMode(currentConfig.isPremiumOnlyMode()); - targetConfig.setPremiumUserPermission(currentConfig.getPremiumUserPermission()); - targetConfig.premiumOnlyModeKickMessage(currentConfig.getPremiumOnlyModeKickMessage()); - targetConfig.kickNonPremiumPlayerWhenFull(currentConfig.kickNonPremiumPlayerWhenFull()); - targetConfig.setKickNonPremiumMessage(currentConfig.kickNonPremiumMessage()); - - /* - World configuration! - */ - targetConfig.teleportToSpawnOnJoin(currentConfig.teleportToSpawnOnJoin()); - targetConfig.disableWeather(currentConfig.disableWeather()); - targetConfig.disableLightning(currentConfig.disableLightning()); - targetConfig.disableThunder(currentConfig.disableThunder()); - targetConfig.disableIceAccumulation(currentConfig.disableIceAccumulation()); - targetConfig.disableSnowAccumulation(currentConfig.disableSnowAccumulation()); - targetConfig.disableMyceliumSpread(currentConfig.disableMyceliumSpread()); - targetConfig.disableFireSpread(currentConfig.disableFireSpread()); - targetConfig.launchpadPressurePlates(currentConfig.hasLaunchpadPressurePlates()); - targetConfig.enableBlockBreak(currentConfig.enableBlockBreak()); - targetConfig.enableItemDrop(currentConfig.enableItemDrop()); - targetConfig.enableItemPickup(currentConfig.enableItemPickup()); - targetConfig.enableFoodChange(currentConfig.enableFoodChange()); - targetConfig.explosionFireworks(currentConfig.hasExplosionFireworks()); - targetConfig.enableFallDamage(currentConfig.enableFallDamage()); - - /* - Maintenance mode configuration! - */ - targetConfig.setMaintenanceMode(currentConfig.isMaintenanceModeEnabled()); - targetConfig.maintenanceModeKickMessage(currentConfig.maintenanceModeKickMessage()); - targetConfig.maintenanceModeMotd(currentConfig.maintenanceModeMotd()); - - /* - Debug configuration! - */ - targetConfig.enableStackTraceEvent(currentConfig.enableStackTraceEvent()); - targetConfig.enableStackTraceBook(currentConfig.enableStackTraceBook()); - targetConfig.enableStackTraceChat(currentConfig.enableStackTraceChat()); - - /* - Warps Configuration! - */ - targetConfig.enableWarpsMenu(currentConfig.enableWarpsMenu()); - } - - public static class TeleportMenuSettings { - private List disabledUuids = new ArrayList<>(); - - private static TeleportMenuSettings instance; - - private TextFile textFile; - - public static TeleportMenuSettings getInstance() { - return instance; - } - - public static void init(String path) { - instance = new TeleportMenuSettings(path); - } - - protected TeleportMenuSettings(String filePath) { - textFile = new TextFile(filePath); - } - - public boolean hasMenuDisabled(UUID id) { - return disabledUuids.contains(id.toString()); - } - - public void disableMenu(UUID id) { - disabledUuids.add(id.toString()); - save(); - } - - public void enableMenu(UUID id) { - disabledUuids.remove(id.toString()); - save(); - } - - private void save() { - textFile.overwriteFile(disabledUuids); - } - } - - public static class Rules { - private static List rules = Lists.newArrayList( - "1. You may not use vulgar or abusive language.", - "2. You musn't be racist.", - "3. You musn't use hacks or (unnapproved) mods that give you an unfair advantage", - "4. You may not spam", - "5. You may not advertise", - "6. You musn't use excessive caps", - "7. You may not advertise any links that are not Tunnels related", - "8. You musn't abuse glitches or game exploits", - "9. You may not troll any of the members, or ellicit ill behaviour in any way.", - "10. You must be respectful to players", - "11. Do not abuse glitches, and report them if found", - "12. Do not steal, nor cheat the server or players", - "13. AFK Machines are forbidden." - ); + /* + If there's no data option file present, and there's a YML file present + then it's likely someone deleted their data-option.txt - private static File file; + We'll send a nice notice to the console, and inform them of the issues caused + by doing this. Hopefully warning them to not do it again! - private static Rules instance; + It's also a fail-safe to prevent loading a different configuration file / type + when it's not required. + */ + if (ymlConfigFile.exists()) { + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you have config.yml |", + "| as your config file, though |", + "| you have no data-option.txt |", + "| |", + "| To properly config and data |", + "| throughout commons we require |", + "| this file be present. It will |", + "| be re-created, though please |", + "| don't remove this file again. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); - public static void init(File file) { - instance = new Rules(file); - } + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } - public static Rules getInstance() { - return instance; - } + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------"); + Plugins.disablePlugin(this); + return; + } + } else { + /* + No data-option.txt and no config file, then we're going to want to + create the config.yml file by default. - protected Rules(File f) { - file = f; + Give them a notice of this functionality, and also explain + that an XML based configuration file is also + available if they choose! + */ - /* - If the rules file doesn't exist, then create it! - - */ - if (!file.exists()) { + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); - //todo implement option for players who have their swear filter off, to things like "don't be a dick" try { - FileUtils.writeLines(file, rules); + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); } catch (IOException e) { e.printStackTrace(); } - return; - } - - - load(); - } - public static void load() { - try { - rules = FileUtils.readLines(file); - } catch (IOException e) { - e.printStackTrace(); + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + //INVALID INITIAL CONFIG? + e.printStackTrace(); + } } - } - public static void add(String rule) { - rules.add(String.format("%s. %s", rules.size() + 1, rule)); + } else { + /* + In this case they actually have a data-option.txt file present, + so we're going to parse their file for type of chosen configuration + and see if they're converting, or simply loading the previous choice they had made. + + If they're converting, they'll have (for example) commons-data-format=yml + in their data-option.txt and a 'Config.xml' file present in their + plugin data folder (Or vice versa) + */ + String dataFileContents = null; try { - FileUtils.writeLines(file, rules, false); + dataFileContents = FileUtils.readFileToString(dataOptionFile); } catch (IOException e) { - //unable to add rules. e.printStackTrace(); } - } - - public static List getRules() { - return rules; - } - - } - public static int getServerId() { - return 0; - } + /* + If there's an error while attempting to load their data-option file + then we're going to give them a nice message warning about this, + and then disable commons from loading to prevent any further Errors from happening! + */ + if (dataFileContents == null) { + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| It appears you have an error |", + "| or invalid format in the file |", + "| 'data-option.txt' inside of |", + "| Commons plugin folder. |", + "| |", + "| Please fix this error/syntax |", + "| or delete it and then restart |", + "| your server to regenerate it. |", + "| |", + "| This file is essential to the |", + "| method Commons uses to convert |", + "|between xml and yml based files |", + "| |", + "| ........ |", + "| Meaning something, or someone |", + "|along the way broke a key part |", + "|of Commons functionality! Oops! |", + "| ........ |", + "| |", + "| No big deal. Follow the steps |", + "| above and everything should go |", + "| back to normal in no time! :) |", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + Plugins.disablePlugin(this); - private void prepForCustomEnchantments() { - ReflectionUtilities.setField(Enchantment.class, "acceptingNew", null, true); - } + return; + } + /* + Though if it makes it this far then we're going to continue with parsing + their chosen config format, and perhaps performing a Conversion! + */ - private void registerListeners() { + String[] options = dataFileContents.split("="); + String option = options[1].trim().replace("\n", "").replace("\r", ""); + if (option.equalsIgnoreCase("xml")) { + /* + They've chosen to use XMl as the configuration option. + We check if they have a YML based configuration file available + and if they do perform a conversion! - registerListeners(new ChatListener()); - debug("&aCreated the Chat Listener"); + If they don't have a YML based file, and they have an XML file then they're + simply loading the configuration they had previously. + */ - if (globalConfig.hasLaunchpadPressurePlates()) { - registerListeners(new LauncherListener()); // Register fire pad listener if its enabled - debug("&aRegistered the fire pad listener"); - } + if (ymlConfigFile.exists()) { + CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); + try { + yamlConfig.load(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from yml to XML", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } - if (globalConfig.disableIceAccumulation() || globalConfig.disableSnowAccumulation()) { - registerListeners(new BlockFormListener()); - debug("&aRegistered the block spread listener"); - } + CommonsXmlConfiguration cxmlConfig = new CommonsXmlConfiguration(); - if (globalConfig.disableMyceliumSpread()) { - registerListeners(new BlockSpreadListener()); - debug("&aRegistered the mycelium spread listener"); - } + /* + Attempting to move all the values from the previous config.yml + to the new Config.xml file! - if (globalConfig.disableThunder()) { - registerListeners(new ThungerChangeListener()); - debug("&aRegistered the thunder listener"); - } + Then after that, we delete the config.yml! (So there's no further confusion :) + */ + alternateCommonsConfig(yamlConfig, cxmlConfig); + globalConfig = cxmlConfig; + /* + Delete the previous config.yml file to avoid issues! + */ + try { + FileUtils.forceDelete(ymlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + } - if (globalConfig.disableWeather()) { - registerListeners(new WeatherChangeListener()); - debug("&aRegistered the Weather-Change listener"); - } + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| yml based config file to using |", + "| an xml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to yml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + } else { + /* + In this case, they've chosen XML as their configuration, and don't have + a previous config.yml file to convert from! - if (globalConfig.disableLightning()) { - registerListeners(new LightningStrikeListener()); - debug("&aRegistered the lightning listener"); - } + If they have an existing Config.xml file we'll load that bad boy up + and use that as configuration (Meaning they already chose xml as the option before) + though if not, they must have DELETED their configuration file in a previous attempt.... + */ - if (globalConfig.disableFireSpread()) { - registerListeners(new FireSpreadListener()); - debug("&aRegistered the fire-spread listener"); - } + if (xmlConfigFile.exists()) { + try { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + if (globalConfig == null) { + } else { + } + } catch (Exception e) { + e.printStackTrace(); + Plugins.disablePlugin(this); + return; + } + } else { + //todo send notice about not deleting configuration + /* + In this case, they've chosen XMl as their config type, and don't (or no longer) + have their Config.xml file! This is an issue, so we'll sort this out! + */ + globalConfig = new CommonsXmlConfiguration(); - if (!globalConfig.enableItemPickup()) { - registerListeners(new ItemPickupListener()); - debug("&aRegistered the item-pickup listener"); - } + try { + configSerializer.write(globalConfig, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } else if (option.equalsIgnoreCase("yml")) { - if (!globalConfig.enableFoodChange()) { - registerListeners(new FoodChangeListener()); - debug("&aRegistered the food change listener"); - } + /* + This means they're converting from a previous configuration file + and wish to use YML instead! - //If the server is backed by SQL, then push the specific listeners - if (globalConfig.hasSqlBackend()) { - //Used to handle kicking of banned / temp-banned players - registerListeners(new PrePlayerLoginListener()); - debug("&aRegistered the player pre-login listener"); - } + Begin the process! + */ + if (xmlConfigFile.exists()) { + CommonsXmlConfiguration xmlConfiguration = null; + try { + xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + debug( + "====================================================", + "There was an error while processing your Config.xml", + "File inside of plugins/Commons/Config.xml", + "To prevent this from happening again you need", + "To assure the format and syntax of Config.xml", + "Is correct (in accordance to standard XML Documents", + "", + "COMMONS HAS BEEN DISABLED UNTIL THIS ISSUE IS CORRECTED", + "", + "RESTART YOUR SERVER ONCE FIXED TO CONTINUE AS DESIRED!", + "====================================================" + ); + Plugins.disablePlugin(this); + return; + } - registerListeners( - //Used for gadgets, interaction restriction, etc. - new PlayerInteractListener(), - new BlockBreakPlaceListener(), - new EntityExplodeListener(), - new WorldLoadedListener(), - new ServerPingListener(), - new PlayerLoginListener(), - new PlayerJoinListener(), - new PlayerKickListener(), - new InventoryListener(), - new PlayerTeleportListener(), - new PlayerQuitListener(), - //Listen to the command pre-process event so we can spit params at debuggers, and drop disabled commands - new CommandPreProcessListener(), - //Listen to when a player dies so we can get the return location, incase they use /back - new PlayerDeathListener(), - //Used to handle the dropping of weapons. and items in general. - new ItemDropListener(), - //Used with the Weapons API. - new EntityDamageEntityListener(), - new ItemBreakListener(), - new ItemDamageListener(), - new EntityDamageListener(), - new SignEditListener() - ); - } + /* + If a yml file already exists and so does an XML then delete the previous + yml file to avoid issues with instancing a new version! (Such as path changes, and such) + */ + if (ymlConfigFile.exists()) { + try { + FileUtils.forceDelete(ymlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + } + } - public boolean hasDatabaseBackend() { - return Commons.getInstance().getConfiguration().hasSqlBackend(); - } + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + alternateCommonsConfig(xmlConfiguration, yamlConfiguration); + globalConfig = yamlConfiguration; + try { + yamlConfiguration.init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); - public void reloadConfiguration() { - getInstance().initConfig(); - } + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from XML to yml", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.xml/config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } - public Configuration getConfiguration() { - return globalConfig; - } + try { + FileUtils.forceDelete(xmlConfigFile); + debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", + "Your Commons config is now based out of config.yml"); + } catch (IOException e) { + e.printStackTrace(); + debug("Failed to delete the previous Config.xml from your Commons plugin folder."); + } - public static boolean bukkitVersionMatches(String versionNumber) { - return Plugins.getBukkitVersion().contains(versionNumber); - } - public ItemSetManager getItemSetManager() { - return itemSetManager; - } + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| xml based config file to using |", + "| an yml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to xml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); - public ServerDatabaseConnector getServerDatabase() { - return database; - } + return; + } - public Players getPlayerHandler() { - return players; - } + /* + They've previously chosen to use YML as a configuration style and have an existing config file + their plugins/Commons/ folder; Loading this file for configuration. + */ + if (ymlConfigFile.exists()) { - public PrivateMessageManager getPrivateMessageManager() { - return privateMessageManager; - } + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.load(ymlConfigFile); + globalConfig = yamlConfiguration; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } - public Worlds getWorldHandler() { - return worlds; - } + /* + They've chosen to use yml as their config file, though don't currently have a config.yml file! + Send them a notice saying they've likely deleted their previous version of configuration + and create a new one for them! + */ + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you no config.yml in |", + "| your Commons plugin folder |", + "| but have yml as your chosen |", + "| data type in data-option.txt |", + "| |", + "| A new config.yml file will be |", + "| generated for you to use, and |", + "| configure accordingly to your |", + "| likings, and servers desire. |", + "| |", + "| To prevent this issue from |", + "| happening again, please don't |", + "| delete your config.yml file! |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); - public boolean isServerFull() { - return Players.getOnlineCount() >= Bukkit.getMaxPlayers(); - } + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.init(ymlConfigFile); + globalConfig = yamlConfiguration; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + //Error initializing initial configutration!? SHOULD NEVER HAPPEN + } + } else { + } - public ChatMenuCommandListener getChatMenuListener() { - return chatMenuListener; + } } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java index 11d91b0..c91c3f4 100644 --- a/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java @@ -375,6 +375,16 @@ public void disableFireSpread(boolean val) { worldConfig.setDisableFireSpread(val); } + @Override + public boolean disableLeavesDecay() { + return worldConfig.isDisableLeafDecay(); + } + + @Override + public void disableLeavesDecay(boolean val) { + worldConfig.setDisableLeafDecay(val); + } + @Override public boolean hasLaunchpadPressurePlates() { return worldConfig.hasLaunchpadPressurePlates(); diff --git a/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java b/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java index 5b68ae2..415b904 100644 --- a/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/CommonsYamlConfiguration.java @@ -155,7 +155,6 @@ public class CommonsYamlConfiguration extends YamlConfig implements Configuratio @Comment("When enabled, players will be teleported to their world spawn when joining the server") private boolean teleportToSpawnOnJoin = false; - @Path("Server.Worlds.disable-lightning") @Comment("Changes whether or not lightning will strike during a storm") private boolean disableLightning = false; @@ -180,6 +179,10 @@ public class CommonsYamlConfiguration extends YamlConfig implements Configuratio @Comment("Changes whether or not fire will spread") private boolean disableFireSpread = false; + @Path("Server.Worlds.disable-leaf-decay") + @Comment("Changes whether or not leaves will decay over time") + private boolean disableLeafDecay = false; + @Path("Server.Worlds.launchpad-pressure-plates") @Comment("When enabled it changes pressure plates into launch pads, like many server hubs have") private boolean launchpadPressurePlates = false; @@ -560,6 +563,16 @@ public void disableFireSpread(boolean val) { disableFireSpread = val; } + @Override + public boolean disableLeavesDecay() { + return disableLeafDecay; + } + + @Override + public void disableLeavesDecay(boolean val) { + disableLeafDecay = val; + } + @Override public boolean hasLaunchpadPressurePlates() { return launchpadPressurePlates; diff --git a/src/main/java/com/caved_in/commons/config/Configuration.java b/src/main/java/com/caved_in/commons/config/Configuration.java index 3f70fa7..59ffb31 100644 --- a/src/main/java/com/caved_in/commons/config/Configuration.java +++ b/src/main/java/com/caved_in/commons/config/Configuration.java @@ -118,6 +118,10 @@ public interface Configuration { public void disableFireSpread(boolean val); + public boolean disableLeavesDecay(); + + public void disableLeavesDecay(boolean val); + public boolean hasLaunchpadPressurePlates(); public void launchpadPressurePlates(boolean val); diff --git a/src/main/java/com/caved_in/commons/config/WorldConfiguration.java b/src/main/java/com/caved_in/commons/config/WorldConfiguration.java index f75d464..0180c12 100644 --- a/src/main/java/com/caved_in/commons/config/WorldConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/WorldConfiguration.java @@ -9,25 +9,28 @@ public class WorldConfiguration { private boolean teleportToSpawnOnJoin = false; @Element(name = "disable-weather") - private boolean disableWeather = true; + private boolean disableWeather = false; @Element(name = "disable-lightning") - private boolean disableLightning = true; + private boolean disableLightning = false; @Element(name = "disable-thunder") - private boolean disableThunder = true; + private boolean disableThunder = false; @Element(name = "disable-ice-accumulation") - private boolean disableIceAccumulation = true; + private boolean disableIceAccumulation = false; @Element(name = "disable-snow-accumulation") - private boolean disableSnowAccumulation = true; + private boolean disableSnowAccumulation = false; @Element(name = "disable-mycelium-spread") - private boolean disableMyceliumSpread = true; + private boolean disableMyceliumSpread = false; @Element(name = "disable-fire-spread") - private boolean disableFireSpread = true; + private boolean disableFireSpread = false; + + @Element(name = "disable-leaf-decay", required = false) + private boolean disableLeafDecay = false; @Element(name = "launchpad-pressure-plates") private boolean launchpadPressurePlates = false; @@ -57,11 +60,12 @@ public class WorldConfiguration { private boolean externalChatHandler = true; @Element(name = "explosion-fireworks") - private boolean explosionFireworks = true; + private boolean explosionFireworks = false; @Element(name = "enable-fall-damage") private boolean fallDamage = true; + @Element(name = "silence-chat", required = false) private boolean silenceChat = false; public WorldConfiguration( @@ -83,7 +87,9 @@ public WorldConfiguration( @Element(name = "enable-food-change") boolean enableFoodChange, @Element(name = "disable-fire-spread") boolean disableFireSpread, @Element(name = "explosion-fireworks") boolean explosionFireworks, - @Element(name = "enable-fall-damage") boolean fallDamage + @Element(name = "enable-fall-damage") boolean fallDamage, + @Element(name = "silence-chat", required = false) boolean silenceChat, + @Element(name = "disable-leaf-decay", required = false) boolean disableLeafDecay ) { this.teleportToSpawnOnJoin = teleportToSpawnOnJoin; this.disableIceAccumulation = disableIceAccumulation; @@ -104,6 +110,8 @@ public WorldConfiguration( this.disableFireSpread = disableFireSpread; this.explosionFireworks = explosionFireworks; this.fallDamage = fallDamage; + this.silenceChat = silenceChat; + this.disableLeafDecay = disableLeafDecay; } public WorldConfiguration() { @@ -313,4 +321,12 @@ public boolean isEnableKickMessages() { public void setEnableKickMessages(boolean enableKickMessages) { this.enableKickMessages = enableKickMessages; } + + public boolean isDisableLeafDecay() { + return disableLeafDecay; + } + + public void setDisableLeafDecay(boolean disableLeafDecay) { + this.disableLeafDecay = disableLeafDecay; + } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/listeners/LeavesDecayListener.java b/src/main/java/com/caved_in/commons/listeners/LeavesDecayListener.java new file mode 100644 index 0000000..46848f4 --- /dev/null +++ b/src/main/java/com/caved_in/commons/listeners/LeavesDecayListener.java @@ -0,0 +1,24 @@ +package com.caved_in.commons.listeners; + +import com.caved_in.commons.Commons; +import com.caved_in.commons.config.Configuration; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.LeavesDecayEvent; + +public class LeavesDecayListener implements Listener { + + private Configuration config = null; + + public LeavesDecayListener() { + config = Commons.getInstance().getConfiguration(); + } + + @EventHandler + public void onLeavesDecay(LeavesDecayEvent e) { + if (config.disableLeavesDecay()) { + e.setCancelled(true); + } + } + +} diff --git a/src/main/java/com/caved_in/commons/yml/ConfigMapper.java b/src/main/java/com/caved_in/commons/yml/ConfigMapper.java index 83a9f9d..d81f06a 100644 --- a/src/main/java/com/caved_in/commons/yml/ConfigMapper.java +++ b/src/main/java/com/caved_in/commons/yml/ConfigMapper.java @@ -76,8 +76,25 @@ public void loadFromMap(Map section, Class clazz) throws Exception { continue; } - String path = (CONFIG_MODE.equals(ConfigMode.PATH_BY_UNDERSCORE)) ? field.getName().replaceAll("_", ".") : field.getName(); + String path = ""; + switch (CONFIG_MODE) { + case PATH_BY_UNDERSCORE: + path = field.getName().replace("_", "."); + break; + case FIELD_IS_KEY: + path = field.getName(); + break; + case DEFAULT: + default: + String fieldName = field.getName(); + if (fieldName.contains("_")) { + path = field.getName().replace("_", "."); + } else { + path = field.getName(); + } + break; + } if (field.isAnnotationPresent(Path.class)) { Path path1 = field.getAnnotation(Path.class); path = path1.value(); From f4ee743b64a4bf932ec523aac95f3ee53b2139fb Mon Sep 17 00:00:00 2001 From: TheGamersCave Date: Fri, 29 Jan 2016 15:53:05 -0330 Subject: [PATCH 4/5] minor bug fixes and removal of debug statements --- src/main/java/com/caved_in/commons/Commons.java | 5 ++++- src/main/java/com/caved_in/commons/yml/ConfigMapper.java | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/caved_in/commons/Commons.java b/src/main/java/com/caved_in/commons/Commons.java index 22d91e1..4408d51 100644 --- a/src/main/java/com/caved_in/commons/Commons.java +++ b/src/main/java/com/caved_in/commons/Commons.java @@ -666,12 +666,15 @@ public void initConfig() { } globalConfig = new CommonsYamlConfiguration(); + CommonsYamlConfiguration ymlConfig = new CommonsYamlConfiguration(); try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + ymlConfig.init(ymlConfigFile); + globalConfig = ymlConfig; } catch (InvalidConfigurationException e) { e.printStackTrace(); } + return; } if (!dataOptionFile.exists()) { diff --git a/src/main/java/com/caved_in/commons/yml/ConfigMapper.java b/src/main/java/com/caved_in/commons/yml/ConfigMapper.java index d81f06a..86fdfd4 100644 --- a/src/main/java/com/caved_in/commons/yml/ConfigMapper.java +++ b/src/main/java/com/caved_in/commons/yml/ConfigMapper.java @@ -95,6 +95,7 @@ public void loadFromMap(Map section, Class clazz) throws Exception { } break; } + if (field.isAnnotationPresent(Path.class)) { Path path1 = field.getAnnotation(Path.class); path = path1.value(); From 8df67434fd851ef0c0829193cf2dbacb5815e76d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 5 Feb 2016 15:03:33 -0330 Subject: [PATCH 5/5] Finalized updated for Commons 1.8.8-3; YAML Serialization, Yaml Config, Xml Config, converting between the both, moving Config.xml to config.xml, future plans to expand configuration versions and more! --- .../java/com/caved_in/commons/Commons.java | 2030 +++++++++-------- .../config/CommonsXmlConfiguration.java | 2 + .../config/MaintenanceConfiguration.java | 5 +- .../com/caved_in/commons/yml/YamlConfig.java | 1 - 4 files changed, 1032 insertions(+), 1006 deletions(-) diff --git a/src/main/java/com/caved_in/commons/Commons.java b/src/main/java/com/caved_in/commons/Commons.java index 4408d51..144a957 100644 --- a/src/main/java/com/caved_in/commons/Commons.java +++ b/src/main/java/com/caved_in/commons/Commons.java @@ -22,6 +22,7 @@ import com.caved_in.commons.world.Worlds; import com.caved_in.commons.yml.InvalidConfigurationException; import com.google.common.collect.Lists; +import com.google.common.io.Files; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.enchantments.Enchantment; @@ -35,89 +36,89 @@ import java.util.*; public class Commons extends BukkitPlugin { - private static Commons plugin; - - public static final String WARP_DATA_FOLDER = "plugins/Commons/Warps/"; - public static final String PLUGIN_DATA_FOLDER = "plugins/Commons/"; - public static final String DEBUG_DATA_FOLDER = "plugins/Commons/Debug/"; - public static final String ITEM_DATA_FOLDER = "plugins/Commons/Items"; - public static final String ITEM_SET_DATA_FOLDER = "plugins/Commons/ItemSets/"; - public static final String RULES_LOCATION = "plugins/Commons/rules.txt"; - public static final String TELEPORT_MENU_DISABLED_LOCATION = "plugins/Commons/disabled-teleport-menus.txt"; - public static final String DATA_OPTION_FILE = "plugins/Commons/data-option.txt"; - - private static Configuration globalConfig = null; - - /* - A(n) instance of the worlds class - to internally manage worlds and apply their settings - specified in the WorldConfiguration section of Commons Config. - */ - private Worlds worlds; - - /* - A(n) instance of the players class - to internally manage data of players for Commons. - */ - private Players players; - - /* - Create the item-set manager, which allows us to save a players inventories - and swap them out at any time; Useful for creative, kits, etc. - - Initialized on a class-level so there's no discrepancies before the setup method is called. - */ - private ItemSetManager itemSetManager = new ItemSetManager(); - - /* - Used to manage private messages between players. - */ - private PrivateMessageManager privateMessageManager; - - /* - Instance of the Commons database connector; Handles - saving and loading of data to and from the database. - */ - private ServerDatabaseConnector database = null; - - private ChatMenuCommandListener chatMenuListener = null; - - public static synchronized Commons getInstance() { - if (plugin == null) { - plugin = (Commons) Plugins.getPlugin("Commons"); - } - return plugin; - } - - - public void startup() { - /* - Initialize all NMS! + private static Commons plugin; + + public static final String WARP_DATA_FOLDER = "plugins/Commons/Warps/"; + public static final String PLUGIN_DATA_FOLDER = "plugins/Commons/"; + public static final String DEBUG_DATA_FOLDER = "plugins/Commons/Debug/"; + public static final String ITEM_DATA_FOLDER = "plugins/Commons/Items"; + public static final String ITEM_SET_DATA_FOLDER = "plugins/Commons/ItemSets/"; + public static final String RULES_LOCATION = "plugins/Commons/rules.txt"; + public static final String TELEPORT_MENU_DISABLED_LOCATION = "plugins/Commons/disabled-teleport-menus.txt"; + public static final String DATA_OPTION_FILE = "plugins/Commons/data-option.txt"; + + private static Configuration globalConfig = null; + + /* + A(n) instance of the worlds class + to internally manage worlds and apply their settings + specified in the WorldConfiguration section of Commons Config. + */ + private Worlds worlds; + + /* + A(n) instance of the players class + to internally manage data of players for Commons. + */ + private Players players; + + /* + Create the item-set manager, which allows us to save a players inventories + and swap them out at any time; Useful for creative, kits, etc. + + Initialized on a class-level so there's no discrepancies before the setup method is called. + */ + private ItemSetManager itemSetManager = new ItemSetManager(); + + /* + Used to manage private messages between players. + */ + private PrivateMessageManager privateMessageManager; + + /* + Instance of the Commons database connector; Handles + saving and loading of data to and from the database. + */ + private ServerDatabaseConnector database = null; + + private ChatMenuCommandListener chatMenuListener = null; + + public static synchronized Commons getInstance() { + if (plugin == null) { + plugin = (Commons) Plugins.getPlugin("Commons"); + } + return plugin; + } + + + public void startup() { + /* + Initialize all NMS! */ - NMS.init(); + NMS.init(); - //Use reflection to prepare for custom enchants. - prepForCustomEnchantments(); + //Use reflection to prepare for custom enchants. + prepForCustomEnchantments(); - try { - Metrics metrics = new Metrics(this); - metrics.start(); - getLogger().info("Metrics for Commons has been Enabled!"); - } catch (IOException e) { - getLogger().info("Metrics for Commons failed to enable!"); - } + try { + Metrics metrics = new Metrics(this); + metrics.start(); + getLogger().info("Metrics for Commons has been Enabled!"); + } catch (IOException e) { + getLogger().info("Metrics for Commons failed to enable!"); + } - chatMenuListener = new ChatMenuCommandListener(this); + chatMenuListener = new ChatMenuCommandListener(this); /* Create the private message manager; used to track private messages for players on the server. */ - privateMessageManager = new PrivateMessageManager(); + privateMessageManager = new PrivateMessageManager(); /* Create the worlds instance */ - worlds = new Worlds(); + worlds = new Worlds(); /* Create the players instance, used internally to track commons-required @@ -125,560 +126,581 @@ public void startup() { Externally the Players class provides a static API */ - players = new Players(); - - //If the SQL Backend is enabled, then register all the database interfaces - if (globalConfig.hasSqlBackend()) { - SqlConfiguration sqlConfig = new SqlConfiguration( - globalConfig.getMysqlHost(), - globalConfig.getMysqlPort(), - globalConfig.getMysqlDatabaseName(), - globalConfig.getMysqlUsername(), - globalConfig.getMysqlPassword(), - globalConfig.trackOnlinePlayerStatus() - ); - //Create the database connection - database = new ServerDatabaseConnector(sqlConfig); - - getThreadManager().runTaskAsync(() -> { - database.updateServerOnlineStatus(true); - }); - } - - //If the commands are to be registered: do so. - if (getConfiguration().registerCommands()) { - try { - registerCommandsByPackage("com.caved_in.commons.command.commands"); - } catch (RegisterCommandMethodException e) { - e.printStackTrace(); - debug("Unable to register commands; If you're using the no-commands version of commons assure '' inside of Config.xml is set to false. Otherwise, send the stack trace to our developers for assistance."); - } catch (Exception e) { - e.printStackTrace(); - } - } - - //Register the debugger actions and triggers to 'case test' features in-game - try { - registerDebugActionsByPackage("com.caved_in.commons.debug.actions"); - } catch (Exception e) { - e.printStackTrace(); - Chat.debug("Unable to register all debug actions. To register via class and reflection it requires a constructor with 0 arguments"); - } - - registerListeners(); // Register all our event listeners - - // Load all the warps - Warps.loadWarps(); - - //Load all the players data - for (Player player : Players.allPlayers()) { - players.addData(player); - } - } - - @Override - public void shutdown() { - /* + players = new Players(); + + //If the SQL Backend is enabled, then register all the database interfaces + if (globalConfig.hasSqlBackend()) { + SqlConfiguration sqlConfig = new SqlConfiguration( + globalConfig.getMysqlHost(), + globalConfig.getMysqlPort(), + globalConfig.getMysqlDatabaseName(), + globalConfig.getMysqlUsername(), + globalConfig.getMysqlPassword(), + globalConfig.trackOnlinePlayerStatus() + ); + //Create the database connection + database = new ServerDatabaseConnector(sqlConfig); + + getThreadManager().runTaskAsync(() -> { + database.updateServerOnlineStatus(true); + }); + } + + //If the commands are to be registered: do so. + if (getConfiguration().registerCommands()) { + try { + registerCommandsByPackage("com.caved_in.commons.command.commands"); + } catch (RegisterCommandMethodException e) { + e.printStackTrace(); + debug("Unable to register commands; If you're using the no-commands version of commons assure '' inside of Config.xml is set to false. Otherwise, send the stack trace to our developers for assistance."); + } catch (Exception e) { + e.printStackTrace(); + } + } + + //Register the debugger actions and triggers to 'case test' features in-game + try { + registerDebugActionsByPackage("com.caved_in.commons.debug.actions"); + } catch (Exception e) { + e.printStackTrace(); + Chat.debug("Unable to register all debug actions. To register via class and reflection it requires a constructor with 0 arguments"); + } + + registerListeners(); // Register all our event listeners + + // Load all the warps + Warps.loadWarps(); + + //Load all the players data + for (Player player : Players.allPlayers()) { + players.addData(player); + } + } + + @Override + public void shutdown() { + /* Update the server-online status for the server that's stopping to false! */ - if (hasDatabaseBackend()) { - database.updateServerOnlineStatus(false); - getLogger().info("Updated the online-status for this server to false! b-bye!"); - } - - for (Player player : Players.allPlayers()) { - UUID playerId = player.getUniqueId(); - Players.removeData(playerId); - } - Warps.saveWarps(); - } - - @Override - public String getAuthor() { - return "Brandon Curtis"; - } - - public static class TeleportMenuSettings { - private List disabledUuids = new ArrayList<>(); - - private static TeleportMenuSettings instance; - - private TextFile textFile; - - public static TeleportMenuSettings getInstance() { - return instance; - } - - public static void init(String path) { - instance = new TeleportMenuSettings(path); - } - - protected TeleportMenuSettings(String filePath) { - textFile = new TextFile(filePath); - } - - public boolean hasMenuDisabled(UUID id) { - return disabledUuids.contains(id.toString()); - } - - public void disableMenu(UUID id) { - disabledUuids.add(id.toString()); - save(); - } - - public void enableMenu(UUID id) { - disabledUuids.remove(id.toString()); - save(); - } - - private void save() { - textFile.overwriteFile(disabledUuids); - } - } - - public static class Rules { - private static List rules = Lists.newArrayList( - "1. You may not use vulgar or abusive language.", - "2. You musn't be racist.", - "3. You musn't use hacks or (unnapproved) mods that give you an unfair advantage", - "4. You may not spam", - "5. You may not advertise", - "6. You musn't use excessive caps", - "7. You may not advertise any links that are not Tunnels related", - "8. You musn't abuse glitches or game exploits", - "9. You may not troll any of the members, or ellicit ill behaviour in any way.", - "10. You must be respectful to players", - "11. Do not abuse glitches, and report them if found", - "12. Do not steal, nor cheat the server or players", - "13. AFK Machines are forbidden." - ); - - private static File file; - - private static Rules instance; - - public static void init(File file) { - instance = new Rules(file); - } - - public static Rules getInstance() { - return instance; - } - - protected Rules(File f) { - file = f; + if (hasDatabaseBackend()) { + database.updateServerOnlineStatus(false); + getLogger().info("Updated the online-status for this server to false! b-bye!"); + } + + for (Player player : Players.allPlayers()) { + UUID playerId = player.getUniqueId(); + Players.removeData(playerId); + } + Warps.saveWarps(); + } + + @Override + public String getAuthor() { + return "Brandon Curtis"; + } + + public static class TeleportMenuSettings { + private List disabledUuids = new ArrayList<>(); + + private static TeleportMenuSettings instance; + + private TextFile textFile; + + public static TeleportMenuSettings getInstance() { + return instance; + } + + public static void init(String path) { + instance = new TeleportMenuSettings(path); + } + + protected TeleportMenuSettings(String filePath) { + textFile = new TextFile(filePath); + } + + public boolean hasMenuDisabled(UUID id) { + return disabledUuids.contains(id.toString()); + } + + public void disableMenu(UUID id) { + disabledUuids.add(id.toString()); + save(); + } + + public void enableMenu(UUID id) { + disabledUuids.remove(id.toString()); + save(); + } + + private void save() { + textFile.overwriteFile(disabledUuids); + } + } + + public static class Rules { + private static List rules = Lists.newArrayList( + "1. You may not use vulgar or abusive language.", + "2. You musn't be racist.", + "3. You musn't use hacks or (unnapproved) mods that give you an unfair advantage", + "4. You may not spam", + "5. You may not advertise", + "6. You musn't use excessive caps", + "7. You may not advertise any links that are not Tunnels related", + "8. You musn't abuse glitches or game exploits", + "9. You may not troll any of the members, or ellicit ill behaviour in any way.", + "10. You must be respectful to players", + "11. Do not abuse glitches, and report them if found", + "12. Do not steal, nor cheat the server or players", + "13. AFK Machines are forbidden." + ); + + private static File file; + + private static Rules instance; + + public static void init(File file) { + instance = new Rules(file); + } + + public static Rules getInstance() { + return instance; + } + + protected Rules(File f) { + file = f; /* If the rules file doesn't exist, then create it! */ - if (!file.exists()) { - - //todo implement option for players who have their swear filter off, to things like "don't be a dick" - try { - FileUtils.writeLines(file, rules); - } catch (IOException e) { - e.printStackTrace(); - } - return; - } - - - load(); - } - - public static void load() { - try { - rules = FileUtils.readLines(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void add(String rule) { - rules.add(String.format("%s. %s", rules.size() + 1, rule)); - try { - FileUtils.writeLines(file, rules, false); - } catch (IOException e) { - //unable to add rules. - e.printStackTrace(); - } - } - - public static List getRules() { - return rules; - } - - } - - public static int getServerId() { - return 0; - } - - private void prepForCustomEnchantments() { - ReflectionUtilities.setField(Enchantment.class, "acceptingNew", null, true); - } - - private void registerListeners() { - - registerListeners(new ChatListener()); - debug("&aCreated the Chat Listener"); - - if (globalConfig.hasLaunchpadPressurePlates()) { - registerListeners(new LauncherListener()); // Register fire pad listener if its enabled - debug("&aRegistered the fire pad listener"); - } - - if (globalConfig.disableIceAccumulation() || globalConfig.disableSnowAccumulation()) { - registerListeners(new BlockFormListener()); - debug("&aRegistered the block spread listener"); - } - - if (globalConfig.disableMyceliumSpread()) { - registerListeners(new BlockSpreadListener()); - debug("&aRegistered the mycelium spread listener"); - } - - if (globalConfig.disableThunder()) { - registerListeners(new ThungerChangeListener()); - debug("&aRegistered the thunder listener"); - } - - if (globalConfig.disableWeather()) { - registerListeners(new WeatherChangeListener()); - debug("&aRegistered the Weather-Change listener"); - } - - if (globalConfig.disableLightning()) { - registerListeners(new LightningStrikeListener()); - debug("&aRegistered the lightning listener"); - } - - if (globalConfig.disableFireSpread()) { - registerListeners(new FireSpreadListener()); - debug("&aRegistered the fire-spread listener"); - } - - if (!globalConfig.enableItemPickup()) { - registerListeners(new ItemPickupListener()); - debug("&aRegistered the item-pickup listener"); - } - - if (!globalConfig.enableFoodChange()) { - registerListeners(new FoodChangeListener()); - debug("&aRegistered the food change listener"); - } - - //If the server is backed by SQL, then push the specific listeners - if (globalConfig.hasSqlBackend()) { - //Used to handle kicking of banned / temp-banned players - registerListeners(new PrePlayerLoginListener()); - debug("&aRegistered the player pre-login listener"); - } - - registerListeners( - //Used for gadgets, interaction restriction, etc. - new PlayerInteractListener(), - new BlockBreakPlaceListener(), - new EntityExplodeListener(), - new WorldLoadedListener(), - new ServerPingListener(), - new PlayerLoginListener(), - new PlayerJoinListener(), - new PlayerKickListener(), - new InventoryListener(), - new PlayerTeleportListener(), - new PlayerQuitListener(), - //Listen to the command pre-process event so we can spit params at debuggers, and drop disabled commands - new CommandPreProcessListener(), - //Listen to when a player dies so we can get the return location, incase they use /back - new PlayerDeathListener(), - //Used to handle the dropping of weapons. and items in general. - new ItemDropListener(), - //Used with the Weapons API. - new EntityDamageEntityListener(), - new ItemBreakListener(), - new ItemDamageListener(), - new EntityDamageListener(), - new SignEditListener(), - new LeavesDecayListener() - ); - } - - public boolean hasDatabaseBackend() { - return Commons.getInstance().getConfiguration().hasSqlBackend(); - } - - public void reloadConfiguration() { - getInstance().initConfig(); - } - - public Configuration getConfiguration() { - return globalConfig; - } - - public static boolean bukkitVersionMatches(String versionNumber) { - return Plugins.getBukkitVersion().contains(versionNumber); - } - - public ItemSetManager getItemSetManager() { - return itemSetManager; - } - - public ServerDatabaseConnector getServerDatabase() { - return database; - } - - public Players getPlayerHandler() { - return players; - } - - public PrivateMessageManager getPrivateMessageManager() { - return privateMessageManager; - } - - public Worlds getWorldHandler() { - return worlds; - } - - public boolean isServerFull() { - return Players.getOnlineCount() >= Bukkit.getMaxPlayers(); - } - - public ChatMenuCommandListener getChatMenuListener() { - return chatMenuListener; - } - - - private void alternateCommonsConfig(Configuration currentConfig, Configuration targetConfig) { - /* + if (!file.exists()) { + + //todo implement option for players who have their swear filter off, to things like "don't be a dick" + try { + FileUtils.writeLines(file, rules); + } catch (IOException e) { + e.printStackTrace(); + } + return; + } + + + load(); + } + + public static void load() { + try { + rules = FileUtils.readLines(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void add(String rule) { + rules.add(String.format("%s. %s", rules.size() + 1, rule)); + try { + FileUtils.writeLines(file, rules, false); + } catch (IOException e) { + //unable to add rules. + e.printStackTrace(); + } + } + + public static List getRules() { + return rules; + } + + } + + public static int getServerId() { + return 0; + } + + private void prepForCustomEnchantments() { + ReflectionUtilities.setField(Enchantment.class, "acceptingNew", null, true); + } + + private void registerListeners() { + + registerListeners(new ChatListener()); + debug("&aCreated the Chat Listener"); + + if (globalConfig.hasLaunchpadPressurePlates()) { + registerListeners(new LauncherListener()); // Register fire pad listener if its enabled + debug("&aRegistered the fire pad listener"); + } + + if (globalConfig.disableIceAccumulation() || globalConfig.disableSnowAccumulation()) { + registerListeners(new BlockFormListener()); + debug("&aRegistered the block spread listener"); + } + + if (globalConfig.disableMyceliumSpread()) { + registerListeners(new BlockSpreadListener()); + debug("&aRegistered the mycelium spread listener"); + } + + if (globalConfig.disableThunder()) { + registerListeners(new ThungerChangeListener()); + debug("&aRegistered the thunder listener"); + } + + if (globalConfig.disableWeather()) { + registerListeners(new WeatherChangeListener()); + debug("&aRegistered the Weather-Change listener"); + } + + if (globalConfig.disableLightning()) { + registerListeners(new LightningStrikeListener()); + debug("&aRegistered the lightning listener"); + } + + if (globalConfig.disableFireSpread()) { + registerListeners(new FireSpreadListener()); + debug("&aRegistered the fire-spread listener"); + } + + if (!globalConfig.enableItemPickup()) { + registerListeners(new ItemPickupListener()); + debug("&aRegistered the item-pickup listener"); + } + + if (!globalConfig.enableFoodChange()) { + registerListeners(new FoodChangeListener()); + debug("&aRegistered the food change listener"); + } + + //If the server is backed by SQL, then push the specific listeners + if (globalConfig.hasSqlBackend()) { + //Used to handle kicking of banned / temp-banned players + registerListeners(new PrePlayerLoginListener()); + debug("&aRegistered the player pre-login listener"); + } + + registerListeners( + //Used for gadgets, interaction restriction, etc. + new PlayerInteractListener(), + new BlockBreakPlaceListener(), + new EntityExplodeListener(), + new WorldLoadedListener(), + new ServerPingListener(), + new PlayerLoginListener(), + new PlayerJoinListener(), + new PlayerKickListener(), + new InventoryListener(), + new PlayerTeleportListener(), + new PlayerQuitListener(), + //Listen to the command pre-process event so we can spit params at debuggers, and drop disabled commands + new CommandPreProcessListener(), + //Listen to when a player dies so we can get the return location, incase they use /back + new PlayerDeathListener(), + //Used to handle the dropping of weapons. and items in general. + new ItemDropListener(), + //Used with the Weapons API. + new EntityDamageEntityListener(), + new ItemBreakListener(), + new ItemDamageListener(), + new EntityDamageListener(), + new SignEditListener(), + new LeavesDecayListener() + ); + } + + public boolean hasDatabaseBackend() { + return Commons.getInstance().getConfiguration().hasSqlBackend(); + } + + public void reloadConfiguration() { + getInstance().initConfig(); + } + + public Configuration getConfiguration() { + return globalConfig; + } + + public static boolean bukkitVersionMatches(String versionNumber) { + return Plugins.getBukkitVersion().contains(versionNumber); + } + + public ItemSetManager getItemSetManager() { + return itemSetManager; + } + + public ServerDatabaseConnector getServerDatabase() { + return database; + } + + public Players getPlayerHandler() { + return players; + } + + public PrivateMessageManager getPrivateMessageManager() { + return privateMessageManager; + } + + public Worlds getWorldHandler() { + return worlds; + } + + public boolean isServerFull() { + return Players.getOnlineCount() >= Bukkit.getMaxPlayers(); + } + + public ChatMenuCommandListener getChatMenuListener() { + return chatMenuListener; + } + + + private void alternateCommonsConfig(Configuration currentConfig, Configuration targetConfig) { + /* Configure all the database options! */ - targetConfig.setMysqlBackend(currentConfig.hasSqlBackend()); - targetConfig.setMysqlHost(currentConfig.getMysqlHost()); - targetConfig.setMysqlPort(currentConfig.getMysqlPort()); - targetConfig.setMysqlDatabaseName(currentConfig.getMysqlDatabaseName()); - targetConfig.setMysqlUsername(currentConfig.getMysqlUsername()); - targetConfig.setMysqlPassword(currentConfig.getMysqlPassword()); - targetConfig.setTrackOnlinePlayerStatus(currentConfig.trackOnlinePlayerStatus()); - targetConfig.setServerName(currentConfig.getServerName()); + targetConfig.setMysqlBackend(currentConfig.hasSqlBackend()); + targetConfig.setMysqlHost(currentConfig.getMysqlHost()); + targetConfig.setMysqlPort(currentConfig.getMysqlPort()); + targetConfig.setMysqlDatabaseName(currentConfig.getMysqlDatabaseName()); + targetConfig.setMysqlUsername(currentConfig.getMysqlUsername()); + targetConfig.setMysqlPassword(currentConfig.getMysqlPassword()); + targetConfig.setTrackOnlinePlayerStatus(currentConfig.trackOnlinePlayerStatus()); + targetConfig.setServerName(currentConfig.getServerName()); /* Commands configuration! */ - targetConfig.registerCommands(currentConfig.registerCommands()); - targetConfig.enableBukkitCommands(currentConfig.enableBukkitCommands()); - targetConfig.enablePluginsCommand(currentConfig.enablePluginsCommand()); + targetConfig.registerCommands(currentConfig.registerCommands()); + targetConfig.enableBukkitCommands(currentConfig.enableBukkitCommands()); + targetConfig.enablePluginsCommand(currentConfig.enablePluginsCommand()); /* Server-specific configuration! */ - targetConfig.enableJoinMessages(currentConfig.enableJoinMessages()); - targetConfig.enableLeaveMessages(currentConfig.enableLeaveMessages()); - targetConfig.enableKickMessages(currentConfig.enableKickMessages()); - targetConfig.externalChatPlugin(currentConfig.hasExternalChatPlugin()); - targetConfig.silenceChat(currentConfig.isChatSilenced()); + targetConfig.enableJoinMessages(currentConfig.enableJoinMessages()); + targetConfig.enableLeaveMessages(currentConfig.enableLeaveMessages()); + targetConfig.enableKickMessages(currentConfig.enableKickMessages()); + targetConfig.externalChatPlugin(currentConfig.hasExternalChatPlugin()); + targetConfig.silenceChat(currentConfig.isChatSilenced()); /* Premium Only mode configuration! */ - targetConfig.setPremiumOnlyMode(currentConfig.isPremiumOnlyMode()); - targetConfig.setPremiumUserPermission(currentConfig.getPremiumUserPermission()); - targetConfig.premiumOnlyModeKickMessage(currentConfig.getPremiumOnlyModeKickMessage()); - targetConfig.kickNonPremiumPlayerWhenFull(currentConfig.kickNonPremiumPlayerWhenFull()); - targetConfig.setKickNonPremiumMessage(currentConfig.kickNonPremiumMessage()); + targetConfig.setPremiumOnlyMode(currentConfig.isPremiumOnlyMode()); + targetConfig.setPremiumUserPermission(currentConfig.getPremiumUserPermission()); + targetConfig.premiumOnlyModeKickMessage(currentConfig.getPremiumOnlyModeKickMessage()); + targetConfig.kickNonPremiumPlayerWhenFull(currentConfig.kickNonPremiumPlayerWhenFull()); + targetConfig.setKickNonPremiumMessage(currentConfig.kickNonPremiumMessage()); /* World configuration! */ - targetConfig.teleportToSpawnOnJoin(currentConfig.teleportToSpawnOnJoin()); - targetConfig.disableWeather(currentConfig.disableWeather()); - targetConfig.disableLightning(currentConfig.disableLightning()); - targetConfig.disableThunder(currentConfig.disableThunder()); - targetConfig.disableIceAccumulation(currentConfig.disableIceAccumulation()); - targetConfig.disableSnowAccumulation(currentConfig.disableSnowAccumulation()); - targetConfig.disableMyceliumSpread(currentConfig.disableMyceliumSpread()); - targetConfig.disableFireSpread(currentConfig.disableFireSpread()); - targetConfig.launchpadPressurePlates(currentConfig.hasLaunchpadPressurePlates()); - targetConfig.enableBlockBreak(currentConfig.enableBlockBreak()); - targetConfig.enableItemDrop(currentConfig.enableItemDrop()); - targetConfig.enableItemPickup(currentConfig.enableItemPickup()); - targetConfig.enableFoodChange(currentConfig.enableFoodChange()); - targetConfig.explosionFireworks(currentConfig.hasExplosionFireworks()); - targetConfig.enableFallDamage(currentConfig.enableFallDamage()); - targetConfig.disableLeavesDecay(currentConfig.disableLeavesDecay()); + targetConfig.teleportToSpawnOnJoin(currentConfig.teleportToSpawnOnJoin()); + targetConfig.disableWeather(currentConfig.disableWeather()); + targetConfig.disableLightning(currentConfig.disableLightning()); + targetConfig.disableThunder(currentConfig.disableThunder()); + targetConfig.disableIceAccumulation(currentConfig.disableIceAccumulation()); + targetConfig.disableSnowAccumulation(currentConfig.disableSnowAccumulation()); + targetConfig.disableMyceliumSpread(currentConfig.disableMyceliumSpread()); + targetConfig.disableFireSpread(currentConfig.disableFireSpread()); + targetConfig.launchpadPressurePlates(currentConfig.hasLaunchpadPressurePlates()); + targetConfig.enableBlockBreak(currentConfig.enableBlockBreak()); + targetConfig.enableItemDrop(currentConfig.enableItemDrop()); + targetConfig.enableItemPickup(currentConfig.enableItemPickup()); + targetConfig.enableFoodChange(currentConfig.enableFoodChange()); + targetConfig.explosionFireworks(currentConfig.hasExplosionFireworks()); + targetConfig.enableFallDamage(currentConfig.enableFallDamage()); + targetConfig.disableLeavesDecay(currentConfig.disableLeavesDecay()); /* Maintenance mode configuration! */ - targetConfig.setMaintenanceMode(currentConfig.isMaintenanceModeEnabled()); - targetConfig.maintenanceModeKickMessage(currentConfig.maintenanceModeKickMessage()); - targetConfig.maintenanceModeMotd(currentConfig.maintenanceModeMotd()); + targetConfig.setMaintenanceMode(currentConfig.isMaintenanceModeEnabled()); + targetConfig.maintenanceModeKickMessage(currentConfig.maintenanceModeKickMessage()); + targetConfig.maintenanceModeMotd(currentConfig.maintenanceModeMotd()); /* Debug configuration! */ - targetConfig.enableStackTraceEvent(currentConfig.enableStackTraceEvent()); - targetConfig.enableStackTraceBook(currentConfig.enableStackTraceBook()); - targetConfig.enableStackTraceChat(currentConfig.enableStackTraceChat()); + targetConfig.enableStackTraceEvent(currentConfig.enableStackTraceEvent()); + targetConfig.enableStackTraceBook(currentConfig.enableStackTraceBook()); + targetConfig.enableStackTraceChat(currentConfig.enableStackTraceChat()); /* Warps Configuration! */ - targetConfig.enableWarpsMenu(currentConfig.enableWarpsMenu()); - } + targetConfig.enableWarpsMenu(currentConfig.enableWarpsMenu()); + } + + @Override + public void initConfig() { + Serializer configSerializer = new Persister(); + + File dataOptionFile = new File(DATA_OPTION_FILE); + + File oldXmlConfigFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); - @Override - public void initConfig() { - Serializer configSerializer = new Persister(); + File xmlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.xml"); + File ymlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.yml"); - File dataOptionFile = new File(DATA_OPTION_FILE); + if (oldXmlConfigFile.exists()) { + debug("Attempting to move previous Config.xml to config.xml"); - File xmlConfigFile = new File(PLUGIN_DATA_FOLDER + "Config.xml"); - File ymlConfigFile = new File(PLUGIN_DATA_FOLDER + "config.yml"); + if (xmlConfigFile.exists()) { + try { + FileUtils.forceDelete(xmlConfigFile); + } catch (IOException e) { + debug("Unable to delete the conflicting XML config file 'config.xml', you have an old 'Config.xml' in the same folder"); + } + } + try { + Files.move(oldXmlConfigFile, xmlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + debug("Unable to move the old config file to the new Format."); + } + + } /* Check if the warps folder exists, and if not then create it! */ - File warpsFolder = new File(WARP_DATA_FOLDER); - if (!warpsFolder.exists()) { - warpsFolder.mkdirs(); - } + File warpsFolder = new File(WARP_DATA_FOLDER); + if (!warpsFolder.exists()) { + warpsFolder.mkdirs(); + } /* Create the items folder, where serializable items are stored */ - File itemsFolder = new File(ITEM_DATA_FOLDER); - if (!itemsFolder.exists()) { - itemsFolder.mkdirs(); - } + File itemsFolder = new File(ITEM_DATA_FOLDER); + if (!itemsFolder.exists()) { + itemsFolder.mkdirs(); + } /* Create the sets folder for the item manager; used to save and load- track and update item sets. */ - File itemSetsFolder = new File(ITEM_SET_DATA_FOLDER); - if (!itemSetsFolder.exists()) { - itemSetsFolder.mkdirs(); - } - - Collection itemSetFiles = FileUtils.listFiles(itemSetsFolder, null, false); - if (itemSetFiles.size() > 0) { - /* Load all the files in the item folder, into the item set manager */ - for (File file : itemSetFiles) { - try { - ItemSetManager.ItemSet set = configSerializer.read(ItemSetManager.ItemSet.class, file); - - if (set == null) { - continue; - } - - itemSetManager.addSet(set); - debug(String.format("Loaded itemset '%s' into the ItemSet Manager", set.getName())); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - Collection itemFiles = FileUtils.listFiles(itemsFolder, null, false); - - if (itemFiles.size() > 0) { - /* Load all the files in the item folder, into the saved item manager */ - for (File file : itemFiles) { - SavedItemManager.loadItem(file); - } - } + File itemSetsFolder = new File(ITEM_SET_DATA_FOLDER); + if (!itemSetsFolder.exists()) { + itemSetsFolder.mkdirs(); + } + + Collection itemSetFiles = FileUtils.listFiles(itemSetsFolder, null, false); + if (itemSetFiles.size() > 0) { + /* Load all the files in the item folder, into the item set manager */ + for (File file : itemSetFiles) { + try { + ItemSetManager.ItemSet set = configSerializer.read(ItemSetManager.ItemSet.class, file); + + if (set == null) { + continue; + } + + itemSetManager.addSet(set); + debug(String.format("Loaded itemset '%s' into the ItemSet Manager", set.getName())); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + Collection itemFiles = FileUtils.listFiles(itemsFolder, null, false); + + if (itemFiles.size() > 0) { + /* Load all the files in the item folder, into the saved item manager */ + for (File file : itemFiles) { + SavedItemManager.loadItem(file); + } + } /* Check if the debug data folder exists, and if not then create it! */ - File debugFolder = new File(DEBUG_DATA_FOLDER); - if (!debugFolder.exists()) { - debugFolder.mkdirs(); - } + File debugFolder = new File(DEBUG_DATA_FOLDER); + if (!debugFolder.exists()) { + debugFolder.mkdirs(); + } /* Initialize the rules class! */ - Rules.init(new File(RULES_LOCATION)); + Rules.init(new File(RULES_LOCATION)); /* Initialize the Teleport Menu Settings */ - TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); + TeleportMenuSettings.init(TELEPORT_MENU_DISABLED_LOCATION); /* This is a fresh install of commons! */ - if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { - - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| This may be the first time |", - "| you've ever used Commons, or |", - "| simply the first time you've |", - "| used it since release 1.8.8-3 |", - "| but either way, please assure |", - "| you've chosen your data type |", - "| in the 'data-option.txt' file |", - "| inside 'Commons' plugin-data |", - "| folder. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| (Conversion is automatic) |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); - } catch (IOException e) { - e.printStackTrace(); - } - - globalConfig = new CommonsYamlConfiguration(); - CommonsYamlConfiguration ymlConfig = new CommonsYamlConfiguration(); - - try { - ymlConfig.init(ymlConfigFile); - globalConfig = ymlConfig; - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - return; - } - - if (!dataOptionFile.exists()) { - /* + if (!dataOptionFile.exists() && !xmlConfigFile.exists() && !ymlConfigFile.exists()) { + + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + CommonsYamlConfiguration ymlConfig = new CommonsYamlConfiguration(); + + try { + ymlConfig.init(ymlConfigFile); + globalConfig = ymlConfig; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + return; + } + + if (!dataOptionFile.exists()) { + /* This usually happens when servers are upgrading from a previous Commons version, to version 1.8.8-3 @@ -686,68 +708,68 @@ public void initConfig() { then we're going to make their default the XML Config (that they had previously) though at the same time inform them of how to convert, and so forth. */ - if (xmlConfigFile.exists()) { - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=xml" - )); - } catch (IOException e) { - e.printStackTrace(); - } - - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| It seems you've used commons |", - "| before, and have an existing |", - "| configuration file available |", - "| so we'll continue using that. |", - "| |", - "| To Convert to YML config, you |", - "| must change 'data-option.txt' |", - "| inside Commons plugin folder. |", - "| |", - "| Supported options are |", - "| 'commons-data-format=yml' and |", - "| 'commons-data-format=xml' |", - "| which signal your format. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| (Conversion is automatic) |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - - //They've got an XML File for config. - try { - globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - } - return; - } + if (xmlConfigFile.exists()) { + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=xml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| It seems you've used commons |", + "| before, and have an existing |", + "| configuration file available |", + "| so we'll continue using that. |", + "| |", + "| To Convert to YML config, you |", + "| must change 'data-option.txt' |", + "| inside Commons plugin folder. |", + "| |", + "| Supported options are |", + "| 'commons-data-format=yml' and |", + "| 'commons-data-format=xml' |", + "| which signal your format. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| (Conversion is automatic) |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + //They've got an XML File for config. + try { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + } + return; + } /* If there's no data option file present, and there's a YML file present @@ -759,60 +781,60 @@ public void initConfig() { It's also a fail-safe to prevent loading a different configuration file / type when it's not required. */ - if (ymlConfigFile.exists()) { - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| It seems you have config.yml |", - "| as your config file, though |", - "| you have no data-option.txt |", - "| |", - "| To properly config and data |", - "| throughout commons we require |", - "| this file be present. It will |", - "| be re-created, though please |", - "| don't remove this file again. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); - } catch (IOException e) { - e.printStackTrace(); - } - - globalConfig = new CommonsYamlConfiguration(); - try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------"); - Plugins.disablePlugin(this); - return; - } - } else { - /* + if (ymlConfigFile.exists()) { + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you have config.yml |", + "| as your config file, though |", + "| you have no data-option.txt |", + "| |", + "| To properly config and data |", + "| throughout commons we require |", + "| this file be present. It will |", + "| be re-created, though please |", + "| don't remove this file again. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------"); + Plugins.disablePlugin(this); + return; + } + } else { + /* No data-option.txt and no config file, then we're going to want to create the config.yml file by default. @@ -821,65 +843,65 @@ public void initConfig() { available if they choose! */ - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| From here out, Commons uses |", - "| YML based config files |", - "| by default. |", - "| |", - "| This may be the first time |", - "| you've ever used Commons, or |", - "| simply the first time you've |", - "| used it since release 1.8.8-3 |", - "| but either way, please assure |", - "| you've chosen your data type |", - "| in the 'data-option.txt' file |", - "| inside 'Commons' plugin-data |", - "| folder. |", - "| |", - "| This can be changed down the |", - "| road if you choose to do so, |", - "| though data and config files |", - "| in the opposing format will |", - "| have to be converted. |", - "| |", - "| For information regarding |", - "| this change, and its affects, |", - "| visit the Commons wiki, or |", - "| its release page. |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - - try { - FileUtils.writeLines(dataOptionFile, Arrays.asList( - "commons-data-format=yml" - )); - } catch (IOException e) { - e.printStackTrace(); - } - - globalConfig = new CommonsYamlConfiguration(); - try { - ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - //INVALID INITIAL CONFIG? - e.printStackTrace(); - } - } - - } else { - /* + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| From here out, Commons uses |", + "| YML based config files |", + "| by default. |", + "| |", + "| This may be the first time |", + "| you've ever used Commons, or |", + "| simply the first time you've |", + "| used it since release 1.8.8-3 |", + "| but either way, please assure |", + "| you've chosen your data type |", + "| in the 'data-option.txt' file |", + "| inside 'Commons' plugin-data |", + "| folder. |", + "| |", + "| This can be changed down the |", + "| road if you choose to do so, |", + "| though data and config files |", + "| in the opposing format will |", + "| have to be converted. |", + "| |", + "| For information regarding |", + "| this change, and its affects, |", + "| visit the Commons wiki, or |", + "| its release page. |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + try { + FileUtils.writeLines(dataOptionFile, Arrays.asList( + "commons-data-format=yml" + )); + } catch (IOException e) { + e.printStackTrace(); + } + + globalConfig = new CommonsYamlConfiguration(); + try { + ((CommonsYamlConfiguration) globalConfig).init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + //INVALID INITIAL CONFIG? + e.printStackTrace(); + } + } + + } else { + /* In this case they actually have a data-option.txt file present, so we're going to parse their file for type of chosen configuration and see if they're converting, or simply loading the previous choice they had made. @@ -888,65 +910,65 @@ public void initConfig() { in their data-option.txt and a 'Config.xml' file present in their plugin data folder (Or vice versa) */ - String dataFileContents = null; - try { - dataFileContents = FileUtils.readFileToString(dataOptionFile); - } catch (IOException e) { - e.printStackTrace(); - } + String dataFileContents = null; + try { + dataFileContents = FileUtils.readFileToString(dataOptionFile); + } catch (IOException e) { + e.printStackTrace(); + } /* If there's an error while attempting to load their data-option file then we're going to give them a nice message warning about this, and then disable commons from loading to prevent any further Errors from happening! */ - if (dataFileContents == null) { - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| It appears you have an error |", - "| or invalid format in the file |", - "| 'data-option.txt' inside of |", - "| Commons plugin folder. |", - "| |", - "| Please fix this error/syntax |", - "| or delete it and then restart |", - "| your server to regenerate it. |", - "| |", - "| This file is essential to the |", - "| method Commons uses to convert |", - "|between xml and yml based files |", - "| |", - "| ........ |", - "| Meaning something, or someone |", - "|along the way broke a key part |", - "|of Commons functionality! Oops! |", - "| ........ |", - "| |", - "| No big deal. Follow the steps |", - "| above and everything should go |", - "| back to normal in no time! :) |", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); - Plugins.disablePlugin(this); - - return; - } - /* + if (dataFileContents == null) { + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| It appears you have an error |", + "| or invalid format in the file |", + "| 'data-option.txt' inside of |", + "| Commons plugin folder. |", + "| |", + "| Please fix this error/syntax |", + "| or delete it and then restart |", + "| your server to regenerate it. |", + "| |", + "| This file is essential to the |", + "| method Commons uses to convert |", + "|between xml and yml based files |", + "| |", + "| ........ |", + "| Meaning something, or someone |", + "|along the way broke a key part |", + "|of Commons functionality! Oops! |", + "| ........ |", + "| |", + "| No big deal. Follow the steps |", + "| above and everything should go |", + "| back to normal in no time! :) |", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + Plugins.disablePlugin(this); + + return; + } + /* Though if it makes it this far then we're going to continue with parsing their chosen config format, and perhaps performing a Conversion! */ - String[] options = dataFileContents.split("="); - String option = options[1].trim().replace("\n", "").replace("\r", ""); - if (option.equalsIgnoreCase("xml")) { - /* + String[] options = dataFileContents.split("="); + String option = options[1].trim().replace("\n", "").replace("\r", ""); + if (option.equalsIgnoreCase("xml")) { + /* They've chosen to use XMl as the configuration option. We check if they have a YML based configuration file available and if they do perform a conversion! @@ -955,33 +977,33 @@ plugin data folder (Or vice versa) simply loading the configuration they had previously. */ - if (ymlConfigFile.exists()) { - CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); - try { - yamlConfig.load(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Before continueing with the conversion from yml to XML", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "", - "Choosing to regenerate your config file, and deleting config.yml", - "Will render you a fresh configuration!", - "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------" - ); - Plugins.disablePlugin(this); - return; - } - - CommonsXmlConfiguration cxmlConfig = new CommonsXmlConfiguration(); + if (ymlConfigFile.exists()) { + CommonsYamlConfiguration yamlConfig = new CommonsYamlConfiguration(); + try { + yamlConfig.load(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from yml to XML", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } + + CommonsXmlConfiguration cxmlConfig = new CommonsXmlConfiguration(); /* Attempting to move all the values from the previous config.yml @@ -989,41 +1011,41 @@ plugin data folder (Or vice versa) Then after that, we delete the config.yml! (So there's no further confusion :) */ - alternateCommonsConfig(yamlConfig, cxmlConfig); - globalConfig = cxmlConfig; - /* + alternateCommonsConfig(yamlConfig, cxmlConfig); + globalConfig = cxmlConfig; + /* Delete the previous config.yml file to avoid issues! */ - try { - FileUtils.forceDelete(ymlConfigFile); - } catch (IOException e) { - e.printStackTrace(); - } - - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| ~~~ITS A SUCCESS~~~ |", - "| |", - "| You've converted from using a |", - "| yml based config file to using |", - "| an xml based configuration file|", - "| |", - "| To convert back simply change |", - "| the option to yml in your |", - "| data-option.txt file and then |", - "| restart your server to start |", - "|the automatic conversion process|", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); - } else { - /* + try { + FileUtils.forceDelete(ymlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + } + + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| yml based config file to using |", + "| an xml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to yml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + } else { + /* In this case, they've chosen XML as their configuration, and don't have a previous config.yml file to convert from! @@ -1032,33 +1054,33 @@ and use that as configuration (Meaning they already chose xml as the option befo though if not, they must have DELETED their configuration file in a previous attempt.... */ - if (xmlConfigFile.exists()) { - try { - globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - if (globalConfig == null) { - } else { - } - } catch (Exception e) { - e.printStackTrace(); - Plugins.disablePlugin(this); - return; - } - } else { - //todo send notice about not deleting configuration - /* + if (xmlConfigFile.exists()) { + try { + globalConfig = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + if (globalConfig == null) { + } else { + } + } catch (Exception e) { + e.printStackTrace(); + Plugins.disablePlugin(this); + return; + } + } else { + //todo send notice about not deleting configuration + /* In this case, they've chosen XMl as their config type, and don't (or no longer) have their Config.xml file! This is an issue, so we'll sort this out! */ - globalConfig = new CommonsXmlConfiguration(); + globalConfig = new CommonsXmlConfiguration(); - try { - configSerializer.write(globalConfig, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } else if (option.equalsIgnoreCase("yml")) { + try { + configSerializer.write(globalConfig, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } else if (option.equalsIgnoreCase("yml")) { /* This means they're converting from a previous configuration file @@ -1066,165 +1088,165 @@ and use that as configuration (Meaning they already chose xml as the option befo Begin the process! */ - if (xmlConfigFile.exists()) { - CommonsXmlConfiguration xmlConfiguration = null; - try { - xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); - } catch (Exception e) { - e.printStackTrace(); - debug( - "====================================================", - "There was an error while processing your Config.xml", - "File inside of plugins/Commons/Config.xml", - "To prevent this from happening again you need", - "To assure the format and syntax of Config.xml", - "Is correct (in accordance to standard XML Documents", - "", - "COMMONS HAS BEEN DISABLED UNTIL THIS ISSUE IS CORRECTED", - "", - "RESTART YOUR SERVER ONCE FIXED TO CONTINUE AS DESIRED!", - "====================================================" - ); - Plugins.disablePlugin(this); - return; - } + if (xmlConfigFile.exists()) { + CommonsXmlConfiguration xmlConfiguration = null; + try { + xmlConfiguration = configSerializer.read(CommonsXmlConfiguration.class, xmlConfigFile); + } catch (Exception e) { + e.printStackTrace(); + debug( + "====================================================", + "There was an error while processing your Config.xml", + "File inside of plugins/Commons/Config.xml", + "To prevent this from happening again you need", + "To assure the format and syntax of Config.xml", + "Is correct (in accordance to standard XML Documents", + "", + "COMMONS HAS BEEN DISABLED UNTIL THIS ISSUE IS CORRECTED", + "", + "RESTART YOUR SERVER ONCE FIXED TO CONTINUE AS DESIRED!", + "====================================================" + ); + Plugins.disablePlugin(this); + return; + } /* If a yml file already exists and so does an XML then delete the previous yml file to avoid issues with instancing a new version! (Such as path changes, and such) */ - if (ymlConfigFile.exists()) { - try { - FileUtils.forceDelete(ymlConfigFile); - } catch (IOException e) { - e.printStackTrace(); - } - } - - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - alternateCommonsConfig(xmlConfiguration, yamlConfiguration); - globalConfig = yamlConfiguration; - try { - yamlConfiguration.init(ymlConfigFile); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - - debug( - "Commons 'plugin.yml' is invalid, and will cause", - "the plugin to malfunction without valid", - "configuration available....", - "Before continueing with the conversion from XML to yml", - "Please check the formatting of your config file, or delete", - "it and regenerate it via restarting the server", - "to continue!", - "", - "Choosing to regenerate your config file, and deleting config.xml/config.yml", - "Will render you a fresh configuration!", - "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", - "----------------", - "COMMONS HAS BEEN DISABLED", - "----------------" - ); - Plugins.disablePlugin(this); - return; - } - - try { - FileUtils.forceDelete(xmlConfigFile); - debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", - "Your Commons config is now based out of config.yml"); - } catch (IOException e) { - e.printStackTrace(); - debug("Failed to delete the previous Config.xml from your Commons plugin folder."); - } - - - debug( - "[================================]", - "| COMMONS NOTICE |", - "|--------------------------------|", - "| |", - "| ~~~ITS A SUCCESS~~~ |", - "| |", - "| You've converted from using a |", - "| xml based config file to using |", - "| an yml based configuration file|", - "| |", - "| To convert back simply change |", - "| the option to xml in your |", - "| data-option.txt file and then |", - "| restart your server to start |", - "|the automatic conversion process|", - "| |", - "|--------------------------------|", - "| |", - "| ~Thanks for choosing Commons! |", - "[================================]" - ); - - return; - } + if (ymlConfigFile.exists()) { + try { + FileUtils.forceDelete(ymlConfigFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + alternateCommonsConfig(xmlConfiguration, yamlConfiguration); + globalConfig = yamlConfiguration; + try { + yamlConfiguration.init(ymlConfigFile); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + + debug( + "Commons 'plugin.yml' is invalid, and will cause", + "the plugin to malfunction without valid", + "configuration available....", + "Before continueing with the conversion from XML to yml", + "Please check the formatting of your config file, or delete", + "it and regenerate it via restarting the server", + "to continue!", + "", + "Choosing to regenerate your config file, and deleting config.xml/config.yml", + "Will render you a fresh configuration!", + "If this is fine by you, then so be it; Just don't say we didn't heave warning :)", + "----------------", + "COMMONS HAS BEEN DISABLED", + "----------------" + ); + Plugins.disablePlugin(this); + return; + } + + try { + FileUtils.forceDelete(xmlConfigFile); + debug("Deleted the previous Config.xml file to avoid confusion, and future potential errors!", + "Your Commons config is now based out of config.yml"); + } catch (IOException e) { + e.printStackTrace(); + debug("Failed to delete the previous Config.xml from your Commons plugin folder."); + } + + + debug( + "[================================]", + "| COMMONS NOTICE |", + "|--------------------------------|", + "| |", + "| ~~~ITS A SUCCESS~~~ |", + "| |", + "| You've converted from using a |", + "| xml based config file to using |", + "| an yml based configuration file|", + "| |", + "| To convert back simply change |", + "| the option to xml in your |", + "| data-option.txt file and then |", + "| restart your server to start |", + "|the automatic conversion process|", + "| |", + "|--------------------------------|", + "| |", + "| ~Thanks for choosing Commons! |", + "[================================]" + ); + + return; + } /* They've previously chosen to use YML as a configuration style and have an existing config file their plugins/Commons/ folder; Loading this file for configuration. */ - if (ymlConfigFile.exists()) { + if (ymlConfigFile.exists()) { - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - try { - yamlConfiguration.load(ymlConfigFile); - globalConfig = yamlConfiguration; - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - } + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.load(ymlConfigFile); + globalConfig = yamlConfiguration; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } /* They've chosen to use yml as their config file, though don't currently have a config.yml file! Send them a notice saying they've likely deleted their previous version of configuration and create a new one for them! */ - debug( - "[===============================]", - "| COMMONS NOTICE |", - "|-------------------------------|", - "| |", - "| Commons now support both |", - "| XML and YAML (YML) Config |", - "| as of release 1.8.8-3. |", - "| |", - "| It seems you no config.yml in |", - "| your Commons plugin folder |", - "| but have yml as your chosen |", - "| data type in data-option.txt |", - "| |", - "| A new config.yml file will be |", - "| generated for you to use, and |", - "| configure accordingly to your |", - "| likings, and servers desire. |", - "| |", - "| To prevent this issue from |", - "| happening again, please don't |", - "| delete your config.yml file! |", - "| |", - "|-------------------------------|", - "| |", - "| Thanks for choosing Commons! |", - "[===============================]" - ); - - CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); - try { - yamlConfiguration.init(ymlConfigFile); - globalConfig = yamlConfiguration; - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - //Error initializing initial configutration!? SHOULD NEVER HAPPEN - } - } else { - } - - } - } + debug( + "[===============================]", + "| COMMONS NOTICE |", + "|-------------------------------|", + "| |", + "| Commons now support both |", + "| XML and YAML (YML) Config |", + "| as of release 1.8.8-3. |", + "| |", + "| It seems you no config.yml in |", + "| your Commons plugin folder |", + "| but have yml as your chosen |", + "| data type in data-option.txt |", + "| |", + "| A new config.yml file will be |", + "| generated for you to use, and |", + "| configure accordingly to your |", + "| likings, and servers desire. |", + "| |", + "| To prevent this issue from |", + "| happening again, please don't |", + "| delete your config.yml file! |", + "| |", + "|-------------------------------|", + "| |", + "| Thanks for choosing Commons! |", + "[===============================]" + ); + + CommonsYamlConfiguration yamlConfiguration = new CommonsYamlConfiguration(); + try { + yamlConfiguration.init(ymlConfigFile); + globalConfig = yamlConfiguration; + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + //Error initializing initial configutration!? SHOULD NEVER HAPPEN + } + } else { + } + + } + } } \ No newline at end of file diff --git a/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java index c91c3f4..ed434fc 100644 --- a/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/CommonsXmlConfiguration.java @@ -1,10 +1,12 @@ package com.caved_in.commons.config; import org.simpleframework.xml.Element; +import org.simpleframework.xml.Root; /** * Commons configuration. */ +@Root(name = "Configuration") public class CommonsXmlConfiguration implements Configuration { @Element(name = "mysql-backend") diff --git a/src/main/java/com/caved_in/commons/config/MaintenanceConfiguration.java b/src/main/java/com/caved_in/commons/config/MaintenanceConfiguration.java index 6131af3..6aee5fa 100644 --- a/src/main/java/com/caved_in/commons/config/MaintenanceConfiguration.java +++ b/src/main/java/com/caved_in/commons/config/MaintenanceConfiguration.java @@ -4,17 +4,20 @@ import org.simpleframework.xml.Element; public class MaintenanceConfiguration { + @Element(name = "maintenance-motd") private String maintenanceModeMOTD = "&aThis server is currently undergoing maintenance"; @Element(name = "maintenance-kick-message") private String maintenanceKickMessage = "&cThis server is currently undergoing maintenance; Sorry for the inconvenience"; + @Element(name = "enabled", required = false) private boolean maintenanceMode = false; - public MaintenanceConfiguration(@Element(name = "maintenance-motd") String maintenanceMOTD, @Element(name = "maintenance-kick-message") String maintenanceKickMessage) { + public MaintenanceConfiguration(@Element(name = "maintenance-motd") String maintenanceMOTD, @Element(name = "maintenance-kick-message") String maintenanceKickMessage, @Element(name = "enabled", required = false) boolean maintenanceMode) { this.maintenanceModeMOTD = maintenanceMOTD; this.maintenanceKickMessage = maintenanceKickMessage; + this.maintenanceMode = maintenanceMode; } public MaintenanceConfiguration() { diff --git a/src/main/java/com/caved_in/commons/yml/YamlConfig.java b/src/main/java/com/caved_in/commons/yml/YamlConfig.java index b4b10a7..0a0a210 100644 --- a/src/main/java/com/caved_in/commons/yml/YamlConfig.java +++ b/src/main/java/com/caved_in/commons/yml/YamlConfig.java @@ -69,7 +69,6 @@ private void internalSave(Class clazz) throws InvalidConfigurationException { if (annotation instanceof Comment) { Comment comment = (Comment) annotation; comments.add(comment.value()); - } if (annotation instanceof Comments) {