NOTE: Avoid running this method Synchronously with the main thread!It blocks while attempting to get a response from Mojang servers!
+ * @param player The UUID of the player to be looked up.
+ * @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
+ * @throws IOException {@link #getPlayerPreviousNames(String)}
+ */
+ public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException {
+ return getPlayerPreviousNames(player.toString());
+ }
+
+ /**
+ *
NOTE: Avoid running this method Synchronously with the main thread! It blocks while attempting to get a response from Mojang servers!
+ * Alternative method accepting an 'OfflinePlayer' (and therefore 'Player') objects as parameter.
+ * @param player The OfflinePlayer object to obtain the UUID from.
+ * @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
+ * @throws IOException {@link #getPlayerPreviousNames(UUID)}
+ */
+ public static PreviousPlayerNameEntry[] getPlayerPreviousNames(OfflinePlayer player) throws IOException {
+ return getPlayerPreviousNames(player.getUniqueId());
+ }
+
+ /**
+ *
NOTE: Avoid running this method Synchronously with the main thread! It blocks while attempting to get a response from Mojang servers!
+ * Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter.
+ * @param uuid The UUID String to lookup
+ * @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
+ * @throws IOException
+ */
+ public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException {
+ if (uuid == null || uuid.isEmpty())
+ return null;
+ String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid)));
+ PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class);
+ return names;
+ }
+
+ /**
+ * If you don't have the UUID of a player, this method will resolve it for you.
+ * The output of this method may be used directly with {@link #getPlayerPreviousNames(String)}.
+ * NOTE: as with the rest, this method opens a connection with a remote server, so running it synchronously will block the main thread which will lead to server lag.
+ * @param name The name of the player to lookup.
+ * @return A String which represents the player's UUID. Note: the uuid cannot be parsed to a UUID object directly, as it doesnt contain dashes. This feature will be implemented later
+ * @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
+ */
+ public static String getPlayerUUID(String name) throws IOException {
+ String response = getRawJsonResponse(new URL(String.format(GET_UUID_URL, name)));
+ JsonObject o = JSON_PARSER.fromJson(response, JsonObject.class);
+ if (o == null)
+ return null;
+ return o.get("id") == null ? null : o.get("id").getAsString();
+ }
+
+ /**
+ * This is a helper method used to read the response of Mojang's API webservers.
+ * @param u the URL to connect to
+ * @return a String with the data read.
+ * @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
+ */
+ private static String getRawJsonResponse(URL u) throws IOException {
+ HttpURLConnection con = (HttpURLConnection) u.openConnection();
+ con.setDoInput(true);
+ con.setConnectTimeout(2000);
+ con.setReadTimeout(2000);
+ con.connect();
+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
+ String response = in.readLine();
+ in.close();
+ return response;
+ }
+
+ /**
+ * This class represents the typical response expected by Mojang servers when requesting the name history of a player.
+ */
+ public class PreviousPlayerNameEntry {
+ private String name;
+ @SerializedName("changedToAt")
+ private long changeTime;
+
+ /**
+ * Gets the player name of this entry.
+ * @return The name of the player.
+ */
+ public String getPlayerName() {
+ return name;
+ }
+
+ /**
+ * Get the time of change of the name.
+ * Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling!
+ * Parsing 0 to a Date will result in the date "01/01/1970".
+ * @return a timestamp in miliseconds that you can turn into a date or handle however you want :)
+ */
+ public long getChangeTime() {
+ return changeTime;
+ }
+
+ /**
+ * Check if this name is the name used to register the account (the initial/original name)
+ * @return a boolean, true if it is the the very first name of the player, otherwise false.
+ */
+ public boolean isPlayersInitialName() {
+ return getChangeTime() == 0;
+ }
+
+ @Override
+ public String toString() {
+ return "Name: " + name + " Date of change: " + new Date(changeTime).toString();
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginCheck.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginCheck.java
new file mode 100644
index 0000000..1ce7861
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginCheck.java
@@ -0,0 +1,86 @@
+package net.t2code.t2codelib.SPIGOT.api.plugins;
+
+import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+
+import java.util.logging.Level;
+
+public class T2CpluginCheck {
+ public static Boolean pluginCheck(String pluginName){
+ return Bukkit.getPluginManager().getPlugin(pluginName) != null;
+ }
+ public static Plugin pluginInfos(String pluginName){
+ return Bukkit.getPluginManager().getPlugin(pluginName);
+ }
+ public static Boolean papi(){
+ return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
+ }
+ public static Boolean vault(){
+ return Bukkit.getPluginManager().getPlugin("Vault") != null;
+ }
+ public static Boolean plotSquared(){
+ return Bukkit.getPluginManager().getPlugin("PlotSquared") != null;
+ }
+ public static Boolean plugManGUI(){
+ return Bukkit.getPluginManager().getPlugin("PlugManGUI") != null;
+ }
+ public static Boolean cmi(){
+ return Bukkit.getPluginManager().getPlugin("CMI") != null;
+ }
+ public static Boolean votingPlugin(){
+ return Bukkit.getPluginManager().getPlugin("VotingPlugin") != null;
+ }
+
+ /**
+ * T2Code Plugins
+ * @return
+ */
+
+ public static Boolean cgui(){
+ return Bukkit.getPluginManager().getPlugin("CommandGUI") != null;
+ }
+ public static Boolean functiongui(){
+ return Bukkit.getPluginManager().getPlugin("T2C-CommandGUI") != null;
+ }
+ public static Boolean plotSquaredGUI(){
+ return Bukkit.getPluginManager().getPlugin("PlotSquaredGUI") != null;
+ }
+ public static Boolean luckyBox(){
+ return Bukkit.getPluginManager().getPlugin("T2C-LuckyBox") != null;
+ }
+ public static Boolean autoResponse(){
+ return Bukkit.getPluginManager().getPlugin("T2C-AutoResponse") != null;
+ }
+ public static Boolean opSec(){
+ return Bukkit.getPluginManager().getPlugin("OPSecurity") != null;
+ }
+ public static Boolean papiTest(){
+ return Bukkit.getPluginManager().getPlugin("PaPiTest") != null;
+ }
+ public static Boolean booster(){
+ return Bukkit.getPluginManager().getPlugin("Booster") != null;
+ }
+ public static Boolean antiMapCopy(){
+ return Bukkit.getPluginManager().getPlugin("AntiMapCopy") != null;
+ }
+ public static Boolean loreEditor(){
+ return Bukkit.getPluginManager().getPlugin("LoreEditor") != null;
+ }
+ public static Boolean t2cAlias(){
+ return Bukkit.getPluginManager().getPlugin("T2C-Alias") != null;
+ }
+ public static Boolean t2cWarp(){
+ return Bukkit.getPluginManager().getPlugin("T2C-Warp") != null;
+ }
+
+ public static Boolean pluginNotFound(Plugin plugin, String prefix, String pl, Integer spigotID) {
+ if (Bukkit.getPluginManager().getPlugin(pl) == null) {
+ plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
+ Bukkit.getConsoleSender().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " +
+ "§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
+ T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(T2CodeLibMain.getPlugin());
+ return true;
+ } else return false;
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginManager.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginManager.java
new file mode 100644
index 0000000..0cfad7a
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/plugins/T2CpluginManager.java
@@ -0,0 +1,42 @@
+package net.t2code.t2codelib.SPIGOT.api.plugins;
+
+import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+
+import java.util.Objects;
+
+public class T2CpluginManager {
+
+ public static void restart(String plugin) {
+ if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
+ T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
+ }
+
+ public static void enable(String plugin) {
+ if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
+ }
+
+ public static void disable(String plugin) {
+ if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
+ }
+
+ public static void restart(Plugin plugin) {
+ if (plugin == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(plugin);
+ T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(plugin);
+ }
+
+ public static void enable(Plugin plugin) {
+ if (plugin == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(plugin);
+ }
+
+ public static void disable(Plugin plugin) {
+ if (plugin == null) return;
+ T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(plugin);
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/register/T2Cregister.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/register/T2Cregister.java
new file mode 100644
index 0000000..159b2d2
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/register/T2Cregister.java
@@ -0,0 +1,39 @@
+package net.t2code.t2codelib.SPIGOT.api.register;
+
+import org.bukkit.Bukkit;
+import org.bukkit.event.Listener;
+import org.bukkit.permissions.Permission;
+import org.bukkit.permissions.PermissionDefault;
+import org.bukkit.plugin.Plugin;
+
+public class T2Cregister {
+ public static void listener(Listener listener, Plugin plugin) {
+ Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
+ }
+
+ public static void permission(String permission, Plugin plugin) {
+ if (plugin.getServer().getPluginManager().getPermission(permission) == null) {
+ plugin.getServer().getPluginManager().addPermission(new Permission(permission));
+ }
+ }
+
+ public static void permission(String permission, PermissionDefault setDefault, Plugin plugin) {
+ permission(permission, plugin);
+ plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
+ }
+
+ public static void permission(String permission, String children, Boolean setBoolean, Plugin plugin) {
+ permission(permission, plugin);
+ plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
+ }
+
+ public static void permission(String permission, PermissionDefault setDefault, String children, Boolean setBoolean, Plugin plugin) {
+ permission(permission, plugin);
+ plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
+ plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
+ }
+ public static void permissionDescription(String permission, String description, Plugin plugin) {
+ plugin.getServer().getPluginManager().getPermission(permission).setDescription(description);
+
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java
new file mode 100644
index 0000000..08be958
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateAPI.java
@@ -0,0 +1,123 @@
+package net.t2code.t2codelib.SPIGOT.api.update;
+
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
+import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.HashMap;
+
+public class T2CupdateAPI {
+ public static HashMap pluginVersions = new HashMap<>();
+
+ public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) {
+ if (!SelectLibConfig.getUpdateCheckOnJoin()) {
+ return;
+ }
+ if (!player.hasPermission(perm) && !player.isOp()) {
+ return;
+ }
+ if (pluginVersions.get(plugin.getName()) == null) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ join(plugin, prefix, perm, player, spigotID, discord);
+ }
+ }.runTaskLaterAsynchronously(plugin, 20L);
+ return;
+ }
+ String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
+ String pluginVersion = plugin.getDescription().getVersion();
+ if (pluginVersion.equals(publicVersion)) return;
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ sendUpdateMsg(prefix, spigotID, discord, plugin, player);
+ }
+ }.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L);
+ }
+
+ public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) {
+ String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
+ String pluginVersion = plugin.getDescription().getVersion();
+ if (publicVersion.equals("§4No public version found!")) {
+ return;
+ }
+ String st = "[prefix] " +
+ "You can download it here: [link]'>[prefix] A new [value]version was found! " +
+ "You can download it here: [link]'>[prefix] [plv]->[puv] " +
+ "[dc]'>[prefix] You can find more information on Discord. " +
+ "[prefix]";
+ String value = "";
+ if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
+ if (publicVersion.toLowerCase().contains("dev")) {
+ value = "DEV ";
+ }
+ if (publicVersion.toLowerCase().contains("beta")) {
+ value = "BETA ";
+ }
+ if (publicVersion.toLowerCase().contains("snapshot")) {
+ value = "SNAPSHOT ";
+ }
+ }
+ T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", "https://www.spigotmc.org/resources/" + spigotID)
+ .replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
+ }
+
+ public static void sendUpdateMsg(String prefix, Integer spigot, String discord, Plugin plugin) {
+ String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
+ String pluginVersion = plugin.getDescription().getVersion();
+ T2Csend.console("§4=========== " + prefix + " §4===========");
+ if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
+ if (publicVersion.toLowerCase().contains("dev")) {
+ T2Csend.console("§6A new §4DEV§6 version was found!");
+ }
+ if (publicVersion.toLowerCase().contains("beta")) {
+ T2Csend.console("§6A new §2BETA§6 version was found!");
+ }
+ if (publicVersion.toLowerCase().contains("snapshot")) {
+ T2Csend.console("§6A new §eSNAPSHOT§6 version was found!");
+ }
+ } else {
+ T2Csend.console("§6A new version was found!");
+ }
+ T2Csend.console("§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion);
+ T2Csend.console("§6You can download it here: §ehttps://www.spigotmc.org/resources/" + spigot);
+ T2Csend.console("§6You can find more information on Discord: §e" + discord);
+ T2Csend.console("§4=========== " + prefix + " §4===========");
+ }
+
+ private static Boolean load = false;
+
+ public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ (new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> {
+ T2CupdateObject update = new T2CupdateObject(
+ plugin.getName(),
+ plugin.getDescription().getVersion(),
+ update_version
+ );
+ pluginVersions.put(plugin.getName(), update);
+ if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
+ if (!load) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ load = true;
+ sendUpdateMsg(prefix, spigotID, discord, plugin);
+ }
+ }.runTaskLaterAsynchronously(plugin, 600L);
+ } else sendUpdateMsg(prefix, spigotID, discord, plugin);
+ } else {
+ T2Csend.console(prefix + " §2No update found.");
+ }
+ }, prefix, plugin.getDescription().getVersion());
+ }
+ }.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java
new file mode 100644
index 0000000..7183967
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateChecker.java
@@ -0,0 +1,66 @@
+package net.t2code.t2codelib.SPIGOT.api.update;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Scanner;
+import java.util.function.Consumer;
+
+public class T2CupdateChecker {
+ private JavaPlugin plugin;
+ private int resourceId;
+
+ public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
+ this.plugin = plugin;
+ this.resourceId = resourceId;
+ }
+
+ public void getVersion(Consumer consumer, String Prefix, String pluginVersion) {
+ if (!plugin.isEnabled()) {
+ return;
+ }
+ Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
+ try {
+ InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
+ try {
+ Scanner scanner = new Scanner(inputStream);
+
+ try {
+ if (scanner.hasNext()) {
+ consumer.accept(scanner.next());
+ }
+ } catch (Throwable var8) {
+ try {
+ scanner.close();
+ } catch (Throwable var7) {
+ var8.addSuppressed(var7);
+ }
+ throw var8;
+ }
+ scanner.close();
+ } catch (Throwable var9) {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (Throwable var6) {
+ var9.addSuppressed(var6);
+ }
+ }
+ throw var9;
+ }
+ inputStream.close();
+ } catch (IOException var10) {
+ T2CupdateObject update = new T2CupdateObject(
+ plugin.getName(),
+ pluginVersion,
+ null
+ );
+ T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
+ this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
+ }
+ });
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java
new file mode 100644
index 0000000..b2bc938
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/update/T2CupdateObject.java
@@ -0,0 +1,16 @@
+package net.t2code.t2codelib.SPIGOT.api.update;
+
+public class T2CupdateObject {
+
+ public String pluginName;
+ public String pluginVersion;
+ public String publicVersion;
+
+ public T2CupdateObject(String pluginName,
+ String pluginVersion,
+ String publicVersion ) {
+ this.pluginName = pluginName;
+ this.pluginVersion = pluginVersion;
+ this.publicVersion = publicVersion;
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2Cconfig.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2Cconfig.java
new file mode 100644
index 0000000..29b0abd
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/api/yaml/T2Cconfig.java
@@ -0,0 +1,161 @@
+package net.t2code.t2codelib.SPIGOT.api.yaml;
+
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
+import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
+import org.bukkit.Sound;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class T2Cconfig {
+ public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void set(String path, YamlConfiguration YamlConfiguration) {
+ YamlConfiguration.set(path, null);
+ }
+
+ public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void set(String path, List value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
+ if (!YamlConfiguration.contains(path)) {
+ YamlConfiguration.set(path, value);
+ }
+ }
+
+ public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) {
+ set("Sound." + soundName + ".Enable", true, yamlConfiguration);
+ String sound;
+ if (T2CmcVersion.isMc1_8()) {
+ sound = sound1_8.toString();
+ } else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
+ sound = sound1_9.toString();
+ } else sound = sound1_13.toString();
+ set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
+ }
+
+ public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
+ set("Sound." + soundName + ".Enable", true, yamlConfiguration);
+ String sound;
+ if (T2CmcVersion.isMc1_8()) {
+ sound = sound1_8.toString();
+ } else sound = sound1_13.toString();
+ set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
+ }
+
+ public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
+ set("Sound." + soundName + ".Enable", true, yamlConfiguration);
+ set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration);
+ }
+
+ public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) {
+ return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration);
+ }
+
+ public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) {
+ return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration);
+ }
+
+ public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) {
+ String SOUND;
+ if (T2CmcVersion.isMc1_8()) {
+ SOUND = sound1_8;
+ } else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
+ SOUND = sound1_9;
+ } else SOUND = sound1_13;
+
+ return checkSound(SOUND, selectSoundFromConfig, prefix);
+ }
+
+ public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
+ String SOUND;
+ if (T2CmcVersion.isMc1_8()) {
+ SOUND = sound1_8;
+ } else SOUND = sound1_13;
+
+ return checkSound(SOUND, selectSoundFromConfig, prefix);
+ }
+
+ public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
+ try {
+ return Sound.valueOf(selectSoundFromConfig);
+ } catch (Exception e) {
+ T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", prefix)
+ .replace("[sound]", "§8Buy: §6" + selectSoundFromConfig) + "§4\n§4\n§4\n");
+ return Sound.valueOf(sound);
+ }
+ }
+
+ public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) {
+ return T2Creplace.replace(prefix, yamlConfiguration.getString(path));
+ }
+
+
+ public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) {
+ return (yamlConfiguration.getInt(path));
+ }
+
+ public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
+ return (yamlConfiguration.getBoolean(path));
+ }
+
+ public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
+ return (yamlConfiguration.getDouble(path));
+ }
+
+ public static List selectList(String path, YamlConfiguration yamlConfiguration) {
+ return (yamlConfiguration.getStringList(path));
+ }
+
+ public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
+ return (yamlConfiguration.getItemStack(path));
+ }
+
+
+ public static List selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
+ List output = new ArrayList<>();
+ List input = yamlConfiguration.getStringList(path);
+ for (String st : input) {
+ output.add(T2Creplace.replace(prefix, st));
+ }
+ return output;
+ }
+
+ public static void select(String prefix, List value, String path, YamlConfiguration yamlConfiguration) {
+ List output = new ArrayList<>();
+ List input = yamlConfiguration.getStringList(path);
+ for (String st : input) {
+ output.add(T2Creplace.replace(prefix, st));
+ }
+ value = output;
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java
new file mode 100644
index 0000000..d30f032
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CmdExecuter.java
@@ -0,0 +1,113 @@
+package net.t2code.t2codelib.SPIGOT.system;
+
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.SPIGOT.system.CreateReportLog;
+import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class CmdExecuter implements CommandExecutor, TabCompleter {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!sender.hasPermission("t2code.admin")) {
+ T2Csend.sender(sender, "§4No Permission §8t2code.admin");
+ return false;
+ }
+ if (args.length == 0) {
+ //todo T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeLibMain.getAutor(), T2CodeLibMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPlugin().getName()).publicVersion);
+ return false;
+ }
+ switch (args[0].toLowerCase()) {
+ case "info":
+ case "plugin":
+ case "pl":
+ case "version":
+ case "ver":
+ //todo T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeLibMain.getAutor(), T2CodeLibMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPerm().getName()).publicVersion);
+ return false;
+ case "reloadconfig":
+ SelectLibConfig.onSelect();
+ return false;
+ case "debug":
+ if (args.length != 2) {
+ T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
+ return false;
+ }
+ if ("createreportlog".equals(args[1].toLowerCase())) {
+ CreateReportLog.create(sender);
+ } else T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
+ return false;
+
+ default:
+ T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
+ return false;
+ }
+ }
+
+ //TabCompleter
+ private static HashMap arg1 = new HashMap() {{
+ put("debug", "t2code.admin");
+ put("info", "t2code.admin");
+ put("reloadconfig", "t2code.admin");
+ }};
+
+ @Override
+ public List onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
+ List list = new ArrayList<>();
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ if (args.length == 1) {
+ for (String command : arg1.keySet()) {
+ if (hasPermission(p, arg1.get(command)) && passend(command, args[0])) {
+ list.add(command);
+ }
+ }
+ }
+
+ if (args.length == 2 && args[0].equalsIgnoreCase("debug")) {
+ if (sender.hasPermission("t2code.admin")) {
+ if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) {
+ list.add("createReportLog");
+ }
+ }
+ return list;
+ }
+
+ }
+ return list;
+ }
+
+ private static Boolean passend(String command, String arg) {
+ for (int i = 0; i < arg.toUpperCase().length(); i++) {
+ if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
+ return false;
+ } else {
+ if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static boolean hasPermission(Player player, String permission) {
+ if (player.isOp()) {
+ return true;
+ }
+ String[] Permissions = permission.split(";");
+ for (String perm : Permissions) {
+ if (player.hasPermission(perm)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java
new file mode 100644
index 0000000..6dee9c9
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/CreateReportLog.java
@@ -0,0 +1,186 @@
+package net.t2code.t2codelib.SPIGOT.system;
+
+import net.t2code.luckyBox.api.LuckyBoxAPI;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
+import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
+import net.t2code.t2codelib.Util;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class CreateReportLog {
+ protected static void create(CommandSender sender) {
+ T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created...");
+ String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
+
+ File directory = new File(T2CodeLibMain.getPath() + "/DebugLogs");
+ if (!directory.exists()) {
+ directory.mkdir();
+ }
+
+ File file = new File(T2CodeLibMain.getPath(), "/DebugLogs/T2CodeLog.txt");
+ PrintWriter pWriter = null;
+ try {
+ pWriter = new PrintWriter(new FileWriter(file.getPath()));
+ String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime());
+ pWriter.println("Created on: " + timeStamp);
+ pWriter.println();
+ pWriter.println("Server Bukkit version: " + T2CmcVersion.getBukkitVersion());
+ pWriter.println("Server run on: " + T2CmcVersion.getMcVersion());
+ pWriter.println("Server NMS: " + T2CmcVersion.getNms());
+ pWriter.println();
+ pWriter.println("Online Mode: " + Bukkit.getOnlineMode());
+ pWriter.println("Worlds: " + Bukkit.getWorlds());
+ pWriter.println("OP-Player:");
+ for (OfflinePlayer player : Bukkit.getOperators()) {
+ pWriter.println(" - Player: " + player.getName() + " - " + player.getUniqueId());
+ }
+ pWriter.println();
+ if (Vault.vaultEnable) {
+ pWriter.println("Vault: " + Bukkit.getPluginManager().getPlugin("Vault").getName() + " - " + Bukkit.getPluginManager().getPlugin("Vault")
+ .getDescription().getVersion());
+ } else pWriter.println("Vault: not connected");
+ if (T2CodeLibMain.getEco() != null) {
+ String st = T2CodeLibMain.getEco().getName();
+ if (T2CodeLibMain.getEco().getName().equals("CMIEconomy")) st = "CMI";
+ if (Bukkit.getPluginManager().getPlugin(st) != null) {
+ pWriter.println("Economy: " + T2CodeLibMain.getEco().isEnabled() + " - " + st + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion());
+ } else pWriter.println("Economy: " + T2CodeLibMain.getEco().isEnabled() + " - " + st);
+ } else pWriter.println("Economy: not connected via vault");
+ if (T2CodeLibMain.getPerm() != null) {
+ if (Bukkit.getPluginManager().getPlugin(T2CodeLibMain.getPerm().getName()) != null) {
+ pWriter.println("Permission: " + T2CodeLibMain.getPerm().isEnabled() + " - " + T2CodeLibMain.getPerm().getName() + " - " + Bukkit.getPluginManager()
+ .getPlugin(T2CodeLibMain.getPerm().getName()).getDescription().getVersion());
+ } else pWriter.println("Permission: " + T2CodeLibMain.getPerm().isEnabled() + " - " + T2CodeLibMain.getPerm().getName());
+ } else pWriter.println("Permission: not connected via vault");
+ pWriter.println();
+ pWriter.println("Java: " + System.getProperty("java.version"));
+ pWriter.println("System: " + System.getProperty("os.name"));
+ pWriter.println("System: " + System.getProperty("os.version"));
+ pWriter.println("User Home: " + System.getProperty("user.home"));
+ pWriter.println();
+ pWriter.println("T2CodeLib: " + T2CodeLibMain.getPlugin().getDescription().getVersion());
+ pWriter.println();
+ if (T2CpluginCheck.luckyBox()) {
+ pWriter.println("T2C-PremiumPlugins: ");
+ pWriter.println("T2C-LuckyBox UID: " + LuckyBoxAPI.getUID());
+ pWriter.println("T2C-LuckyBox RID: " + LuckyBoxAPI.getRID());
+ pWriter.println("T2C-LuckyBox DID: " + LuckyBoxAPI.getDID());
+ pWriter.println("T2C-LuckyBox isP: " + LuckyBoxAPI.isP());
+ pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV());
+ pWriter.println();
+ }
+ pWriter.println("Plugins: ");
+ for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
+ pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription()
+ .getAuthors() + " - Website: " + pl.getDescription().getWebsite());
+ }
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ } finally {
+ if (pWriter != null) {
+ pWriter.flush();
+ pWriter.close();
+ }
+ }
+
+ String filePath = T2CodeLibMain.getPath() + "/DebugLogs/T2CodeLog.txt";
+ String log = "logs/latest.log";
+ String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip";
+ try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) {
+ File fileToZip = new File(filePath);
+ zip.putNextEntry(new ZipEntry(fileToZip.getName()));
+ Files.copy(fileToZip.toPath(), zip);
+
+ addFileToZip("", "logs/latest.log", zip, false);
+
+ for (String pl : Util.getT2cPlugins()){
+ pluginToDebug(pl, zip);
+ }
+ zip.closeEntry();
+ zip.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ file.delete();
+ if (sender instanceof Player) {
+ T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
+ T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
+ } else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
+
+ }
+
+ private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException {
+ if (T2CpluginCheck.pluginCheck(pluginName)) {
+ Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
+ File plConfigs = new File(plugin.getDataFolder().getPath());
+ if (plConfigs.exists()) {
+ addFolderToZip("T2Code-Plugins", plugin.getDataFolder().getPath(), zip);
+ }
+ File f = new File("plugins/");
+ File[] fileArray = f.listFiles();
+
+ for (File config : fileArray) {
+ if (config.getName().contains(pluginName) && config.getName().contains(".jar")) {
+ addFileToZip("T2Code-Plugins", config.getPath(), zip, false);
+ }
+ }
+ }
+ }
+
+ private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
+ File folder = new File(srcFolder);
+ if (folder.list() == null) {
+ addFileToZip(path + "/" + folder.getName(), srcFolder, zip, false);
+ } else if (folder.list().length == 0) {
+ addFileToZip(path, srcFolder, zip, true);
+ } else {
+ for (String fileName : folder.list()) {
+ if (path.equals("")) {
+ addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
+ } else {
+ addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
+ }
+ }
+ }
+ }
+
+ private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
+ File folder = new File(srcFile);
+ if (flag) {
+ zip.putNextEntry(new ZipEntry(path + "/" + folder.getName() + "/"));
+ } else {
+ if (folder.isDirectory()) {
+ addFolderToZip(path, srcFile, zip);
+ } else {
+ byte[] buf = new byte[1024];
+ int len;
+ FileInputStream in = new FileInputStream(srcFile);
+
+ if (path.equals("")) {
+ zip.putNextEntry(new ZipEntry((folder.getName())));
+ } else {
+ zip.putNextEntry(new ZipEntry((path + "/" + folder.getName())));
+ }
+
+ while ((len = in.read(buf)) > 0) {
+ try {
+ zip.write(buf, 0, len);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/JoinEvent.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/JoinEvent.java
new file mode 100644
index 0000000..e037ca8
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/JoinEvent.java
@@ -0,0 +1,17 @@
+// This claas was created by JaTiTV
+
+package net.t2code.t2codelib.SPIGOT.system;
+
+import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
+import net.t2code.t2codelib.Util;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerLoginEvent;
+
+public class JoinEvent implements Listener {
+
+ @EventHandler
+ public void onJoinEvent(PlayerLoginEvent event) {
+ T2CupdateAPI.join(T2CodeLibMain.getPlugin(), Util.getPrefix(),"t2code.lib.updatemsg",event.getPlayer(),Util.getSpigotID(),Util.getDiscord());
+ }
+}
\ No newline at end of file
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java
new file mode 100644
index 0000000..3a80041
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/T2CodeLibMain.java
@@ -0,0 +1,152 @@
+package net.t2code.t2codelib.SPIGOT.system;
+
+import net.kyori.adventure.platform.bukkit.BukkitAudiences;
+import net.milkbowl.vault.economy.Economy;
+import net.milkbowl.vault.permission.Permission;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
+import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
+import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
+import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
+import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics;
+import net.t2code.t2codelib.SPIGOT.system.config.config.ConfigCreate;
+import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
+import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate;
+import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
+import net.t2code.t2codelib.Util;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+import java.util.List;
+
+public final class T2CodeLibMain extends JavaPlugin {
+ private static T2CodeLibMain plugin;
+ private static Economy eco = null;
+ private static Permission perm = null;
+
+ private static List autor;
+ private static String version;
+
+ @Override
+ public void onEnable() {
+ // Plugin startup logic
+ plugin = this;
+ autor = plugin.getDescription().getAuthors();
+ version = plugin.getDescription().getVersion();
+ this.adventure = BukkitAudiences.create(this);
+ long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
+ String prefix = Util.getPrefix();
+
+ try {
+ Vault.loadVault();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ T2CmcVersion.onCheck();
+
+ if (T2CmcVersion.isMc1_19()) {
+ T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
+ T2Csend.console(prefix);
+ T2Csend.warning(plugin,"The 1.19.* is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net");
+ T2Csend.console(prefix);
+ T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ T2Csend.console(prefix + " §3Server run on: §6" + T2CmcVersion.getMcVersion() + " / " + T2CmcVersion.getNms());
+ if (eco != null) {
+ String st = eco.getName();
+ if (eco.getName().equals("CMIEconomy")) st = "CMI";
+ if (Bukkit.getPluginManager().getPlugin(st) != null) {
+ T2Csend.console(prefix + " §3Economy: §6" + eco.getName() + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion() + " §7- §e" +
+ (System.currentTimeMillis() - long_) + "ms");
+ } else T2Csend.console(prefix + " §3Economy: §6" + eco.getName() + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ } else T2Csend.console(prefix + " §3Economy: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+
+ if (perm != null) {
+ if (Bukkit.getPluginManager().getPlugin(perm.getName()) != null) {
+ T2Csend.console(prefix + " §3Permission plugin: §6" + perm.getName() + " - " + Bukkit.getPluginManager().getPlugin(perm.getName()).getDescription().getVersion()
+ + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ } else T2Csend.console(prefix + " §3Permission plugin: §6" + perm.getName() + " - §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ } else T2Csend.console(prefix + " §3Permission plugin: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+
+ if (T2CpluginCheck.papi()) {
+ T2Csend.console(prefix + " §3PlaceholderAPI: §6connected" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ }
+
+ plugin.getCommand("t2code").setExecutor(new CmdExecuter());
+ ConfigCreate.configCreate();
+ LanguagesCreate.langCreate();
+ SelectLibConfig.onSelect();
+ SelectLibMsg.onSelect();
+
+ T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getSpigotID(), Util.getDiscord());
+ Metrics.Bstats(plugin, Util.getBstatsID());
+
+ Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
+ T2Ctemplate.onLoadFooter(prefix, long_);
+ }
+
+ @Override
+ public void onDisable() {
+ // Plugin shutdown logic
+ if (SelectLibConfig.getInventoriesCloseByServerStop()) {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ player.closeInventory();
+ }
+ }
+ if(this.adventure != null) {
+ this.adventure.close();
+ this.adventure = null;
+ }
+
+ Vault.vaultDisable();
+ T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
+ }
+
+ public static File getPath() {
+ return plugin.getDataFolder();
+ }
+
+ static void setEco(Economy eco) {
+ T2CodeLibMain.eco = eco;
+ }
+
+ static void setPerm(Permission perm) {
+ T2CodeLibMain.perm = perm;
+ }
+
+ public static T2CodeLibMain getPlugin() {
+ return plugin;
+ }
+
+ public static Economy getEco() {
+ return eco;
+ }
+
+ public static Permission getPerm() {
+ return perm;
+ }
+
+ public static List getAutor() {
+ return autor;
+ }
+
+ public static String getVersion() {
+ return version;
+ }
+
+ private static BukkitAudiences adventure;
+
+ public static BukkitAudiences adventure() {
+ if (adventure == null) {
+ throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
+ }
+ return adventure;
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/Vault.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/Vault.java
new file mode 100644
index 0000000..15a4030
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/Vault.java
@@ -0,0 +1,48 @@
+package net.t2code.t2codelib.SPIGOT.system;
+
+import net.milkbowl.vault.economy.Economy;
+import net.milkbowl.vault.permission.Permission;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
+import net.t2code.t2codelib.Util;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+public class Vault {
+
+ public static Boolean vaultEnable;
+ public static Boolean connected;
+
+ public static void loadVault() throws InterruptedException {
+ long long_ = System.currentTimeMillis();
+ if (T2CodeLibMain.getPlugin().getServer().getPluginManager().getPlugin("Vault") != null) {
+ vaultEnable = true;
+ RegisteredServiceProvider eco = T2CodeLibMain.getPlugin().getServer().getServicesManager().getRegistration(Economy.class);
+ if (eco != null) {
+ T2CodeLibMain.setEco(eco.getProvider());
+ if (T2CodeLibMain.getEco() != null) {
+ connected = true;
+ T2Csend.console(Util.getPrefix() + " §2Vault / Economy successfully connected!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ } else {
+ connected = false;
+ T2Csend.console(Util.getPrefix() + " §4Economy could not be connected / found! [1]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ }
+ } else {
+ connected = false;
+ T2Csend.console(Util.getPrefix() + " §4Economy could not be connected / found! [2]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ }
+ RegisteredServiceProvider perm = T2CodeLibMain.getPlugin().getServer().getServicesManager().getRegistration(Permission.class);
+ if (perm != null) {
+ T2CodeLibMain.setPerm(perm.getProvider());
+ }
+ } else {
+ vaultEnable = false;
+ connected = false;
+ T2Csend.console(Util.getPrefix() + " §4Vault could not be connected! [3]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
+ }
+ }
+
+ public static void vaultDisable() {
+ if (!connected) return;
+ connected = false;
+ T2Csend.console(Util.getPrefix() + " §4Vault / Economy successfully deactivated.");
+ }
+}
diff --git a/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/bstats/Metrics.java b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/bstats/Metrics.java
new file mode 100644
index 0000000..c4d1bb2
--- /dev/null
+++ b/T2CodeLibNew/src/main/java/net/t2code/t2codelib/SPIGOT/system/bstats/Metrics.java
@@ -0,0 +1,851 @@
+// This claas was created by JaTiTV
+
+
+package net.t2code.t2codelib.SPIGOT.system.bstats;
+import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
+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.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import java.util.logging.Level;
+import java.util.stream.Collectors;
+import java.util.zip.GZIPOutputStream;
+
+public class Metrics {
+
+ public static void Bstats(Plugin plugin, int bstatsID) {
+ int pluginId = bstatsID; // <-- Replace with the id of your plugin!
+ Metrics metrics = new Metrics((JavaPlugin) plugin, pluginId);
+ metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(SelectLibConfig.getUpdateCheckOnJoin())));
+ }
+
+ private final Plugin plugin;
+
+ private final MetricsBase metricsBase;
+
+ /**
+ * Creates a new Metrics instance.
+ *
+ * @param plugin Your plugin instance.
+ * @param serviceId The id of the service. It can be found at What is my plugin id?
+ */
+ public Metrics(JavaPlugin plugin, int serviceId) {
+ this.plugin = plugin;
+ // Get the config file
+ File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
+ File configFile = new File(bStatsFolder, "config.yml");
+ YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
+ if (!config.isSet("serverUuid")) {
+ config.addDefault("enabled", true);
+ config.addDefault("serverUuid", UUID.randomUUID().toString());
+ config.addDefault("logFailedRequests", false);
+ config.addDefault("logSentData", false);
+ config.addDefault("logResponseStatusText", false);
+ // Inform the server owners about bStats
+ config
+ .options()
+ .header(
+ "bStats (https://bStats.org) collects some basic information for plugin authors, like how\n"
+ + "many people use their plugin and their total player count. It's recommended to keep bStats\n"
+ + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
+ + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
+ + "anonymous.")
+ .copyDefaults(true);
+ try {
+ config.save(configFile);
+ } catch (IOException ignored) {
+ }
+ }
+ // Load the data
+ boolean enabled = config.getBoolean("enabled", true);
+ String serverUUID = config.getString("serverUuid");
+ boolean logErrors = config.getBoolean("logFailedRequests", false);
+ boolean logSentData = config.getBoolean("logSentData", false);
+ boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
+ metricsBase =
+ new MetricsBase(
+ "bukkit",
+ serverUUID,
+ serviceId,
+ enabled,
+ this::appendPlatformData,
+ this::appendServiceData,
+ submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
+ plugin::isEnabled,
+ (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
+ (message) -> this.plugin.getLogger().log(Level.INFO, message),
+ logErrors,
+ logSentData,
+ logResponseStatusText);
+ }
+
+ /**
+ * Adds a custom chart.
+ *
+ * @param chart The chart to add.
+ */
+ public void addCustomChart(CustomChart chart) {
+ metricsBase.addCustomChart(chart);
+ }
+
+ private void appendPlatformData(JsonObjectBuilder builder) {
+ builder.appendField("playerAmount", getPlayerAmount());
+ builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0);
+ builder.appendField("bukkitVersion", Bukkit.getVersion());
+ builder.appendField("bukkitName", Bukkit.getName());
+ builder.appendField("javaVersion", System.getProperty("java.version"));
+ builder.appendField("osName", System.getProperty("os.name"));
+ builder.appendField("osArch", System.getProperty("os.arch"));
+ builder.appendField("osVersion", System.getProperty("os.version"));
+ builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
+ }
+
+ private void appendServiceData(JsonObjectBuilder builder) {
+ builder.appendField("pluginVersion", plugin.getDescription().getVersion());
+ }
+
+ private int getPlayerAmount() {
+ try {
+ // Around MC 1.8 the return type was changed from an array to a collection,
+ // This fixes java.lang.NoSuchMethodError:
+ // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
+ Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
+ return onlinePlayersMethod.getReturnType().equals(Collection.class)
+ ? ((Collection>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
+ : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
+ } catch (Exception e) {
+ // Just use the new method if the reflection failed
+ return Bukkit.getOnlinePlayers().size();
+ }
+ }
+
+ public static class MetricsBase {
+
+ /**
+ * The version of the Metrics class.
+ */
+ public static final String METRICS_VERSION = "2.2.1";
+
+ private static final ScheduledExecutorService scheduler =
+ Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
+
+ private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
+
+ private final String platform;
+
+ private final String serverUuid;
+
+ private final int serviceId;
+
+ private final Consumer appendPlatformDataConsumer;
+
+ private final Consumer appendServiceDataConsumer;
+
+ private final Consumer submitTaskConsumer;
+
+ private final Supplier checkServiceEnabledSupplier;
+
+ private final BiConsumer errorLogger;
+
+ private final Consumer infoLogger;
+
+ private final boolean logErrors;
+
+ private final boolean logSentData;
+
+ private final boolean logResponseStatusText;
+
+ private final Set customCharts = new HashSet<>();
+
+ private final boolean enabled;
+
+ /**
+ * 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 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.
+ */
+ public MetricsBase(
+ String platform,
+ String serverUuid,
+ int serviceId,
+ boolean enabled,
+ Consumer appendPlatformDataConsumer,
+ Consumer appendServiceDataConsumer,
+ Consumer submitTaskConsumer,
+ Supplier checkServiceEnabledSupplier,
+ BiConsumer errorLogger,
+ Consumer infoLogger,
+ boolean logErrors,
+ boolean logSentData,
+ boolean logResponseStatusText) {
+ this.platform = platform;
+ this.serverUuid = serverUuid;
+ this.serviceId = serviceId;
+ this.enabled = enabled;
+ this.appendPlatformDataConsumer = appendPlatformDataConsumer;
+ this.appendServiceDataConsumer = appendServiceDataConsumer;
+ this.submitTaskConsumer = submitTaskConsumer;
+ this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
+ this.errorLogger = errorLogger;
+ this.infoLogger = infoLogger;
+ this.logErrors = logErrors;
+ this.logSentData = logSentData;
+ this.logResponseStatusText = logResponseStatusText;
+ checkRelocation();
+ if (enabled) {
+ startSubmitting();
+ }
+ }
+
+ public void addCustomChart(CustomChart chart) {
+ this.customCharts.add(chart);
+ }
+
+ private void startSubmitting() {
+ final Runnable submitTask =
+ () -> {
+ if (!enabled || !checkServiceEnabledSupplier.get()) {
+ // Submitting data or service is disabled
+ scheduler.shutdown();
+ return;
+ }
+ if (submitTaskConsumer != null) {
+ submitTaskConsumer.accept(this::submitData);
+ } else {
+ this.submitData();
+ }
+ };
+ // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution
+ // of requests on the
+ // bStats backend. To circumvent this problem, we introduce some randomness into the initial
+ // and second delay.
+ // WARNING: You must not modify and part of this Metrics class, including the submit delay or
+ // frequency!
+ // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
+ long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
+ long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
+ scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
+ scheduler.scheduleAtFixedRate(
+ submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
+ }
+
+ private void submitData() {
+ final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
+ appendPlatformDataConsumer.accept(baseJsonBuilder);
+ final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
+ appendServiceDataConsumer.accept(serviceJsonBuilder);
+ JsonObjectBuilder.JsonObject[] chartData =
+ customCharts.stream()
+ .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
+ .filter(Objects::nonNull)
+ .toArray(JsonObjectBuilder.JsonObject[]::new);
+ serviceJsonBuilder.appendField("id", serviceId);
+ serviceJsonBuilder.appendField("customCharts", chartData);
+ baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
+ baseJsonBuilder.appendField("serverUUID", serverUuid);
+ baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
+ JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
+ scheduler.execute(
+ () -> {
+ try {
+ // Send the data
+ sendData(data);
+ } catch (Exception e) {
+ // Something went wrong! :(
+ if (logErrors) {
+ errorLogger.accept("Could not submit bStats metrics data", e);
+ }
+ }
+ });
+ }
+
+ private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
+ if (logSentData) {
+ infoLogger.accept("Sent bStats metrics data: " + data.toString());
+ }
+ String url = String.format(REPORT_URL, platform);
+ HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
+ // Compress the data to save bandwidth
+ byte[] compressedData = compress(data.toString());
+ connection.setRequestMethod("POST");
+ connection.addRequestProperty("Accept", "application/json");
+ connection.addRequestProperty("Connection", "close");
+ connection.addRequestProperty("Content-Encoding", "gzip");
+ connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
+ connection.setRequestProperty("Content-Type", "application/json");
+ connection.setRequestProperty("User-Agent", "Metrics-Service/1");
+ connection.setDoOutput(true);
+ try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
+ outputStream.write(compressedData);
+ }
+ StringBuilder builder = new StringBuilder();
+ try (BufferedReader bufferedReader =
+ new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ builder.append(line);
+ }
+ }
+ if (logResponseStatusText) {
+ infoLogger.accept("Sent data to bStats and received response: " + builder);
+ }
+ }
+
+ /**
+ * 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'});
+ final String examplePackage =
+ 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)
+ || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
+ throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
+ }
+ }
+ }
+
+ /**
+ * Gzips the given string.
+ *
+ * @param str The string to gzip.
+ * @return The gzipped string.
+ */
+ private static byte[] compress(final String str) throws IOException {
+ if (str == null) {
+ return null;
+ }
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
+ gzip.write(str.getBytes(StandardCharsets.UTF_8));
+ }
+ return outputStream.toByteArray();
+ }
+ }
+
+ public static class AdvancedBarChart extends CustomChart {
+
+ private final Callable