added h and f mods for timecheck.formattime
This commit is contained in:
parent
4af9e11bf4
commit
f756811440
6 changed files with 42 additions and 38 deletions
|
@ -1,5 +0,0 @@
|
|||
# This is the default settings file. All lines starting with a '#' are treated as comments and will be ignored.
|
||||
# 'resurrection_time' is the amount of time in milliseconds Resurrection will force the player to wait. Default value is 8640000 milliseconds (24 hours).
|
||||
resurrection_time=8640000
|
||||
# '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.
|
||||
debug=false
|
|
@ -3,15 +3,12 @@ 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.io.*;
|
||||
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;
|
||||
|
@ -20,8 +17,19 @@ public class ParseSettings {
|
|||
|
||||
public ParseSettings() {
|
||||
try {
|
||||
File settingsFile = new File("data/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"));
|
||||
BufferedReader reader = new BufferedReader(new FileReader("data/settings.resurrection"));
|
||||
String line;
|
||||
String[] setting;
|
||||
while (true) {
|
||||
|
@ -39,12 +47,12 @@ public class ParseSettings {
|
|||
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: \"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=8640000\"\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.");
|
||||
|
|
|
@ -88,15 +88,8 @@ 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 {
|
||||
settingsFile.createNewFile();
|
||||
ParseSettings parseSettings = new ParseSettings();
|
||||
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.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
} else {
|
||||
System.out.println("[Resurrection] The settings file has also been found!");
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ public class CommandHowLong implements CommandExecutor {
|
|||
|
||||
TimeCheck timeCheck = new TimeCheck(resurrectionTime - currentTime);
|
||||
if (self) {
|
||||
commandSender.sendMessage("You will respawn in " + timeCheck.formatTime());
|
||||
commandSender.sendMessage("You will respawn in " + timeCheck.formatTime('f'));
|
||||
} else {
|
||||
commandSender.sendMessage(p.getDisplayName() + " will respawn in " + timeCheck.formatTime());
|
||||
commandSender.sendMessage(p.getDisplayName() + " will respawn in " + timeCheck.formatTime('f'));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ public class CommandHowLong implements CommandExecutor {
|
|||
|
||||
TimeCheck timeCheck = new TimeCheck(resurrectionTime - currentTime);
|
||||
|
||||
System.out.println("[Resurrection] " + p.getDisplayName() + " will respawn in " + timeCheck.formatTime());
|
||||
System.out.println("[Resurrection] " + p.getDisplayName() + " will respawn in " + timeCheck.formatTime('f'));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.brysonsteck.Resurrection.player;
|
||||
|
||||
import net.brysonsteck.Resurrection.ParseSettings;
|
||||
import net.brysonsteck.Resurrection.Resurrection;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -24,6 +25,11 @@ public class PlayerListener implements Listener {
|
|||
World world = Bukkit.getWorlds().get(0);
|
||||
Location spawn = world.getSpawnLocation();
|
||||
Hashtable<String, Location> playerSpawns = new Hashtable<>();
|
||||
ParseSettings parseSettings;
|
||||
|
||||
public PlayerListener() {
|
||||
parseSettings = new ParseSettings();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
|
@ -108,16 +114,11 @@ public class PlayerListener implements Listener {
|
|||
System.out.println("Resurrection: A player has died!");
|
||||
Player p = e.getEntity();
|
||||
stillDead = true;
|
||||
//
|
||||
// TimeCheck death = new TimeCheck(timeOfDeath);
|
||||
// TimeCheck resurrect = new TimeCheck((timeOfDeath + 86400000) - timeOfDeath);
|
||||
//
|
||||
// String deathFormatted = death.formatTime();
|
||||
// String resurrectFormatted = resurrect.formatTime();
|
||||
// long timeOfDeath = System.currentTimeMillis();
|
||||
TimeCheck timeCheck = new TimeCheck(Long.parseLong(parseSettings.getSetting("resurrection_time")));
|
||||
|
||||
long resurrectionTime = System.currentTimeMillis() + 86400000;
|
||||
|
||||
p.sendMessage("You have died!! You will be able to respawn in the next 24 hours.");
|
||||
p.sendMessage("You have died!! You will be able to respawn in the next " + timeCheck.formatTime('h'));
|
||||
timerRunning = true;
|
||||
|
||||
// save death state
|
||||
|
|
|
@ -9,11 +9,18 @@ public class TimeCheck {
|
|||
this.millis = millis;
|
||||
}
|
||||
|
||||
public String formatTime() {
|
||||
public String formatTime(char format) {
|
||||
// h = hours only, f = full time
|
||||
if (format == 'f') {
|
||||
return String.format("%d hrs, %d min, %d sec",
|
||||
TimeUnit.MILLISECONDS.toHours(millis),
|
||||
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
|
||||
TimeUnit.MILLISECONDS.toSeconds(millis) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
|
||||
} else if (format == 'h') {
|
||||
return String.format("%d hours",
|
||||
TimeUnit.MILLISECONDS.toHours(millis));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue