better saving

master
Default 4 years ago
parent a9f7f68a1b
commit 6cdf10ddaa
  1. 19
      src/main/java/com/benjocraeft/sharehealth/FileManager.java
  2. 2
      src/main/java/com/benjocraeft/sharehealth/HealthManager.java
  3. 6
      src/main/java/com/benjocraeft/sharehealth/Messenger.java
  4. 10
      src/main/java/com/benjocraeft/sharehealth/Sharehealth.java
  5. 2
      src/main/java/com/benjocraeft/sharehealth/Statistics.java

@ -2,6 +2,7 @@ package com.benjocraeft.sharehealth;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.logging.Logger;
public class FileManager { public class FileManager {
@ -22,17 +23,15 @@ public class FileManager {
settingsFile = new File(pluginPath + "/settings.txt"); settingsFile = new File(pluginPath + "/settings.txt");
statisticsFile = new File(pluginPath + "/statistics.txt"); statisticsFile = new File(pluginPath + "/statistics.txt");
statusFile = new File(pluginPath + "/status.txt"); statusFile = new File(pluginPath + "/status.txt");
Logger logger = Sharehealth.Instance.getLogger();
try { try {
if (settingsFile.createNewFile()){ if (settingsFile.createNewFile())
//TODO Log logger.info(settingsFile.getName() + " created");
} if (statisticsFile.createNewFile())
if (statisticsFile.createNewFile()){ logger.info(statisticsFile.getName() + " created");
//TODO Log if (statusFile.createNewFile())
} logger.info(statusFile.getName() + " created");
if (statusFile.createNewFile()){
//TODO Log
}
} catch(IOException e){ } catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }

@ -25,7 +25,7 @@ public class HealthManager {
} }
String getHealthString(){ String getHealthString(){
return new Formatter(Locale.US).format("%.2f", health).toString(); return new Formatter(Locale.US).format("%.2f", health / 2).toString();
} }

@ -114,8 +114,12 @@ public class Messenger {
} }
String statisticsMessage(){ String statisticsMessage(){
Map<UUID, Pair<Double, Double>> statistics = Sharehealth.Instance.getStatistics().getStatistics();
if (statistics.size() == 0)
return "There are no statistics yet.";
StringBuilder stats = new StringBuilder("Statistics:"); StringBuilder stats = new StringBuilder("Statistics:");
Sharehealth.Instance.getStatistics().getStatistics().forEach(((uuid, values) -> { statistics.forEach(((uuid, values) -> {
String playerName = Bukkit.getOfflinePlayer(uuid).getName(); String playerName = Bukkit.getOfflinePlayer(uuid).getName();
String stat = "\n" + ChatColor.BLUE + playerName + String stat = "\n" + ChatColor.BLUE + playerName +
ChatColor.WHITE + ": Damage caused: " + ChatColor.WHITE + ": Damage caused: " +

@ -61,8 +61,11 @@ public class Sharehealth extends JavaPlugin {
//Create statistics from file //Create statistics from file
statistics = new Statistics(fileManager.loadStatistics(), fileManager.loadSettings()); statistics = new Statistics(fileManager.loadStatistics(), fileManager.loadSettings());
getLogger().info("Statistics and Settings loaded");
loadStatus(); loadStatus();
getLogger().info("Status loaded");
//Starts custom health regeneration //Starts custom health regeneration
new FoodRegeneration(); new FoodRegeneration();
@ -91,6 +94,7 @@ public class Sharehealth extends JavaPlugin {
healthManager.updatePlayer(player); healthManager.updatePlayer(player);
statistics.onPlayerJoined(player); statistics.onPlayerJoined(player);
fileManager.saveStatistics(statistics.getStatistics()); fileManager.saveStatistics(statistics.getStatistics());
fileManager.saveSettings(statistics.getSettings());
} }
void onPlayerRespawn(Player player){ void onPlayerRespawn(Player player){
@ -205,6 +209,9 @@ public class Sharehealth extends JavaPlugin {
Map<String, Object> map = fileManager.loadStatus(); Map<String, Object> map = fileManager.loadStatus();
defaultStatus.forEach(map::putIfAbsent); defaultStatus.forEach(map::putIfAbsent);
map.forEach((String key, Object value) -> {
getLogger().info(key + "=" + value);
});
healthManager.setHealth((Double)map.get("health")); healthManager.setHealth((Double)map.get("health"));
isFailed = (boolean) map.get("isFailed"); isFailed = (boolean) map.get("isFailed");
@ -221,7 +228,8 @@ public class Sharehealth extends JavaPlugin {
} }
boolean getLogging(Player player){ boolean getLogging(Player player){
return statistics.getSettings().get(player.getUniqueId()); Map<UUID, Boolean> settings = statistics.getSettings();
return settings.get(player.getUniqueId());
} }
} }

@ -38,8 +38,8 @@ public class Statistics {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
Pair<Double, Double> empty = Pair.pair(0., 0.); Pair<Double, Double> empty = Pair.pair(0., 0.);
statistics.putIfAbsent(uuid, empty); statistics.putIfAbsent(uuid, empty);
settings.putIfAbsent(uuid, true); settings.putIfAbsent(uuid, true);
} }
void onPlayerRegainedHealth(Player player, double amount){ void onPlayerRegainedHealth(Player player, double amount){

Loading…
Cancel
Save