瀏覽代碼

L2Properties - better way to find out what configs are missing in properties files

Charus 15 年之前
父節點
當前提交
ca9699889b
共有 2 個文件被更改,包括 163 次插入41 次删除
  1. 41 41
      L2_GameServer/java/net/sf/l2j/Config.java
  2. 122 0
      L2_GameServer/java/net/sf/l2j/util/L2Properties.java

+ 41 - 41
L2_GameServer/java/net/sf/l2j/Config.java

@@ -24,13 +24,13 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.logging.Logger;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
 import net.sf.l2j.gameserver.util.FloodProtectorConfig;
 import net.sf.l2j.gameserver.util.StringUtil;
+import net.sf.l2j.util.L2Properties;
 
 public final class Config
 {
@@ -870,7 +870,7 @@ public final class Config
 			{
 				try
 				{
-					Properties serverSettings = new Properties();
+					L2Properties serverSettings = new L2Properties();
 					is = new FileInputStream(new File(CONFIGURATION_FILE));
 					serverSettings.load(is);
 
@@ -915,10 +915,10 @@ public final class Config
 					throw new Error("Failed to Load "+CONFIGURATION_FILE+" File.");
 				}
 
-				// Load Feature Properties file (if exists)
+				// Load Feature L2Properties file (if exists)
 				try
 				{
-					Properties Feature = new Properties();
+					L2Properties Feature = new L2Properties();
 					is = new FileInputStream(new File(FEATURE_CONFIG_FILE));
 					Feature.load(is);
 
@@ -1126,10 +1126,10 @@ public final class Config
 					throw new Error("Failed to Load "+FEATURE_CONFIG_FILE+" File.");
 				}
 
-				// Load Character Properties file (if exists)
+				// Load Character L2Properties file (if exists)
 				try
 				{
-					Properties Character = new Properties();
+					L2Properties Character = new L2Properties();
 					is = new FileInputStream(new File(CHARACTER_CONFIG_FILE));
 					Character.load(is);
 
@@ -1347,10 +1347,10 @@ public final class Config
 					throw new Error("Failed to Load "+CHARACTER_CONFIG_FILE+" file.");
 				}
 
-				// Load L2J Server Version Properties file (if exists)
+				// Load L2J Server Version L2Properties file (if exists)
 				try
 				{
-					Properties serverVersion = new Properties();
+					L2Properties serverVersion = new L2Properties();
 					is = new FileInputStream(new File(SERVER_VERSION_FILE));
 					serverVersion.load(is);
 
@@ -1359,15 +1359,15 @@ public final class Config
 				}
 				catch (Exception e)
 				{
-					//Ignore Properties file if it doesnt exist
+					//Ignore L2Properties file if it doesnt exist
 					SERVER_VERSION = "Unsupported Custom Version.";
 					SERVER_BUILD_DATE = "Undefined Date.";
 				}
 
-				// Load L2J Datapack Version Properties file (if exists)
+				// Load L2J Datapack Version L2Properties file (if exists)
 				try
 				{
-					Properties serverVersion = new Properties();
+					L2Properties serverVersion = new L2Properties();
 					is = new FileInputStream(new File(DATAPACK_VERSION_FILE));
 					serverVersion.load(is);
 
@@ -1375,14 +1375,14 @@ public final class Config
 				}
 				catch (Exception e)
 				{
-					//Ignore Properties file if it doesnt exist
+					//Ignore L2Properties file if it doesnt exist
 					DATAPACK_VERSION = "Unsupported Custom Version.";
 				}
 
-				// Load Telnet Properties file (if exists)
+				// Load Telnet L2Properties file (if exists)
 				try
 				{
-					Properties telnetSettings = new Properties();
+					L2Properties telnetSettings = new L2Properties();
 					is = new FileInputStream(new File(TELNET_FILE));
 					telnetSettings.load(is);
 
@@ -1398,7 +1398,7 @@ public final class Config
 				try
 				{
 					_log.info("Loading " + MMO_CONFIG_FILE.replaceAll("./config/", ""));
-					Properties mmoSettings = new Properties();
+					L2Properties mmoSettings = new L2Properties();
 					is = new FileInputStream(new File(MMO_CONFIG_FILE));
 					mmoSettings.load(is);
 					MMO_SELECTOR_SLEEP_TIME = Integer.parseInt(mmoSettings.getProperty("SleepTime", "20"));
@@ -1413,10 +1413,10 @@ public final class Config
 					throw new Error("Failed to Load " + MMO_CONFIG_FILE + " File.");
 				}
 
-				// Load IdFactory Properties file (if exists)
+				// Load IdFactory L2Properties file (if exists)
 				try
 				{
-					Properties idSettings = new Properties();
+					L2Properties idSettings = new L2Properties();
 					is = new FileInputStream(new File(ID_CONFIG_FILE));
 					idSettings.load(is);
 
@@ -1431,10 +1431,10 @@ public final class Config
 					throw new Error("Failed to Load "+ID_CONFIG_FILE+" file.");
 				}
 
-				// Load General Properties file (if exists)
+				// Load General L2Properties file (if exists)
 				try
 				{
-					Properties General = new Properties();
+					L2Properties General = new L2Properties();
 					is = new FileInputStream(new File(GENERAL_CONFIG_FILE));
 					General.load(is);
 
@@ -1639,10 +1639,10 @@ public final class Config
 					throw new Error("Failed to Load "+GENERAL_CONFIG_FILE+" File.");
 				}
 				
-				// Load FloodProtector Properties file
+				// Load FloodProtector L2Properties file
 				try
 				{
-					Properties security = new Properties();
+					L2Properties security = new L2Properties();
 					is = new FileInputStream(new File(FLOOD_PROTECTOR_FILE));
 					security.load(is);
 					
@@ -1654,10 +1654,10 @@ public final class Config
 					throw new Error("Failed to Load "+FLOOD_PROTECTOR_FILE);
 				}
 
-				// Load NPC Properties file (if exists)
+				// Load NPC L2Properties file (if exists)
 				try
 				{
-					Properties NPC = new Properties();
+					L2Properties NPC = new L2Properties();
 					is = new FileInputStream(new File(NPC_CONFIG_FILE));
 					NPC.load(is);
 
@@ -1694,10 +1694,10 @@ public final class Config
 					throw new Error("Failed to Load "+NPC_CONFIG_FILE+" File.");
 				}
 
-				// Load Rates Properties file (if exists)
+				// Load Rates L2Properties file (if exists)
 				try
 				{
-					Properties ratesSettings = new Properties();
+					L2Properties ratesSettings = new L2Properties();
 					is = new FileInputStream(new File(RATES_CONFIG_FILE));
 					ratesSettings.load(is);
 
@@ -1785,10 +1785,10 @@ public final class Config
 					throw new Error("Failed to Load "+RATES_CONFIG_FILE+" File.");
 				}
 
-				// Load L2JMod Properties file (if exists)
+				// Load L2JMod L2Properties file (if exists)
 				try
 				{
-					Properties L2JModSettings = new Properties();
+					L2Properties L2JModSettings = new L2Properties();
 					is = new FileInputStream(new File(L2JMOD_CONFIG_FILE));
 					L2JModSettings.load(is);
 
@@ -2021,10 +2021,10 @@ public final class Config
 					throw new Error("Failed to Load "+L2JMOD_CONFIG_FILE+" File.");
 				}
 
-				// Load PvP Properties file (if exists)
+				// Load PvP L2Properties file (if exists)
 				try
 				{
-					Properties pvpSettings = new Properties();
+					L2Properties pvpSettings = new L2Properties();
 					is = new FileInputStream(new File(PVP_CONFIG_FILE));
 					pvpSettings.load(is);
 
@@ -2065,7 +2065,7 @@ public final class Config
 				}
 				try
 				{
-					Properties Settings = new Properties();
+					L2Properties Settings = new L2Properties();
 					is = new FileInputStream(HEXID_FILE);
 					Settings.load(is);
 					SERVER_ID = Integer.parseInt(Settings.getProperty("ServerID"));
@@ -2093,7 +2093,7 @@ public final class Config
 			{
 				try
 				{
-					Properties serverSettings = new Properties();
+					L2Properties serverSettings = new L2Properties();
 					is = new FileInputStream(new File(LOGIN_CONFIGURATION_FILE));
 					serverSettings.load(is);
 
@@ -2151,7 +2151,7 @@ public final class Config
 				try
 				{
 					_log.info("Loading " + MMO_CONFIG_FILE.replaceAll("./config/", ""));
-					Properties mmoSettings = new Properties();
+					L2Properties mmoSettings = new L2Properties();
 					is = new FileInputStream(new File(MMO_CONFIG_FILE));
 					mmoSettings.load(is);
 					MMO_SELECTOR_SLEEP_TIME = Integer.parseInt(mmoSettings.getProperty("SleepTime", "20"));
@@ -2166,10 +2166,10 @@ public final class Config
 					throw new Error("Failed to Load " + MMO_CONFIG_FILE + " File.");
 				}
 
-				// Load Telnet Properties file (if exists)
+				// Load Telnet L2Properties file (if exists)
 				try
 				{
-					Properties telnetSettings = new Properties();
+					L2Properties telnetSettings = new L2Properties();
 					is = new FileInputStream(new File(TELNET_FILE));
 					telnetSettings.load(is);
 
@@ -2473,7 +2473,7 @@ public final class Config
 	private Config() { }
 
 	/**
-	 * Save hexadecimal ID of the server in the properties file.
+	 * Save hexadecimal ID of the server in the L2Properties file.
 	 * @param string (String) : hexadecimal ID of the server to store
 	 * @see HEXID_FILE
 	 * @see saveHexid(String string, String fileName)
@@ -2485,15 +2485,15 @@ public final class Config
 	}
 
 	/**
-	 * Save hexadecimal ID of the server in the properties file.
+	 * Save hexadecimal ID of the server in the L2Properties file.
 	 * @param hexId (String) : hexadecimal ID of the server to store
-	 * @param fileName (String) : name of the properties file
+	 * @param fileName (String) : name of the L2Properties file
 	 */
 	public static void saveHexid(int serverId, String hexId, String fileName)
 	{
 		try
 		{
-			Properties hexSetting = new Properties();
+			L2Properties hexSetting = new L2Properties();
 			File file = new File(fileName);
 			//Create a new empty file only if it doesn't exist
 			file.createNewFile();
@@ -2513,7 +2513,7 @@ public final class Config
 	/**
 	 * Loads flood protector configurations.
 	 */
-	private static void loadFloodProtectorConfigs(final Properties properties)
+	private static void loadFloodProtectorConfigs(final L2Properties properties)
 	{
 		loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_USE_ITEM, "UseItem", "4");
 		loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ROLL_DICE, "RollDice", "42");
@@ -2532,7 +2532,7 @@ public final class Config
 	 * Loads single flood protector configuration.
 	 * 
 	 * @param properties
-	 *            properties file reader
+	 *            L2Properties file reader
 	 * @param config
 	 *            flood protector configuration instance
 	 * @param configString
@@ -2541,7 +2541,7 @@ public final class Config
 	 * @param defaultInterval
 	 *            default flood protector interval
 	 */
-	private static void loadFloodProtectorConfig(final Properties properties, final FloodProtectorConfig config, final String configString, final String defaultInterval)
+	private static void loadFloodProtectorConfig(final L2Properties properties, final FloodProtectorConfig config, final String configString, final String defaultInterval)
 	{
 		config.FLOOD_PROTECTION_INTERVAL = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "Interval"), defaultInterval));
 		config.LOG_FLOODING = Boolean.parseBoolean(properties.getProperty(StringUtil.concat("FloodProtector", configString, "LogFlooding"), "False"));

+ 122 - 0
L2_GameServer/java/net/sf/l2j/util/L2Properties.java

@@ -0,0 +1,122 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+/**
+ * @author Noctarius
+ */
+
+public final class L2Properties extends Properties
+{
+    private static final long serialVersionUID = 1L;
+
+    private static Logger _log = Logger.getLogger(L2Properties.class.getName());
+
+	public L2Properties() { }
+
+	public L2Properties(String name) throws IOException
+	{
+		load(new FileInputStream(name));
+	}
+
+	public L2Properties(File file) throws IOException
+	{
+		load(new FileInputStream(file));
+	}
+
+	public L2Properties(InputStream inStream) throws IOException
+	{
+		load(inStream);
+	}
+
+	public L2Properties(Reader reader) throws IOException
+	{
+		load(reader);
+	}
+
+	public void load(String name) throws IOException
+	{
+		load(new FileInputStream(name));
+	}
+
+	public void load(File file) throws IOException
+	{
+		load(new FileInputStream(file));
+	}
+
+	@Override
+	public void load(InputStream inStream) throws IOException
+	{
+		try
+		{
+			super.load(inStream);
+		}
+		finally
+		{
+			inStream.close();
+		}
+	}
+
+	@Override
+	public void load(Reader reader) throws IOException
+	{
+		try
+		{
+			super.load(reader);
+		}
+		finally
+		{
+			reader.close();
+		}
+	}
+
+	@Override
+	public String getProperty(String key)
+	{
+		String property = super.getProperty(key);
+
+		if (property == null)
+		{
+			_log.info("L2Properties: Missing property for key - " + key);
+
+			return null;
+		}
+
+		return property.trim();
+	}
+
+	@Override
+	public String getProperty(String key, String defaultValue)
+	{
+		String property = super.getProperty(key, defaultValue);
+
+		if (property == null)
+		{
+			_log.warning("L2Properties: Missing defaultValue for key - " + key);
+
+			return null;
+		}
+
+		return property.trim();
+	}
+}