From f75681144085e729b4e9972908c1fc859670bb4b Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Thu, 19 Aug 2021 21:58:40 -0600 Subject: added h and f mods for timecheck.formattime --- .../Resurrection/player/PlayerListener.java | 17 +++++++++-------- .../brysonsteck/Resurrection/player/TimeCheck.java | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'src/net/brysonsteck/Resurrection/player') diff --git a/src/net/brysonsteck/Resurrection/player/PlayerListener.java b/src/net/brysonsteck/Resurrection/player/PlayerListener.java index 749d6b6..09ff124 100644 --- a/src/net/brysonsteck/Resurrection/player/PlayerListener.java +++ b/src/net/brysonsteck/Resurrection/player/PlayerListener.java @@ -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 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 diff --git a/src/net/brysonsteck/Resurrection/player/TimeCheck.java b/src/net/brysonsteck/Resurrection/player/TimeCheck.java index a12bb16..4012e48 100644 --- a/src/net/brysonsteck/Resurrection/player/TimeCheck.java +++ b/src/net/brysonsteck/Resurrection/player/TimeCheck.java @@ -9,11 +9,18 @@ public class TimeCheck { this.millis = millis; } - public String formatTime() { - 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))); + 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; } } -- cgit v1.2.3