diff --git a/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java b/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java index 3a7c51ff..0ce59616 100644 --- a/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java +++ b/example/death-holograms/src/main/java/me/filoghost/example/deathholograms/DeathHolograms.java @@ -14,8 +14,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.Instant; +import java.time.format.DateTimeFormatter; public class DeathHolograms extends JavaPlugin implements Listener { @@ -39,7 +39,7 @@ public class DeathHolograms extends JavaPlugin implements Listener { Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation()); hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!"); - hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + new SimpleDateFormat("H:m").format(new Date())); + hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + DateTimeFormatter.ofPattern("H:mm").format(Instant.now())); } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java index 4ec72aea..afa0607f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/Configuration.java @@ -20,12 +20,13 @@ import org.bukkit.plugin.Plugin; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; +import java.time.DateTimeException; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.TimeZone; /** * Just a bunch of static variables to hold the settings. @@ -40,7 +41,7 @@ public class Configuration { public static boolean updateNotification; public static ChatColor transparencyColor; - public static SimpleDateFormat timeFormat; + public static DateTimeFormatter timeFormat; public static int bungeeRefreshSeconds; public static boolean useRedisBungee; @@ -197,13 +198,18 @@ public class Configuration { } try { - timeFormat = new SimpleDateFormat(config.getString(ConfigNode.TIME_FORMAT.getPath())); - timeFormat.setTimeZone(TimeZone.getTimeZone(config.getString(ConfigNode.TIME_ZONE.getPath()))); + timeFormat = DateTimeFormatter.ofPattern(config.getString(ConfigNode.TIME_FORMAT.getPath())); } catch (IllegalArgumentException ex) { - timeFormat = new SimpleDateFormat("H:mm"); + timeFormat = DateTimeFormatter.ofPattern("H:mm"); Log.warning("Time format not valid in the configuration, using the default."); } + try { + timeFormat = timeFormat.withZone(ZoneId.of(config.getString(ConfigNode.TIME_ZONE.getPath()))); + } catch (DateTimeException e) { + Log.warning("Time zone not valid in the configuration, using the default."); + } + if (bungeeRefreshSeconds < 1) { Log.warning("The minimum interval for pinging BungeeCord's servers is 1 second. It has been automatically set."); bungeeRefreshSeconds = 1; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java index 857af34c..9779f13c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/PlaceholdersRegister.java @@ -12,7 +12,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.plugin.Plugin; -import java.util.Date; +import java.time.Instant; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -37,7 +37,7 @@ public class PlaceholdersRegister { })); register(new Placeholder(HolographicDisplays.getInstance(), "{time}", 0.9, () -> { - return Configuration.timeFormat.format(new Date()); + return Configuration.timeFormat.format(Instant.now()); })); register(new Placeholder(HolographicDisplays.getInstance(), "&u", 0.2, new CyclicPlaceholderReplacer(Utils.toStringList(