From 2a6465534d7d652f1adb694c9e688ad3ce87fa11 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 13 Sep 2021 15:31:29 -0600 Subject: found parsesettings bug --- .../brysonsteck/Resurrection/ParseSettings.java | 106 --------------------- src/net/brysonsteck/Resurrection/Resurrection.java | 23 +++-- .../Resurrection/commands/CommandAbout.java | 2 +- .../Resurrection/commands/CommandBug.java | 3 + .../Resurrection/commands/CommandHowLong.java | 3 + .../Resurrection/commands/CommandResurrect.java | 3 + .../Resurrection/commands/CommandSource.java | 5 + .../Resurrection/player/PlayerListener.java | 3 +- .../Resurrection/startup/ParseSettings.java | 106 +++++++++++++++++++++ 9 files changed, 137 insertions(+), 117 deletions(-) delete mode 100644 src/net/brysonsteck/Resurrection/ParseSettings.java create mode 100644 src/net/brysonsteck/Resurrection/startup/ParseSettings.java (limited to 'src/net/brysonsteck/Resurrection') diff --git a/src/net/brysonsteck/Resurrection/ParseSettings.java b/src/net/brysonsteck/Resurrection/ParseSettings.java deleted file mode 100644 index 6de7269..0000000 --- a/src/net/brysonsteck/Resurrection/ParseSettings.java +++ /dev/null @@ -1,106 +0,0 @@ -package net.brysonsteck.Resurrection; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.util.Hashtable; -import java.util.Locale; - -public class ParseSettings { - Hashtable settings = new Hashtable<>(); - // - String failedSetting; - boolean settingsComplete; - boolean valuesComplete; - - public ParseSettings() { - try { - File settingsFile = new File("plugins/settings.resurrection"); - if (!settingsFile.exists()) { - // create default settings file - FileWriter writer = new FileWriter(settingsFile); - writer.write("# This is the default settings file. All lines starting with a '#' are treated as comments and will be ignored.\n" + - "# 'resurrection_time' is the amount of time in milliseconds Resurrection will force the player to wait. Default value is 8640000 milliseconds (24 hours).\n" + - "resurrection_time=86400000\n" + - "# 'debug' enables debug messages in the console and players' chat as the plugin runs. The only valid values are 'true' and 'false'. Default value is false.\n" + - "debug=false"); - writer.close(); - } - String rawData = ""; - BufferedReader reader = new BufferedReader(new FileReader("plugins/settings.resurrection")); - String line; - String[] setting; - while (true) { - line = reader.readLine(); - if (line == null) { - break; - } else if (!line.startsWith("#")) { - rawData = rawData + line; - setting = line.split("="); - settings.put(setting[0], setting[1]); - } - } - if (!verifySettings()) { - System.out.println("[Resurrection] There is a syntax issue inside the Settings file:"); - if (!settingsComplete) { - System.out.println("[Resurrection] The setting \"" + failedSetting + "\" is not present in the settings file.\n" + - "[Resurrection] Please double check the settings file to make sure the setting exists and a valid corresponding value is set.\n" + - "[Resurrection] Example: \"resurrection_time=86400000\"\n" + - "[Resurrection] Example: \"debug=false\""); - } else if (!valuesComplete) { - System.out.println("[Resurrection] The setting \"" + failedSetting + "\" contains an invalid or empty value.\n" + - "[Resurrection] Please double check the settings file to make sure that a valid value is set for this setting.\n" + - "[Resurrection] Example: \"resurrection_time=86400000\"\n" + - "[Resurrection] Example: \"debug=false\""); - } - System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file is not complete, the plugin will now stop."); - System.exit(1); - } - } catch (IOException e) { - System.out.println("[Resurrection] There was an issue reading the Settings file:"); - e.printStackTrace(); - System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file is not complete, the plugin will now stop."); - System.exit(1); - } - } - - public boolean verifySettings() { - settingsComplete = false; - valuesComplete = false; - - if (!settings.containsKey("resurrection_time")) { - failedSetting = "resurrection_time"; - return false; - } else if (!settings.containsKey("debug")) { - failedSetting = "debug"; - return false; - } - settingsComplete = true; - - // is resurrection_time a long? - try { - long time = Long.parseLong(settings.get("resurrection_time")); - } catch (NumberFormatException | NullPointerException e) { - failedSetting = "resurrection_time"; - return false; - } - - // is debug a boolean? - if (settings.get("debug") == null) { - failedSetting = "debug"; - return false; - } - if (settings.get("debug").toLowerCase().contains("true") && settings.get("debug").toLowerCase().contains("false")) { - failedSetting = "debug"; - return false; - } - valuesComplete = true; - - return true; - } - - public String getSetting(String setting) { - return settings.get(setting); - } -} diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java index e8aed53..a4a70a4 100644 --- a/src/net/brysonsteck/Resurrection/Resurrection.java +++ b/src/net/brysonsteck/Resurrection/Resurrection.java @@ -2,9 +2,8 @@ package net.brysonsteck.Resurrection; import net.brysonsteck.Resurrection.commands.*; import net.brysonsteck.Resurrection.player.PlayerListener; -import net.brysonsteck.Resurrection.player.TimeCheck; import net.brysonsteck.Resurrection.startup.CheckForUpdate; -import org.bukkit.Bukkit; +import net.brysonsteck.Resurrection.startup.ParseSettings; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; @@ -66,6 +65,8 @@ public class Resurrection extends JavaPlugin implements Listener { System.out.println("[Resurrection] ---------------------------------------------------------"); + ParseSettings parseSettings = null; + System.out.println("[Resurrection] Locating player data and settings files..."); // check if playerData.resurrection exists File playerFile = new File("plugins/playerData.resurrection"); @@ -85,7 +86,7 @@ public class Resurrection extends JavaPlugin implements Listener { } if (!settingsFile.exists()) { System.out.println("[Resurrection] Settings file does not exist. (This file is new with the 0.2 beta if you upgraded.) Creating now in the \"plugins\" directory..."); - ParseSettings parseSettings = new ParseSettings(); + parseSettings = new ParseSettings(); System.out.println("[Resurrection] Settings file created successfully."); } else { System.out.println("[Resurrection] The settings file has also been found!"); @@ -98,11 +99,11 @@ public class Resurrection extends JavaPlugin implements Listener { this.getServer().getPluginManager().registerEvents(new PlayerListener(), this); // register commands - this.getCommand("about").setExecutor(new CommandAbout(pluginInfo.getVersion(), outdated)); - this.getCommand("bug").setExecutor(new CommandBug()); - this.getCommand("resurrect").setExecutor(new CommandResurrect()); - this.getCommand("howlong").setExecutor(new CommandHowLong()); - this.getCommand("source").setExecutor(new CommandSource()); + this.getCommand("about").setExecutor(new CommandAbout(parseSettings.getSetting("debug"), pluginInfo.getVersion(), outdated)); + this.getCommand("bug").setExecutor(new CommandBug(parseSettings.getSetting("debug"))); + this.getCommand("resurrect").setExecutor(new CommandResurrect(parseSettings.getSetting("debug"))); + this.getCommand("howlong").setExecutor(new CommandHowLong(parseSettings.getSetting("debug"))); + this.getCommand("source").setExecutor(new CommandSource(parseSettings.getSetting("debug"))); System.out.println("[Resurrection] ---------------------------------------------------------"); System.out.println("[Resurrection] Successfully Started!"); @@ -112,6 +113,12 @@ public class Resurrection extends JavaPlugin implements Listener { public static void main(String[] args) { +// String test = "fals"; +// +// if (!test.toLowerCase().contains("true") && !test.toLowerCase().contains("false")) { +// System.out.println("fail"); +// } + // DO THIS // PlayerData playerData = new PlayerData(); // System.out.println("--- Reading Player data file ---"); diff --git a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java index 3d16878..272b4d0 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandAbout.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandAbout.java @@ -10,7 +10,7 @@ public class CommandAbout implements CommandExecutor { String currentVersion; boolean outdated; - public CommandAbout(String currentVersion, boolean outdated) { + public CommandAbout(String debug, String currentVersion, boolean outdated) { this.currentVersion = currentVersion; this.outdated = outdated; } diff --git a/src/net/brysonsteck/Resurrection/commands/CommandBug.java b/src/net/brysonsteck/Resurrection/commands/CommandBug.java index 894fcbc..75ed5cf 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandBug.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandBug.java @@ -11,6 +11,9 @@ import org.bukkit.scheduler.BukkitRunnable; public class CommandBug implements CommandExecutor { + public CommandBug(String debug) { + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if (commandSender instanceof Player) { diff --git a/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java index f36987a..29314d7 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandHowLong.java @@ -11,6 +11,9 @@ import org.bukkit.entity.Player; public class CommandHowLong implements CommandExecutor { + public CommandHowLong(String debug) { + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if (commandSender instanceof Player) { diff --git a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java index 106cb71..9f97c29 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandResurrect.java @@ -12,6 +12,9 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; public class CommandResurrect implements CommandExecutor { + public CommandResurrect(String debug) { + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { boolean valid = (strings.length == 1); diff --git a/src/net/brysonsteck/Resurrection/commands/CommandSource.java b/src/net/brysonsteck/Resurrection/commands/CommandSource.java index ecab174..92e51c6 100644 --- a/src/net/brysonsteck/Resurrection/commands/CommandSource.java +++ b/src/net/brysonsteck/Resurrection/commands/CommandSource.java @@ -10,6 +10,11 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class CommandSource implements CommandExecutor { + boolean debug; + + public CommandSource(String debug) { + this.debug = Boolean.parseBoolean(debug); + } @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { diff --git a/src/net/brysonsteck/Resurrection/player/PlayerListener.java b/src/net/brysonsteck/Resurrection/player/PlayerListener.java index c94e8f5..c54fcf0 100644 --- a/src/net/brysonsteck/Resurrection/player/PlayerListener.java +++ b/src/net/brysonsteck/Resurrection/player/PlayerListener.java @@ -1,9 +1,8 @@ package net.brysonsteck.Resurrection.player; -import net.brysonsteck.Resurrection.ParseSettings; +import net.brysonsteck.Resurrection.startup.ParseSettings; import net.brysonsteck.Resurrection.Resurrection; import org.bukkit.*; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/net/brysonsteck/Resurrection/startup/ParseSettings.java b/src/net/brysonsteck/Resurrection/startup/ParseSettings.java new file mode 100644 index 0000000..de0bb5d --- /dev/null +++ b/src/net/brysonsteck/Resurrection/startup/ParseSettings.java @@ -0,0 +1,106 @@ +package net.brysonsteck.Resurrection.startup; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.*; +import java.util.Hashtable; +import java.util.Locale; + +public class ParseSettings { + Hashtable settings = new Hashtable<>(); + // + String failedSetting; + boolean settingsComplete; + boolean valuesComplete; + + public ParseSettings() { + try { + File settingsFile = new File("plugins/settings.resurrection"); + if (!settingsFile.exists()) { + // create default settings file + FileWriter writer = new FileWriter(settingsFile); + writer.write("# This is the default settings file. All lines starting with a '#' are treated as comments and will be ignored.\n" + + "# 'resurrection_time' is the amount of time in milliseconds Resurrection will force the player to wait. Default value is 8640000 milliseconds (24 hours).\n" + + "resurrection_time=86400000\n" + + "# 'debug' enables debug messages in the console and players' chat as the plugin runs. The only valid values are 'true' and 'false'. Default value is false.\n" + + "debug=false"); + writer.close(); + } + String rawData = ""; + BufferedReader reader = new BufferedReader(new FileReader("plugins/settings.resurrection")); + String line; + String[] setting; + while (true) { + line = reader.readLine(); + if (line == null) { + break; + } else if (!line.startsWith("#")) { + rawData = rawData + line; + setting = line.split("="); + settings.put(setting[0], setting[1]); + } + } + if (!verifySettings()) { + System.out.println("[Resurrection] There is a syntax issue inside the Settings file:"); + if (!settingsComplete) { + System.out.println("[Resurrection] The setting \"" + failedSetting + "\" is not present in the settings file.\n" + + "[Resurrection] Please double check the settings file to make sure the setting exists and a valid corresponding value is set.\n" + + "[Resurrection] Example: \"resurrection_time=86400000\"\n" + + "[Resurrection] Example: \"debug=false\""); + } else if (!valuesComplete) { + System.out.println("[Resurrection] The setting \"" + failedSetting + "\" contains an invalid or empty value.\n" + + "[Resurrection] Please double check the settings file to make sure that a valid value is set for this setting.\n" + + "[Resurrection] Example: \"resurrection_time=86400000\"\n" + + "[Resurrection] Example: \"debug=false\""); + } + System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file is not complete, the plugin will now stop."); + System.exit(1); + } + } catch (IOException e) { + System.out.println("[Resurrection] There was an issue reading the Settings file:"); + e.printStackTrace(); + System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file is not complete, the plugin will now stop."); + System.exit(1); + } + } + + public boolean verifySettings() { + settingsComplete = false; + valuesComplete = false; + + if (!settings.containsKey("resurrection_time")) { + failedSetting = "resurrection_time"; + return false; + } else if (!settings.containsKey("debug")) { + failedSetting = "debug"; + return false; + } + settingsComplete = true; + + // is resurrection_time a long? + try { + long time = Long.parseLong(settings.get("resurrection_time")); + } catch (NumberFormatException | NullPointerException e) { + failedSetting = "resurrection_time"; + return false; + } + + // is debug a boolean? + if (settings.get("debug") == null) { + failedSetting = "debug"; + return false; + } + if (!settings.get("debug").toLowerCase().contains("true") && !settings.get("debug").toLowerCase().contains("false")) { + failedSetting = "debug"; + return false; + } + valuesComplete = true; + + return true; + } + + public String getSetting(String setting) { + return settings.get(setting); + } +} -- cgit v1.2.3