-
-
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
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 |
|---|---|---|
|
|
@@ -4,27 +4,30 @@ | |
| 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.combat.time.DurationService; | ||
| import com.eternalcode.commons.time.DurationParser; | ||
| import java.util.Optional; | ||
| 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 DurationService durationService; | ||
| private final FightManager fightManager; | ||
| private final Server server; | ||
| private final Plugin plugin; | ||
|
|
||
| public FightTagPlaceholder(PluginConfig pluginConfig, FightManager fightManager, Server server, Plugin plugin) { | ||
| public FightTagPlaceholder(PluginConfig pluginConfig, DurationService durationService, FightManager fightManager, Server server, Plugin plugin) { | ||
| this.placeholderSettings = pluginConfig.placeholders; | ||
| this.durationService = durationService; | ||
| this.fightManager = fightManager; | ||
| this.server = server; | ||
| this.plugin = plugin; | ||
|
|
@@ -51,7 +54,7 @@ private String handleRemainingMillis(OfflinePlayer player) { | |
|
|
||
| private String handleRemainingSeconds(OfflinePlayer player) { | ||
| return this.getFightTag(player) | ||
| .map(tag -> DurationUtil.format(tag.getRemainingDuration())) | ||
| .map(tag -> durationService.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. ja już tu zmieniamy to przydało by się wywalić remaining_millis i remaining_seconds bo w tym kontekście te placeholdery wdają się być bez sensu |
||
| .orElse(""); | ||
| } | ||
|
|
||
|
|
@@ -110,7 +113,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.", | ||
| "# 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 |
||
|
|
||
| @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"; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cofnijmy te importy