-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-357 Add configurable duration formatter with plural support #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c81f73a
7885b03
e64f555
6a02e62
01fa48c
87650c3
56815d5
96920f0
aae1f6b
85d20b6
0a5ae2a
795017b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,30 +1,29 @@ | ||||||
| package com.eternalcode.combat.bridge.placeholder; | ||||||
|
|
||||||
| import com.eternalcode.combat.config.implementation.PlaceholderSettings; | ||||||
| import com.eternalcode.combat.config.implementation.PluginConfig; | ||||||
| import com.eternalcode.combat.fight.FightManager; | ||||||
| import com.eternalcode.combat.fight.FightTag; | ||||||
| import com.eternalcode.combat.util.DurationUtil; | ||||||
| import com.eternalcode.commons.time.DurationParser; | ||||||
| import java.util.Optional; | ||||||
| import com.eternalcode.combat.time.DurationFormatter; | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| import org.bukkit.OfflinePlayer; | ||||||
| import org.bukkit.Server; | ||||||
| import org.bukkit.entity.Player; | ||||||
| import org.bukkit.plugin.Plugin; | ||||||
| import org.jetbrains.annotations.NotNull; | ||||||
|
|
||||||
| import java.util.Optional; | ||||||
|
|
||||||
| public class FightTagPlaceholder extends PlaceholderExpansion { | ||||||
|
|
||||||
| private static final String IDENTIFIER = "eternalcombat"; | ||||||
|
|
||||||
| private final PlaceholderSettings placeholderSettings; | ||||||
| private final PluginConfig config; | ||||||
| private final FightManager fightManager; | ||||||
| private final Server server; | ||||||
| private final Plugin plugin; | ||||||
|
|
||||||
| public FightTagPlaceholder(PluginConfig pluginConfig, FightManager fightManager, Server server, Plugin plugin) { | ||||||
| this.placeholderSettings = pluginConfig.placeholders; | ||||||
| public FightTagPlaceholder(PluginConfig config, FightManager fightManager, Server server, Plugin plugin) { | ||||||
| this.config = config; | ||||||
| this.fightManager = fightManager; | ||||||
| this.server = server; | ||||||
| this.plugin = plugin; | ||||||
|
|
@@ -33,8 +32,7 @@ public FightTagPlaceholder(PluginConfig pluginConfig, FightManager fightManager, | |||||
| @Override | ||||||
| public String onRequest(OfflinePlayer player, String identifier) { | ||||||
| return switch (identifier) { | ||||||
| case "remaining_millis" -> this.handleRemainingMillis(player); | ||||||
| case "remaining_seconds" -> this.handleRemainingSeconds(player); | ||||||
| case "remaining" -> this.handleRemaining(player); | ||||||
| case "opponent" -> this.handleOpponent(player); | ||||||
| case "opponent_health" -> this.handleOpponentHealth(player); | ||||||
| case "isInCombat" -> this.handleIsInCombat(player); | ||||||
|
|
@@ -43,15 +41,9 @@ public String onRequest(OfflinePlayer player, String identifier) { | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| private String handleRemainingMillis(OfflinePlayer player) { | ||||||
| return this.getFightTag(player) | ||||||
| .map(tag -> DurationParser.TIME_UNITS.format(tag.getRemainingDuration())) | ||||||
| .orElse(""); | ||||||
| } | ||||||
|
|
||||||
| private String handleRemainingSeconds(OfflinePlayer player) { | ||||||
| private String handleRemaining(OfflinePlayer player) { | ||||||
| return this.getFightTag(player) | ||||||
| .map(tag -> DurationUtil.format(tag.getRemainingDuration())) | ||||||
| .map(tag -> DurationFormatter.of(config.durationFormat).format(tag.getRemainingDuration())) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| .orElse(""); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -73,8 +65,8 @@ private String handleIsInCombat(OfflinePlayer player) { | |||||
|
|
||||||
| private String handleIsInCombatFormatted(OfflinePlayer player) { | ||||||
| return this.isPlayerInCombat(player) | ||||||
| ? this.placeholderSettings.isInCombatFormattedTrue | ||||||
| : this.placeholderSettings.isInCombatFormattedFalse; | ||||||
| ? this.config.placeholders.isInCombatFormattedTrue | ||||||
| : this.config.placeholders.isInCombatFormattedFalse; | ||||||
| } | ||||||
|
|
||||||
| private boolean isPlayerInCombat(OfflinePlayer player) { | ||||||
|
|
@@ -110,7 +102,7 @@ public boolean canRegister() { | |||||
|
|
||||||
| @Override | ||||||
| public @NotNull String getAuthor() { | ||||||
| return this.plugin.getDescription().getAuthors().get(0); | ||||||
| return this.plugin.getDescription().getAuthors().getFirst(); | ||||||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||
| package com.eternalcode.combat.config.implementation; | ||||||||
|
|
||||||||
| import eu.okaeri.configs.OkaeriConfig; | ||||||||
| import eu.okaeri.configs.annotation.Comment; | ||||||||
|
|
||||||||
| public class DurationFormatSettings extends OkaeriConfig { | ||||||||
|
|
||||||||
| @Comment({ | ||||||||
| "# Pattern used to format durations.", | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| "# Placeholders:", | ||||||||
| "# %d{singular|plural} - days", | ||||||||
| "# %h{singular|plural} - hours", | ||||||||
| "# %m{singular|plural} - minutes", | ||||||||
| "# %s{singular|plural} - seconds", | ||||||||
| "# %ms{singular|plural} - milliseconds", | ||||||||
| "# Example:", | ||||||||
| "# %d{day|days} %h{hour|hours} %m{minute|minutes} %s{second|seconds} %ms{millisecond|milliseconds}" | ||||||||
| }) | ||||||||
| public String pattern = "%d {day|days} %h {hour|hours} %m {minute|minutes} %s {second|seconds} %ms {millisecond|milliseconds}"; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nie możemy tego rozłożyć może na filedy typu: days: "{x} day|{x} days" w ogóle w językach typu Polski jest problem z
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moim zdaniem w takiej formie jest to zrobione lepiej i zostawiłbym to. Jest prosto, jest czytelnie. Wiem o co Ci chodzi, coś w stylu config per unit, ale zmiana = wieksza struktura configu, wiecej "edge case" no i zmiana parseru. Do dyskusji to jest generalnie
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W sumie configurowałem przed chwilą dla testu i przyjemnie się tego używa -> potem i tak jest parsowane do wiadmości przez placeholder. Dzięki separatorom jest spoko.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||
|
|
||||||||
| @Comment({ | ||||||||
| "# Separator used between duration parts.", | ||||||||
| "# Example result:", | ||||||||
| "# 1 hour, 2 minutes, 5 seconds" | ||||||||
| }) | ||||||||
| public String separator = ", "; | ||||||||
|
|
||||||||
| @Comment({ | ||||||||
| "# Separator used before the last duration part.", | ||||||||
| "# Example result:", | ||||||||
| "# 1 hour, 2 minutes and 5 seconds" | ||||||||
| }) | ||||||||
| public String lastSeparator = " and "; | ||||||||
|
|
||||||||
| @Comment({"# Text displayed when duration is zero or negative."}) | ||||||||
| public String zero = "<1 second"; | ||||||||
| } | ||||||||


Uh oh!
There was an error while loading. Please reload this page.