diff --git a/src/main/java/net/flectone/chat/builder/MessageBuilder.java b/src/main/java/net/flectone/chat/builder/MessageBuilder.java index 555d4167..53aecab7 100644 --- a/src/main/java/net/flectone/chat/builder/MessageBuilder.java +++ b/src/main/java/net/flectone/chat/builder/MessageBuilder.java @@ -175,7 +175,7 @@ public BaseComponent[] buildMessage(@Nullable Player sender, @NotNull Player rec } } else if (wordParams.isUrl()) { - wordComponent = new FURLComponent(sender, recipient, word, wordParams.getUrl()); + wordComponent = new FURLComponent(sender, recipient, word, wordParams.getUrlText()); } else if (wordParams.isHide()) { wordComponent = new FComponent(MessageUtil.formatAll(sender, recipient, wordParams.getHideMessage())); wordComponent.addHoverText(word); diff --git a/src/main/java/net/flectone/chat/model/message/WordParams.java b/src/main/java/net/flectone/chat/model/message/WordParams.java index 1d60f981..1f5cd35a 100644 --- a/src/main/java/net/flectone/chat/model/message/WordParams.java +++ b/src/main/java/net/flectone/chat/model/message/WordParams.java @@ -1,109 +1,31 @@ package net.flectone.chat.model.message; +import lombok.Getter; +import lombok.Setter; import org.bukkit.ChatColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +@Setter +@Getter public class WordParams { - private boolean isPlayerPing = false; + private String text; private String playerPingName; - private boolean clickable = false; - private boolean isItem = false; - private boolean isUrl = false; - private String url; - private boolean isHide; + private String urlText; private String hideMessage; - private String text; + private boolean clickable; + private boolean isHide; + private boolean isPlayerPing; + private boolean isItem; + private boolean isUrl; private boolean isFormatted; private boolean isCords; - private boolean isStats; + private boolean isPing; - public void setCords(boolean cords) { - isCords = cords; - } - - public boolean isCords() { - return isCords; - } - - public void setStats(boolean stats) { - isStats = stats; - } - - public boolean isStats() { - return isStats; - } - - @Nullable - public String getPlayerPingName() { - return playerPingName; - } - - public boolean isPlayerPing() { - return isPlayerPing; - } - - public void setPlayerPing(boolean playerPing) { - isPlayerPing = playerPing; - } - - public void setClickable(boolean clickable, String playerPingName) { - this.clickable = clickable; - this.playerPingName = playerPingName; - } - - public boolean isClickable() { - return clickable; - } - - public boolean isItem() { - return isItem; - } - - public void setItem(boolean item) { - isItem = item; - } - - @Nullable - public String getUrl() { - return url; - } - - public boolean isUrl() { - return isUrl; - } - - public void setUrl(String url) { - isUrl = true; - this.url = url; - } - - public boolean isHide() { - return isHide; - } - - public void setHide(boolean hide) { - isHide = hide; - } - - @Nullable - public String getHideMessage() { - return hideMessage; - } - - public void setHideMessage(@NotNull String hideMessage) { - this.hideMessage = hideMessage; - } - - @NotNull - public String getText() { - return text; - } + private final List parameters = new ArrayList<>(); public String getFormatting() { return getChatColor("**") + getChatColor("__") + getChatColor("##") + getChatColor("~~") + getChatColor("??"); @@ -122,24 +44,10 @@ public String getChatColor(String param) { }; } - public void setText(@NotNull String text) { - this.text = text; - } - - public boolean isFormatted() { - return isFormatted; - } - - public void setFormatted(boolean formatted) { - isFormatted = formatted; - } - public boolean isEdited() { - return isPlayerPing() || isHide() || isUrl() || isClickable() || isItem() || isCords() || isStats(); + return isPlayerPing() || isHide() || isUrl() || isClickable() || isItem() || isCords() || isStats() || isPing(); } - private final List parameters = new ArrayList<>(); - public void addParameters(List parameters) { this.parameters.addAll(parameters); } @@ -147,8 +55,4 @@ public void addParameters(List parameters) { public boolean contains(String parameter) { return parameters.contains(parameter); } - - public List getParameters() { - return parameters; - } } diff --git a/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java b/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java index 68763ce3..9b920877 100644 --- a/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java +++ b/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java @@ -192,7 +192,8 @@ private void splitStringToWordParams(@Nullable Player sender, @NotNull String co word = config.getVaultString(sender, this + ".list.mention.format") .replace("", player.getName()); - wordParams.setClickable(true, player.getName()); + wordParams.setClickable(true); + wordParams.setPlayerPingName(player.getName()); wordParams.setPlayerPing(true); wordParams.setText(word); @@ -208,7 +209,8 @@ private void splitStringToWordParams(@Nullable Player sender, @NotNull String co if (formattingMap.containsKey("url")) { Matcher urlMatcher = Pattern.compile(formattingMap.get("url")).matcher(word); if (urlMatcher.find()) { - wordParams.setUrl(word.substring(urlMatcher.start(0), urlMatcher.end(0))); + wordParams.setUrlText(word.substring(urlMatcher.start(0), urlMatcher.end(0))); + wordParams.setUrl(true); word = config.getVaultString(sender, this + ".list.url.format") .replace("", word); @@ -219,9 +221,37 @@ private void splitStringToWordParams(@Nullable Player sender, @NotNull String co if (sender != null) { - switch (word) { - case "%cords%" -> { - if (!formattingMap.containsKey("cords")) break; + if (formattingMap.containsKey("ping")) { + String value = formattingMap.get("ping"); + if (value.equals(word)) { + wordParams.setPing(true); + + int ping = sender.getPing(); + int badPing = config.getVaultInt(sender, this + ".list.ping.bad.count"); + int mediumPing = config.getVaultInt(sender, this + ".list.ping.medium.count"); + + String pingColor; + if (ping > badPing) { + pingColor = config.getVaultString(sender, this + ".list.ping.bad.color"); + } else if (ping > mediumPing) { + pingColor = config.getVaultString(sender, this + ".list.ping.medium.color"); + } else { + pingColor = config.getVaultString(sender, this + ".list.ping.good.color"); + } + + word = locale.getVaultString(sender, this + ".list.ping.message") + .replace("", sender.getName()) + .replace("", pingColor + ping); + wordParams.setText(word); + + return wordParams; + } + } + + if (formattingMap.containsKey("cords")) { + String value = formattingMap.get("cords"); + + if (value.equals(word)) { wordParams.setCords(true); Location location = sender.getLocation(); @@ -236,9 +266,11 @@ private void splitStringToWordParams(@Nullable Player sender, @NotNull String co return wordParams; } - case "%stats%" -> { - if (!formattingMap.containsKey("stats")) break; + } + if (formattingMap.containsKey("stats")) { + String value = formattingMap.get("stats"); + if (value.equals(word)) { wordParams.setStats(true); AttributeInstance armor = sender.getAttribute(Attribute.GENERIC_ARMOR); diff --git a/src/main/resources/settings/languages/en.yml b/src/main/resources/settings/languages/en.yml index d182a784..f0bf4602 100644 --- a/src/main/resources/settings/languages/en.yml +++ b/src/main/resources/settings/languages/en.yml @@ -119,6 +119,8 @@ default: player-message: formatting: list: + ping: + message: "&&1 ping - " cords: message: "&&1World:&&2 &&1Biome:&&2 &&1X:&&2 &&1Y:&&2 &&1Z:&&2" stats: diff --git a/src/main/resources/settings/languages/ru.yml b/src/main/resources/settings/languages/ru.yml index 70d561f6..bf67d18e 100644 --- a/src/main/resources/settings/languages/ru.yml +++ b/src/main/resources/settings/languages/ru.yml @@ -119,6 +119,8 @@ default: player-message: formatting: list: + ping: + message: "&&1Пинг - " cords: message: "&&1Мир:&&2 &&1Биом:&&2 &&1X:&&2 &&1Y:&&2 &&1Z:&&2" stats: