diff --git a/src/main/java/dev/mylesmor/sudosigns/config/ConfigManager.java b/src/main/java/dev/mylesmor/sudosigns/config/ConfigManager.java index 276f71d..6f6189d 100644 --- a/src/main/java/dev/mylesmor/sudosigns/config/ConfigManager.java +++ b/src/main/java/dev/mylesmor/sudosigns/config/ConfigManager.java @@ -1,22 +1,24 @@ package dev.mylesmor.sudosigns.config; -import dev.mylesmor.sudosigns.SudoSigns; -import dev.mylesmor.sudosigns.data.PlayerInput; -import dev.mylesmor.sudosigns.data.SignCommand; -import dev.mylesmor.sudosigns.data.SignMessage; -import dev.mylesmor.sudosigns.data.SudoSign; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; -import net.kyori.adventure.text.TextComponent; + import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import dev.mylesmor.sudosigns.SudoSigns; +import dev.mylesmor.sudosigns.data.PlayerInput; +import dev.mylesmor.sudosigns.data.SignCommand; +import dev.mylesmor.sudosigns.data.SignMessage; +import dev.mylesmor.sudosigns.data.SudoSign; +import net.kyori.adventure.text.TextComponent; + /** * The class for managing the plugins config. * @@ -131,30 +133,25 @@ public class ConfigManager { public boolean loadCustomConfig() { - if (!SudoSigns.sudoSignsPlugin.getDataFolder().exists()) { + try { - SudoSigns.sudoSignsPlugin.getDataFolder().mkdir(); + final File dataFolder = SudoSigns.sudoSignsPlugin.getDataFolder(); + if (!dataFolder.exists() && !dataFolder.mkdirs()) { - } + Bukkit.getLogger().warning("ERROR: Failed to create plugin data folder!"); - signConfigFile = new File(SudoSigns.sudoSignsPlugin.getDataFolder(), "signs.yml"); - if (!signConfigFile.exists()) { - - try { - - signConfigFile.createNewFile(); - - } catch (IOException e) { - - Bukkit.getLogger().warning(SudoSigns.getPlugin().getConfig().getString("config.console-prefix") - + "ERROR: Failed to create config!"); - e.printStackTrace(); + return false; } - } + signConfigFile = new File(dataFolder, "signs.yml"); - try { + // Copy default from jar if missing + if (!signConfigFile.exists()) { + + SudoSigns.sudoSignsPlugin.saveResource("signs.yml", false); + + } signConfig = YamlConfiguration.loadConfiguration(signConfigFile); @@ -180,7 +177,6 @@ public class ConfigManager { if (!signConfig.contains("version")) { - signConfig.createSection("version"); signConfig.set("version", "1.2.3"); save(); @@ -188,23 +184,24 @@ public class ConfigManager { } - } catch (Exception e) { + return true; + + } catch (Exception error) { Bukkit.getLogger().warning(SudoSigns.getPlugin().getConfig().getString("config.console-prefix") + "ERROR: Failed to initialise signs.yml!"); - e.printStackTrace(); + + error.printStackTrace(); return false; } - return true; - } public void fixConfig() { - Set signSection = signConfig.getConfigurationSection("signs").getKeys(false); + final Set signSection = signConfig.getConfigurationSection("signs").getKeys(false); String name = null; for (String key : signSection) { @@ -213,9 +210,9 @@ public class ConfigManager { name = key; - List pCommands = signConfig.getStringList("signs." + key + ".player-commands"); - List cCommands = signConfig.getStringList("signs." + key + ".console-commands"); - List messages = signConfig.getStringList("signs." + key + ".messages"); + final List pCommands = signConfig.getStringList("signs." + key + ".player-commands"); + final List cCommands = signConfig.getStringList("signs." + key + ".console-commands"); + final List messages = signConfig.getStringList("signs." + key + ".messages"); if (pCommands.size() == 0 && cCommands.size() == 0 && messages.size() == 0) { @@ -228,7 +225,7 @@ public class ConfigManager { try { - ArrayList> mapList = new ArrayList<>(); + final ArrayList> mapList = new ArrayList<>(); HashMap map = new HashMap<>(); for (String cmd : pCommands) { diff --git a/src/main/java/dev/mylesmor/sudosigns/config/SignConfig.java b/src/main/java/dev/mylesmor/sudosigns/config/SignConfig.java index 54c7e2a..09874f6 100644 --- a/src/main/java/dev/mylesmor/sudosigns/config/SignConfig.java +++ b/src/main/java/dev/mylesmor/sudosigns/config/SignConfig.java @@ -26,7 +26,7 @@ import org.bukkit.entity.Player; public class SignConfig { private FileConfiguration signConfig; - private ConfigManager configManager; + private final ConfigManager configManager; SignConfig(ConfigManager configManager) { @@ -44,12 +44,11 @@ public class SignConfig { // Loads the signs from the config. public ArrayList loadSigns() { - Map tempSigns = new HashMap<>(); + final Map tempSigns = new HashMap<>(); Set signSection = signConfig.getConfigurationSection("signs").getKeys(false); String name; ArrayList invalidSigns = new ArrayList<>(); - for (String key : signSection) { name = key; @@ -277,10 +276,11 @@ public class SignConfig { if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof Sign) { - Sign facing = (Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData(); + final Sign facing = (Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()) + .getBlockData(); - Rotatable data = (Rotatable) facing.getBlockData(); - BlockFace rotation = data.getRotation(); + final Rotatable data = (Rotatable) facing.getBlockData(); + final BlockFace rotation = data.getRotation(); locSec.set("rotation", rotation); @@ -288,7 +288,7 @@ public class SignConfig { .getBlockData() instanceof WallSign) { - WallSign facing = (WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()) + final WallSign facing = (WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()) .getBlockData(); locSec.set("rotation", facing.getFacing().toString()); @@ -304,11 +304,12 @@ public class SignConfig { } - } catch (Exception e) { + } catch (Exception error) { if (p != null) { Util.sudoSignsMessage(p, "&cERROR: Failed to save sign %NAME% to the config!", name); + error.printStackTrace(); } @@ -320,7 +321,7 @@ public class SignConfig { if (signConfig.isConfigurationSection("signs." + name + "")) { - List text = signConfig.getStringList("signs." + name + ".text"); + final List text = signConfig.getStringList("signs." + name + ".text"); text.set(lineNumber - 1, newText.content()); signConfig.set("signs." + name + ".text", text); diff --git a/src/main/resources/signs.yml b/src/main/resources/signs.yml new file mode 100644 index 0000000..522cf4a --- /dev/null +++ b/src/main/resources/signs.yml @@ -0,0 +1,248 @@ +signs: + 1Withdraw: + text: + - §l[Teller] + - §BWithdraw + - §B1 Diamond + - §BFrom Bank + price: 0.0 + location: + world: world + x: -121.0 + y: 44.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - withdraw 1: 0.0 + console-commands: {} + Deposit: + text: + - §l[Teller] + - §BDeposit + - §BDiamonds + - §BTo Bank + price: 0.0 + location: + world: world + x: -123.0 + y: 44.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - deposit all: 0.0 + console-commands: {} + Balance: + text: + - §l[Teller] + - §BCheck + - §BYour + - §BBalance + price: 0.0 + location: + world: world + x: -125.0 + y: 44.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - balance: 0.0 + console-commands: {} + SpleggDuel: + text: + - §8[§31v1 Duel§8] + - §60 of 10 + - §6Players Waiting + - §8[§lJOIN§8] + price: 0.0 + location: + world: world + x: -1.0 + y: 64.0 + z: -249.0 + rotation: SOUTH + blocktype: OAK_WALL_SIGN + permissions: {} + messages: + - Splegg is not out yet!: 0.0 + player-commands: {} + console-commands: {} + SpleggFFA: + text: + - §8[§aFFA§8] + - §60 of 10 + - §6Players Waiting + - §8[§B§lJOIN§8] + price: 0.0 + location: + world: world + x: 1.0 + y: 64.0 + z: -249.0 + rotation: SOUTH + blocktype: OAK_WALL_SIGN + permissions: {} + messages: + - Splegg is not out yet!: 0.0 + player-commands: {} + console-commands: {} + communitychest: + text: + - '' + - §5Community + - §BChest + - '' + price: 0.0 + location: + world: world + x: -21.0 + y: 63.0 + z: -200.0 + rotation: NORTH + blocktype: OAK_WALL_SIGN + permissions: {} + messages: + - Use this chest to share items with the community.: 0.0 + player-commands: {} + console-commands: {} + balance: + text: + - '' + - §BCHECK + - §BBALANCE + - '' + price: 0.0 + location: + world: world + x: -125.0 + y: 43.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - balance: 0.0 + console-commands: {} + deposit: + text: + - '' + - §BDEPOSIT + - §BDIAMONDS + - '' + price: 0.0 + location: + world: world + x: -123.0 + y: 43.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - deposit all: 0.0 + console-commands: {} + withdraw1: + text: + - '' + - §BWITHDRAW + - §B1 DIAMOND + - '' + price: 0.0 + location: + world: world + x: -120.0 + y: 41.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - withdraw 1: 0.0 + console-commands: {} + withdraw4: + text: + - '' + - §BWITHDRAW + - §B4 DIAMONDS + - '' + price: 0.0 + location: + world: world + x: -120.0 + y: 42.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: {} + console-commands: {} + withdraw16: + text: + - '' + - §BWITHDRAW + - §B16 DIAMONDS + - '' + price: 0.0 + location: + world: world + x: -120.0 + y: 43.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - withdraw 16: 0.0 + console-commands: {} + withdraw64: + text: + - '' + - §BWITHDRAW + - §B64 DIAMONDS + - '' + price: 0.0 + location: + world: world + x: -121.0 + y: 43.0 + z: -261.0 + rotation: NORTH + blocktype: WARPED_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - withdraw 64: 0.0 + console-commands: {} + store: + text: + - §2True§4OG Shop + - §BClick here to + - §bpurchase a + - §brank! + price: 0.0 + location: + world: world + x: -128.0 + y: 42.0 + z: -261.0 + rotation: NORTH + blocktype: OAK_WALL_SIGN + permissions: {} + messages: {} + player-commands: + - buy: 0.0 + console-commands: {} +version: 1.2.3