Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Formatting: simplify WorldParams and add %ping%
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 9, 2023
1 parent 602c14b commit eaf5179
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
124 changes: 14 additions & 110 deletions src/main/java/net/flectone/chat/model/message/WordParams.java
Original file line number Diff line number Diff line change
@@ -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<String> parameters = new ArrayList<>();

public String getFormatting() {
return getChatColor("**") + getChatColor("__") + getChatColor("##") + getChatColor("~~") + getChatColor("??");
Expand All @@ -122,33 +44,15 @@ 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<String> parameters = new ArrayList<>();

public void addParameters(List<String> parameters) {
this.parameters.addAll(parameters);
}

public boolean contains(String parameter) {
return parameters.contains(parameter);
}

public List<String> getParameters() {
return parameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private void splitStringToWordParams(@Nullable Player sender, @NotNull String co
word = config.getVaultString(sender, this + ".list.mention.format")
.replace("<message>", player.getName());

wordParams.setClickable(true, player.getName());
wordParams.setClickable(true);
wordParams.setPlayerPingName(player.getName());
wordParams.setPlayerPing(true);
wordParams.setText(word);

Expand All @@ -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("<message>", word);
Expand All @@ -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("<player>", sender.getName())
.replace("<ping>", 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();
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/settings/languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ default:
player-message:
formatting:
list:
ping:
message: "&&1<player> ping - <ping>"
cords:
message: "&&1World:&&2<world> &&1Biome:&&2<biome> &&1X:&&2<block_x> &&1Y:&&2<block_y> &&1Z:&&2<block_z>"
stats:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/settings/languages/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ default:
player-message:
formatting:
list:
ping:
message: "&&1Пинг <player> - <ping>"
cords:
message: "&&1Мир:&&2<world> &&1Биом:&&2<biome> &&1X:&&2<block_x> &&1Y:&&2<block_y> &&1Z:&&2<block_z>"
stats:
Expand Down

0 comments on commit eaf5179

Please sign in to comment.