Fix configuration handling.
Dieser Commit ist enthalten in:
Ursprung
f5dce019df
Commit
abafb7a6c5
@ -35,7 +35,7 @@ class CommandProtocol extends CommandBase {
|
|||||||
String subCommand = args[0];
|
String subCommand = args[0];
|
||||||
|
|
||||||
// Only return TRUE if we executed the correct command
|
// Only return TRUE if we executed the correct command
|
||||||
if (subCommand.equalsIgnoreCase("config"))
|
if (subCommand.equalsIgnoreCase("config") || subCommand.equalsIgnoreCase("reload"))
|
||||||
reloadConfiguration(sender);
|
reloadConfiguration(sender);
|
||||||
else if (subCommand.equalsIgnoreCase("check"))
|
else if (subCommand.equalsIgnoreCase("check"))
|
||||||
checkVersion(sender);
|
checkVersion(sender);
|
||||||
@ -52,7 +52,7 @@ class CommandProtocol extends CommandBase {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true);
|
UpdateResult result = updater.update(UpdateType.NO_DOWNLOAD, true);
|
||||||
sender.sendMessage(ChatColor.BLUE + "Version check: " + result.toString());
|
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class CommandProtocol extends CommandBase {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UpdateResult result = updater.update(UpdateType.DEFAULT, true);
|
UpdateResult result = updater.update(UpdateType.DEFAULT, true);
|
||||||
sender.sendMessage(ChatColor.BLUE + "Update: " + result.toString());
|
sender.sendMessage(ChatColor.BLUE + "[ProtocolLib] " + result.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -76,12 +76,13 @@ class CommandProtocol extends CommandBase {
|
|||||||
* Prevent further automatic updates until the next delay.
|
* Prevent further automatic updates until the next delay.
|
||||||
*/
|
*/
|
||||||
public void updateFinished() {
|
public void updateFinished() {
|
||||||
config.setAutoLastTime(System.currentTimeMillis());
|
long currentTime = System.currentTimeMillis() / ProtocolLibrary.MILLI_PER_SECOND;
|
||||||
|
|
||||||
|
config.setAutoLastTime(currentTime);
|
||||||
config.saveAll();
|
config.saveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadConfiguration(CommandSender sender) {
|
public void reloadConfiguration(CommandSender sender) {
|
||||||
plugin.saveConfig();
|
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
sender.sendMessage(ChatColor.BLUE + "Reloaded configuration!");
|
sender.sendMessage(ChatColor.BLUE + "Reloaded configuration!");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.comphenix.protocol;
|
package com.comphenix.protocol;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -26,6 +28,7 @@ class ProtocolConfig {
|
|||||||
|
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
|
private boolean loadingSections;
|
||||||
|
|
||||||
private ConfigurationSection global;
|
private ConfigurationSection global;
|
||||||
private ConfigurationSection updater;
|
private ConfigurationSection updater;
|
||||||
@ -35,7 +38,15 @@ class ProtocolConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolConfig(Plugin plugin, Configuration config) {
|
public ProtocolConfig(Plugin plugin, Configuration config) {
|
||||||
this.config = config;
|
this.plugin = plugin;
|
||||||
|
reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload configuration file.
|
||||||
|
*/
|
||||||
|
public void reloadConfig() {
|
||||||
|
this.config = plugin.getConfig();
|
||||||
loadSections(true);
|
loadSections(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +55,9 @@ class ProtocolConfig {
|
|||||||
* @param copyDefaults - whether or not to copy configuration defaults.
|
* @param copyDefaults - whether or not to copy configuration defaults.
|
||||||
*/
|
*/
|
||||||
private void loadSections(boolean copyDefaults) {
|
private void loadSections(boolean copyDefaults) {
|
||||||
|
if (loadingSections)
|
||||||
|
return;
|
||||||
|
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
global = config.getConfigurationSection(SECTION_GLOBAL);
|
global = config.getConfigurationSection(SECTION_GLOBAL);
|
||||||
}
|
}
|
||||||
@ -52,13 +66,30 @@ class ProtocolConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Automatically copy defaults
|
// Automatically copy defaults
|
||||||
if (copyDefaults && (global == null || updater == null)) {
|
if (copyDefaults && (!getFile().exists() || global == null || updater == null)) {
|
||||||
|
loadingSections = true;
|
||||||
|
|
||||||
|
if (config != null)
|
||||||
|
config.options().copyDefaults(true);
|
||||||
plugin.saveDefaultConfig();
|
plugin.saveDefaultConfig();
|
||||||
config = plugin.getConfig();
|
config = plugin.getConfig();
|
||||||
|
|
||||||
|
loadingSections = false;
|
||||||
loadSections(false);
|
loadSections(false);
|
||||||
|
|
||||||
|
// Inform the user
|
||||||
|
System.out.println("[ProtocolLib] Created default configuration.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a reference to the configuration file.
|
||||||
|
* @return Configuration file on disk.
|
||||||
|
*/
|
||||||
|
public File getFile() {
|
||||||
|
return new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve whether or not ProtocolLib should determine if a new version has been released.
|
* Retrieve whether or not ProtocolLib should determine if a new version has been released.
|
||||||
* @return TRUE if it should do this automatically, FALSE otherwise.
|
* @return TRUE if it should do this automatically, FALSE otherwise.
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package com.comphenix.protocol;
|
package com.comphenix.protocol;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
@ -43,7 +42,11 @@ import com.comphenix.protocol.reflect.compiler.BackgroundCompiler;
|
|||||||
*/
|
*/
|
||||||
public class ProtocolLibrary extends JavaPlugin {
|
public class ProtocolLibrary extends JavaPlugin {
|
||||||
|
|
||||||
private static final long MILLI_PER_SECOND = 1000;
|
/**
|
||||||
|
* The number of milliseconds per second.
|
||||||
|
*/
|
||||||
|
static final long MILLI_PER_SECOND = 1000;
|
||||||
|
|
||||||
private static final String PERMISSION_INFO = "protocol.info";
|
private static final String PERMISSION_INFO = "protocol.info";
|
||||||
|
|
||||||
// There should only be one protocol manager, so we'll make it static
|
// There should only be one protocol manager, so we'll make it static
|
||||||
@ -118,17 +121,16 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void deleteConfig() {
|
private void deleteConfig() {
|
||||||
File configFile = new File(getDataFolder(), "config.yml");
|
config.getFile().delete();
|
||||||
|
|
||||||
// Delete the file
|
|
||||||
configFile.delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
super.reloadConfig();
|
super.reloadConfig();
|
||||||
// Reload configuration
|
// Reload configuration
|
||||||
config = new ProtocolConfig(this);
|
if (config != null) {
|
||||||
|
config.reloadConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void broadcastUsers(final String permission) {
|
private void broadcastUsers(final String permission) {
|
||||||
@ -237,7 +239,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND;
|
long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND;
|
||||||
|
|
||||||
// Should we update?
|
// Should we update?
|
||||||
if (currentTime < config.getAutoLastTime() + config.getAutoDelay()) {
|
if (currentTime > config.getAutoLastTime() + config.getAutoDelay()) {
|
||||||
// Initiate the update as if it came from the console
|
// Initiate the update as if it came from the console
|
||||||
if (config.isAutoDownload())
|
if (config.isAutoDownload())
|
||||||
commandProtocol.updateVersion(getServer().getConsoleSender());
|
commandProtocol.updateVersion(getServer().getConsoleSender());
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren