aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-08-19 21:12:47 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-08-19 21:12:47 -0600
commit4af9e11bf4abae7f866b62af0877b4ce8bd94365 (patch)
tree8349a50f8c97f9cc634cf68fbcb66f4cf0f10090 /src/net/brysonsteck/Resurrection
parent4cf58d64b58506334da594405f81d6e936aa6c3b (diff)
downloadresurrection-4af9e11bf4abae7f866b62af0877b4ce8bd94365.tar
resurrection-4af9e11bf4abae7f866b62af0877b4ce8bd94365.tar.gz
resurrection-4af9e11bf4abae7f866b62af0877b4ce8bd94365.tar.bz2
completed setting parser
Diffstat (limited to 'src/net/brysonsteck/Resurrection')
-rw-r--r--src/net/brysonsteck/Resurrection/ParseSettings.java82
-rw-r--r--src/net/brysonsteck/Resurrection/Resurrection.java6
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerData.java7
-rw-r--r--src/net/brysonsteck/Resurrection/plugin.yml2
4 files changed, 92 insertions, 5 deletions
diff --git a/src/net/brysonsteck/Resurrection/ParseSettings.java b/src/net/brysonsteck/Resurrection/ParseSettings.java
index 03463e8..bd476e7 100644
--- a/src/net/brysonsteck/Resurrection/ParseSettings.java
+++ b/src/net/brysonsteck/Resurrection/ParseSettings.java
@@ -1,12 +1,94 @@
package net.brysonsteck.Resurrection;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.Hashtable;
+import java.util.Locale;
public class ParseSettings {
Hashtable<String, String> settings = new Hashtable<>();
+ // <setting that failed / does it exist? (true = the value is wrong, false = the setting is missing)>
+ String failedSetting;
+ boolean settingsComplete;
+ boolean valuesComplete;
+
+
public ParseSettings() {
+ try {
+ 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=8640000\"\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=8640000\"\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();
+ }
+ }
+
+ 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) {
diff --git a/src/net/brysonsteck/Resurrection/Resurrection.java b/src/net/brysonsteck/Resurrection/Resurrection.java
index 5879c0c..b487fdf 100644
--- a/src/net/brysonsteck/Resurrection/Resurrection.java
+++ b/src/net/brysonsteck/Resurrection/Resurrection.java
@@ -82,7 +82,6 @@ public class Resurrection extends JavaPlugin implements Listener {
System.out.println("[Resurrection] An error has occurred creating the player data file!");
e.printStackTrace();
System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file could not be created, the plugin will now stop.");
- System.exit(1);
}
} else {
System.out.println("[Resurrection] The player data file has been found!");
@@ -90,13 +89,13 @@ 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...");
try {
- playerFile.createNewFile();
+ settingsFile.createNewFile();
System.out.println("[Resurrection] Settings file created successfully.");
} catch (IOException e) {
System.out.println("[Resurrection] An error has occurred creating the settings file!");
e.printStackTrace();
System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file could not be created, the plugin will now stop.");
- System.exit(1);
+ Bukkit.getPluginManager().disablePlugin(this);
}
} else {
System.out.println("[Resurrection] The settings file has also been found!");
@@ -159,7 +158,6 @@ public class Resurrection extends JavaPlugin implements Listener {
// TimeCheck timeCheck = new TimeCheck((System.currentTimeMillis() + 86212345) - System.currentTimeMillis());
// System.out.println(timeCheck.formatTime());
-
}
}
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerData.java b/src/net/brysonsteck/Resurrection/player/PlayerData.java
index 582d940..eea7c3a 100644
--- a/src/net/brysonsteck/Resurrection/player/PlayerData.java
+++ b/src/net/brysonsteck/Resurrection/player/PlayerData.java
@@ -1,6 +1,10 @@
package net.brysonsteck.Resurrection.player;
+import net.brysonsteck.Resurrection.Resurrection;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+
import java.io.*;
import java.util.Hashtable;
@@ -38,7 +42,10 @@ public class PlayerData {
this.playerData.put(playerData[0], playerHash);
}
} catch (IOException e) {
+ System.out.println("[Resurrection] There was an issue reading the player data file.");
e.printStackTrace();
+ System.out.println("[Resurrection] This file is crucial to Resurrection. Since the file could not be read, the plugin will now stop.");
+ Bukkit.getPluginManager().disablePlugin(JavaPlugin.getProvidingPlugin(Resurrection.class));
}
}
diff --git a/src/net/brysonsteck/Resurrection/plugin.yml b/src/net/brysonsteck/Resurrection/plugin.yml
index 8c6c6be..47d0e8e 100644
--- a/src/net/brysonsteck/Resurrection/plugin.yml
+++ b/src/net/brysonsteck/Resurrection/plugin.yml
@@ -1,7 +1,7 @@
main: net.brysonsteck.Resurrection.Resurrection
name: Resurrection
author: 'Bryson Steck'
-version: '0.1 beta'
+version: '0.2 beta'
commands:
about:
description: Displays information about Resurrection.