Skip to content

Commit ed9afc1

Browse files
committed
backwards compatibility with old flight time format
1 parent 706175a commit ed9afc1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/lol/hyper/toolstats/tools/ItemLore.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lol.hyper.toolstats.ToolStats;
2121
import net.kyori.adventure.text.Component;
2222
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
23+
import org.bukkit.Bukkit;
2324
import org.bukkit.inventory.ItemStack;
2425
import org.bukkit.inventory.meta.ItemMeta;
2526
import org.bukkit.persistence.PersistentDataContainer;
@@ -768,6 +769,13 @@ public ItemMeta updateFlightTime(ItemStack elytra, long duration) {
768769
}
769770
container.remove(toolStats.flightTime);
770771
if (meta.hasLore()) {
772+
// if the old format is in the config, check to see if the old format is on the elytra
773+
if (toolStats.config.getString("messages.flight-time-old") != null) {
774+
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
775+
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
776+
meta.lore(removeLore(meta.lore(), oldFormat));
777+
}
778+
771779
Map<String, String> oldFlightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
772780
Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightTimeFormatted);
773781
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
@@ -818,6 +826,12 @@ public ItemMeta updateFlightTime(ItemStack elytra, long duration) {
818826
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
819827
Map<String, String> oldFlightFormatted = toolStats.numberFormat.formatTime(flightTime);
820828
Map<String, String> newFlightFormatted = toolStats.numberFormat.formatTime(flightTime + duration);
829+
// if the old format is in the config, check to see if the old format is on the elytra
830+
if (toolStats.config.getString("messages.flight-time-old") != null) {
831+
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
832+
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
833+
meta.lore(removeLore(meta.lore(), oldFormat));
834+
}
821835
Component oldLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightFormatted);
822836
Component newLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", newFlightFormatted);
823837
if (oldLine == null || newLine == null) {

src/main/java/lol/hyper/toolstats/tools/config/versions/Version11.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public void update() {
8787
toolStats.logger.info("Adding enabled.damage-done.mace to config.yml");
8888

8989
toolStats.logger.info("Updating entry for messages.flight-time");
90+
String oldFlightTime = toolStats.config.getString("messages.flight-time");
91+
toolStats.config.set("messages.flight-time-old", oldFlightTime);
9092
toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s");
9193

9294
// save the config and reload it

0 commit comments

Comments
 (0)