From 413eb283a48810bfda176266e313081470c9fc03 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sat, 3 Nov 2012 00:54:03 +0100 Subject: [PATCH] Fix handling of configuration. --- .../comphenix/protocol/ProtocolConfig.java | 3 ++- .../comphenix/protocol/ProtocolLibrary.java | 21 +++++++++++++++++-- ProtocolLib/src/main/resources/config.yml | 4 ++-- ProtocolLib/src/main/resources/plugin.yml | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java index 516db0fc..517cf6f1 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java @@ -51,7 +51,8 @@ class ProtocolConfig { // Automatically copy defaults if (copyDefaults && (global == null || updater == null)) { - config.options().copyDefaults(true); + plugin.saveDefaultConfig(); + config = plugin.getConfig(); loadSections(false); } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index e0acc802..c9da1902 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -17,6 +17,7 @@ package com.comphenix.protocol; +import java.io.File; import java.io.IOException; import java.util.logging.Logger; @@ -80,8 +81,17 @@ public class ProtocolLibrary extends JavaPlugin { // Load configuration updater = new Updater(this, "protocollib", getFile(), "protocol.info"); - config = new ProtocolConfig(this); - + + try { + config = new ProtocolConfig(this); + } catch (Exception e) { + reporter.reportWarning(this, "Cannot load configuration", e); + + // Load it again + deleteConfig(); + config = new ProtocolConfig(this); + } + try { unhookTask = new DelayedSingleTask(this); protocolManager = new PacketFilterManager(getClassLoader(), getServer(), unhookTask, reporter); @@ -97,6 +107,13 @@ public class ProtocolLibrary extends JavaPlugin { } } + private void deleteConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + + // Delete the file + configFile.delete(); + } + @Override public void reloadConfig() { super.reloadConfig(); diff --git a/ProtocolLib/src/main/resources/config.yml b/ProtocolLib/src/main/resources/config.yml index a16abc8f..aa16c45f 100644 --- a/ProtocolLib/src/main/resources/config.yml +++ b/ProtocolLib/src/main/resources/config.yml @@ -5,6 +5,6 @@ global: download: true # Number of seconds to wait until a new update is downloaded - delay = 43200 # 12 hours + delay: 43200 # 12 hours # Last update time - last = 0 \ No newline at end of file + last: 0 \ No newline at end of file diff --git a/ProtocolLib/src/main/resources/plugin.yml b/ProtocolLib/src/main/resources/plugin.yml index c684d1d4..8fd825ea 100644 --- a/ProtocolLib/src/main/resources/plugin.yml +++ b/ProtocolLib/src/main/resources/plugin.yml @@ -14,7 +14,7 @@ commands: permission: experiencemod.admin permission-message: You don't have packet: - description: Adds or removes a simple packet listener. + description: Add or remove a simple packet listener. usage: / add|remove client|server|both [ID start] [ID stop] [detailed] permission: experiencemod.admin permission-message: You don't have