diff options
author | Cow <cow@volloeko.de> | 2020-12-17 22:22:18 +0100 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2020-12-17 22:22:18 +0100 |
commit | 1b1b1c6293a184066e30cb98349f472a41e1c66d (patch) | |
tree | 158975a1c179e667d8815b425ae2d16f60e77b45 | |
parent | 43485912b30895d5735a445d3ebd2f831df004af (diff) | |
download | Cowlection-1b1b1c6293a184066e30cb98349f472a41e1c66d.tar.gz Cowlection-1b1b1c6293a184066e30cb98349f472a41e1c66d.tar.bz2 Cowlection-1b1b1c6293a184066e30cb98349f472a41e1c66d.zip |
Item age: show in local timezone
- also fixed the incorrect 12h ↔ 24h clock conversion
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java | 72 |
2 files changed, 33 insertions, 44 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 128d492..1ab1798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [1.8.9-0.12.0] - unreleased +### Changed +- Item age: show timestamp in the local timezone instead of "SkyBlock"-timezone (Eastern Time; also fixed the incorrect 12h ↔ 24h clock conversion) + ## [1.8.9-0.11.0] - 28.09.2020 ### Added - SkyBlock Dungeons Party: new command `/moo dungeon party` @@ -227,6 +231,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). *Note:* The 'best friends' list is currently available via <kbd>ESC</kbd> > Mod Options > Cowlection > Config > bestFriends. +[1.8.9-0.12.0]: https://github.com/cow-mc/Cowlection/compare/v1.8.9-0.11.0...master [1.8.9-0.11.0]: https://github.com/cow-mc/Cowlection/compare/v1.8.9-0.10.2...v1.8.9-0.11.0 [1.8.9-0.10.2]: https://github.com/cow-mc/Cowlection/compare/v1.8.9-0.10.1...v1.8.9-0.10.2 [1.8.9-0.10.1]: https://github.com/cow-mc/Cowlection/compare/v1.8.9-0.10.0...v1.8.9-0.10.1 diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java index 27be613..4702ede 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java @@ -26,7 +26,6 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Locale; -import java.util.regex.Matcher; import java.util.regex.Pattern; public class SkyBlockListener { @@ -76,39 +75,36 @@ public class SkyBlockListener { NBTTagCompound extraAttributes = e.itemStack.getSubCompound("ExtraAttributes", false); if (extraAttributes != null && extraAttributes.hasKey("timestamp") && (tooltipItemAgeDisplay != MooConfig.Setting.DISABLED || tooltipItemTimestampDisplay != MooConfig.Setting.DISABLED)) { - String rawTimestamp = extraAttributes.getString("timestamp"); - Matcher sbTimestampMatcher = SB_TIMESTAMP_PATTERN.matcher(rawTimestamp); - if (sbTimestampMatcher.matches()) { - // Timezone = America/Toronto! headquarter is in Val-des-Monts, Quebec, Canada; timezone can also be confirmed by looking at the timestamps of New Year Cakes - ZonedDateTime dateTime = getDateTimeWithZone(sbTimestampMatcher, ZoneId.of("America/Toronto")); // EDT/EST - String dateTimeFormatted = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm zzz")); - - int index = Math.max(0, e.toolTip.size() - (e.showAdvancedItemTooltips ? /* item name & nbt info */ 2 : 0)); - - switch (tooltipItemTimestampDisplay) { - case SPECIAL: - if (!MooConfig.isTooltipToggleKeyBindingPressed()) { - break; - } - case ALWAYS: - e.toolTip.add(index, "Timestamp: " + EnumChatFormatting.DARK_GRAY + dateTimeFormatted); - break; - default: - // do nothing - break; - } - switch (tooltipItemAgeDisplay) { - case SPECIAL: - if (!MooConfig.isTooltipToggleKeyBindingPressed()) { - break; - } - case ALWAYS: - e.toolTip.add(index, "Item age: " + EnumChatFormatting.DARK_GRAY + ((MooConfig.tooltipItemAgeShortened) ? Utils.getDurationAsWord(dateTime.toEpochSecond() * 1000) : Utils.getDurationAsWords(dateTime.toEpochSecond() * 1000).first())); + LocalDateTime skyBlockDateTime = LocalDateTime.parse(extraAttributes.getString("timestamp"), DateTimeFormatter.ofPattern("M/d/yy h:mm a", Locale.US)); + + // Timezone = America/Toronto! headquarter is in Val-des-Monts, Quebec, Canada; timezone can also be confirmed by looking at the timestamps of New Year Cakes + ZonedDateTime dateTime = ZonedDateTime.of(skyBlockDateTime, ZoneId.of("America/Toronto")); // EDT/EST + + int index = Math.max(0, e.toolTip.size() - (e.showAdvancedItemTooltips ? /* item name & nbt info */ 2 : 0)); + + switch (tooltipItemTimestampDisplay) { + case SPECIAL: + if (!MooConfig.isTooltipToggleKeyBindingPressed()) { break; - default: - // do nothing + } + case ALWAYS: + e.toolTip.add(index, "Timestamp: " + EnumChatFormatting.DARK_GRAY + dateTime.withZoneSameInstant(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm zzz"))); + break; + default: + // do nothing + break; + } + switch (tooltipItemAgeDisplay) { + case SPECIAL: + if (!MooConfig.isTooltipToggleKeyBindingPressed()) { break; - } + } + case ALWAYS: + e.toolTip.add(index, "Item age: " + EnumChatFormatting.DARK_GRAY + ((MooConfig.tooltipItemAgeShortened) ? Utils.getDurationAsWord(dateTime.toEpochSecond() * 1000) : Utils.getDurationAsWords(dateTime.toEpochSecond() * 1000).first())); + break; + default: + // do nothing + break; } } @@ -159,18 +155,6 @@ public class SkyBlockListener { } } - private ZonedDateTime getDateTimeWithZone(Matcher sbTimestampMatcher, ZoneId zoneId) { - int year = 2000 + Integer.parseInt(sbTimestampMatcher.group(3)); - int month = Integer.parseInt(sbTimestampMatcher.group(1)); - int day = Integer.parseInt(sbTimestampMatcher.group(2)); - int hour = (Integer.parseInt(sbTimestampMatcher.group(4)) + (sbTimestampMatcher.group(6).equals("PM") ? 12 : 0)) % 24; - int minute = Integer.parseInt(sbTimestampMatcher.group(5)); - - LocalDateTime localDateTime = LocalDateTime.of(year, month, day, hour, minute); - - return ZonedDateTime.of(localDateTime, zoneId); - } - private boolean isSubmitBidItem(ItemStack itemStack) { return ((itemStack.getItem().equals(Items.gold_nugget) || itemStack.getItem().equals(Item.getItemFromBlock(Blocks.gold_block))) && (itemStack.hasDisplayName() && (itemStack.getDisplayName().endsWith("Submit Bid") || itemStack.getDisplayName().endsWith("Collect Auction")))) |