Deprecated default Bukkit config methods

This commit is contained in:
Rsl1122 2017-11-06 15:12:35 +02:00
parent aca1affe9d
commit 3c8ec7c8f3
5 changed files with 87 additions and 24 deletions

View File

@ -59,6 +59,7 @@ import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
import main.java.com.djrapitops.plan.utilities.metrics.BStats;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
@ -336,7 +337,11 @@ public class Plan extends BukkitPlugin implements IPlan {
@Override
public void onReload() {
reloadConfig();
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
private void registerListeners() {
@ -493,4 +498,40 @@ public class Plan extends BukkitPlugin implements IPlan {
public boolean isReloading() {
return reloading;
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void reloadConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use onReload() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public FileConfiguration getConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use getMainConfig() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void saveConfig() {
throw new IllegalStateException("This method should be used on this plugin. Use getMainConfig().save() instead");
}
/**
* @deprecated Deprecated due to use of APF Config
*/
@Override
@Deprecated
public void saveDefaultConfig() {
throw new IllegalStateException("This method should be used on this plugin.");
}
}

View File

@ -174,7 +174,11 @@ public class PlanBungee extends BungeePlugin implements IPlan {
@Override
public void onReload() {
try {
config.read();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
private void initDatabase() throws DatabaseInitException {
@ -249,4 +253,5 @@ public class PlanBungee extends BungeePlugin implements IPlan {
public UUID getServerUuid() {
return serverInfoManager.getServerUUID();
}
}

View File

@ -6,8 +6,10 @@ package main.java.com.djrapitops.plan;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -63,7 +65,11 @@ public class WorldAliasSettings {
if (Verify.isEmpty(previousValue)) {
aliasSect.set(world, world);
}
plugin.saveConfig();
try {
aliasSect.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
/**

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
@ -7,12 +8,15 @@ import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Condition;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import java.io.IOException;
/**
* This manage subcommand is used to swap to a different database and reload the
* plugin if the connection to the new database can be established.
@ -80,10 +84,14 @@ public class ManageHotswapCommand extends SubCommand {
return true;
}
plugin.getConfig().set("database.type", dbName);
plugin.saveConfig();
plugin.onDisable();
plugin.onEnable();
Config config = plugin.getMainConfig();
config.set(Settings.DB_TYPE.getPath(), dbName);
try {
config.save();
plugin.reloadPlugin(true);
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
return true;
}
}

View File

@ -1,8 +1,10 @@
package main.java.com.djrapitops.plan.data.additional;
import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
/**
* Class responsible for generating and generating settings for PluginData
@ -20,36 +22,37 @@ public class PluginConfigSectionHandler {
}
public boolean hasSection(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.contains(pluginName)) {
if (!section.getChildren().containsKey(pluginName)) {
return false;
}
ConfigurationSection pluginSection = section.getConfigurationSection(pluginName);
return pluginSection.contains(dataSource.getPlaceholder());
ConfigNode pluginSection = section.getConfigNode(pluginName);
return pluginSection.getChildren().containsKey(dataSource.placeholder);
}
private ConfigurationSection getPluginsSection() {
FileConfiguration config = plan.getConfig();
return config.getConfigurationSection("Plugins");
private ConfigNode getPluginsSection() {
return plan.getMainConfig().getConfigNode("Plugins");
}
public void createSection(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
String source = dataSource.placeholder;
section.addDefault(pluginName + ".Enabled", true);
section.addDefault(pluginName + ".Data." + source, true);
FileConfiguration config = plan.getConfig();
config.set("Plugins", section);
plan.saveConfig();
section.set(pluginName + ".Enabled", true);
section.set(pluginName + ".Data." + source, true);
try {
section.sort();
section.save();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
public boolean isEnabled(PluginData dataSource) {
ConfigurationSection section = getPluginsSection();
ConfigNode section = getPluginsSection();
String pluginName = dataSource.getSourcePlugin();
if (!section.getBoolean(pluginName + ".Enabled")) {