Skip to content

Commit b080d33

Browse files
committed
Added performances diagnostic and 1.13+ fixes.
- If the latency or the TPS is high, displays an informational message explaining the probable cause of the performances issue to the user. - Fixed 113+ compatibility. - Added flag for this compatibility.
1 parent 951e750 commit b080d33

File tree

12 files changed

+171
-62
lines changed

12 files changed

+171
-62
lines changed

.gitignore

100644100755
File mode changed.

README.md

100644100755
File mode changed.

pom.xml

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.zcraft.Ping</groupId>
88
<artifactId>Ping</artifactId>
9-
<version>1.1</version>
9+
<version>1.2</version>
1010

1111
<packaging>jar</packaging>
1212

src/main/java/fr/zcraft/Ping/ContinuousPingSender.java

100644100755
File mode changed.

src/main/java/fr/zcraft/Ping/Ping.java

100644100755
File mode changed.

src/main/java/fr/zcraft/Ping/PingConfig.java

100644100755
File mode changed.

src/main/java/fr/zcraft/Ping/Pinger.java

100644100755
File mode changed.

src/main/java/fr/zcraft/Ping/commands/PingCommand.java

100644100755
Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@
3434
import fr.zcraft.Ping.Pinger;
3535
import fr.zcraft.zlib.components.i18n.I;
3636
import fr.zcraft.zlib.components.rawtext.RawText;
37-
import fr.zcraft.zlib.tools.items.ItemStackBuilder;
3837
import fr.zcraft.zlib.tools.text.RawMessage;
3938
import org.bukkit.Bukkit;
4039
import org.bukkit.ChatColor;
41-
import org.bukkit.Material;
4240
import org.bukkit.command.Command;
4341
import org.bukkit.command.CommandExecutor;
4442
import org.bukkit.command.CommandSender;
@@ -100,13 +98,13 @@ else if (label.equalsIgnoreCase("ping"))
10098

