diff --git a/pom.xml b/pom.xml
index c45afe4..7a424a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.skymc
TabooLib
- 4.27
+ 4.28
UTF-8
diff --git a/src/main/java/com/ilummc/tlib/TLib.java b/src/main/java/com/ilummc/tlib/TLib.java
index 3857f35..06c5863 100644
--- a/src/main/java/com/ilummc/tlib/TLib.java
+++ b/src/main/java/com/ilummc/tlib/TLib.java
@@ -14,15 +14,16 @@ import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.IO;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.fileutils.FileUtils;
+import me.skymc.taboolib.plugin.PluginUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
+import java.util.Arrays;
@Dependency(type = Dependency.Type.LIBRARY, maven = "com.zaxxer:HikariCP:3.1.0")
@Dependency(type = Dependency.Type.LIBRARY, maven = "org.slf4j:slf4j-api:1.7.25")
@@ -58,14 +59,6 @@ public class TLib {
}
}
- public static TLib getTLib() {
- return tLib;
- }
-
- public static YamlConfiguration getInternalLanguage() {
- return internalLanguage;
- }
-
public static void init() {
tLib = new TLib();
@@ -94,6 +87,11 @@ public class TLib {
}
public static void injectPluginManager() {
+ if (!tLib.isInjectEnabled() || tLib.isBlackListPluginExists()) {
+ TLocale.Logger.fatal("TLIB.INJECTION-DISABLED");
+ Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin != Main.getInst()).forEach(plugin -> TDependencyInjector.inject(plugin, plugin));
+ return;
+ }
try {
Field field = Bukkit.getServer().getClass().getDeclaredField("pluginManager");
field.setAccessible(true);
@@ -101,14 +99,18 @@ public class TLib {
TLocale.Logger.info("TLIB.INJECTION-SUCCESS");
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) {
TLocale.Logger.fatal("TLIB.INJECTION-FAILED");
- for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
- if (plugin != Main.getInst()) {
- TDependencyInjector.inject(plugin, plugin);
- }
- }
+ Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin != Main.getInst()).forEach(plugin -> TDependencyInjector.inject(plugin, plugin));
}
}
+ public static TLib getTLib() {
+ return tLib;
+ }
+
+ public static YamlConfiguration getInternalLanguage() {
+ return internalLanguage;
+ }
+
public TLogger getLogger() {
return logger;
}
@@ -124,4 +126,18 @@ public class TLib {
public File getLibsFolder() {
return libsFolder;
}
+
+ // *********************************
+ //
+ // Private Methods
+ //
+ // *********************************
+
+ private boolean isInjectEnabled() {
+ return Main.getInst().getConfig().getBoolean("PLUGIN-INJECTOR.ENABLE", true);
+ }
+
+ private boolean isBlackListPluginExists() {
+ return Main.getInst().getConfig().getStringList("PLUGIN-INJECTOR.DISABLE-ON-PLUGIN-EXISTS").stream().anyMatch(PluginUtils::isPluginExists);
+ }
}
diff --git a/src/main/java/me/skymc/taboolib/TabooLibLoader.java b/src/main/java/me/skymc/taboolib/TabooLibLoader.java
index 108a652..4348b67 100644
--- a/src/main/java/me/skymc/taboolib/TabooLibLoader.java
+++ b/src/main/java/me/skymc/taboolib/TabooLibLoader.java
@@ -165,6 +165,5 @@ public class TabooLibLoader implements Listener {
static void registerMetrics() {
Metrics metrics = new Metrics(TabooLib.instance());
metrics.addCustomChart(new Metrics.SingleLineChart("plugins_using_taboolib", () -> Math.toIntExact(Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains("TabooLib")).count())));
- metrics.addCustomChart(new Metrics.AdvancedPie("plugins_using_taboolib_name", () -> Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains("TabooLib")).collect(Collectors.toMap(Plugin::getName, plugin -> 1, (a, b) -> b))));
}
}
diff --git a/src/main/java/me/skymc/taboolib/bstats/Metrics.java b/src/main/java/me/skymc/taboolib/bstats/Metrics.java
index 42b50c0..3685992 100644
--- a/src/main/java/me/skymc/taboolib/bstats/Metrics.java
+++ b/src/main/java/me/skymc/taboolib/bstats/Metrics.java
@@ -17,13 +17,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
@@ -36,13 +30,22 @@ import java.util.zip.GZIPOutputStream;
*/
public class Metrics {
+ // The version of this bStats class
+ public static final int B_STATS_VERSION = 1;
+ // The url to which the data is sent
+ private static final String URL = "https://bStats.org/submitData/bukkit";
+ // Should failed requests be logged?
+ private static boolean logFailedRequests;
+ // The uuid of the server
+ private static String serverUUID;
+
static {
// 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', '.', 'b', 'u', 'k', 'k', 'i', 't'});
- final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
+ new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
+ final String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
@@ -50,18 +53,6 @@ public class Metrics {
}
}
- // The version of this bStats class
- public static final int B_STATS_VERSION = 1;
-
- // The url to which the data is sent
- private static final String URL = "https://bStats.org/submitData/bukkit";
-
- // Should failed requests be logged?
- private static boolean logFailedRequests;
-
- // The uuid of the server
- private static String serverUUID;
-
// The plugin
private final JavaPlugin plugin;
@@ -103,7 +94,8 @@ public class Metrics {
).copyDefaults(true);
try {
config.save(configFile);
- } catch (IOException ignored) { }
+ } catch (IOException ignored) {
+ }
}
// Load the data
@@ -117,7 +109,8 @@ public class Metrics {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
- } catch (NoSuchFieldException ignored) { }
+ } catch (NoSuchFieldException ignored) {
+ }
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
@@ -128,6 +121,61 @@ public class Metrics {
}
}
+ /**
+ * Sends the data to the bStats server.
+ *
+ * @param data The data to send.
+ * @throws Exception If the request failed.
+ */
+ private static void sendData(JSONObject data) throws Exception {
+ if (data == null) {
+ throw new IllegalArgumentException("Data cannot be null!");
+ }
+ if (Bukkit.isPrimaryThread()) {
+ throw new IllegalAccessException("This method must not be called from the main thread!");
+ }
+ HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
+
+ // Compress the data to save bandwidth
+ byte[] compressedData = compress(data.toString());
+
+ // Add headers
+ connection.setRequestMethod("POST");
+ connection.addRequestProperty("Accept", "application/json");
+ connection.addRequestProperty("Connection", "close");
+ connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
+ connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
+ connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
+ connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
+
+ // Send data
+ connection.setDoOutput(true);
+ DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
+ outputStream.write(compressedData);
+ outputStream.flush();
+ outputStream.close();
+
+ connection.getInputStream().close(); // We don't care about the response - Just send our data :)
+ }
+
+ /**
+ * Gzips the given String.
+ *
+ * @param str The string to gzip.
+ * @return The gzipped String.
+ * @throws IOException If the compression failed.
+ */
+ private static byte[] compress(final String str) throws IOException {
+ if (str == null) {
+ return null;
+ }
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
+ gzip.write(str.getBytes("UTF-8"));
+ gzip.close();
+ return outputStream.toByteArray();
+ }
+
/**
* Adds a custom chart.
*
@@ -161,7 +209,7 @@ public class Metrics {
}
});
}
- }, 1000*60*5, 1000*60*30);
+ }, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
@@ -256,9 +304,11 @@ public class Metrics {
for (RegisteredServiceProvider> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
- } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
+ } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
+ }
}
- } catch (NoSuchFieldException ignored) { }
+ } catch (NoSuchFieldException ignored) {
+ }
}
data.put("plugins", pluginData);
@@ -280,61 +330,6 @@ public class Metrics {
}).start();
}
- /**
- * Sends the data to the bStats server.
- *
- * @param data The data to send.
- * @throws Exception If the request failed.
- */
- private static void sendData(JSONObject data) throws Exception {
- if (data == null) {
- throw new IllegalArgumentException("Data cannot be null!");
- }
- if (Bukkit.isPrimaryThread()) {
- throw new IllegalAccessException("This method must not be called from the main thread!");
- }
- HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
-
- // Compress the data to save bandwidth
- byte[] compressedData = compress(data.toString());
-
- // Add headers
- connection.setRequestMethod("POST");
- connection.addRequestProperty("Accept", "application/json");
- connection.addRequestProperty("Connection", "close");
- connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
- connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
- connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
- connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
-
- // Send data
- connection.setDoOutput(true);
- DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
- outputStream.write(compressedData);
- outputStream.flush();
- outputStream.close();
-
- connection.getInputStream().close(); // We don't care about the response - Just send our data :)
- }
-
- /**
- * Gzips the given String.
- *
- * @param str The string to gzip.
- * @return The gzipped String.
- * @throws IOException If the compression failed.
- */
- private static byte[] compress(final String str) throws IOException {
- if (str == null) {
- return null;
- }
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
- gzip.write(str.getBytes("UTF-8"));
- gzip.close();
- return outputStream.toByteArray();
- }
-
/**
* Represents a custom chart.
*/
@@ -388,7 +383,7 @@ public class Metrics {
/**
* 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 callable) {
@@ -419,7 +414,7 @@ public class Metrics {
/**
* 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