aboutsummaryrefslogtreecommitdiff
path: root/src/net/brysonsteck/Resurrection/player/PlayerData.java
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-09-13 17:14:31 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-09-13 17:14:31 -0600
commit9e8c0c2a881100939a63ba4d610af5d26b53938d (patch)
tree430ac0be6ad787a63212d9465549436f0a0af01b /src/net/brysonsteck/Resurrection/player/PlayerData.java
parenteec11316107edbd69d97080cebc369e042ce5183 (diff)
downloadresurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar
resurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar.gz
resurrection-9e8c0c2a881100939a63ba4d610af5d26b53938d.tar.bz2
found lack of saving data if player joins during dead state and resurrects
Diffstat (limited to 'src/net/brysonsteck/Resurrection/player/PlayerData.java')
-rw-r--r--src/net/brysonsteck/Resurrection/player/PlayerData.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/net/brysonsteck/Resurrection/player/PlayerData.java b/src/net/brysonsteck/Resurrection/player/PlayerData.java
index eea7c3a..4771af5 100644
--- a/src/net/brysonsteck/Resurrection/player/PlayerData.java
+++ b/src/net/brysonsteck/Resurrection/player/PlayerData.java
@@ -2,7 +2,9 @@ package net.brysonsteck.Resurrection.player;
import net.brysonsteck.Resurrection.Resurrection;
+import net.brysonsteck.Resurrection.startup.ParseSettings;
import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
@@ -11,20 +13,38 @@ import java.util.Hashtable;
public class PlayerData {
Hashtable<String, Hashtable<String, String>> playerData = new Hashtable<>();
String rawData;
+ boolean DEBUG = Boolean.parseBoolean(new ParseSettings()
+ .getSetting("debug"));
public void saveData(String write) {
try {
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Attempting to save player data");
+ }
FileWriter writer = new FileWriter("plugins/playerData.resurrection");
writer.write(write);
writer.close();
} catch (IOException e) {
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Error occurred while trying to save player data, avoid shutting down the server");
+ }
+ System.out.println("[Resurrection] There was an issue saving the player data file.");
e.printStackTrace();
+ System.out.println("[Resurrection] Resurrection will continue to run despite this error, but avoid shutting down the server until a successful save occurs.");
+ System.out.println("[Resurrection] In the mean time, check to make sure the playerData file exists and you have permissions to write to it.");
}
readData();
+
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player data saved successfully");
+ }
}
public void readData() {
try {
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Attempting to read player data");
+ }
rawData = "";
BufferedReader reader = new BufferedReader(new FileReader("plugins/playerData.resurrection"));
String line;
@@ -40,13 +60,24 @@ public class PlayerData {
playerHash.put("dead", playerData[1]);
playerHash.put("timeLeft", playerData[2]);
this.playerData.put(playerData[0], playerHash);
+ if (DEBUG) {
+ TimeCheck timeCheck = new TimeCheck(Long.parseLong(playerData[2]));
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: player: " + playerData[0] + " | dead: " + playerData[1] + " | ms to resurrect at: " + playerData[2]);
+ }
}
} catch (IOException e) {
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Error occurred while trying to read player data. Resurrection is shutting down");
+ }
+
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));
}
+ if (DEBUG) {
+ Bukkit.broadcastMessage(ChatColor.YELLOW +""+ ChatColor.BOLD + "[Res. DEBUG]: Player data read successfully");
+ }
}
// public Hashtable<String, Hashtable<String, String>> getPlayers() {