10199
if (!isSelf)
102100
{
103-
sender.sendMessage(I.t("{green}{bold}{0}'s ping", target.getName()));
101+
sender.sendMessage(" " + I.t("{green}{bold}{0}'s ping", target.getName()));
104102
sender.sendMessage("");
105103
}
106104
else if (label.toLowerCase().endsWith("ping"))
107105
{
108106
if (sender.hasPermission("ping.toggleping"))
109-
RawMessage.send(sender, new RawText(I.t("{green}{bold}Pong!"))
107+
RawMessage.send(sender, new RawText(" " + I.t("{green}{bold}Pong!"))
110108
.then(" ")
111109
.then(I.t("(keep displayed)"))
112110
.color(ChatColor.GRAY)
@@ -115,51 +113,93 @@ else if (label.toLowerCase().endsWith("ping"))
115113
.build()
116114
);
117115
else
118-
sender.sendMessage(I.t("{green}{bold}Pong!"));
116+
sender.sendMessage(" " + I.t("{green}{bold}Pong!"));
119117

120118
sender.sendMessage("");
121119
}
122120

123-
RawMessage.send(sender, new RawText("")
121+
RawMessage.send(sender, new RawText(" ")
124122
.then(I.t("Latency: "))
125123
.color(ChatColor.GOLD)
126124
.hover(
127-
new ItemStackBuilder(Material.POTATO_ITEM)
128-
.title(ChatColor.BOLD + I.t("Latency"))
129-
.longLore(ChatColor.RESET, isSelf
130-
? I.t("The time needed to transfer data from you to the server.")
131-
: I.t("The time needed to transfer data from {0} to the server.", target.getName()), 38)
132-
.loreLine(ChatColor.GREEN, I.t("The lower the better."))
133-
.hideAttributes()
134-
.item()
125+
new RawText()
126+
.then(I.t("Latency")).style(ChatColor.BOLD).then("\n")
127+
.then(
128+
isSelf
129+
? I.t("The time needed to transfer data from you to the server.")
130+
: I.t("The time needed to transfer data from {0} to the server.", target.getName())
131+
).then("\n")
132+
.then(I.t("The lower the better.")).color(ChatColor.GREEN)
135133
)
136134

137135
.then(latency != -1 ? Pinger.formatLatency(latency) : I.t("{gray}(unable to retrieve latency)"))
138136

139137
.build()
140138
);
141139

142-
RawMessage.send(sender, new RawText("")
140+
RawMessage.send(sender, new RawText(" ")
143141
.then(I.t("Server load: "))
144142
.color(ChatColor.GOLD)
145143
.hover(
146-
new ItemStackBuilder(Material.POTATO_ITEM)
147-
.title(ChatColor.BOLD + I.t("Ticks per second"))
148-
.longLore(ChatColor.RESET, I.t("The number of cycles the server executes per second. The best is 20; under 15, the server is experiencing difficulties."), 38)
149-
.longLore(ChatColor.GRAY, I.t("The three values are the average number of TPS during the last 1, 5 and 15 minutes."), 38)
150-
.loreLine(ChatColor.GREEN, I.t("The closest to 20 the better."))
151-
.hideAttributes()
152-
.item()
144+
new RawText()
145+
.then(I.t("Ticks per second")).style(ChatColor.BOLD).then("\n")
146+
.then(I.t("The number of cycles the server executes per second. The best is 20; under 15, the server is experiencing difficulties.")).then("\n")
147+
.then(I.t("The three values are the average number of TPS during the last 1, 5 and 15 minutes.")).color(ChatColor.GRAY).then("\n")
148+
.then(I.t("The closest to 20 the better.")).color(ChatColor.GREEN)
153149
)
154150

155151
.then(tps != null ? Pinger.formatTPS(tps) : I.t("{gray}(unable to retrieve server load)"))
156152

157153
.build()
158154
);
159155

156+
final boolean highLatency = latency > 150;
157+
final boolean lowTPS = tps != null && tps[0] < 16.5;
158+
159+
if (highLatency || lowTPS)
160+
{
161+
sender.sendMessage("");
162+
163+
if (isSelf)
164+
{
165+
if (lowTPS && highLatency)
166+
{
167+
sendWarning(sender, I.t("Both your latency and the server load are high."), I.t("If you are experiencing poor performances, it may come from your internet connection, the server, or both."));
168+
}
169+
else if (highLatency)
170+
{
171+
sendWarning(sender, I.t("Your latency is high."), I.t("If you are experiencing poor performances, it probably comes from your internet connection."));
172+
}
173+
else
174+
{
175+
sendWarning(sender, I.t("The server load is high."), I.t("If you are experiencing poor performances, it probably comes from the server."));
176+
}
177+
}
178+
else
179+
{
180+
if (lowTPS && highLatency)
181+
{
182+
sendWarning(sender, I.t("Both {0}'s latency and the server load are high.", target.getName()), I.t("If they are experiencing poor performances, it may come from their internet connection, the server, or both."));
183+
}
184+
else if (highLatency)
185+
{
186+
sendWarning(sender, I.t("{0}'s latency is high.", target.getName()), I.t("If they are experiencing poor performances, it probably comes from their internet connection."));
187+
}
188+
else
189+
{
190+
sendWarning(sender, I.t("The server load is high."), I.t("If {0} is experiencing poor performances, it probably comes from the server.", target.getName()));
191+
}
192+
}
193+
}
194+
160195
if (sender instanceof Player)
161196
sender.sendMessage(ChatColor.GRAY + "⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅");
162197

163198
return true;
164199
}
200+
201+
private void sendWarning(final CommandSender receiver, final String title, final String explanation)
202+
{
203+
receiver.sendMessage(ChatColor.RED + " \u26A0 " + ChatColor.GRAY + ChatColor.BOLD + title + " " + ChatColor.GRAY + explanation);
204+
}
165205
}

src/main/java/fr/zcraft/Ping/commands/TogglePingCommand.java

100644100755
File mode changed.

src/main/resources/config.yml

100644100755
File mode changed.

0 commit comments

Comments
 (0)