Skip to content

Commit

Permalink
Optimise
Browse files Browse the repository at this point in the history
  • Loading branch information
Smudgge committed Jul 29, 2023
1 parent 9918204 commit 6dac56f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 77 deletions.
21 changes: 1 addition & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cozyplugins</groupId>
<artifactId>CozyTreasureHunt</artifactId>
<version>1.0.0</version>
<version>0.0.0-BETA</version>
<packaging>jar</packaging>
<name>CozyTreasureHunt</name>

Expand Down Expand Up @@ -100,25 +100,6 @@
</execution>
</executions>
</plugin>
<!-- Docs for jit pack-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<inherited>false</inherited>
<configuration>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate-jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
110 changes: 53 additions & 57 deletions src/main/java/com/github/cozyplugins/cozytreasurehunt/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
*/
package com.github.cozyplugins.cozytreasurehunt;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
Expand All @@ -40,12 +36,6 @@
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class Metrics {

Expand All @@ -56,9 +46,9 @@ public class Metrics {
/**
* Creates a new Metrics instance.
*
* @param plugin Your plugin instance.
* @param plugin Your plugin instance.
* @param serviceId The id of the service. It can be found at <a
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(JavaPlugin plugin, int serviceId) {
this.plugin = plugin;
Expand Down Expand Up @@ -110,7 +100,9 @@ public Metrics(JavaPlugin plugin, int serviceId) {
logResponseStatusText);
}

/** Shuts down the underlying scheduler service. */
/**
* Shuts down the underlying scheduler service.
*/
public void shutdown() {
metricsBase.shutdown();
}
Expand Down Expand Up @@ -157,7 +149,9 @@ private int getPlayerAmount() {

public static class MetricsBase {

/** The version of the Metrics class. */
/**
* The version of the Metrics class.
*/
public static final String METRICS_VERSION = "3.0.2";

private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
Expand Down Expand Up @@ -195,23 +189,23 @@ public static class MetricsBase {
/**
* Creates a new MetricsBase class instance.
*
* @param platform The platform of the service.
* @param serviceId The id of the service.
* @param serverUuid The server uuid.
* @param enabled Whether or not data sending is enabled.
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
* appends all platform-specific data.
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
* appends all service-specific data.
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
* used to delegate the data collection to a another thread to prevent errors caused by
* concurrency. Can be {@code null}.
* @param platform The platform of the service.
* @param serviceId The id of the service.
* @param serverUuid The server uuid.
* @param enabled Whether or not data sending is enabled.
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
* appends all platform-specific data.
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
* appends all service-specific data.
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
* used to delegate the data collection to a another thread to prevent errors caused by
* concurrency. Can be {@code null}.
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
* @param errorLogger A consumer that accepts log message and an error.
* @param infoLogger A consumer that accepts info log messages.
* @param logErrors Whether or not errors should be logged.
* @param logSentData Whether or not the sent data should be logged.
* @param logResponseStatusText Whether or not the response status text should be logged.
* @param errorLogger A consumer that accepts log message and an error.
* @param infoLogger A consumer that accepts info log messages.
* @param logErrors Whether or not errors should be logged.
* @param logSentData Whether or not the sent data should be logged.
* @param logResponseStatusText Whether or not the response status text should be logged.
*/
public MetricsBase(
String platform,
Expand Down Expand Up @@ -355,17 +349,19 @@ private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
}
}

/** Checks that the class was properly relocated. */
/**
* Checks that the class was properly relocated.
*/
private void checkRelocation() {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this
// little "trick" ... :D
final String defaultPackage =
new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
final String examplePackage =
new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure no one just copy & pastes the example and uses the wrong
// package names
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
Expand Down Expand Up @@ -400,7 +396,7 @@ public static class SimplePie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
Expand All @@ -426,7 +422,7 @@ public static class MultiLineChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
Expand Down Expand Up @@ -466,7 +462,7 @@ public static class AdvancedPie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
Expand Down Expand Up @@ -506,7 +502,7 @@ public static class SimpleBarChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
Expand All @@ -523,7 +519,7 @@ protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()});
}
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
}
Expand All @@ -536,7 +532,7 @@ public static class AdvancedBarChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
Expand Down Expand Up @@ -576,7 +572,7 @@ public static class DrilldownPie extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
Expand Down Expand Up @@ -654,7 +650,7 @@ public static class SingleLineChart extends CustomChart {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
Expand Down Expand Up @@ -703,7 +699,7 @@ public JsonObjectBuilder appendNull(String key) {
/**
* Appends a string field to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param value The value of the field.
* @return A reference to this object.
*/
Expand All @@ -718,7 +714,7 @@ public JsonObjectBuilder appendField(String key, String value) {
/**
* Appends an integer field to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param value The value of the field.
* @return A reference to this object.
*/
Expand All @@ -730,7 +726,7 @@ public JsonObjectBuilder appendField(String key, int value) {
/**
* Appends an object to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param object The object.
* @return A reference to this object.
*/
Expand All @@ -745,7 +741,7 @@ public JsonObjectBuilder appendField(String key, JsonObject object) {
/**
* Appends a string array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The string array.
* @return A reference to this object.
*/
Expand All @@ -764,7 +760,7 @@ public JsonObjectBuilder appendField(String key, String[] values) {
/**
* Appends an integer array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The integer array.
* @return A reference to this object.
*/
Expand All @@ -781,7 +777,7 @@ public JsonObjectBuilder appendField(String key, int[] values) {
/**
* Appends an object array to the JSON.
*
* @param key The key of the field.
* @param key The key of the field.
* @param values The integer array.
* @return A reference to this object.
*/
Expand All @@ -798,7 +794,7 @@ public JsonObjectBuilder appendField(String key, JsonObject[] values) {
/**
* Appends a field to the object.
*
* @param key The key of the field.
* @param key The key of the field.
* @param escapedValue The escaped value of the field.
*/
private void appendFieldUnescaped(String key, String escapedValue) {
Expand Down

0 comments on commit 6dac56f

Please sign in to comment.