valueEntry : map.get(entryValues.getKey()).entrySet()) {
- valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
- allSkipped = false;
- }
- if (!allSkipped) {
- reallyAllSkipped = false;
- valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
- }
- }
- if (reallyAllSkipped) {
- // Null = skip the chart
- return null;
- }
- return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
- }
- }
-
- /**
- * An extremely simple JSON builder.
- *
- * While this class is neither feature-rich nor the most performant one, it's sufficient enough
- * for its use-case.
- */
- public static class JsonObjectBuilder {
-
- private StringBuilder builder = new StringBuilder();
-
- private boolean hasAtLeastOneField = false;
-
- public JsonObjectBuilder() {
- builder.append("{");
- }
-
- /**
- * Appends a null field to the JSON.
- *
- * @param key The key of the field.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendNull(String key) {
- appendFieldUnescaped(key, "null");
- return this;
- }
-
- /**
- * Appends a string field to the JSON.
- *
- * @param key The key of the field.
- * @param value The value of the field.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, String value) {
- if (value == null) {
- throw new IllegalArgumentException("JSON value must not be null");
- }
- appendFieldUnescaped(key, "\"" + escape(value) + "\"");
- return this;
- }
-
- /**
- * Appends an integer field to the JSON.
- *
- * @param key The key of the field.
- * @param value The value of the field.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, int value) {
- appendFieldUnescaped(key, String.valueOf(value));
- return this;
- }
-
- /**
- * Appends an object to the JSON.
- *
- * @param key The key of the field.
- * @param object The object.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, JsonObject object) {
- if (object == null) {
- throw new IllegalArgumentException("JSON object must not be null");
- }
- appendFieldUnescaped(key, object.toString());
- return this;
- }
-
- /**
- * Appends a string array to the JSON.
- *
- * @param key The key of the field.
- * @param values The string array.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, String[] values) {
- if (values == null) {
- throw new IllegalArgumentException("JSON values must not be null");
- }
- String escapedValues =
- Arrays.stream(values)
- .map(value -> "\"" + escape(value) + "\"")
- .collect(Collectors.joining(","));
- appendFieldUnescaped(key, "[" + escapedValues + "]");
- return this;
- }
-
- /**
- * Appends an integer array to the JSON.
- *
- * @param key The key of the field.
- * @param values The integer array.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, int[] values) {
- if (values == null) {
- throw new IllegalArgumentException("JSON values must not be null");
- }
- String escapedValues =
- Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
- appendFieldUnescaped(key, "[" + escapedValues + "]");
- return this;
- }
-
- /**
- * Appends an object array to the JSON.
- *
- * @param key The key of the field.
- * @param values The integer array.
- * @return A reference to this object.
- */
- public JsonObjectBuilder appendField(String key, JsonObject[] values) {
- if (values == null) {
- throw new IllegalArgumentException("JSON values must not be null");
- }
- String escapedValues =
- Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
- appendFieldUnescaped(key, "[" + escapedValues + "]");
- return this;
- }
-
- /**
- * Appends a field to the object.
- *
- * @param key The key of the field.
- * @param escapedValue The escaped value of the field.
- */
- private void appendFieldUnescaped(String key, String escapedValue) {
- if (builder == null) {
- throw new IllegalStateException("JSON has already been built");
- }
- if (key == null) {
- throw new IllegalArgumentException("JSON key must not be null");
- }
- if (hasAtLeastOneField) {
- builder.append(",");
- }
- builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
- hasAtLeastOneField = true;
- }
-
- /**
- * Builds the JSON string and invalidates this builder.
- *
- * @return The built JSON string.
- */
- public JsonObject build() {
- if (builder == null) {
- throw new IllegalStateException("JSON has already been built");
- }
- JsonObject object = new JsonObject(builder.append("}").toString());
- builder = null;
- return object;
- }
-
- /**
- * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
- *
- *
This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
- * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
- *
- * @param value The value to escape.
- * @return The escaped value.
- */
- private static String escape(String value) {
- final StringBuilder builder = new StringBuilder();
- for (int i = 0; i < value.length(); i++) {
- char c = value.charAt(i);
- if (c == '"') {
- builder.append("\\\"");
- } else if (c == '\\') {
- builder.append("\\\\");
- } else if (c <= '\u000F') {
- builder.append("\\u000").append(Integer.toHexString(c));
- } else if (c <= '\u001F') {
- builder.append("\\u00").append(Integer.toHexString(c));
- } else {
- builder.append(c);
- }
- }
- return builder.toString();
- }
-
- /**
- * A super simple representation of a JSON object.
- *
- *
This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
- * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
- * JsonObject)}.
- */
- public static class JsonObject {
-
- private final String value;
-
- private JsonObject(String value) {
- this.value = value;
- }
-
- @Override
- public String toString() {
- return value;
- }
- }
- }
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/files/FileManager.java b/src/main/java/net/zerotoil/dev/cybercore/files/FileManager.java
deleted file mode 100644
index 91247f6..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/files/FileManager.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package net.zerotoil.dev.cybercore.files;
-
-import net.zerotoil.dev.cybercore.CyberCore;
-import org.bukkit.configuration.Configuration;
-
-import java.util.HashMap;
-
-public class FileManager {
-
- private final CyberCore main;
- private final HashMap files = new HashMap<>();
-
- public FileManager(CyberCore main) {
- this.main = main;
- }
-
- public void load(String... additionalFiles) {
- load(true, true, additionalFiles);
- }
-
- public void load(boolean sendMessages, boolean defaultFiles, String... fileNames) {
- if (!files.isEmpty()) files.clear();
- if (sendMessages) main.logger(main.themeColor() + "Loading YAML files...");
- long startTime = System.currentTimeMillis();
-
- if (defaultFiles) {
- addFile("config", sendMessages);
- addFile("lang", sendMessages);
- }
-
- for (String string : fileNames) addFile(string, sendMessages);
-
- if (sendMessages) main.logger("&7Loaded &e" + files.size() + "&7 files in &a" + (System.currentTimeMillis() - startTime) + "ms&7.", "&7");
- }
-
- public void addFile(String file, boolean sendMessages) {
- files.put(file, new YAMLFile(main, main.getPlugin(), file + ".yml"));
- files.get(file).reloadConfig();
- if (sendMessages) main.logger("&7Loaded file &e" + file + ".yml&7.");
- }
-
-
- public HashMap getFiles() {
- return this.files;
- }
- public YAMLFile get(String file){
- return files.get(file);
- }
- public Configuration getConfig(String file) {
- return files.get(file).getConfig();
- }
-
-
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/files/YAMLFile.java b/src/main/java/net/zerotoil/dev/cybercore/files/YAMLFile.java
deleted file mode 100644
index 11dcfe9..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/files/YAMLFile.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package net.zerotoil.dev.cybercore.files;
-
-import net.zerotoil.dev.cybercore.CyberCore;
-import net.zerotoil.dev.cybercore.files.configupdater.ConfigUpdater;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-
-import java.io.IOException;
-import java.util.Collections;
-
-public class YAMLFile {
-
- private final CyberCore main;
- private final JavaPlugin plugin;
- private java.io.File configFile;
- private FileConfiguration dataConfig;
- private final String location;
- private final String name;
-
- public YAMLFile(CyberCore main, JavaPlugin plugin, String location) {
- this.main = main;
- this.plugin = plugin;
- this.location = location;
- this.name = location.replace(".yml", "");
- saveDefaultConfig();
- dataConfig = YamlConfiguration.loadConfiguration(getFile());
- }
-
- private java.io.File getFile() {
- return new java.io.File(plugin.getDataFolder(), location);
- }
-
- public FileConfiguration getConfig() {
- return dataConfig;
- }
-
- public void saveConfig() throws IOException {
- if (!((this.dataConfig == null) || (this.configFile == null))) {
- this.getConfig().save(this.configFile);
- }
- }
-
- public void updateConfig() {
- try {
- ConfigUpdater.update(plugin, location, getFile(), Collections.emptyList());
- if (main.isLegacy()) ConfigUpdater.update(plugin, location, getFile(), Collections.emptyList());
- } catch (IOException e) {
- e.printStackTrace();
- }
- reloadConfig();
- }
-
- public void reloadConfig() {
- dataConfig = YamlConfiguration.loadConfiguration(getFile());
- }
-
- public void saveDefaultConfig() {
- if (configFile == null) {
- configFile = getFile();
- }
-
- if (configFile.exists()) {
- return;
- }
- plugin.saveResource(location, false);
- }
-
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/ConfigUpdater.java b/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/ConfigUpdater.java
deleted file mode 100644
index e450ba9..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/ConfigUpdater.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package net.zerotoil.dev.cybercore.files.configupdater;
-
-import com.google.common.base.Preconditions;
-import org.bukkit.Bukkit;
-import org.bukkit.configuration.ConfigurationSection;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.Plugin;
-
-import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ConfigUpdater {
-
- //Used for separating keys in the keyBuilder inside parseComments method
- private static final char SEPARATOR = '.';
-
- public static void update(Plugin plugin, String resourceName, File toUpdate, List ignoredSections) throws IOException {
- Preconditions.checkArgument(toUpdate.exists(), "The toUpdate file doesn't exist!");
-
- FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource(resourceName), StandardCharsets.UTF_8));
- FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(toUpdate);
- Map comments = parseComments(plugin, resourceName, defaultConfig);
- Map ignoredSectionsValues = parseIgnoredSections(toUpdate, currentConfig, comments, ignoredSections == null ? Collections.emptyList() : ignoredSections);
-
- // will write updated config file "contents" to a string
- StringWriter writer = new StringWriter();
- write(defaultConfig, currentConfig, new BufferedWriter(writer), comments, ignoredSectionsValues);
- String value = replace(writer.toString()); // config contents
-
- Path toUpdatePath = toUpdate.toPath();
- if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) { // if updated contents are not the same as current file contents, update
- Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
- }
- }
-
- private static int getVersion() {
- return Integer.parseInt(Bukkit.getBukkitVersion().split("-")[0].split("\\.")[1]);
- }
-
- private static String replace(String string) {
- if (getVersion() < 13)
- return string.replace("\\xe2", "").replace("\\u20ac", "-").replace("\\u2022", "-")
- .replace("\\u017e", "-").replace("\\xbc", "").replace("\\xc2", ">")
- .replace("\\xbb", ">").replace("\\", "").replace("- -", "--")
- .replace("---------------------------------------------------------", "-----------------------------------------------");
- return string;
- }
-
- private static void write(FileConfiguration defaultConfig, FileConfiguration currentConfig, BufferedWriter writer, Map comments, Map ignoredSectionsValues) throws IOException {
- //Used for converting objects to yaml, then cleared
- FileConfiguration parserConfig = new YamlConfiguration();
-
- keyLoop: for (String fullKey : defaultConfig.getKeys(true)) {
- String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
-
- if (ignoredSectionsValues.isEmpty()) {
- writeCommentIfExists(comments, writer, fullKey, indents);
- } else {
- for (Map.Entry entry : ignoredSectionsValues.entrySet()) {
- if (entry.getKey().equals(fullKey)) {
- writer.write(replace(entry.getValue()) + "\n");
- continue keyLoop;
- } else if (KeyBuilder.isSubKeyOf(entry.getKey(), fullKey, SEPARATOR)) {
- continue keyLoop;
- } else {
- writeCommentIfExists(comments, writer, fullKey, indents);
- }
- }
- }
-
- Object currentValue = currentConfig.get(fullKey);
-
- if (currentValue == null)
- currentValue = defaultConfig.get(fullKey);
-
- String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
- String trailingKey = splitFullKey[splitFullKey.length - 1];
-
- if (currentValue instanceof ConfigurationSection) {
- writer.write(indents + trailingKey + ":");
-
- if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty())
- writer.write("\n");
- else
- writer.write(" {}\n");
-
- continue;
- }
-
- parserConfig.set(trailingKey, currentValue);
- String yaml = parserConfig.saveToString();
- yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
- String toWrite = indents + yaml + "\n";
- parserConfig.set(trailingKey, null);
- writer.write(toWrite);
- }
-
- String danglingComments = comments.get(null);
-
- if (danglingComments != null)
- writer.write(danglingComments);
-
- writer.close();
- }
-
- //Returns a map of key comment pairs. If a key doesn't have any comments it won't be included in the map.
- private static Map parseComments(Plugin plugin, String resourceName, FileConfiguration defaultConfig) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName)));
- Map comments = new LinkedHashMap<>();
- StringBuilder commentBuilder = new StringBuilder();
- KeyBuilder keyBuilder = new KeyBuilder(defaultConfig, SEPARATOR);
-
- String line;
- while ((line = reader.readLine()) != null) {
- String trimmedLine = line.trim();
-
- //Only getting comments for keys. A list/array element comment(s) not supported
- if (trimmedLine.startsWith("-")) {
- continue;
- }
-
- if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {//Is blank line or is comment
- commentBuilder.append(trimmedLine).append("\n");
- } else {//is a valid yaml key
- keyBuilder.parseLine(trimmedLine);
- String key = keyBuilder.toString();
-
- //If there is a comment associated with the key it is added to comments map and the commentBuilder is reset
- if (commentBuilder.length() > 0) {
- comments.put(key, commentBuilder.toString());
- commentBuilder.setLength(0);
- }
-
- //Remove the last key from keyBuilder if current path isn't a config section or if it is empty to prepare for the next key
- if (!keyBuilder.isConfigSectionWithKeys()) {
- keyBuilder.removeLastKey();
- }
- }
- }
-
- reader.close();
-
- if (commentBuilder.length() > 0)
- comments.put(null, commentBuilder.toString());
-
- return comments;
- }
-
- private static Map parseIgnoredSections(File toUpdate, FileConfiguration currentConfig, Map comments, List ignoredSections) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(toUpdate));
- Map ignoredSectionsValues = new LinkedHashMap<>(ignoredSections.size());
- KeyBuilder keyBuilder = new KeyBuilder(currentConfig, SEPARATOR);
- StringBuilder valueBuilder = new StringBuilder();
-
- String currentIgnoredSection = null;
- String line;
- while ((line = reader.readLine()) != null) {
- String trimmedLine = line.trim();
-
- if (trimmedLine.isEmpty() || trimmedLine.startsWith("#") || trimmedLine.startsWith("-"))
- continue;
-
- keyBuilder.parseLine(trimmedLine);
- String fullKey = keyBuilder.toString();
-
- //If building the value for an ignored section and this line is no longer a part of the ignored section,
- // write the valueBuilder, reset it, and set the current ignored section to null
- if (currentIgnoredSection != null && !KeyBuilder.isSubKeyOf(currentIgnoredSection, fullKey, SEPARATOR)) {
- ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
- valueBuilder.setLength(0);
- currentIgnoredSection = null;
- }
-
- for (String ignoredSection : ignoredSections) {
- boolean isIgnoredParent = ignoredSection.equals(fullKey);
-
- if (isIgnoredParent || keyBuilder.isSubKeyOf(ignoredSection)) {
- if (valueBuilder.length() > 0)
- valueBuilder.append("\n");
-
- String comment = comments.get(fullKey);
-
- if (comment != null) {
- String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
- valueBuilder.append(indents).append(comment.replace("\n", "\n" + indents));//Should end with new line (\n)
- valueBuilder.setLength(valueBuilder.length() - indents.length());//Get rid of trailing \n and spaces
- }
-
- valueBuilder.append(line);
-
- //Set the current ignored section for future iterations of while loop
- //Don't set currentIgnoredSection to any ignoredSection sub-keys
- if (isIgnoredParent)
- currentIgnoredSection = fullKey;
-
- break;
- }
- }
- }
-
- reader.close();
-
- if (valueBuilder.length() > 0)
- ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
-
- return ignoredSectionsValues;
- }
-
- private static void writeCommentIfExists(Map comments, BufferedWriter writer, String fullKey, String indents) throws IOException {
- String comment = comments.get(fullKey);
-
- //Comments always end with new line (\n)
- if (comment != null)
- //Replaces all '\n' with '\n' + indents except for the last one
- writer.write(indents + comment.substring(0, comment.length() - 1).replace("\n", "\n" + indents) + "\n");
- }
-
- //Input: 'key1.key2' Result: 'key1'
- private static void removeLastKey(StringBuilder keyBuilder) {
- if (keyBuilder.length() == 0)
- return;
-
- String keyString = keyBuilder.toString();
- //Must be enclosed in brackets in case a regex special character is the separator
- String[] split = keyString.split("[" + SEPARATOR + "]");
- //Makes sure begin index isn't < 0 (error). Occurs when there is only one key in the path
- int minIndex = Math.max(0, keyBuilder.length() - split[split.length - 1].length() - 1);
- keyBuilder.replace(minIndex, keyBuilder.length(), "");
- }
-
- private static void appendNewLine(StringBuilder builder) {
- if (builder.length() > 0)
- builder.append("\n");
- }
-
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/KeyBuilder.java b/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/KeyBuilder.java
deleted file mode 100644
index c901c8d..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/files/configupdater/KeyBuilder.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package net.zerotoil.dev.cybercore.files.configupdater;
-
-import org.bukkit.configuration.file.FileConfiguration;
-
-public class KeyBuilder implements Cloneable {
-
- private final FileConfiguration config;
- private final char separator;
- private final StringBuilder builder;
-
- public KeyBuilder(FileConfiguration config, char separator) {
- this.config = config;
- this.separator = separator;
- this.builder = new StringBuilder();
- }
-
- private KeyBuilder(KeyBuilder keyBuilder) {
- this.config = keyBuilder.config;
- this.separator = keyBuilder.separator;
- this.builder = new StringBuilder(keyBuilder.toString());
- }
-
- public void parseLine(String line) {
- line = line.trim();
- String[] currentSplitLine = line.split(":");
-
- //Checks keyBuilder path against config to see if the path is valid.
- //If the path doesn't exist in the config it keeps removing last key in keyBuilder.
- while (builder.length() > 0 && !config.contains(builder.toString() + separator + currentSplitLine[0])) {
- removeLastKey();
- }
-
- //Add the separator if there is already a key inside keyBuilder
- //If currentSplitLine[0] is 'key2' and keyBuilder contains 'key1' the result will be 'key1.' if '.' is the separator
- if (builder.length() > 0)
- builder.append(separator);
-
- //Appends the current key to keyBuilder
- //If keyBuilder is 'key1.' and currentSplitLine[0] is 'key2' the resulting keyBuilder will be 'key1.key2' if separator is '.'
- builder.append(currentSplitLine[0]);
- }
-
- public String getLastKey() {
- if (builder.length() == 0)
- return "";
-
- return builder.toString().split("[" + separator + "]")[0];
- }
-
- public boolean isEmpty() {
- return builder.length() == 0;
- }
-
- //Checks to see if the full key path represented by this instance is a sub-key of the key parameter
- public boolean isSubKeyOf(String parentKey) {
- return isSubKeyOf(parentKey, builder.toString(), separator);
- }
-
- //Checks to see if subKey is a sub-key of the key path this instance represents
- public boolean isSubKey(String subKey) {
- return isSubKeyOf(builder.toString(), subKey, separator);
- }
-
- public static boolean isSubKeyOf(String parentKey, String subKey, char separator) {
- if (parentKey.isEmpty())
- return false;
-
- return subKey.startsWith(parentKey)
- && subKey.substring(parentKey.length()).startsWith(String.valueOf(separator));
- }
-
- public static String getIndents(String key, char separator) {
- String[] splitKey = key.split("[" + separator + "]");
- StringBuilder builder = new StringBuilder();
-
- for (int i = 1; i < splitKey.length; i++) {
- builder.append(" ");
- }
-
- return builder.toString();
- }
-
- public boolean isConfigSection() {
- String key = builder.toString();
- return config.isConfigurationSection(key);
- }
-
- public boolean isConfigSectionWithKeys() {
- String key = builder.toString();
- return config.isConfigurationSection(key) && !config.getConfigurationSection(key).getKeys(false).isEmpty();
- }
-
- //Input: 'key1.key2' Result: 'key1'
- public void removeLastKey() {
- if (builder.length() == 0)
- return;
-
- String keyString = builder.toString();
- //Must be enclosed in brackets in case a regex special character is the separator
- String[] split = keyString.split("[" + separator + "]");
- //Makes sure begin index isn't < 0 (error). Occurs when there is only one key in the path
- int minIndex = Math.max(0, builder.length() - split[split.length - 1].length() - 1);
- builder.replace(minIndex, builder.length(), "");
- }
-
- @Override
- public String toString() {
- return builder.toString();
- }
-
- @Override
- protected KeyBuilder clone() {
- return new KeyBuilder(this);
- }
-}
-
diff --git a/src/main/java/net/zerotoil/dev/cybercore/objects/Lag.java b/src/main/java/net/zerotoil/dev/cybercore/objects/Lag.java
deleted file mode 100644
index e10a041..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/objects/Lag.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package net.zerotoil.dev.cybercore.objects;
-
-import org.bukkit.Bukkit;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-
-public class Lag implements Runnable {
-
- public static int TICK_COUNT = 0;
- public static long[] TICKS = new long[600];
- public static long LAST_TICK = 0L;
-
- public static double getTPS() {
- return getTPS(100);
- }
-
- public static double getTPS(int ticks) {
- try {
- if (TICK_COUNT < ticks)
- return 20.0D;
-
- int target = (TICK_COUNT - 1 - ticks) % TICKS.length;
- long elapsed = System.currentTimeMillis() - TICKS[target];
-
- double tps = ticks / (elapsed / 1000.0D);
- return Math.min(tps, 20.0);
- } catch (Exception e) {
- return 20.0;
- }
- }
-
- public static double getNewTPS() {
-
- if (!Bukkit.getServer().getVersion().contains("1.16.5")) return getTPS();
-
- String name1 = Bukkit.getServer().getClass().getPackage().getName();
- String version = name1.substring(name1.lastIndexOf('.') + 1);
-
- Class> mcsclass;
-
- Object si = null;
- Field tpsField = null;
-
- try {
- mcsclass = Class.forName("net.minecraft.server." + version + "." + "MinecraftServer");
-
- si = mcsclass.getMethod("getServer").invoke(null);
-
- tpsField = si.getClass().getField("recentTps");
-
- } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | NoSuchFieldException e) {
- e.printStackTrace();
- }
-
- double[] tps = null;
-
- try {
- tps = ((double[]) tpsField.get(si));
-
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
-
- if (tps[0] > 20) return 20;
- return tps[0];
- }
-
- public static double getLowerTPS() {
- return Math.min(getTPS(), getNewTPS());
- }
-
- public static long getElapsed(int tickID)
- {
- long time = TICKS[(tickID % TICKS.length)];
- return System.currentTimeMillis() - time;
- }
-
- public void run()
- {
- TICKS[(TICK_COUNT% TICKS.length)] = System.currentTimeMillis();
-
- TICK_COUNT += 1;
- }
-
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/utilities/GeneralUtils.java b/src/main/java/net/zerotoil/dev/cybercore/utilities/GeneralUtils.java
deleted file mode 100644
index 2af1a17..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/utilities/GeneralUtils.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package net.zerotoil.dev.cybercore.utilities;
-
-import me.croabeast.beanslib.utility.ArrayUtils;
-import me.croabeast.beanslib.utility.LibUtils;
-import me.croabeast.beanslib.utility.TextUtils;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.ThreadLocalRandom;
-
-public class GeneralUtils {
-
- /**
- * Combines two arrays into a new array of the same type.
- *
- * @author Kihsomray
- * @since 1.3
- *
- * @param array First array
- * @param additionalArrays Any additional arrays
- * @param Type of array (must be same)
- * @return New array of combined values
- */
- @Deprecated
- @SafeVarargs
- public static T[] combineArrays(@NotNull T[] array, @Nullable T[]... additionalArrays) {
- return ArrayUtils.combineArrays(array, additionalArrays);
- }
-
- /**
- * Gets a random double.
- *
- * @return Randomly generated double
- */
- public static double randomDouble() {
- return ThreadLocalRandom.current().nextDouble();
- }
-
- /**
- * Gets a random double within a bound.
- *
- * @param bound Bounds to generate within
- * @return Randomly generated double
- */
- public static double randomDouble(double bound) {
- return ThreadLocalRandom.current().nextDouble(bound);
- }
-
- /**
- * Gets a random integer.
- *
- * @return Randomly generated integer
- */
- public static int randomInt() {
- return ThreadLocalRandom.current().nextInt();
- }
-
- /**
- * Gets a random integer within a bound.
- *
- * @param bound Bounds to generate within
- * @return Randomly generated integer
- */
- public static int randomInt(int bound) {
- return ThreadLocalRandom.current().nextInt(bound);
- }
-
- /**
- * Gets a random long.
- *
- * @return Randomly generated long
- */
- public static long randomLong() {
- return ThreadLocalRandom.current().nextLong();
- }
-
- /**
- * Gets a random long within a bound.
- *
- * @param bound Bounds to generate within
- * @return Randomly generated long
- */
- public static long randomLong(long bound) {
- return ThreadLocalRandom.current().nextLong(bound);
- }
-
- /**
- * Version of Java that is currently running.
- *
- * @return Current version of java
- * @deprecated See {@link LibUtils#majorJavaVersion()}
- */
- @Deprecated
- public static int getJavaVersion() {
- return LibUtils.majorJavaVersion();
- }
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/utilities/PlayerUtils.java b/src/main/java/net/zerotoil/dev/cybercore/utilities/PlayerUtils.java
deleted file mode 100644
index f5632b7..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/utilities/PlayerUtils.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.zerotoil.dev.cybercore.utilities;
-
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.Nullable;
-
-public class PlayerUtils {
-
- private final static String[] plPlaceholders = new String[]{
- "player",
- "playerDisplayName",
- "playerUUID"
- };
-
- /**
- * Get the player's placeholders.
- *
- * @return Array of placeholders
- */
- public static String[] getPlPlaceholders() {
- return plPlaceholders;
- }
-
- /**
- * Get the player's placeholder replacements.
- *
- * @return Array of placeholder replacements
- */
- public static String[] getPlReplacements(Player player) {
- return new String[] {
- player.getName(),
- player.getDisplayName(),
- player.getUniqueId().toString()
- };
- }
-
- /**
- * replace placeholders within a message
- * with corresponding replacements.
- *
- * Use BeansLIB's replace placeholders instead.
- *
- * @param string String to replace placeholders
- * @param placeholders Array of placeholders
- * @param replacements Array of replacements
- * @return Replacements/placeholders applied to string
- */
- @Deprecated
- public static String replacePlaceholders(String string, String[] placeholders, String... replacements) {
- if (replacements.length < placeholders.length) throw new IllegalArgumentException();
-
- for (int i = 0; i < placeholders.length; i++) {
- string = string.replace("{" + placeholders[i] + "}", replacements[i]);
- }
-
- return string;
- }
-
- /**
- * Apply curly brackets (braces) around all
- * placeholders within the string array.
- *
- * @param placeholders Array of placeholder values
- * @return same array with placeholder applied
- */
- public static String[] applyPlaceholderBraces(@Nullable String[] placeholders) {
- if (placeholders == null) return null;
- for (int i = 0; i < placeholders.length; i++) placeholders[i] = "{" + placeholders[i] + "}";
- return placeholders;
- }
-
-}
diff --git a/src/main/java/net/zerotoil/dev/cybercore/utilities/TimeUtils.java b/src/main/java/net/zerotoil/dev/cybercore/utilities/TimeUtils.java
deleted file mode 100644
index 5a60460..0000000
--- a/src/main/java/net/zerotoil/dev/cybercore/utilities/TimeUtils.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package net.zerotoil.dev.cybercore.utilities;
-
-import me.croabeast.beanslib.Beans;
-import me.croabeast.beanslib.BeansLib;
-
-/**
- * Basic time utilities for any server.
- *
- * @author Kihsomray
- * @version 1.0
- */
-public class TimeUtils {
-
- // formatting strings
- private static String secondFormat = "{time} Second(s)";
- private static String minuteFormat = "{time} Minute(s)";
- private static String hourFormat = "{time} Hour(s)";
- private static String dayFormat = "{time} Day(s)";
- private static String splitterFormat = ", ";
-
- // fields needed for time formatter
- private static String pluralRegex = "\\s*\\([^)]*\\)\\s*";
- private static char startDelimiter = '(';
- private static char endDelimiter = ')';
-
- private static String colorize(String input) {
- return Beans.colorize(input);
- }
-
- /**
- * Takes in seconds and returns a very nicely formatted string
- * that can contain seconds, minutes, hours and days.
- *
- * @param seconds Amount of seconds to format
- * @return Formatted string with seconds, minutes, hours and days
- */
- public static String formatTime(long seconds) {
-
- // if time 0, return right away
- if (seconds <= 0) return colorize(checkPluralFormat(0, secondFormat));
-
- String formattedTime = "";
- long daysTotal, hoursTotal, minutesTotal;
-
- // gets day time
- daysTotal = getFixedTime(seconds, 86400);
- seconds = seconds - (daysTotal * 86400);
- if (daysTotal > 0) formattedTime += (checkPluralFormat(daysTotal, dayFormat) + splitterFormat);
-
- // gets hour time
- hoursTotal = getFixedTime(seconds, 3600);
- seconds = seconds - (hoursTotal * 3600);
- if (hoursTotal > 0) formattedTime += checkPluralFormat(hoursTotal, hourFormat) + splitterFormat;
-
- // gets minute time
- minutesTotal = getFixedTime(seconds, 60);
- seconds = seconds - (minutesTotal * 60);
- if (minutesTotal > 0) formattedTime += checkPluralFormat(minutesTotal, minuteFormat) + splitterFormat;
-
- // gets second time
- if (seconds > 0) formattedTime += checkPluralFormat(seconds, secondFormat + splitterFormat);
-
- // returns final string
- return colorize(formattedTime.substring(0, formattedTime.length() - splitterFormat.length()));
-
- }
-
- // gets proper time for a time format
- private static long getFixedTime(long seconds, long formatter) {
- long tempSeconds = seconds % formatter;
- return (seconds - tempSeconds) / formatter;
- }
-
- // checks plural formatting and applies it
- private static String checkPluralFormat(long value, String string) {
- string = string.replace("{time}", value + "");
- if (value == 1) return string.replaceAll(pluralRegex, "");
- else return string.replace(startDelimiter + "", "").replace(endDelimiter + "", "");
- }
-
- /**
- * Change the days in time formatter, placeholders: {time}.
- *
- * @param format string to use as days
- */
- public static void setDayFormat(String format) {
- dayFormat = format;
- }
-
- /**
- * Change the hours in time formatter, placeholders: {time}.
- *
- * @param format string to use as hours
- */
- public static void setHourFormat(String format) {
- hourFormat = format;
- }
-
- /**
- * Change the minutes in time formatter, placeholders: {time}.
- *
- * @param format string to use as minutes
- */
- public static void setMinuteFormat(String format) {
- minuteFormat = format;
- }
-
- /**
- * Change the seconds in time formatter, placeholders: {time}.
- *
- * @param format string to use as seconds
- */
- public static void setSecondFormat(String format) {
- secondFormat = format;
- }
-
- /**
- * Change the splitter in time formatter.
- *
- * @param format string to use as splitter
- */
- public static void setSplitterFormat(String format) {
- splitterFormat = format;
- }
-
- /**
- * When there is only one item, what should be replaced?
- *
- * @param regex a custom regex
- */
- public static void pluralRegexFormat(String regex) {
- pluralRegex = regex;
- }
-
- /**
- * Start delimiter for time formatter.
- *
- * @param delimiter Delimiter of your choice
- */
- public static void setStartDelimiter(char delimiter) {
- startDelimiter = delimiter;
- }
-
- /**
- * End delimiter for time formatter.
- *
- * @param delimiter Delimiter of your choice
- */
- public static void setEndDelimiter(char delimiter) {
- endDelimiter = delimiter;
- }
-
-}