backwards compatibility with old flight time format

This commit is contained in:
hyperdefined
2025-03-31 19:06:43 -04:00
parent 706175a13a
commit ed9afc1812
2 changed files with 16 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ package lol.hyper.toolstats.tools;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
@@ -768,6 +769,13 @@ public class ItemLore {
} }
container.remove(toolStats.flightTime); container.remove(toolStats.flightTime);
if (meta.hasLore()) { if (meta.hasLore()) {
// if the old format is in the config, check to see if the old format is on the elytra
if (toolStats.config.getString("messages.flight-time-old") != null) {
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
meta.lore(removeLore(meta.lore(), oldFormat));
}
Map<String, String> oldFlightTimeFormatted = toolStats.numberFormat.formatTime(flightTime); Map<String, String> oldFlightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightTimeFormatted); Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightTimeFormatted);
List<Component> newLore = removeLore(meta.lore(), lineToRemove); List<Component> newLore = removeLore(meta.lore(), lineToRemove);
@@ -818,6 +826,12 @@ public class ItemLore {
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration); container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
Map<String, String> oldFlightFormatted = toolStats.numberFormat.formatTime(flightTime); Map<String, String> oldFlightFormatted = toolStats.numberFormat.formatTime(flightTime);
Map<String, String> newFlightFormatted = toolStats.numberFormat.formatTime(flightTime + duration); Map<String, String> newFlightFormatted = toolStats.numberFormat.formatTime(flightTime + duration);
// if the old format is in the config, check to see if the old format is on the elytra
if (toolStats.config.getString("messages.flight-time-old") != null) {
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
meta.lore(removeLore(meta.lore(), oldFormat));
}
Component oldLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightFormatted); Component oldLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightFormatted);
Component newLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", newFlightFormatted); Component newLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", newFlightFormatted);
if (oldLine == null || newLine == null) { if (oldLine == null || newLine == null) {

View File

@@ -87,6 +87,8 @@ public class Version11 {
toolStats.logger.info("Adding enabled.damage-done.mace to config.yml"); toolStats.logger.info("Adding enabled.damage-done.mace to config.yml");
toolStats.logger.info("Updating entry for messages.flight-time"); toolStats.logger.info("Updating entry for messages.flight-time");
String oldFlightTime = toolStats.config.getString("messages.flight-time");
toolStats.config.set("messages.flight-time-old", oldFlightTime);
toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"); toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s");
// save the config and reload it // save the config and reload it