Skip to content

Commit

Permalink
Changed style of working with config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ceskyDJ committed May 29, 2020
1 parent 1815c25 commit c529d6b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/com/leetzilantonis/netherwater/NetherWater.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onEnable() {

@Override
public void onDisable() {
this.saveConfig();
this.getLogger().info("Plugin disabled successfully");
}

private WorldGuardPlugin getWorldGuard() throws PluginNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (!sender.hasPermission("netherwater.reload")) {
sender.sendMessage(ChatColor.RED + this.configManager.getMessage("permissions"));
} else {
this.configManager.reloadConfig();
this.configManager.loadConfig();
sender.sendMessage(ChatColor.GREEN + this.configManager.getMessage("config-reload"));
}

Expand Down
33 changes: 18 additions & 15 deletions src/com/leetzilantonis/netherwater/config/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
package com.leetzilantonis.netherwater.config;

import com.leetzilantonis.netherwater.NetherWater;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.List;

public class ConfigManager {
private final NetherWater plugin;

private FileConfiguration configData;

public ConfigManager(NetherWater plugin) {
this.plugin = plugin;

this.loadConfig();
}

private void loadConfig() {
public void loadConfig() {
if (!this.plugin.getDataFolder().exists()) {
this.plugin.getDataFolder().mkdir();
}

if (!new File(this.plugin.getDataFolder(), "config.yml").exists()) {
this.plugin.saveDefaultConfig();
File configFile = new File(this.plugin.getDataFolder(), "config.yml");

if (!configFile.exists()) {
this.plugin.saveResource("config.yml", false);
} else {
this.reloadConfig();
this.configData = YamlConfiguration.loadConfiguration(configFile);
}
}

public void reloadConfig() {
this.plugin.reloadConfig();
}

public boolean isDebugOn() {
return this.plugin.getConfig().getBoolean("debug");
return this.configData.getBoolean("debug");
}

public List<String> getDisabledWorlds() {
return this.plugin.getConfig().getStringList("disabled-worlds");
return this.configData.getStringList("disabled-worlds");
}

public String getMessage(String name) {
return this.plugin.getConfig().getString("messages." + name);
return this.configData.getString("messages." + name);
}

public int getMinHeight() {
return this.plugin.getConfig().getInt("min-height");
return this.configData.getInt("min-height");
}

public int getMaxHeight() {
return this.plugin.getConfig().getInt("max-height");
return this.configData.getInt("max-height");
}

public boolean isSpreadBypassEnabled() {
return this.plugin.getConfig().getBoolean("spread-bypass");
return this.configData.getBoolean("spread-bypass");
}

public boolean isSpreadEnabled() {
return this.plugin.getConfig().getBoolean("spread-enabled");
return this.configData.getBoolean("spread-enabled");
}
}
9 changes: 9 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#--------------------------------------------------------------------------------------------
# _ _ _ _ __ __ _
# | \ | | ___ | |_ | |__ ___ _ __ \ \ / / __ _ | |_ ___ _ __
# | \| | / _ \ | __| | '_ \ / _ \ | '__| \ \ /\ / / / _` | | __| / _ \ | '__|
# | |\ | | __/ | |_ | | | | | __/ | | \ V V / | (_| | | |_ | __/ | |
# |_| \_| \___| \__| |_| |_| \___| |_| \_/\_/ \__,_| \__| \___| |_|
#
#--------------------------------------------------------------------------------------------

# Allow using debug dumps. It's not recommended on production servers.
debug: false
# Worlds where the plugin is disabled
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: NetherWater
version: 1.0.9.1
version: 1.0.10
description: Allow players to use water in the nether
authors: [Lee Tzilantonis, ceskyDJ]

Expand Down

0 comments on commit c529d6b

Please sign in to comment.