Skip to content

Commit dc77f81

Browse files
5.1.2.4 - hotfixes (PotatoCraft-Studio#402)
* Update Metrics code from bstats and fix typo * Fix StackOverflow when appending components * Bump version
1 parent d5b729a commit dc77f81

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<artifactId>QuickShop</artifactId>
2626

2727
<properties>
28-
<pluginver>5.1.2.3</pluginver>
28+
<pluginver>5.1.2.4</pluginver>
2929
<package>org.maxgamer.quickshop</package>
3030
<developer>Ghost-chu</developer>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/org/maxgamer/quickshop/Metrics.java

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,28 @@
2828
import org.bukkit.plugin.RegisteredServiceProvider;
2929
import org.bukkit.plugin.ServicePriority;
3030
import org.maxgamer.quickshop.util.JsonUtil;
31-
import org.maxgamer.quickshop.util.Util;
3231

3332
import javax.net.ssl.HttpsURLConnection;
34-
import java.io.*;
33+
import java.io.BufferedReader;
34+
import java.io.ByteArrayOutputStream;
35+
import java.io.DataOutputStream;
36+
import java.io.File;
37+
import java.io.IOException;
38+
import java.io.InputStreamReader;
3539
import java.lang.reflect.InvocationTargetException;
3640
import java.lang.reflect.Method;
3741
import java.net.URL;
3842
import java.nio.charset.StandardCharsets;
39-
import java.util.*;
43+
import java.util.ArrayList;
44+
import java.util.Collection;
45+
import java.util.List;
46+
import java.util.Map;
47+
import java.util.UUID;
4048
import java.util.concurrent.Callable;
49+
import java.util.concurrent.Executors;
50+
import java.util.concurrent.ScheduledExecutorService;
51+
import java.util.concurrent.ThreadFactory;
52+
import java.util.concurrent.TimeUnit;
4153
import java.util.logging.Level;
4254
import java.util.zip.GZIPOutputStream;
4355

@@ -248,33 +260,35 @@ private static byte[] compress(final String str) throws IOException {
248260
return outputStream.toByteArray();
249261
}
250262

263+
// This ThreadFactory enforces the naming convention for our Threads
264+
private final ThreadFactory threadFactory = task -> new Thread(task, "bStats-Metrics");
265+
266+
// Executor service for requests
267+
// We use an executor service because the Bukkit scheduler is affected by server lags
268+
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, threadFactory);
269+
251270
/**
252271
* Starts the Scheduler which submits our data every 30 minutes.
253272
*/
254273
private void startSubmitting() {
255-
final Timer timer =
256-
new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
257-
timer.scheduleAtFixedRate(
258-
new TimerTask() {
259-
@Override
260-
public void run() {
261-
if (!plugin.isEnabled()) { // Plugin was disabled
262-
timer.cancel();
263-
return;
264-
}
265-
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the
266-
// Bukkit scheduler
267-
// Don't be afraid! The connection to the bStats server is still async, only the stats
268-
// collection is sync ;)
269-
Util.mainThreadRun(() -> submitData());
270-
}
271-
},
272-
1000 * 60 * 5,
273-
1000 * 60 * 30);
274-
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough
275-
// time to start
276-
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
277-
// WARNING: Just don't do it!
274+
final Runnable submitTask = () -> {
275+
if (!plugin.isEnabled()) { // Plugin was disabled
276+
scheduler.shutdown();
277+
return;
278+
}
279+
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
280+
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
281+
plugin.getServer().getScheduler().runTask(plugin, this::submitData);
282+
};
283+
284+
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution of requests on the
285+
// bStats backend. To circumvent this problem, we introduce some randomness into the initial and second delay.
286+
// WARNING: You must not modify and part of this Metrics class, including the submit delay or frequency!
287+
// WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
288+
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
289+
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
290+
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
291+
scheduler.scheduleAtFixedRate(submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
278292
}
279293

280294
/**

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ public void run() {
11431143
@Override
11441144
public void run() {
11451145
getLogger().info("Registering bStats metrics...");
1146-
submitMeritcs();
1146+
submitMetrics();
11471147
}
11481148
}.runTask(this);
11491149
if (loaded) {
@@ -1237,7 +1237,7 @@ private boolean setupDatabase() {
12371237
return true;
12381238
}
12391239

1240-
private void submitMeritcs() {
1240+
private void submitMetrics() {
12411241
if (!getConfig().getBoolean("disabled-metrics")) {
12421242
String vaultVer;
12431243
Plugin vault = Bukkit.getPluginManager().getPlugin("Vault");

src/main/java/org/maxgamer/quickshop/chat/platform/minedown/BungeeQuickChat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public BungeeComponentBuilder append(BaseComponent component) {
335335
if (builder.getCursor() == -1) {
336336
append(component, ComponentBuilder.FormatRetention.EVENTS);
337337
} else {
338-
append(component);
338+
append(component, ComponentBuilder.FormatRetention.ALL);
339339
}
340340
return this;
341341
}

0 commit comments

Comments
 (0)