From 3935c9b330bc009c67b260bb227a930354a93781 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 27 Mar 2022 10:33:19 +0000 Subject: [PATCH 1/5] Restyled by clang-format --- .../libby/BungeeLibraryManager.java | 69 +- .../common/libraries/libby/Library.java | 753 +++++++++--------- .../libraries/libby/LibraryManager.java | 748 ++++++++--------- .../common/libraries/libby/Repositories.java | 39 +- .../classloader/IsolatedClassLoader.java | 65 +- .../classloader/URLClassLoaderHelper.java | 403 +++++----- .../libraries/libby/logging/LogLevel.java | 32 +- .../libraries/libby/logging/Logger.java | 356 ++++----- .../libby/logging/adapters/JDKLogAdapter.java | 121 ++- .../libby/logging/adapters/LogAdapter.java | 30 +- .../libby/relocation/Relocation.java | 261 +++--- .../libby/relocation/RelocationHelper.java | 214 ++--- .../spigot/libby/BukkitLibraryManager.java | 69 +- 13 files changed, 1578 insertions(+), 1582 deletions(-) diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/libby/BungeeLibraryManager.java b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/libby/BungeeLibraryManager.java index 854a279..cb70ff9 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/libby/BungeeLibraryManager.java +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/libby/BungeeLibraryManager.java @@ -1,51 +1,50 @@ package dev.austech.betterstaffchat.bungeecord.libby; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.LibraryManager; import dev.austech.betterstaffchat.common.libraries.libby.classloader.URLClassLoaderHelper; import dev.austech.betterstaffchat.common.libraries.libby.logging.adapters.JDKLogAdapter; -import net.md_5.bungee.api.plugin.Plugin; - import java.net.URLClassLoader; import java.nio.file.Path; - -import static java.util.Objects.requireNonNull; +import net.md_5.bungee.api.plugin.Plugin; /** * A runtime dependency manager for Bungee plugins. */ public class BungeeLibraryManager extends LibraryManager { - /** - * Plugin classpath helper - */ - private final URLClassLoaderHelper classLoader; + /** + * Plugin classpath helper + */ + private final URLClassLoaderHelper classLoader; - /** - * Creates a new Bungee library manager. - * - * @param plugin the plugin to manage - */ - public BungeeLibraryManager(Plugin plugin) { - this(plugin, "lib"); - } + /** + * Creates a new Bungee library manager. + * + * @param plugin the plugin to manage + */ + public BungeeLibraryManager(Plugin plugin) { this(plugin, "lib"); } - /** - * Creates a new Bungee library manager. - * - * @param plugin the plugin to manage - * @param directoryName download directory name - */ - public BungeeLibraryManager(Plugin plugin, String directoryName) { - super(new JDKLogAdapter(requireNonNull(plugin, "plugin").getLogger()), plugin.getDataFolder().toPath(), directoryName); - classLoader = new URLClassLoaderHelper((URLClassLoader) plugin.getClass().getClassLoader(), this); - } + /** + * Creates a new Bungee library manager. + * + * @param plugin the plugin to manage + * @param directoryName download directory name + */ + public BungeeLibraryManager(Plugin plugin, String directoryName) { + super(new JDKLogAdapter(requireNonNull(plugin, "plugin").getLogger()), + plugin.getDataFolder().toPath(), directoryName); + classLoader = new URLClassLoaderHelper( + (URLClassLoader)plugin.getClass().getClassLoader(), this); + } - /** - * Adds a file to the Bungee plugin's classpath. - * - * @param file the file to add - */ - @Override - protected void addToClasspath(Path file) { - classLoader.addToClasspath(file); - } + /** + * Adds a file to the Bungee plugin's classpath. + * + * @param file the file to add + */ + @Override + protected void addToClasspath(Path file) { + classLoader.addToClasspath(file); + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Library.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Library.java index 019a53f..dc13f31 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Library.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Library.java @@ -1,17 +1,16 @@ package dev.austech.betterstaffchat.common.libraries.libby; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.LibraryManager; import dev.austech.betterstaffchat.common.libraries.libby.Repositories; import dev.austech.betterstaffchat.common.libraries.libby.relocation.Relocation; - import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.UUID; -import static java.util.Objects.requireNonNull; - /** * An immutable representation of a Maven artifact that can be downloaded, * relocated and then loaded into a plugin's classpath at runtime. @@ -19,493 +18,465 @@ * @see #builder() */ public class Library { + /** + * Direct download URLs for this library + */ + private final Collection urls; + + /** + * Repository URLs for this library + */ + private final Collection repositories; + + /** + * Library id (used by Isolated Class Loaders) + */ + private final String id; + + /** + * Maven group ID + */ + private final String groupId; + + /** + * Maven artifact ID + */ + private final String artifactId; + + /** + * Artifact version + */ + private final String version; + + /** + * Artifact classifier + */ + private final String classifier; + + /** + * Binary SHA-256 checksum for this library's jar file + */ + private final byte[] checksum; + + /** + * Jar relocations to apply + */ + private final Collection relocations; + + /** + * Relative Maven path to this library's artifact + */ + private final String path; + + /** + * Relative path to this library's relocated jar + */ + private final String relocatedPath; + + /** + * Should this library be loaded in an isolated class loader? + */ + private final boolean isolatedLoad; + + /** + * Creates a new library. + * + * @param urls direct download URLs + * @param id library ID + * @param groupId Maven group ID + * @param artifactId Maven artifact ID + * @param version artifact version + * @param classifier artifact classifier or null + * @param checksum binary SHA-256 checksum or null + * @param relocations jar relocations or null + * @param isolatedLoad isolated load for this library + */ + private Library(Collection urls, String id, String groupId, + String artifactId, String version, String classifier, + byte[] checksum, Collection relocations, + boolean isolatedLoad) { + + this(urls, null, id, groupId, artifactId, version, classifier, checksum, + relocations, isolatedLoad); + } + + /** + * Creates a new library. + * + * @param urls direct download URLs + * @param repositories repository URLs + * @param id library ID + * @param groupId Maven group ID + * @param artifactId Maven artifact ID + * @param version artifact version + * @param classifier artifact classifier or null + * @param checksum binary SHA-256 checksum or null + * @param relocations jar relocations or null + * @param isolatedLoad isolated load for this library + */ + private Library(Collection urls, Collection repositories, + String id, String groupId, String artifactId, String version, + String classifier, byte[] checksum, + Collection relocations, boolean isolatedLoad) { + + this.urls = urls != null + ? Collections.unmodifiableList(new LinkedList<>(urls)) + : Collections.emptyList(); + this.id = id != null ? id : UUID.randomUUID().toString(); + this.groupId = requireNonNull(groupId, "groupId").replace("{}", "."); + this.artifactId = requireNonNull(artifactId, "artifactId"); + this.version = requireNonNull(version, "version"); + this.classifier = classifier; + this.checksum = checksum; + this.relocations = + relocations != null + ? Collections.unmodifiableList(new LinkedList<>(relocations)) + : Collections.emptyList(); + + String path = this.groupId.replace('.', '/') + '/' + artifactId + '/' + + version + '/' + artifactId + '-' + version; + if (hasClassifier()) { + path += '-' + classifier; + } + + this.path = path + ".jar"; + + this.repositories = + repositories != null + ? Collections.unmodifiableList(new LinkedList<>(repositories)) + : Collections.emptyList(); + relocatedPath = + hasRelocations() ? artifactId + '-' + version + "-relocated.jar" : null; + this.isolatedLoad = isolatedLoad; + } + + /** + * Gets the direct download URLs for this library. + * + * @return direct download URLs + */ + public Collection getUrls() { return urls; } + + /** + * Gets the repositories URLs for this library. + * + * @return repositories URLs + */ + public Collection getRepositories() { return repositories; } + + /** + * Gets the library ID + * + * @return the library id + */ + public String getId() { return id; } + + /** + * Gets the Maven group ID for this library. + * + * @return Maven group ID + */ + public String getGroupId() { return groupId; } + + /** + * Gets the Maven artifact ID for this library. + * + * @return Maven artifact ID + */ + public String getArtifactId() { return artifactId; } + + /** + * Gets the artifact version for this library. + * + * @return artifact version + */ + public String getVersion() { return version; } + + /** + * Gets the artifact classifier for this library. + * + * @return artifact classifier or null + */ + public String getClassifier() { return classifier; } + + /** + * Gets whether this library has an artifact classifier. + * + * @return true if library has classifier, false otherwise + */ + public boolean hasClassifier() { return classifier != null; } + + /** + * Gets the binary SHA-256 checksum of this library's jar file. + * + * @return checksum or null + */ + public byte[] getChecksum() { return checksum; } + + /** + * Gets whether this library has a checksum. + * + * @return true if library has checksum, false otherwise + */ + public boolean hasChecksum() { return checksum != null; } + + /** + * Gets the jar relocations to apply to this library. + * + * @return jar relocations to apply + */ + public Collection getRelocations() { return relocations; } + + /** + * Gets whether this library has any jar relocations. + * + * @return true if library has relocations, false otherwise + */ + public boolean hasRelocations() { return !relocations.isEmpty(); } + + /** + * Gets the relative Maven path to this library's artifact. + * + * @return Maven path for this library + */ + public String getPath() { return path; } + + /** + * Gets the relative path to this library's relocated jar. + * + * @return path to relocated artifact or null if has no relocations + */ + public String getRelocatedPath() { return relocatedPath; } + + /** + * Is the library loaded isolated? + * + * @return true if the library is loaded isolated + */ + public boolean isIsolatedLoad() { return isolatedLoad; } + + /** + * Gets a concise, human-readable string representation of this library. + * + * @return string representation + */ + @Override + public String toString() { + String name = groupId + ':' + artifactId + ':' + version; + if (hasClassifier()) { + name += ':' + classifier; + } + + return name; + } + + /** + * Creates a new library builder. + * + * @return new library builder + */ + public static Builder builder() { return new Builder(); } + + /** + * Due to the constructor complexity of an immutable {@link Library}, + * instead this fluent builder is used to configure and then construct + * a new library. + */ + public static class Builder { /** * Direct download URLs for this library */ - private final Collection urls; + private final Collection urls = new LinkedList<>(); /** * Repository URLs for this library */ - private final Collection repositories; + private final Collection repositories = new LinkedList<>(); /** - * Library id (used by Isolated Class Loaders) + * The library ID */ - private final String id; + private String id; /** * Maven group ID */ - private final String groupId; + private String groupId; /** * Maven artifact ID */ - private final String artifactId; + private String artifactId; /** * Artifact version */ - private final String version; + private String version; /** * Artifact classifier */ - private final String classifier; + private String classifier; /** * Binary SHA-256 checksum for this library's jar file */ - private final byte[] checksum; + private byte[] checksum; /** - * Jar relocations to apply + * Isolated load */ - private final Collection relocations; + private boolean isolatedLoad; /** - * Relative Maven path to this library's artifact - */ - private final String path; - - /** - * Relative path to this library's relocated jar - */ - private final String relocatedPath; - - /** - * Should this library be loaded in an isolated class loader? - */ - private final boolean isolatedLoad; - - /** - * Creates a new library. - * - * @param urls direct download URLs - * @param id library ID - * @param groupId Maven group ID - * @param artifactId Maven artifact ID - * @param version artifact version - * @param classifier artifact classifier or null - * @param checksum binary SHA-256 checksum or null - * @param relocations jar relocations or null - * @param isolatedLoad isolated load for this library - */ - private Library(Collection urls, - String id, - String groupId, - String artifactId, - String version, - String classifier, - byte[] checksum, - Collection relocations, - boolean isolatedLoad) { - - this(urls, null, id, groupId, artifactId, version, classifier, checksum, relocations, isolatedLoad); - } - - /** - * Creates a new library. - * - * @param urls direct download URLs - * @param repositories repository URLs - * @param id library ID - * @param groupId Maven group ID - * @param artifactId Maven artifact ID - * @param version artifact version - * @param classifier artifact classifier or null - * @param checksum binary SHA-256 checksum or null - * @param relocations jar relocations or null - * @param isolatedLoad isolated load for this library - */ - private Library(Collection urls, - Collection repositories, - String id, - String groupId, - String artifactId, - String version, - String classifier, - byte[] checksum, - Collection relocations, - boolean isolatedLoad) { - - this.urls = urls != null ? Collections.unmodifiableList(new LinkedList<>(urls)) : Collections.emptyList(); - this.id = id != null ? id : UUID.randomUUID().toString(); - this.groupId = requireNonNull(groupId, "groupId").replace("{}", "."); - this.artifactId = requireNonNull(artifactId, "artifactId"); - this.version = requireNonNull(version, "version"); - this.classifier = classifier; - this.checksum = checksum; - this.relocations = relocations != null ? Collections.unmodifiableList(new LinkedList<>(relocations)) : Collections.emptyList(); - - String path = this.groupId.replace('.', '/') + '/' + artifactId + '/' + version + '/' + artifactId + '-' + version; - if (hasClassifier()) { - path += '-' + classifier; - } - - this.path = path + ".jar"; - - this.repositories = repositories != null ? Collections.unmodifiableList(new LinkedList<>(repositories)) : Collections.emptyList(); - relocatedPath = hasRelocations() ? artifactId + '-' + version + "-relocated.jar" : null; - this.isolatedLoad = isolatedLoad; - } - - /** - * Gets the direct download URLs for this library. - * - * @return direct download URLs - */ - public Collection getUrls() { - return urls; - } - - /** - * Gets the repositories URLs for this library. - * - * @return repositories URLs - */ - public Collection getRepositories() { - return repositories; - } - - /** - * Gets the library ID - * - * @return the library id - */ - public String getId() { - return id; - } - - /** - * Gets the Maven group ID for this library. - * - * @return Maven group ID + * Jar relocations to apply */ - public String getGroupId() { - return groupId; - } + private final Collection relocations = new LinkedList<>(); /** - * Gets the Maven artifact ID for this library. + * Adds a direct download URL for this library. * - * @return Maven artifact ID + * @param url direct download URL + * @return this builder */ - public String getArtifactId() { - return artifactId; + public Builder url(String url) { + urls.add(requireNonNull(url, "url")); + return this; } /** - * Gets the artifact version for this library. + * Adds a repository URL for this library. + *

Most common repositories can be found in {@link Repositories} class as + * constants.

Note that repositories should be preferably added to the + * {@link LibraryManager} via {@link LibraryManager#addRepository(String)}. * - * @return artifact version + * @param url repository URL + * @return this builder */ - public String getVersion() { - return version; + public Builder repository(String url) { + repositories.add( + requireNonNull(url, "repository").endsWith("/") ? url : url + '/'); + return this; } /** - * Gets the artifact classifier for this library. + * Sets the id for this library. * - * @return artifact classifier or null + * @param id the ID + * @return this builder */ - public String getClassifier() { - return classifier; + public Builder id(String id) { + this.id = id != null ? id : UUID.randomUUID().toString(); + return this; } /** - * Gets whether this library has an artifact classifier. + * Sets the Maven group ID for this library. * - * @return true if library has classifier, false otherwise + * @param groupId Maven group ID + * @return this builder */ - public boolean hasClassifier() { - return classifier != null; + public Builder groupId(String groupId) { + this.groupId = requireNonNull(groupId, "groupId"); + return this; } /** - * Gets the binary SHA-256 checksum of this library's jar file. + * Sets the Maven artifact ID for this library. * - * @return checksum or null + * @param artifactId Maven artifact ID + * @return this builder */ - public byte[] getChecksum() { - return checksum; + public Builder artifactId(String artifactId) { + this.artifactId = requireNonNull(artifactId, "artifactId"); + return this; } /** - * Gets whether this library has a checksum. + * Sets the artifact version for this library. * - * @return true if library has checksum, false otherwise + * @param version artifact version + * @return this builder */ - public boolean hasChecksum() { - return checksum != null; + public Builder version(String version) { + this.version = requireNonNull(version, "version"); + return this; } /** - * Gets the jar relocations to apply to this library. + * Sets the artifact classifier for this library. * - * @return jar relocations to apply + * @param classifier artifact classifier + * @return this builder */ - public Collection getRelocations() { - return relocations; + public Builder classifier(String classifier) { + this.classifier = requireNonNull(classifier, "classifier"); + return this; } /** - * Gets whether this library has any jar relocations. + * Sets the binary SHA-256 checksum for this library. * - * @return true if library has relocations, false otherwise + * @param checksum binary SHA-256 checksum + * @return this builder */ - public boolean hasRelocations() { - return !relocations.isEmpty(); + public Builder checksum(byte[] checksum) { + this.checksum = requireNonNull(checksum, "checksum"); + return this; } /** - * Gets the relative Maven path to this library's artifact. + * Sets the Base64-encoded SHA-256 checksum for this library. * - * @return Maven path for this library + * @param checksum Base64-encoded SHA-256 checksum + * @return this builder */ - public String getPath() { - return path; + public Builder checksum(String checksum) { + return checksum( + Base64.getDecoder().decode(requireNonNull(checksum, "checksum"))); } /** - * Gets the relative path to this library's relocated jar. + * Sets the isolated load for this library. * - * @return path to relocated artifact or null if has no relocations + * @param isolatedLoad the isolated load boolean + * @return this builder */ - public String getRelocatedPath() { - return relocatedPath; + public Builder isolatedLoad(boolean isolatedLoad) { + this.isolatedLoad = isolatedLoad; + return this; } /** - * Is the library loaded isolated? + * Adds a jar relocation to apply to this library. * - * @return true if the library is loaded isolated + * @param relocation jar relocation to apply + * @return this builder */ - public boolean isIsolatedLoad() { - return isolatedLoad; + public Builder relocate(Relocation relocation) { + relocations.add(requireNonNull(relocation, "relocation")); + return this; } /** - * Gets a concise, human-readable string representation of this library. + * Adds a jar relocation to apply to this library. * - * @return string representation + * @param pattern search pattern + * @param relocatedPattern replacement pattern + * @return this builder */ - @Override - public String toString() { - String name = groupId + ':' + artifactId + ':' + version; - if (hasClassifier()) { - name += ':' + classifier; - } - - return name; + public Builder relocate(String pattern, String relocatedPattern) { + return relocate(new Relocation(pattern, relocatedPattern)); } /** - * Creates a new library builder. + * Creates a new library using this builder's configuration. * - * @return new library builder - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Due to the constructor complexity of an immutable {@link Library}, - * instead this fluent builder is used to configure and then construct - * a new library. + * @return new library */ - public static class Builder { - /** - * Direct download URLs for this library - */ - private final Collection urls = new LinkedList<>(); - - /** - * Repository URLs for this library - */ - private final Collection repositories = new LinkedList<>(); - - /** - * The library ID - */ - private String id; - - /** - * Maven group ID - */ - private String groupId; - - /** - * Maven artifact ID - */ - private String artifactId; - - /** - * Artifact version - */ - private String version; - - /** - * Artifact classifier - */ - private String classifier; - - /** - * Binary SHA-256 checksum for this library's jar file - */ - private byte[] checksum; - - /** - * Isolated load - */ - private boolean isolatedLoad; - - /** - * Jar relocations to apply - */ - private final Collection relocations = new LinkedList<>(); - - /** - * Adds a direct download URL for this library. - * - * @param url direct download URL - * @return this builder - */ - public Builder url(String url) { - urls.add(requireNonNull(url, "url")); - return this; - } - - /** - * Adds a repository URL for this library. - *

Most common repositories can be found in {@link Repositories} class as constants. - *

Note that repositories should be preferably added to the {@link LibraryManager} via {@link LibraryManager#addRepository(String)}. - * - * @param url repository URL - * @return this builder - */ - public Builder repository(String url) { - repositories.add(requireNonNull(url, "repository").endsWith("/") ? url : url + '/'); - return this; - } - - /** - * Sets the id for this library. - * - * @param id the ID - * @return this builder - */ - public Builder id(String id) { - this.id = id != null ? id : UUID.randomUUID().toString(); - return this; - } - - /** - * Sets the Maven group ID for this library. - * - * @param groupId Maven group ID - * @return this builder - */ - public Builder groupId(String groupId) { - this.groupId = requireNonNull(groupId, "groupId"); - return this; - } - - /** - * Sets the Maven artifact ID for this library. - * - * @param artifactId Maven artifact ID - * @return this builder - */ - public Builder artifactId(String artifactId) { - this.artifactId = requireNonNull(artifactId, "artifactId"); - return this; - } - - /** - * Sets the artifact version for this library. - * - * @param version artifact version - * @return this builder - */ - public Builder version(String version) { - this.version = requireNonNull(version, "version"); - return this; - } - - /** - * Sets the artifact classifier for this library. - * - * @param classifier artifact classifier - * @return this builder - */ - public Builder classifier(String classifier) { - this.classifier = requireNonNull(classifier, "classifier"); - return this; - } - - /** - * Sets the binary SHA-256 checksum for this library. - * - * @param checksum binary SHA-256 checksum - * @return this builder - */ - public Builder checksum(byte[] checksum) { - this.checksum = requireNonNull(checksum, "checksum"); - return this; - } - - /** - * Sets the Base64-encoded SHA-256 checksum for this library. - * - * @param checksum Base64-encoded SHA-256 checksum - * @return this builder - */ - public Builder checksum(String checksum) { - return checksum(Base64.getDecoder().decode(requireNonNull(checksum, "checksum"))); - } - - /** - * Sets the isolated load for this library. - * - * @param isolatedLoad the isolated load boolean - * @return this builder - */ - public Builder isolatedLoad(boolean isolatedLoad) { - this.isolatedLoad = isolatedLoad; - return this; - } - - /** - * Adds a jar relocation to apply to this library. - * - * @param relocation jar relocation to apply - * @return this builder - */ - public Builder relocate(Relocation relocation) { - relocations.add(requireNonNull(relocation, "relocation")); - return this; - } - - /** - * Adds a jar relocation to apply to this library. - * - * @param pattern search pattern - * @param relocatedPattern replacement pattern - * @return this builder - */ - public Builder relocate(String pattern, String relocatedPattern) { - return relocate(new Relocation(pattern, relocatedPattern)); - } - - /** - * Creates a new library using this builder's configuration. - * - * @return new library - */ - public Library build() { - return new Library(urls, repositories, id, groupId, artifactId, version, classifier, checksum, relocations, isolatedLoad); - } + public Library build() { + return new Library(urls, repositories, id, groupId, artifactId, version, + classifier, checksum, relocations, isolatedLoad); } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/LibraryManager.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/LibraryManager.java index 0e0a023..d6da7d6 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/LibraryManager.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/LibraryManager.java @@ -1,5 +1,7 @@ package dev.austech.betterstaffchat.common.libraries.libby; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.Repositories; import dev.austech.betterstaffchat.common.libraries.libby.classloader.IsolatedClassLoader; import dev.austech.betterstaffchat.common.libraries.libby.logging.LogLevel; @@ -7,7 +9,6 @@ import dev.austech.betterstaffchat.common.libraries.libby.logging.adapters.LogAdapter; import dev.austech.betterstaffchat.common.libraries.libby.relocation.Relocation; import dev.austech.betterstaffchat.common.libraries.libby.relocation.RelocationHelper; - import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -34,8 +35,6 @@ import java.util.Map; import java.util.Set; -import static java.util.Objects.requireNonNull; - /** * A runtime dependency manager for plugins. *

@@ -53,403 +52,410 @@ * @see Library */ public abstract class LibraryManager { - /** - * Wrapped plugin logger - */ - protected final Logger logger; - - /** - * Directory where downloaded library jars are saved to - */ - protected final Path saveDirectory; - - /** - * Maven repositories used to resolve artifacts - */ - private final Set repositories = new LinkedHashSet<>(); - - /** - * Lazily-initialized relocation helper that uses reflection to call into - * Luck's Jar Relocator - */ - private RelocationHelper relocator; - - /** - * Map of isolated class loaders and theirs id - */ - private final Map isolatedLibraries = new HashMap<>(); - - /** - * Creates a new library manager. - * - * @param logAdapter plugin logging adapter - * @param dataDirectory plugin's data directory - * - * @deprecated Use {@link LibraryManager#LibraryManager(LogAdapter, Path, String)} - */ - @Deprecated - protected LibraryManager(LogAdapter logAdapter, Path dataDirectory) { - logger = new Logger(requireNonNull(logAdapter, "logAdapter")); - saveDirectory = requireNonNull(dataDirectory, "dataDirectory").toAbsolutePath().resolve("lib"); + /** + * Wrapped plugin logger + */ + protected final Logger logger; + + /** + * Directory where downloaded library jars are saved to + */ + protected final Path saveDirectory; + + /** + * Maven repositories used to resolve artifacts + */ + private final Set repositories = new LinkedHashSet<>(); + + /** + * Lazily-initialized relocation helper that uses reflection to call into + * Luck's Jar Relocator + */ + private RelocationHelper relocator; + + /** + * Map of isolated class loaders and theirs id + */ + private final Map isolatedLibraries = + new HashMap<>(); + + /** + * Creates a new library manager. + * + * @param logAdapter plugin logging adapter + * @param dataDirectory plugin's data directory + * + * @deprecated Use {@link LibraryManager#LibraryManager(LogAdapter, Path, + * String)} + */ + @Deprecated + protected LibraryManager(LogAdapter logAdapter, Path dataDirectory) { + logger = new Logger(requireNonNull(logAdapter, "logAdapter")); + saveDirectory = requireNonNull(dataDirectory, "dataDirectory") + .toAbsolutePath() + .resolve("lib"); + } + + /** + * Creates a new library manager. + * + * @param logAdapter plugin logging adapter + * @param dataDirectory plugin's data directory + * @param directoryName download directory name + */ + protected LibraryManager(LogAdapter logAdapter, Path dataDirectory, + String directoryName) { + logger = new Logger(requireNonNull(logAdapter, "logAdapter")); + saveDirectory = + requireNonNull(dataDirectory, "dataDirectory") + .toAbsolutePath() + .resolve(requireNonNull(directoryName, "directoryName")); + } + + /** + * Adds a file to the plugin's classpath. + * + * @param file the file to add + */ + protected abstract void addToClasspath(Path file); + + /** + * Adds a file to the isolated class loader + * + * @param library the library to add + * @param file the file to add + */ + protected void addToIsolatedClasspath(Library library, Path file) { + IsolatedClassLoader classLoader; + String id = library.getId(); + if (id != null) { + classLoader = + isolatedLibraries.computeIfAbsent(id, s -> new IsolatedClassLoader()); + } else { + classLoader = new IsolatedClassLoader(); } - - /** - * Creates a new library manager. - * - * @param logAdapter plugin logging adapter - * @param dataDirectory plugin's data directory - * @param directoryName download directory name - */ - protected LibraryManager(LogAdapter logAdapter, Path dataDirectory, String directoryName) { - logger = new Logger(requireNonNull(logAdapter, "logAdapter")); - saveDirectory = requireNonNull(dataDirectory, "dataDirectory").toAbsolutePath().resolve(requireNonNull(directoryName, "directoryName")); + classLoader.addPath(file); + } + + /** + * Get the isolated class loader of the library + * + * @param libraryId the id of the library + */ + public IsolatedClassLoader getIsolatedClassLoaderOf(String libraryId) { + return isolatedLibraries.get(libraryId); + } + + /** + * Gets the logging level for this library manager. + * + * @return log level + */ + public LogLevel getLogLevel() { return logger.getLevel(); } + + /** + * Sets the logging level for this library manager. + *

+ * By setting this value, the library manager's logger will not log any + * messages with a level less severe than the configured level. This can be + * useful for silencing the download and relocation logging. + *

+ * Setting this value to {@link LogLevel#WARN} would silence informational + * logging but still print important things like invalid checksum warnings. + * + * @param level the log level to set + */ + public void setLogLevel(LogLevel level) { logger.setLevel(level); } + + /** + * Gets the currently added repositories used to resolve artifacts. + *

+ * For each library this list is traversed to download artifacts after the + * direct download URLs have been attempted. + * + * @return current repositories + */ + public Collection getRepositories() { + List urls; + synchronized (repositories) { urls = new LinkedList<>(repositories); } + + return Collections.unmodifiableList(urls); + } + + /** + * Adds a repository URL to this library manager. + *

+ * Artifacts will be resolved using this repository when attempts to locate + * the artifact through previously added repositories are all unsuccessful. + * + * @param url repository URL to add + */ + public void addRepository(String url) { + String repo = requireNonNull(url, "url").endsWith("/") ? url : url + '/'; + synchronized (repositories) { repositories.add(repo); } + } + + /** + * Adds the current user's local Maven repository. + */ + public void addMavenLocal() { + addRepository(Paths.get(System.getProperty("user.home")) + .resolve(".m2/repository") + .toUri() + .toString()); + } + + /** + * Adds the Maven Central repository. + */ + public void addMavenCentral() { addRepository(Repositories.MAVEN_CENTRAL); } + + /** + * Adds the Sonatype OSS repository. + */ + public void addSonatype() { addRepository(Repositories.SONATYPE); } + + /** + * Adds the Bintray JCenter repository. + */ + public void addJCenter() { addRepository(Repositories.JCENTER); } + + /** + * Adds the JitPack repository. + */ + public void addJitPack() { addRepository(Repositories.JITPACK); } + + /** + * Gets all of the possible download URLs for this library. Entries are + * ordered by direct download URLs first and then repository download URLs. + * + * @param library the library to resolve + * @return download URLs + */ + public Collection resolveLibrary(Library library) { + Set urls = + new LinkedHashSet<>(requireNonNull(library, "library").getUrls()); + + // Try from library-declared repos first + for (String repository : library.getRepositories()) { + urls.add(repository + library.getPath()); } - /** - * Adds a file to the plugin's classpath. - * - * @param file the file to add - */ - protected abstract void addToClasspath(Path file); - - /** - * Adds a file to the isolated class loader - * - * @param library the library to add - * @param file the file to add - */ - protected void addToIsolatedClasspath(Library library, Path file) { - IsolatedClassLoader classLoader; - String id = library.getId(); - if (id != null) { - classLoader = isolatedLibraries.computeIfAbsent(id, s -> new IsolatedClassLoader()); - } else { - classLoader = new IsolatedClassLoader(); - } - classLoader.addPath(file); + for (String repository : getRepositories()) { + urls.add(repository + library.getPath()); } - /** - * Get the isolated class loader of the library - * - * @param libraryId the id of the library - */ - public IsolatedClassLoader getIsolatedClassLoaderOf(String libraryId) { - return isolatedLibraries.get(libraryId); - } + return Collections.unmodifiableSet(urls); + } + + /** + * Downloads a library jar and returns the contents as a byte array. + * + * @param url the URL to the library jar + * @return downloaded jar as byte array or null if nothing was downloaded + */ + private byte[] downloadLibrary(String url) { + try { + URLConnection connection = + new URL(requireNonNull(url, "url")).openConnection(); + + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setRequestProperty( + "User-Agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); + + try (InputStream in = connection.getInputStream()) { + int len; + byte[] buf = new byte[8192]; + ByteArrayOutputStream out = new ByteArrayOutputStream(); - /** - * Gets the logging level for this library manager. - * - * @return log level - */ - public LogLevel getLogLevel() { - return logger.getLevel(); - } - - /** - * Sets the logging level for this library manager. - *

- * By setting this value, the library manager's logger will not log any - * messages with a level less severe than the configured level. This can be - * useful for silencing the download and relocation logging. - *

- * Setting this value to {@link LogLevel#WARN} would silence informational - * logging but still print important things like invalid checksum warnings. - * - * @param level the log level to set - */ - public void setLogLevel(LogLevel level) { - logger.setLevel(level); - } - - /** - * Gets the currently added repositories used to resolve artifacts. - *

- * For each library this list is traversed to download artifacts after the - * direct download URLs have been attempted. - * - * @return current repositories - */ - public Collection getRepositories() { - List urls; - synchronized (repositories) { - urls = new LinkedList<>(repositories); + try { + while ((len = in.read(buf)) != -1) { + out.write(buf, 0, len); + } + } catch (SocketTimeoutException e) { + logger.warn("Download timed out: " + connection.getURL()); + return null; } - return Collections.unmodifiableList(urls); - } - - /** - * Adds a repository URL to this library manager. - *

- * Artifacts will be resolved using this repository when attempts to locate - * the artifact through previously added repositories are all unsuccessful. - * - * @param url repository URL to add - */ - public void addRepository(String url) { - String repo = requireNonNull(url, "url").endsWith("/") ? url : url + '/'; - synchronized (repositories) { - repositories.add(repo); - } + logger.info("Downloaded library " + connection.getURL()); + return out.toByteArray(); + } + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } catch (IOException e) { + if (e instanceof FileNotFoundException) { + logger.debug("File not found: " + url); + } else if (e instanceof SocketTimeoutException) { + logger.debug("Connect timed out: " + url); + } else if (e instanceof UnknownHostException) { + logger.debug("Unknown host: " + url); + } else { + logger.debug("Unexpected IOException", e); + } + + return null; } - - /** - * Adds the current user's local Maven repository. - */ - public void addMavenLocal() { - addRepository(Paths.get(System.getProperty("user.home")).resolve(".m2/repository").toUri().toString()); + } + + /** + * Downloads a library jar to the save directory if it doesn't already + * exist and returns the local file path. + *

+ * If the library has a checksum, it will be compared against the + * downloaded jar's checksum to verify the integrity of the download. If + * the checksums don't match, a warning is generated and the next download + * URL is attempted. + *

+ * Checksum comparison is ignored if the library doesn't have a checksum + * or if the library jar already exists in the save directory. + *

+ * Most of the time it is advised to use {@link #loadLibrary(Library)} + * instead of this method because this one is only concerned with + * downloading the jar and returning the local path. It's usually more + * desirable to download the jar and add it to the plugin's classpath in + * one operation. + * + * @param library the library to download + * @return local file path to library + * @see #loadLibrary(Library) + */ + public Path downloadLibrary(Library library) { + requireNonNull(library, "library"); + Path file = saveDirectory.resolve(library.getArtifactId() + "-" + + library.getVersion() + ".jar"); + if (Files.exists(file)) { + return file; } - /** - * Adds the Maven Central repository. - */ - public void addMavenCentral() { - addRepository(Repositories.MAVEN_CENTRAL); + Collection urls = resolveLibrary(library); + if (urls.isEmpty()) { + throw new RuntimeException("Library '" + library + + "' couldn't be resolved, add a repository"); } - /** - * Adds the Sonatype OSS repository. - */ - public void addSonatype() { - addRepository(Repositories.SONATYPE); + MessageDigest md = null; + if (library.hasChecksum()) { + try { + md = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } } - /** - * Adds the Bintray JCenter repository. - */ - public void addJCenter() { - addRepository(Repositories.JCENTER); - } + Path out = file.resolveSibling(file.getFileName() + ".tmp"); + out.toFile().deleteOnExit(); - /** - * Adds the JitPack repository. - */ - public void addJitPack() { - addRepository(Repositories.JITPACK); - } + try { + Files.createDirectories(file.getParent()); - /** - * Gets all of the possible download URLs for this library. Entries are - * ordered by direct download URLs first and then repository download URLs. - * - * @param library the library to resolve - * @return download URLs - */ - public Collection resolveLibrary(Library library) { - Set urls = new LinkedHashSet<>(requireNonNull(library, "library").getUrls()); - - // Try from library-declared repos first - for (String repository : library.getRepositories()) { - urls.add(repository + library.getPath()); + for (String url : urls) { + byte[] bytes = downloadLibrary(url); + if (bytes == null) { + continue; } - for (String repository : getRepositories()) { - urls.add(repository + library.getPath()); + if (md != null) { + byte[] checksum = md.digest(bytes); + if (!Arrays.equals(checksum, library.getChecksum())) { + logger.warn("*** INVALID CHECKSUM ***"); + logger.warn(" Library : " + library); + logger.warn(" URL : " + url); + logger.warn(" Expected : " + Base64.getEncoder().encodeToString( + library.getChecksum())); + logger.warn(" Actual : " + + Base64.getEncoder().encodeToString(checksum)); + continue; + } } - return Collections.unmodifiableSet(urls); + Files.write(out, bytes); + Files.move(out, file); + + return file; + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } finally { + try { + Files.deleteIfExists(out); + } catch (IOException ignored) { + } } - /** - * Downloads a library jar and returns the contents as a byte array. - * - * @param url the URL to the library jar - * @return downloaded jar as byte array or null if nothing was downloaded - */ - private byte[] downloadLibrary(String url) { - try { - URLConnection connection = new URL(requireNonNull(url, "url")).openConnection(); - - connection.setConnectTimeout(5000); - connection.setReadTimeout(5000); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); - - try (InputStream in = connection.getInputStream()) { - int len; - byte[] buf = new byte[8192]; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - try { - while ((len = in.read(buf)) != -1) { - out.write(buf, 0, len); - } - } catch (SocketTimeoutException e) { - logger.warn("Download timed out: " + connection.getURL()); - return null; - } - - logger.info("Downloaded library " + connection.getURL()); - return out.toByteArray(); - } - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } catch (IOException e) { - if (e instanceof FileNotFoundException) { - logger.debug("File not found: " + url); - } else if (e instanceof SocketTimeoutException) { - logger.debug("Connect timed out: " + url); - } else if (e instanceof UnknownHostException) { - logger.debug("Unknown host: " + url); - } else { - logger.debug("Unexpected IOException", e); - } - - return null; - } + throw new RuntimeException("Failed to download library '" + library + "'"); + } + + /** + * Processes the input jar and generates an output jar with the provided + * relocation rules applied, then returns the path to the relocated jar. + * + * @param in input jar + * @param out output jar + * @param relocations relocations to apply + * @return the relocated file + * @see RelocationHelper#relocate(Path, Path, Collection) + */ + private Path relocate(Path in, String out, + Collection relocations) { + requireNonNull(in, "in"); + requireNonNull(out, "out"); + requireNonNull(relocations, "relocations"); + + Path file = saveDirectory.resolve(out); + if (Files.exists(file)) { + return file; } - /** - * Downloads a library jar to the save directory if it doesn't already - * exist and returns the local file path. - *

- * If the library has a checksum, it will be compared against the - * downloaded jar's checksum to verify the integrity of the download. If - * the checksums don't match, a warning is generated and the next download - * URL is attempted. - *

- * Checksum comparison is ignored if the library doesn't have a checksum - * or if the library jar already exists in the save directory. - *

- * Most of the time it is advised to use {@link #loadLibrary(Library)} - * instead of this method because this one is only concerned with - * downloading the jar and returning the local path. It's usually more - * desirable to download the jar and add it to the plugin's classpath in - * one operation. - * - * @param library the library to download - * @return local file path to library - * @see #loadLibrary(Library) - */ - public Path downloadLibrary(Library library) { - requireNonNull(library, "library"); - Path file = saveDirectory.resolve(library.getArtifactId() + "-" + library.getVersion() + ".jar"); - if (Files.exists(file)) { - return file; - } - - Collection urls = resolveLibrary(library); - if (urls.isEmpty()) { - throw new RuntimeException("Library '" + library + "' couldn't be resolved, add a repository"); - } - - MessageDigest md = null; - if (library.hasChecksum()) { - try { - md = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } + Path tmpOut = file.resolveSibling(file.getFileName() + ".tmp"); + tmpOut.toFile().deleteOnExit(); - Path out = file.resolveSibling(file.getFileName() + ".tmp"); - out.toFile().deleteOnExit(); - - try { - Files.createDirectories(file.getParent()); - - for (String url : urls) { - byte[] bytes = downloadLibrary(url); - if (bytes == null) { - continue; - } - - if (md != null) { - byte[] checksum = md.digest(bytes); - if (!Arrays.equals(checksum, library.getChecksum())) { - logger.warn("*** INVALID CHECKSUM ***"); - logger.warn(" Library : " + library); - logger.warn(" URL : " + url); - logger.warn(" Expected : " + Base64.getEncoder().encodeToString(library.getChecksum())); - logger.warn(" Actual : " + Base64.getEncoder().encodeToString(checksum)); - continue; - } - } - - Files.write(out, bytes); - Files.move(out, file); - - return file; - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } finally { - try { - Files.deleteIfExists(out); - } catch (IOException ignored) { - } - } - - throw new RuntimeException("Failed to download library '" + library + "'"); + synchronized (this) { + if (relocator == null) { + relocator = new RelocationHelper(this); + } } - /** - * Processes the input jar and generates an output jar with the provided - * relocation rules applied, then returns the path to the relocated jar. - * - * @param in input jar - * @param out output jar - * @param relocations relocations to apply - * @return the relocated file - * @see RelocationHelper#relocate(Path, Path, Collection) - */ - private Path relocate(Path in, String out, Collection relocations) { - requireNonNull(in, "in"); - requireNonNull(out, "out"); - requireNonNull(relocations, "relocations"); - - Path file = saveDirectory.resolve(out); - if (Files.exists(file)) { - return file; - } - - Path tmpOut = file.resolveSibling(file.getFileName() + ".tmp"); - tmpOut.toFile().deleteOnExit(); - - synchronized (this) { - if (relocator == null) { - relocator = new RelocationHelper(this); - } - } - - try { - relocator.relocate(in, tmpOut, relocations); - Files.move(tmpOut, file); - - logger.info("Relocations applied to " + saveDirectory.getParent().relativize(in)); - - return file; - } catch (IOException e) { - throw new UncheckedIOException(e); - } finally { - try { - Files.deleteIfExists(tmpOut); - } catch (IOException ignored) { - } - } + try { + relocator.relocate(in, tmpOut, relocations); + Files.move(tmpOut, file); + + logger.info("Relocations applied to " + + saveDirectory.getParent().relativize(in)); + + return file; + } catch (IOException e) { + throw new UncheckedIOException(e); + } finally { + try { + Files.deleteIfExists(tmpOut); + } catch (IOException ignored) { + } + } + } + + /** + * Loads a library jar into the plugin's classpath. If the library jar + * doesn't exist locally, it will be downloaded. + *

+ * If the provided library has any relocations, they will be applied to + * create a relocated jar and the relocated jar will be loaded instead. + * + * @param library the library to load + * @see #downloadLibrary(Library) + */ + public void loadLibrary(Library library) { + Path file = downloadLibrary(requireNonNull(library, "library")); + if (library.hasRelocations()) { + file = + relocate(file, library.getRelocatedPath(), library.getRelocations()); } - /** - * Loads a library jar into the plugin's classpath. If the library jar - * doesn't exist locally, it will be downloaded. - *

- * If the provided library has any relocations, they will be applied to - * create a relocated jar and the relocated jar will be loaded instead. - * - * @param library the library to load - * @see #downloadLibrary(Library) - */ - public void loadLibrary(Library library) { - Path file = downloadLibrary(requireNonNull(library, "library")); - if (library.hasRelocations()) { - file = relocate(file, library.getRelocatedPath(), library.getRelocations()); - } - - if (library.isIsolatedLoad()) { - addToIsolatedClasspath(library, file); - } else { - addToClasspath(file); - } + if (library.isIsolatedLoad()) { + addToIsolatedClasspath(library, file); + } else { + addToClasspath(file); } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Repositories.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Repositories.java index 1d7f40b..d6483c7 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Repositories.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/Repositories.java @@ -5,27 +5,28 @@ */ public class Repositories { - /** - * Maven Central repository URL. - */ - public static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/"; + /** + * Maven Central repository URL. + */ + public static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/"; - /** - * Sonatype OSS repository URL. - */ - public static final String SONATYPE = "https://oss.sonatype.org/content/groups/public/"; + /** + * Sonatype OSS repository URL. + */ + public static final String SONATYPE = + "https://oss.sonatype.org/content/groups/public/"; - /** - * Bintray JCenter repository URL. - */ - public static final String JCENTER = "https://jcenter.bintray.com/"; + /** + * Bintray JCenter repository URL. + */ + public static final String JCENTER = "https://jcenter.bintray.com/"; - /** - * JitPack repository URL. - */ - public static final String JITPACK = "https://jitpack.io/"; + /** + * JitPack repository URL. + */ + public static final String JITPACK = "https://jitpack.io/"; - private Repositories() { - throw new UnsupportedOperationException("Private constructor"); - } + private Repositories() { + throw new UnsupportedOperationException("Private constructor"); + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/IsolatedClassLoader.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/IsolatedClassLoader.java index 39c3737..2dee313 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/IsolatedClassLoader.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/IsolatedClassLoader.java @@ -1,51 +1,50 @@ package dev.austech.betterstaffchat.common.libraries.libby.classloader; +import static java.util.Objects.requireNonNull; + import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; -import static java.util.Objects.requireNonNull; - /** * This class loader is a simple child of {@code URLClassLoader} that uses * the JVM's Extensions Class Loader as the parent instead of the system class * loader to provide an unpolluted classpath. */ public class IsolatedClassLoader extends URLClassLoader { - static { - ClassLoader.registerAsParallelCapable(); - } + static { ClassLoader.registerAsParallelCapable(); } - /** - * Creates a new isolated class loader for the given URLs. - * - * @param urls the URLs to add to the classpath - */ - public IsolatedClassLoader(URL... urls) { - super(requireNonNull(urls, "urls"), ClassLoader.getSystemClassLoader().getParent()); - } + /** + * Creates a new isolated class loader for the given URLs. + * + * @param urls the URLs to add to the classpath + */ + public IsolatedClassLoader(URL... urls) { + super(requireNonNull(urls, "urls"), + ClassLoader.getSystemClassLoader().getParent()); + } - /** - * Adds a URL to the classpath. - * - * @param url the URL to add - */ - @Override - public void addURL(URL url) { - super.addURL(url); - } + /** + * Adds a URL to the classpath. + * + * @param url the URL to add + */ + @Override + public void addURL(URL url) { + super.addURL(url); + } - /** - * Adds a path to the classpath. - * - * @param path the path to add - */ - public void addPath(Path path) { - try { - addURL(requireNonNull(path, "path").toUri().toURL()); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } + /** + * Adds a path to the classpath. + * + * @param path the path to add + */ + public void addPath(Path path) { + try { + addURL(requireNonNull(path, "path").toUri().toURL()); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/URLClassLoaderHelper.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/URLClassLoaderHelper.java index ba41207..4486a06 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/URLClassLoaderHelper.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/classloader/URLClassLoaderHelper.java @@ -1,10 +1,10 @@ package dev.austech.betterstaffchat.common.libraries.libby.classloader; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.Library; import dev.austech.betterstaffchat.common.libraries.libby.LibraryManager; import dev.austech.betterstaffchat.common.libraries.libby.Repositories; -import sun.misc.Unsafe; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; @@ -17,8 +17,7 @@ import java.util.Collections; import java.util.Map; import java.util.Set; - -import static java.util.Objects.requireNonNull; +import sun.misc.Unsafe; /** * A reflection-based wrapper around {@link URLClassLoader} for adding URLs to @@ -26,208 +25,242 @@ */ public class URLClassLoaderHelper { - /** - * Unsafe class instance. Used in {@link #getPrivilegedMethodHandle(Method)}. - */ - private static final Unsafe theUnsafe; + /** + * Unsafe class instance. Used in {@link #getPrivilegedMethodHandle(Method)}. + */ + private static final Unsafe theUnsafe; - static { - Unsafe unsafe = null; // Used to make theUnsafe field final + static { + Unsafe unsafe = null; // Used to make theUnsafe field final - // getDeclaredField("theUnsafe") is not used to avoid breakage on JVMs with changed field name - for (Field f : Unsafe.class.getDeclaredFields()) { - try { - if (f.getType() == Unsafe.class && Modifier.isStatic(f.getModifiers())) { - f.setAccessible(true); - unsafe = (Unsafe) f.get(null); - } - } catch (Exception ignored) { - } + // getDeclaredField("theUnsafe") is not used to avoid breakage on JVMs with + // changed field name + for (Field f : Unsafe.class.getDeclaredFields()) { + try { + if (f.getType() == Unsafe.class && + Modifier.isStatic(f.getModifiers())) { + f.setAccessible(true); + unsafe = (Unsafe)f.get(null); } - theUnsafe = unsafe; + } catch (Exception ignored) { + } } + theUnsafe = unsafe; + } - /** - * The class loader being managed by this helper. - */ - private final URLClassLoader classLoader; - - /** - * A reflected method in {@link URLClassLoader}, when invoked adds a URL to the classpath. - */ - private MethodHandle addURLMethodHandle = null; - - /** - * Creates a new URL class loader helper. - * - * @param classLoader the class loader to manage - * @param libraryManager the library manager used to download dependencies - */ - public URLClassLoaderHelper(URLClassLoader classLoader, LibraryManager libraryManager) { - requireNonNull(libraryManager, "libraryManager"); - this.classLoader = requireNonNull(classLoader, "classLoader"); - - try { - Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + /** + * The class loader being managed by this helper. + */ + private final URLClassLoader classLoader; - try { - openUrlClassLoaderModule(); - } catch (Exception ignored) { - } + /** + * A reflected method in {@link URLClassLoader}, when invoked adds a URL to + * the classpath. + */ + private MethodHandle addURLMethodHandle = null; + + /** + * Creates a new URL class loader helper. + * + * @param classLoader the class loader to manage + * @param libraryManager the library manager used to download dependencies + */ + public URLClassLoaderHelper(URLClassLoader classLoader, + LibraryManager libraryManager) { + requireNonNull(libraryManager, "libraryManager"); + this.classLoader = requireNonNull(classLoader, "classLoader"); + try { + Method addURLMethod = + URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + + try { + openUrlClassLoaderModule(); + } catch (Exception ignored) { + } + + try { + addURLMethod.setAccessible(true); + } catch (Exception exception) { + // InaccessibleObjectException has been added in Java 9 + if (exception.getClass().getName().equals( + "java.lang.reflect.InaccessibleObjectException")) { + // It is Java 9+, try to open java.net package + if (theUnsafe != null) try { - addURLMethod.setAccessible(true); - } catch (Exception exception) { - // InaccessibleObjectException has been added in Java 9 - if (exception.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) { - // It is Java 9+, try to open java.net package - if (theUnsafe != null) - try { - addURLMethodHandle = getPrivilegedMethodHandle(addURLMethod).bindTo(classLoader); - return; // We're done - } catch (Exception ignored) { - addURLMethodHandle = null; // Just to be sure the field is set to null - } - // Cannot use privileged MethodHandles.Lookup, trying with java agent - try { - addOpensWithAgent(libraryManager); - addURLMethod.setAccessible(true); - } catch (Exception e) { - // Cannot access at all - System.err.println("Cannot access URLClassLoader#addURL(URL), if you are using Java 9+ try to add the following option to your java command: --add-opens java.base/java.net=ALL-UNNAMED"); - throw new RuntimeException("Cannot access URLClassLoader#addURL(URL)", e); - } - } else { - throw new RuntimeException("Cannot set accessible URLClassLoader#addURL(URL)", exception); - } + addURLMethodHandle = + getPrivilegedMethodHandle(addURLMethod).bindTo(classLoader); + return; // We're done + } catch (Exception ignored) { + addURLMethodHandle = + null; // Just to be sure the field is set to null } - this.addURLMethodHandle = MethodHandles.lookup().unreflect(addURLMethod).bindTo(classLoader); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new RuntimeException(e); + // Cannot use privileged MethodHandles.Lookup, trying with java agent + try { + addOpensWithAgent(libraryManager); + addURLMethod.setAccessible(true); + } catch (Exception e) { + // Cannot access at all + System.err.println( + "Cannot access URLClassLoader#addURL(URL), if you are using Java 9+ try to add the following option to your java command: --add-opens java.base/java.net=ALL-UNNAMED"); + throw new RuntimeException( + "Cannot access URLClassLoader#addURL(URL)", e); + } + } else { + throw new RuntimeException( + "Cannot set accessible URLClassLoader#addURL(URL)", exception); } + } + this.addURLMethodHandle = + MethodHandles.lookup().unreflect(addURLMethod).bindTo(classLoader); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new RuntimeException(e); } + } - /** - * Adds a URL to the class loader's classpath. - * - * @param url the URL to add - */ - public void addToClasspath(URL url) { - try { - addURLMethodHandle.invokeWithArguments(requireNonNull(url, "url")); - } catch (Throwable e) { - throw new RuntimeException(e); - } + /** + * Adds a URL to the class loader's classpath. + * + * @param url the URL to add + */ + public void addToClasspath(URL url) { + try { + addURLMethodHandle.invokeWithArguments(requireNonNull(url, "url")); + } catch (Throwable e) { + throw new RuntimeException(e); } + } - /** - * Adds a path to the class loader's classpath. - * - * @param path the path to add - */ - public void addToClasspath(Path path) { - try { - addToClasspath(requireNonNull(path, "path").toUri().toURL()); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } + /** + * Adds a path to the class loader's classpath. + * + * @param path the path to add + */ + public void addToClasspath(Path path) { + try { + addToClasspath(requireNonNull(path, "path").toUri().toURL()); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); } + } - private static void openUrlClassLoaderModule() throws Exception { - // - // Thanks to lucko (Luck) for this snippet used in his own class loader - // - // This is a workaround used to maintain Java 9+ support with reflections - // Thanks to this you will be able to run this class loader with Java 8+ - - // This is effectively calling: - // - // URLClassLoader.class.getModule().addOpens( - // URLClassLoader.class.getPackageName(), - // URLClassLoaderHelper.class.getModule() - // ); - // - // We use reflection since we build against Java 8. - - Class moduleClass = Class.forName("java.lang.Module"); - Method getModuleMethod = Class.class.getMethod("getModule"); - Method addOpensMethod = moduleClass.getMethod("addOpens", String.class, moduleClass); - - Object urlClassLoaderModule = getModuleMethod.invoke(URLClassLoader.class); - Object thisModule = getModuleMethod.invoke(URLClassLoaderHelper.class); - - addOpensMethod.invoke(urlClassLoaderModule, URLClassLoader.class.getPackage().getName(), thisModule); - } + private static void openUrlClassLoaderModule() throws Exception { + // + // Thanks to lucko (Luck) for this snippet used in his own + // class loader + // + // This is a workaround used to maintain Java 9+ support with reflections + // Thanks to this you will be able to run this class loader with Java 8+ - private MethodHandle getPrivilegedMethodHandle(Method method) throws Exception { - // Try to get a MethodHandle to URLClassLoader#addURL. - // The Unsafe class is used to get a privileged MethodHandles.Lookup instance. + // This is effectively calling: + // + // URLClassLoader.class.getModule().addOpens( + // URLClassLoader.class.getPackageName(), + // URLClassLoaderHelper.class.getModule() + // ); + // + // We use reflection since we build against Java 8. - // Looking for MethodHandles.Lookup#IMPL_LOOKUP private static field - // getDeclaredField("IMPL_LOOKUP") is not used to avoid breakage on JVMs with changed field name - for (Field trustedLookup : MethodHandles.Lookup.class.getDeclaredFields()) { - if (trustedLookup.getType() != MethodHandles.Lookup.class || !Modifier.isStatic(trustedLookup.getModifiers()) || trustedLookup.isSynthetic()) - continue; + Class moduleClass = Class.forName("java.lang.Module"); + Method getModuleMethod = Class.class.getMethod("getModule"); + Method addOpensMethod = + moduleClass.getMethod("addOpens", String.class, moduleClass); - try { - MethodHandles.Lookup lookup = (MethodHandles.Lookup) theUnsafe.getObject(theUnsafe.staticFieldBase(trustedLookup), theUnsafe.staticFieldOffset(trustedLookup)); - return lookup.unreflect(method); - } catch (Exception ignored) { - // Unreflect went wrong, trying the next field - } - } + Object urlClassLoaderModule = getModuleMethod.invoke(URLClassLoader.class); + Object thisModule = getModuleMethod.invoke(URLClassLoaderHelper.class); + + addOpensMethod.invoke(urlClassLoaderModule, + URLClassLoader.class.getPackage().getName(), + thisModule); + } + + private MethodHandle getPrivilegedMethodHandle(Method method) + throws Exception { + // Try to get a MethodHandle to URLClassLoader#addURL. + // The Unsafe class is used to get a privileged MethodHandles.Lookup + // instance. + + // Looking for MethodHandles.Lookup#IMPL_LOOKUP private static field + // getDeclaredField("IMPL_LOOKUP") is not used to avoid breakage on JVMs + // with changed field name + for (Field trustedLookup : MethodHandles.Lookup.class.getDeclaredFields()) { + if (trustedLookup.getType() != MethodHandles.Lookup.class || + !Modifier.isStatic(trustedLookup.getModifiers()) || + trustedLookup.isSynthetic()) + continue; - // Every field has been tried - throw new RuntimeException("Cannot get privileged method handle."); + try { + MethodHandles.Lookup lookup = (MethodHandles.Lookup)theUnsafe.getObject( + theUnsafe.staticFieldBase(trustedLookup), + theUnsafe.staticFieldOffset(trustedLookup)); + return lookup.unreflect(method); + } catch (Exception ignored) { + // Unreflect went wrong, trying the next field + } } - private void addOpensWithAgent(LibraryManager libraryManager) throws Exception { - // To open URLClassLoader's module we need permissions. - // Try to add a java agent at runtime (specifically, ByteBuddy's agent) and use it to open the module, - // since java agents should have such permission. - - // Download ByteBuddy's agent and load it through an IsolatedClassLoader - IsolatedClassLoader isolatedClassLoader = new IsolatedClassLoader(); - try { - isolatedClassLoader.addPath(libraryManager.downloadLibrary( - Library.builder() - .groupId("net.bytebuddy") - .artifactId("byte-buddy-agent") - .version("1.12.1") - .checksum("mcCtBT9cljUEniB5ESpPDYZMfVxEs1JRPllOiWTP+bM=") - .repository(Repositories.MAVEN_CENTRAL) - .build() - )); - - Class byteBuddyAgent = isolatedClassLoader.loadClass("net.bytebuddy.agent.ByteBuddyAgent"); - - // This is effectively calling: - // - // Instrumentation instrumentation = ByteBuddyAgent.install(); - // instrumentation.redefineModule( - // URLClassLoader.class.getModule(), - // Collections.emptySet(), - // Collections.emptyMap(), - // Collections.singletonMap("java.net", Collections.singleton(getClass().getModule())), - // Collections.emptySet(), - // Collections.emptyMap() - // ); - // - // For more information see https://docs.oracle.com/en/java/javase/16/docs/api/java.instrument/java/lang/instrument/Instrumentation.html - // - // We use reflection since we build against Java 8. - - Object instrumentation = byteBuddyAgent.getDeclaredMethod("install").invoke(null); - Class instrumentationClass = Class.forName("java.lang.instrument.Instrumentation"); - Method redefineModule = instrumentationClass.getDeclaredMethod("redefineModule", Class.forName("java.lang.Module"), Set.class, Map.class, Map.class, Set.class, Map.class); - Method getModule = Class.class.getDeclaredMethod("getModule"); - Map> toOpen = Collections.singletonMap("java.net", Collections.singleton(getModule.invoke(getClass()))); - redefineModule.invoke(instrumentation, getModule.invoke(URLClassLoader.class), Collections.emptySet(), Collections.emptyMap(), toOpen, Collections.emptySet(), Collections.emptyMap()); - } finally { - try { - isolatedClassLoader.close(); - } catch (Exception ignored) { - } - } + // Every field has been tried + throw new RuntimeException("Cannot get privileged method handle."); + } + + private void addOpensWithAgent(LibraryManager libraryManager) + throws Exception { + // To open URLClassLoader's module we need permissions. + // Try to add a java agent at runtime (specifically, ByteBuddy's agent) and + // use it to open the module, since java agents should have such permission. + + // Download ByteBuddy's agent and load it through an IsolatedClassLoader + IsolatedClassLoader isolatedClassLoader = new IsolatedClassLoader(); + try { + isolatedClassLoader.addPath(libraryManager.downloadLibrary( + Library.builder() + .groupId("net.bytebuddy") + .artifactId("byte-buddy-agent") + .version("1.12.1") + .checksum("mcCtBT9cljUEniB5ESpPDYZMfVxEs1JRPllOiWTP+bM=") + .repository(Repositories.MAVEN_CENTRAL) + .build())); + + Class byteBuddyAgent = + isolatedClassLoader.loadClass("net.bytebuddy.agent.ByteBuddyAgent"); + + // This is effectively calling: + // + // Instrumentation instrumentation = ByteBuddyAgent.install(); + // instrumentation.redefineModule( + // URLClassLoader.class.getModule(), + // Collections.emptySet(), + // Collections.emptyMap(), + // Collections.singletonMap("java.net", + // Collections.singleton(getClass().getModule())), + // Collections.emptySet(), + // Collections.emptyMap() + // ); + // + // For more information see + // https://docs.oracle.com/en/java/javase/16/docs/api/java.instrument/java/lang/instrument/Instrumentation.html + // + // We use reflection since we build against Java 8. + + Object instrumentation = + byteBuddyAgent.getDeclaredMethod("install").invoke(null); + Class instrumentationClass = + Class.forName("java.lang.instrument.Instrumentation"); + Method redefineModule = instrumentationClass.getDeclaredMethod( + "redefineModule", Class.forName("java.lang.Module"), Set.class, + Map.class, Map.class, Set.class, Map.class); + Method getModule = Class.class.getDeclaredMethod("getModule"); + Map> toOpen = Collections.singletonMap( + "java.net", Collections.singleton(getModule.invoke(getClass()))); + redefineModule.invoke( + instrumentation, getModule.invoke(URLClassLoader.class), + Collections.emptySet(), Collections.emptyMap(), toOpen, + Collections.emptySet(), Collections.emptyMap()); + } finally { + try { + isolatedClassLoader.close(); + } catch (Exception ignored) { + } } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/LogLevel.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/LogLevel.java index 759c687..29e0c61 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/LogLevel.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/LogLevel.java @@ -4,23 +4,23 @@ * Represents the severity of a log message in {@link Logger}. */ public enum LogLevel { - /** - * Stuff that isn't useful to end-users - */ - DEBUG, + /** + * Stuff that isn't useful to end-users + */ + DEBUG, - /** - * Stuff that might be useful to know - */ - INFO, + /** + * Stuff that might be useful to know + */ + INFO, - /** - * Non-fatal, often recoverable errors or notices - */ - WARN, + /** + * Non-fatal, often recoverable errors or notices + */ + WARN, - /** - * Probably an unrecoverable error - */ - ERROR + /** + * Probably an unrecoverable error + */ + ERROR } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/Logger.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/Logger.java index be152fc..62fbffc 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/Logger.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/Logger.java @@ -1,196 +1,186 @@ package dev.austech.betterstaffchat.common.libraries.libby.logging; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.logging.LogLevel; import dev.austech.betterstaffchat.common.libraries.libby.logging.adapters.LogAdapter; -import static java.util.Objects.requireNonNull; - /** * A logging wrapper that logs to a log adapter and can be configured to filter * log messages by severity. */ public class Logger { - /** - * Log adapter for the current platform - */ - private final LogAdapter adapter; - - /** - * Log level controlling which messages are logged - */ - private LogLevel level = LogLevel.INFO; - - /** - * Creates a new logger with the provided adapter. - * - * @param adapter the adapter to wrap - */ - public Logger(LogAdapter adapter) { - this.adapter = requireNonNull(adapter, "adapter"); - } - - /** - * Gets the current log level. - * - * @return current log level - */ - public LogLevel getLevel() { - return level; - } - - /** - * Sets a new log level. - * - * @param level new log level - */ - public void setLevel(LogLevel level) { - this.level = requireNonNull(level, "level"); + /** + * Log adapter for the current platform + */ + private final LogAdapter adapter; + + /** + * Log level controlling which messages are logged + */ + private LogLevel level = LogLevel.INFO; + + /** + * Creates a new logger with the provided adapter. + * + * @param adapter the adapter to wrap + */ + public Logger(LogAdapter adapter) { + this.adapter = requireNonNull(adapter, "adapter"); + } + + /** + * Gets the current log level. + * + * @return current log level + */ + public LogLevel getLevel() { return level; } + + /** + * Sets a new log level. + * + * @param level new log level + */ + public void setLevel(LogLevel level) { + this.level = requireNonNull(level, "level"); + } + + /** + * Gets whether messages matching the provided level can be logged under + * the current log level setting. + *

+ * Returns true if provided log level is equal to or more severe than the + * logger's configured log level. + * + * @param level the level to check + * @return true if message can be logged, or false + */ + private boolean canLog(LogLevel level) { + return requireNonNull(level, "level").compareTo(this.level) >= 0; + } + + /** + * Logs a message with the provided level. + *

+ * If the provided log level is less severe than the logger's + * configured log level, this message won't be logged. + * + * @param level message severity level + * @param message the message to log + * @see #debug(String) + * @see #info(String) + * @see #warn(String) + * @see #error(String) + */ + public void log(LogLevel level, String message) { + if (canLog(level)) { + adapter.log(level, message); } - - /** - * Gets whether messages matching the provided level can be logged under - * the current log level setting. - *

- * Returns true if provided log level is equal to or more severe than the - * logger's configured log level. - * - * @param level the level to check - * @return true if message can be logged, or false - */ - private boolean canLog(LogLevel level) { - return requireNonNull(level, "level").compareTo(this.level) >= 0; - } - - /** - * Logs a message with the provided level. - *

- * If the provided log level is less severe than the logger's - * configured log level, this message won't be logged. - * - * @param level message severity level - * @param message the message to log - * @see #debug(String) - * @see #info(String) - * @see #warn(String) - * @see #error(String) - */ - public void log(LogLevel level, String message) { - if (canLog(level)) { - adapter.log(level, message); - } - } - - /** - * Logs a message and stack trace with the provided level. - *

- * If the provided log level is less severe than the logger's - * configured log level, this message won't be logged. - * - * @param level message severity level - * @param message the message to log - * @param throwable the throwable to print - * @see #debug(String, Throwable) - * @see #info(String, Throwable) - * @see #warn(String, Throwable) - * @see #error(String, Throwable) - */ - public void log(LogLevel level, String message, Throwable throwable) { - if (canLog(level)) { - adapter.log(level, message, throwable); - } - } - - /** - * Logs a debug message. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#DEBUG}, this message won't be logged. - * - * @param message the message to log - */ - public void debug(String message) { - log(LogLevel.DEBUG, message); - } - - /** - * Logs a debug message with a stack trace. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#DEBUG}, this message won't be logged. - * - * @param message the message to log - * @param throwable the throwable to print - */ - public void debug(String message, Throwable throwable) { - log(LogLevel.DEBUG, message, throwable); - } - - /** - * Logs an informational message. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#INFO}, this message won't be logged. - * - * @param message the message to log - */ - public void info(String message) { - log(LogLevel.INFO, message); - } - - /** - * Logs an informational message with a stack trace. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#INFO}, this message won't be logged. - * - * @param message the message to log - * @param throwable the throwable to print - */ - public void info(String message, Throwable throwable) { - log(LogLevel.INFO, message, throwable); - } - - /** - * Logs a warning message. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#WARN}, this message won't be logged. - * - * @param message the message to log - */ - public void warn(String message) { - log(LogLevel.WARN, message); - } - - /** - * Logs a warning message with a stack trace. - *

- * If the logger's configured log level is more severe than - * {@link LogLevel#WARN}, this message won't be logged. - * - * @param message the message to log - * @param throwable the throwable to print - */ - public void warn(String message, Throwable throwable) { - log(LogLevel.WARN, message, throwable); - } - - /** - * Logs an error message. - * - * @param message the message to log - */ - public void error(String message) { - log(LogLevel.ERROR, message); - } - - /** - * Logs an error message with a stack trace. - * - * @param message message to log - * @param throwable the throwable to print - */ - public void error(String message, Throwable throwable) { - log(LogLevel.ERROR, message, throwable); + } + + /** + * Logs a message and stack trace with the provided level. + *

+ * If the provided log level is less severe than the logger's + * configured log level, this message won't be logged. + * + * @param level message severity level + * @param message the message to log + * @param throwable the throwable to print + * @see #debug(String, Throwable) + * @see #info(String, Throwable) + * @see #warn(String, Throwable) + * @see #error(String, Throwable) + */ + public void log(LogLevel level, String message, Throwable throwable) { + if (canLog(level)) { + adapter.log(level, message, throwable); } + } + + /** + * Logs a debug message. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#DEBUG}, this message won't be logged. + * + * @param message the message to log + */ + public void debug(String message) { log(LogLevel.DEBUG, message); } + + /** + * Logs a debug message with a stack trace. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#DEBUG}, this message won't be logged. + * + * @param message the message to log + * @param throwable the throwable to print + */ + public void debug(String message, Throwable throwable) { + log(LogLevel.DEBUG, message, throwable); + } + + /** + * Logs an informational message. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#INFO}, this message won't be logged. + * + * @param message the message to log + */ + public void info(String message) { log(LogLevel.INFO, message); } + + /** + * Logs an informational message with a stack trace. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#INFO}, this message won't be logged. + * + * @param message the message to log + * @param throwable the throwable to print + */ + public void info(String message, Throwable throwable) { + log(LogLevel.INFO, message, throwable); + } + + /** + * Logs a warning message. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#WARN}, this message won't be logged. + * + * @param message the message to log + */ + public void warn(String message) { log(LogLevel.WARN, message); } + + /** + * Logs a warning message with a stack trace. + *

+ * If the logger's configured log level is more severe than + * {@link LogLevel#WARN}, this message won't be logged. + * + * @param message the message to log + * @param throwable the throwable to print + */ + public void warn(String message, Throwable throwable) { + log(LogLevel.WARN, message, throwable); + } + + /** + * Logs an error message. + * + * @param message the message to log + */ + public void error(String message) { log(LogLevel.ERROR, message); } + + /** + * Logs an error message with a stack trace. + * + * @param message message to log + * @param throwable the throwable to print + */ + public void error(String message, Throwable throwable) { + log(LogLevel.ERROR, message, throwable); + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/JDKLogAdapter.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/JDKLogAdapter.java index f49f4e5..36e5f5b 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/JDKLogAdapter.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/JDKLogAdapter.java @@ -1,77 +1,76 @@ package dev.austech.betterstaffchat.common.libraries.libby.logging.adapters; -import dev.austech.betterstaffchat.common.libraries.libby.logging.LogLevel; +import static java.util.Objects.requireNonNull; +import dev.austech.betterstaffchat.common.libraries.libby.logging.LogLevel; import java.util.logging.Level; import java.util.logging.Logger; -import static java.util.Objects.requireNonNull; - /** * Logging adapter that logs to a JDK logger. */ public class JDKLogAdapter implements LogAdapter { - /** - * JDK logger - */ - private final Logger logger; + /** + * JDK logger + */ + private final Logger logger; - /** - * Creates a new JDK log adapter that logs to a {@link Logger}. - * - * @param logger the JDK logger to wrap - */ - public JDKLogAdapter(Logger logger) { - this.logger = requireNonNull(logger, "logger"); - } + /** + * Creates a new JDK log adapter that logs to a {@link Logger}. + * + * @param logger the JDK logger to wrap + */ + public JDKLogAdapter(Logger logger) { + this.logger = requireNonNull(logger, "logger"); + } - /** - * Logs a message with the provided level to the JDK logger. - * - * @param level message severity level - * @param message the message to log - */ - @Override - public void log(LogLevel level, String message) { - switch (requireNonNull(level, "level")) { - case DEBUG: - logger.log(Level.FINE, message); - break; - case INFO: - logger.log(Level.INFO, message); - break; - case WARN: - logger.log(Level.WARNING, message); - break; - case ERROR: - logger.log(Level.SEVERE, message); - break; - } + /** + * Logs a message with the provided level to the JDK logger. + * + * @param level message severity level + * @param message the message to log + */ + @Override + public void log(LogLevel level, String message) { + switch (requireNonNull(level, "level")) { + case DEBUG: + logger.log(Level.FINE, message); + break; + case INFO: + logger.log(Level.INFO, message); + break; + case WARN: + logger.log(Level.WARNING, message); + break; + case ERROR: + logger.log(Level.SEVERE, message); + break; } + } - /** - * Logs a message and stack trace with the provided level to the JDK - * logger. - * - * @param level message severity level - * @param message the message to log - * @param throwable the throwable to print - */ - @Override - public void log(LogLevel level, String message, Throwable throwable) { - switch (requireNonNull(level, "level")) { - case DEBUG: - logger.log(Level.FINE, message, throwable); - break; - case INFO: - logger.log(Level.INFO, message, throwable); - break; - case WARN: - logger.log(Level.WARNING, message, throwable); - break; - case ERROR: - logger.log(Level.SEVERE, message, throwable); - break; - } + /** + * Logs a message and stack trace with the provided level to the JDK + * logger. + * + * @param level message severity level + * @param message the message to log + * @param throwable the throwable to print + */ + @Override + public void log(LogLevel level, String message, Throwable throwable) { + switch (requireNonNull(level, "level")) { + case DEBUG: + logger.log(Level.FINE, message, throwable); + break; + case INFO: + logger.log(Level.INFO, message, throwable); + break; + case WARN: + logger.log(Level.WARNING, message, throwable); + break; + case ERROR: + logger.log(Level.SEVERE, message, throwable); + break; } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/LogAdapter.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/LogAdapter.java index a5f4aaf..d232da7 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/LogAdapter.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/logging/adapters/LogAdapter.java @@ -6,20 +6,20 @@ * Logging interface for adapting platform-specific loggers to our logging API. */ public interface LogAdapter { - /** - * Logs a message with the provided level. - * - * @param level message severity level - * @param message the message to log - */ - void log(LogLevel level, String message); + /** + * Logs a message with the provided level. + * + * @param level message severity level + * @param message the message to log + */ + void log(LogLevel level, String message); - /** - * Logs a message and stack trace with the provided level. - * - * @param level message severity level - * @param message the message to log - * @param throwable the throwable to print - */ - void log(LogLevel level, String message, Throwable throwable); + /** + * Logs a message and stack trace with the provided level. + * + * @param level message severity level + * @param message the message to log + * @param throwable the throwable to print + */ + void log(LogLevel level, String message, Throwable throwable); } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/Relocation.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/Relocation.java index 6c9b411..3a559ee 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/Relocation.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/Relocation.java @@ -1,184 +1,183 @@ package dev.austech.betterstaffchat.common.libraries.libby.relocation; +import static java.util.Objects.requireNonNull; + import java.util.Collection; import java.util.Collections; import java.util.LinkedList; -import static java.util.Objects.requireNonNull; - /** * Relocations are used to describe a search and replace pattern for renaming * packages in a library jar for the purpose of preventing namespace conflicts * with other plugins that bundle their own version of the same library. */ public class Relocation { + /** + * Search pattern + */ + private final String pattern; + + /** + * Replacement pattern + */ + private final String relocatedPattern; + + /** + * Classes and resources to include + */ + private final Collection includes; + + /** + * Classes and resources to exclude + */ + private final Collection excludes; + + /** + * Creates a new relocation. + * + * @param pattern search pattern + * @param relocatedPattern replacement pattern + * @param includes classes and resources to include + * @param excludes classes and resources to exclude + */ + public Relocation(String pattern, String relocatedPattern, + Collection includes, Collection excludes) { + this.pattern = requireNonNull(pattern, "pattern").replace("{}", "."); + this.relocatedPattern = + requireNonNull(relocatedPattern, "relocatedPattern").replace("{}", "."); + this.includes = + includes != null + ? Collections.unmodifiableList(new LinkedList<>(includes)) + : Collections.emptyList(); + this.excludes = + excludes != null + ? Collections.unmodifiableList(new LinkedList<>(excludes)) + : Collections.emptyList(); + } + + /** + * Creates a new relocation with empty includes and excludes. + * + * @param pattern search pattern + * @param relocatedPattern replacement pattern + */ + public Relocation(String pattern, String relocatedPattern) { + this(pattern, relocatedPattern, null, null); + } + + /** + * Gets the search pattern. + * + * @return pattern to search + */ + public String getPattern() { return pattern; } + + /** + * Gets the replacement pattern. + * + * @return pattern to replace with + */ + public String getRelocatedPattern() { return relocatedPattern; } + + /** + * Gets included classes and resources. + * + * @return classes and resources to include + */ + public Collection getIncludes() { return includes; } + + /** + * Gets excluded classes and resources. + * + * @return classes and resources to exclude + */ + public Collection getExcludes() { return excludes; } + + /** + * Creates a new relocation builder. + * + * @return new relocation builder + */ + public static Builder builder() { return new Builder(); } + + /** + * Provides an alternative method of creating a {@link Relocation}. This + * builder may be more intuitive for configuring relocations that also have + * any includes or excludes. + */ + public static class Builder { /** * Search pattern */ - private final String pattern; + private String pattern; /** * Replacement pattern */ - private final String relocatedPattern; + private String relocatedPattern; /** * Classes and resources to include */ - private final Collection includes; + private final Collection includes = new LinkedList<>(); /** * Classes and resources to exclude */ - private final Collection excludes; - - /** - * Creates a new relocation. - * - * @param pattern search pattern - * @param relocatedPattern replacement pattern - * @param includes classes and resources to include - * @param excludes classes and resources to exclude - */ - public Relocation(String pattern, String relocatedPattern, Collection includes, Collection excludes) { - this.pattern = requireNonNull(pattern, "pattern").replace("{}", "."); - this.relocatedPattern = requireNonNull(relocatedPattern, "relocatedPattern").replace("{}", "."); - this.includes = includes != null ? Collections.unmodifiableList(new LinkedList<>(includes)) : Collections.emptyList(); - this.excludes = excludes != null ? Collections.unmodifiableList(new LinkedList<>(excludes)) : Collections.emptyList(); - } - - /** - * Creates a new relocation with empty includes and excludes. - * - * @param pattern search pattern - * @param relocatedPattern replacement pattern - */ - public Relocation(String pattern, String relocatedPattern) { - this(pattern, relocatedPattern, null, null); - } + private final Collection excludes = new LinkedList<>(); /** - * Gets the search pattern. + * Sets the search pattern. * - * @return pattern to search + * @param pattern pattern to search + * @return this builder */ - public String getPattern() { - return pattern; + public Builder pattern(String pattern) { + this.pattern = requireNonNull(pattern, "pattern"); + return this; } /** - * Gets the replacement pattern. + * Sets the replacement pattern. * - * @return pattern to replace with + * @param relocatedPattern pattern to replace with + * @return this builder */ - public String getRelocatedPattern() { - return relocatedPattern; + public Builder relocatedPattern(String relocatedPattern) { + this.relocatedPattern = + requireNonNull(relocatedPattern, "relocatedPattern"); + return this; } /** - * Gets included classes and resources. + * Adds a class or resource to be included. * - * @return classes and resources to include + * @param include class or resource to include + * @return this builder */ - public Collection getIncludes() { - return includes; + public Builder include(String include) { + includes.add(requireNonNull(include, "include")); + return this; } /** - * Gets excluded classes and resources. + * Adds a class or resource to be excluded. * - * @return classes and resources to exclude + * @param exclude class or resource to exclude + * @return this builder */ - public Collection getExcludes() { - return excludes; + public Builder exclude(String exclude) { + excludes.add(requireNonNull(exclude, "exclude")); + return this; } /** - * Creates a new relocation builder. + * Creates a new relocation using this builder's configuration. * - * @return new relocation builder - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Provides an alternative method of creating a {@link Relocation}. This - * builder may be more intuitive for configuring relocations that also have - * any includes or excludes. + * @return new relocation */ - public static class Builder { - /** - * Search pattern - */ - private String pattern; - - /** - * Replacement pattern - */ - private String relocatedPattern; - - /** - * Classes and resources to include - */ - private final Collection includes = new LinkedList<>(); - - /** - * Classes and resources to exclude - */ - private final Collection excludes = new LinkedList<>(); - - /** - * Sets the search pattern. - * - * @param pattern pattern to search - * @return this builder - */ - public Builder pattern(String pattern) { - this.pattern = requireNonNull(pattern, "pattern"); - return this; - } - - /** - * Sets the replacement pattern. - * - * @param relocatedPattern pattern to replace with - * @return this builder - */ - public Builder relocatedPattern(String relocatedPattern) { - this.relocatedPattern = requireNonNull(relocatedPattern, "relocatedPattern"); - return this; - } - - /** - * Adds a class or resource to be included. - * - * @param include class or resource to include - * @return this builder - */ - public Builder include(String include) { - includes.add(requireNonNull(include, "include")); - return this; - } - - /** - * Adds a class or resource to be excluded. - * - * @param exclude class or resource to exclude - * @return this builder - */ - public Builder exclude(String exclude) { - excludes.add(requireNonNull(exclude, "exclude")); - return this; - } - - /** - * Creates a new relocation using this builder's configuration. - * - * @return new relocation - */ - public Relocation build() { - return new Relocation(pattern, relocatedPattern, includes, excludes); - } + public Relocation build() { + return new Relocation(pattern, relocatedPattern, includes, excludes); } + } } diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/RelocationHelper.java b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/RelocationHelper.java index 565e668..2976b04 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/RelocationHelper.java +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/libby/relocation/RelocationHelper.java @@ -1,10 +1,11 @@ package dev.austech.betterstaffchat.common.libraries.libby.relocation; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.Library; import dev.austech.betterstaffchat.common.libraries.libby.LibraryManager; import dev.austech.betterstaffchat.common.libraries.libby.Repositories; import dev.austech.betterstaffchat.common.libraries.libby.classloader.IsolatedClassLoader; - import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -13,118 +14,117 @@ import java.util.LinkedList; import java.util.List; -import static java.util.Objects.requireNonNull; - /** * A reflection-based helper for relocating library jars. It automatically * downloads and invokes Luck's Jar Relocator to perform jar relocations. * - * @see Luck's Jar Relocator + * @see Luck's Jar + * Relocator */ public class RelocationHelper { - /** - * Reflected constructor for creating new jar relocator instances - */ - private final Constructor jarRelocatorConstructor; - - /** - * Reflected method for running a jar relocator - */ - private final Method jarRelocatorRunMethod; - - /** - * Reflected constructor for creating relocation instances - */ - private final Constructor relocationConstructor; - - /** - * Creates a new relocation helper using the provided library manager to - * download the dependencies required for runtime relocation. - * - * @param libraryManager the library manager used to download dependencies - */ - public RelocationHelper(LibraryManager libraryManager) { - requireNonNull(libraryManager, "libraryManager"); - - IsolatedClassLoader classLoader = new IsolatedClassLoader(); - - // ObjectWeb ASM Commons - classLoader.addPath(libraryManager.downloadLibrary( - Library.builder() - .groupId("org.ow2.asm") - .artifactId("asm-commons") - .version("9.2") - .checksum("vkzlMTiiOLtSLNeBz5Hzulzi9sqT7GLUahYqEnIl4KY=") - .repository(Repositories.MAVEN_CENTRAL) - .build() - )); - - // ObjectWeb ASM - classLoader.addPath(libraryManager.downloadLibrary( - Library.builder() - .groupId("org.ow2.asm") - .artifactId("asm") - .version("9.2") - .checksum("udT+TXGTjfOIOfDspCqqpkz4sxPWeNoDbwyzyhmbR/U=") - .repository(Repositories.MAVEN_CENTRAL) - .build() - )); - - // Luck's Jar Relocator - classLoader.addPath(libraryManager.downloadLibrary( - Library.builder() - .groupId("me.lucko") - .artifactId("jar-relocator") - .version("1.5") - .checksum("0D6eM99gKpEYFNDydgnto3Df0ygZGdRVqy5ahtj0oIs=") - .repository(Repositories.MAVEN_CENTRAL) - .build() - )); - - try { - Class jarRelocatorClass = classLoader.loadClass("me.lucko.jarrelocator.JarRelocator"); - Class relocationClass = classLoader.loadClass("me.lucko.jarrelocator.Relocation"); - - // me.lucko.jarrelocator.JarRelocator(File, File, Collection) - jarRelocatorConstructor = jarRelocatorClass.getConstructor(File.class, File.class, Collection.class); - - // me.lucko.jarrelocator.JarRelocator#run() - jarRelocatorRunMethod = jarRelocatorClass.getMethod("run"); - - // me.lucko.jarrelocator.Relocation(String, String, Collection, Collection) - relocationConstructor = relocationClass.getConstructor(String.class, String.class, Collection.class, Collection.class); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + /** + * Reflected constructor for creating new jar relocator instances + */ + private final Constructor jarRelocatorConstructor; + + /** + * Reflected method for running a jar relocator + */ + private final Method jarRelocatorRunMethod; + + /** + * Reflected constructor for creating relocation instances + */ + private final Constructor relocationConstructor; + + /** + * Creates a new relocation helper using the provided library manager to + * download the dependencies required for runtime relocation. + * + * @param libraryManager the library manager used to download dependencies + */ + public RelocationHelper(LibraryManager libraryManager) { + requireNonNull(libraryManager, "libraryManager"); + + IsolatedClassLoader classLoader = new IsolatedClassLoader(); + + // ObjectWeb ASM Commons + classLoader.addPath(libraryManager.downloadLibrary( + Library.builder() + .groupId("org.ow2.asm") + .artifactId("asm-commons") + .version("9.2") + .checksum("vkzlMTiiOLtSLNeBz5Hzulzi9sqT7GLUahYqEnIl4KY=") + .repository(Repositories.MAVEN_CENTRAL) + .build())); + + // ObjectWeb ASM + classLoader.addPath(libraryManager.downloadLibrary( + Library.builder() + .groupId("org.ow2.asm") + .artifactId("asm") + .version("9.2") + .checksum("udT+TXGTjfOIOfDspCqqpkz4sxPWeNoDbwyzyhmbR/U=") + .repository(Repositories.MAVEN_CENTRAL) + .build())); + + // Luck's Jar Relocator + classLoader.addPath(libraryManager.downloadLibrary( + Library.builder() + .groupId("me.lucko") + .artifactId("jar-relocator") + .version("1.5") + .checksum("0D6eM99gKpEYFNDydgnto3Df0ygZGdRVqy5ahtj0oIs=") + .repository(Repositories.MAVEN_CENTRAL) + .build())); + + try { + Class jarRelocatorClass = + classLoader.loadClass("me.lucko.jarrelocator.JarRelocator"); + Class relocationClass = + classLoader.loadClass("me.lucko.jarrelocator.Relocation"); + + // me.lucko.jarrelocator.JarRelocator(File, File, Collection) + jarRelocatorConstructor = jarRelocatorClass.getConstructor( + File.class, File.class, Collection.class); + + // me.lucko.jarrelocator.JarRelocator#run() + jarRelocatorRunMethod = jarRelocatorClass.getMethod("run"); + + // me.lucko.jarrelocator.Relocation(String, String, Collection, + // Collection) + relocationConstructor = relocationClass.getConstructor( + String.class, String.class, Collection.class, Collection.class); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } - - /** - * Invokes the jar relocator to process the input jar and generate an - * output jar with the provided relocation rules applied. - * - * @param in input jar - * @param out output jar - * @param relocations relocations to apply - */ - public void relocate(Path in, Path out, Collection relocations) { - requireNonNull(in, "in"); - requireNonNull(out, "out"); - requireNonNull(relocations, "relocations"); - - try { - List rules = new LinkedList<>(); - for (Relocation relocation : relocations) { - rules.add(relocationConstructor.newInstance( - relocation.getPattern(), - relocation.getRelocatedPattern(), - relocation.getIncludes(), - relocation.getExcludes() - )); - } - - jarRelocatorRunMethod.invoke(jarRelocatorConstructor.newInstance(in.toFile(), out.toFile(), rules)); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + } + + /** + * Invokes the jar relocator to process the input jar and generate an + * output jar with the provided relocation rules applied. + * + * @param in input jar + * @param out output jar + * @param relocations relocations to apply + */ + public void relocate(Path in, Path out, Collection relocations) { + requireNonNull(in, "in"); + requireNonNull(out, "out"); + requireNonNull(relocations, "relocations"); + + try { + List rules = new LinkedList<>(); + for (Relocation relocation : relocations) { + rules.add(relocationConstructor.newInstance( + relocation.getPattern(), relocation.getRelocatedPattern(), + relocation.getIncludes(), relocation.getExcludes())); + } + + jarRelocatorRunMethod.invoke(jarRelocatorConstructor.newInstance( + in.toFile(), out.toFile(), rules)); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); } + } } diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/libby/BukkitLibraryManager.java b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/libby/BukkitLibraryManager.java index 6548e5c..9acedcc 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/libby/BukkitLibraryManager.java +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/libby/BukkitLibraryManager.java @@ -1,51 +1,50 @@ package dev.austech.betterstaffchat.spigot.libby; +import static java.util.Objects.requireNonNull; + import dev.austech.betterstaffchat.common.libraries.libby.LibraryManager; import dev.austech.betterstaffchat.common.libraries.libby.classloader.URLClassLoaderHelper; import dev.austech.betterstaffchat.common.libraries.libby.logging.adapters.JDKLogAdapter; -import org.bukkit.plugin.Plugin; - import java.net.URLClassLoader; import java.nio.file.Path; - -import static java.util.Objects.requireNonNull; +import org.bukkit.plugin.Plugin; /** * A runtime dependency manager for Bukkit plugins. */ public class BukkitLibraryManager extends LibraryManager { - /** - * Plugin classpath helper - */ - private final URLClassLoaderHelper classLoader; + /** + * Plugin classpath helper + */ + private final URLClassLoaderHelper classLoader; - /** - * Creates a new Bukkit library manager. - * - * @param plugin the plugin to manage - */ - public BukkitLibraryManager(Plugin plugin) { - this(plugin, "libs"); - } + /** + * Creates a new Bukkit library manager. + * + * @param plugin the plugin to manage + */ + public BukkitLibraryManager(Plugin plugin) { this(plugin, "libs"); } - /** - * Creates a new Bukkit library manager. - * - * @param plugin the plugin to manage - * @param directoryName download directory name - */ - public BukkitLibraryManager(Plugin plugin, String directoryName) { - super(new JDKLogAdapter(requireNonNull(plugin, "plugin").getLogger()), plugin.getDataFolder().toPath(), directoryName); - classLoader = new URLClassLoaderHelper((URLClassLoader) plugin.getClass().getClassLoader(), this); - } + /** + * Creates a new Bukkit library manager. + * + * @param plugin the plugin to manage + * @param directoryName download directory name + */ + public BukkitLibraryManager(Plugin plugin, String directoryName) { + super(new JDKLogAdapter(requireNonNull(plugin, "plugin").getLogger()), + plugin.getDataFolder().toPath(), directoryName); + classLoader = new URLClassLoaderHelper( + (URLClassLoader)plugin.getClass().getClassLoader(), this); + } - /** - * Adds a file to the Bukkit plugin's classpath. - * - * @param file the file to add - */ - @Override - protected void addToClasspath(Path file) { - classLoader.addToClasspath(file); - } + /** + * Adds a file to the Bukkit plugin's classpath. + * + * @param file the file to add + */ + @Override + protected void addToClasspath(Path file) { + classLoader.addToClasspath(file); + } } From e3e8f4c96a8214f075b5929d72d8713f202ee3c4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 27 Mar 2022 10:33:21 +0000 Subject: [PATCH 2/5] Restyled by prettier-yaml --- src/main/resources/config.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b1a6652..67a437d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -76,7 +76,6 @@ staffchat: toggle-on: "&8[&dS&8] &7All your messages will &anow&7 go to staffchat." discord: - # If you need help, we're here to assist you at https://austech.dev/to/support # Don't enable if webhook is enabled below @@ -98,7 +97,6 @@ discord: channels: - "N/A: N/A" - # Don't enable if bot is enabled above webhook: enabled: false @@ -107,7 +105,6 @@ discord: url: "" discord-messages: - # The format in game, for when someone sends a message in Discord # Available placeholders: %username%, %discriminator% - The 4 numbers in the username # %nickname% - The nickname on Discord @@ -166,4 +163,4 @@ check-for-updates: true debug: false # no touchy me please [DO NOT TOUCH AS IT CAN BREAK YOUR CONFIG] -config-version: 4 \ No newline at end of file +config-version: 4 From f944f259dee3c7ffef308104ce9df8e9c451a428 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 27 Mar 2022 10:33:35 +0000 Subject: [PATCH 3/5] Restyled by shellharden --- gradlew | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gradlew b/gradlew index 4f906e0..3f80137 100755 --- a/gradlew +++ b/gradlew @@ -35,9 +35,9 @@ while [ -h "$PRG" ] ; do PRG=`dirname "$PRG"`"/$link" fi done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" +SAVED="$(pwd)" +cd "$(dirname \""$PRG"\")/" >/dev/null +APP_HOME="$(pwd -P)" cd "$SAVED" >/dev/null APP_NAME="Gradle" @@ -65,7 +65,7 @@ cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in +case "$(uname)" in CYGWIN* ) cygwin=true ;; @@ -112,7 +112,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi - ulimit -n $MAX_FD + ulimit -n "$MAX_FD" if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi @@ -122,7 +122,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then fi # For Darwin, add options to specify how the application appears in the dock -if $darwin; then +if "$darwin"; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi @@ -136,7 +136,7 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" - for dir in $ROOTDIRSRAW ; do + for dir in "$ROOTDIRSRAW" ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done @@ -151,12 +151,12 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + if [ "$CHECK" -ne 0 ] && [ "$CHECK2" -eq 0 ] ; then ### Added a condition + eval "$(echo args"$i")=$(cygpath --path --ignore --mixed "$arg")" else - eval `echo args$i`="\"$arg\"" + eval "$(echo args"$i")=\"$arg\"" fi - i=`expr $i + 1` + i=`expr "$i" + 1` done case $i in 0) set -- ;; @@ -180,6 +180,6 @@ save () { APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval set -- "$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$GRADLE_OPTS" "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" exec "$JAVACMD" "$@" From 2fdebd472a5579cb15f5754478b0e98f90d19290 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 27 Mar 2022 10:33:36 +0000 Subject: [PATCH 4/5] Restyled by shfmt --- gradlew | 183 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/gradlew b/gradlew index 3f80137..b34c3f9 100755 --- a/gradlew +++ b/gradlew @@ -26,14 +26,14 @@ # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi done SAVED="$(pwd)" cd "$(dirname \""$PRG"\")/" >/dev/null @@ -41,7 +41,7 @@ APP_HOME="$(pwd -P)" cd "$SAVED" >/dev/null APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=$(basename "$0") # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -49,15 +49,15 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn () { - echo "$*" +warn() { + echo "$*" } -die () { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } # OS specific support (must be 'true' or 'false'). @@ -66,118 +66,117 @@ msys=false darwin=false nonstop=false case "$(uname)" in - CYGWIN* ) + CYGWIN*) cygwin=true ;; - Darwin* ) + Darwin*) darwin=true ;; - MINGW* ) + MINGW*) msys=true ;; - NONSTOP* ) + NONSTOP*) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n "$MAX_FD" - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then + MAX_FD_LIMIT=$(ulimit -H -n) + if [ $? -eq 0 ]; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then + MAX_FD="$MAX_FD_LIMIT" fi + ulimit -n "$MAX_FD" + if [ $? -ne 0 ]; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi fi # For Darwin, add options to specify how the application appears in the dock if "$darwin"; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in "$ROOTDIRSRAW" ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" +if [ "$cygwin" = "true" -o "$msys" = "true" ]; then + APP_HOME=$(cygpath --path --mixed "$APP_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") + + JAVACMD=$(cygpath --unix "$JAVACMD") + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) + SEP="" + for dir in "$ROOTDIRSRAW"; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ]; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@"; do + CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) + CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option + + if [ "$CHECK" -ne 0 ] && [ "$CHECK2" -eq 0 ]; then ### Added a condition + eval "$(echo args"$i")=$(cygpath --path --ignore --mixed "$arg")" + else + eval "$(echo args"$i")=\"$arg\"" fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ "$CHECK" -ne 0 ] && [ "$CHECK2" -eq 0 ] ; then ### Added a condition - eval "$(echo args"$i")=$(cygpath --path --ignore --mixed "$arg")" - else - eval "$(echo args"$i")=\"$arg\"" - fi - i=`expr "$i" + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac + i=$(expr "$i" + 1) + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi # Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " +save() { + for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done + echo " " } -APP_ARGS=`save "$@"` +APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- "$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$GRADLE_OPTS" "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" From ca7ecb41bfc48062d78ec06febe7de1cbaeec843 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 27 Mar 2022 10:33:37 +0000 Subject: [PATCH 5/5] Restyled by whitespace --- build.gradle.kts | 2 +- bungeecord/build.gradle.kts | 2 +- .../kotlin/dev/austech/betterstaffchat/bungeecord/BSCBungee.kt | 2 +- .../betterstaffchat/bungeecord/commands/BSCBungeeCommand.kt | 2 +- .../betterstaffchat/bungeecord/commands/CommandManager.kt | 2 +- .../bungeecord/commands/impl/BetterStaffChatCommand.kt | 2 +- .../bungeecord/commands/impl/StaffChatCommand.kt | 2 +- .../bungeecord/commands/impl/StaffChatMuteCommand.kt | 2 +- .../bungeecord/commands/impl/StaffChatToggleCommand.kt | 2 +- .../betterstaffchat/bungeecord/listeners/PlayerListener.kt | 2 +- .../dev/austech/betterstaffchat/bungeecord/util/PlayerUtil.kt | 2 +- common/build.gradle.kts | 2 +- .../main/kotlin/dev/austech/betterstaffchat/common/BSCPlugin.kt | 2 +- .../kotlin/dev/austech/betterstaffchat/common/PlayerMeta.kt | 2 +- .../austech/betterstaffchat/common/libraries/BSCLibraries.kt | 2 +- .../kotlin/dev/austech/betterstaffchat/common/util/Config.kt | 2 +- .../main/kotlin/dev/austech/betterstaffchat/common/util/Data.kt | 2 +- .../dev/austech/betterstaffchat/common/util/StaffChatUtil.kt | 2 +- .../kotlin/dev/austech/betterstaffchat/common/util/TextUtil.kt | 2 +- spigot/build.gradle.kts | 2 +- .../main/kotlin/dev/austech/betterstaffchat/spigot/BSCSpigot.kt | 2 +- .../austech/betterstaffchat/spigot/commands/BSCSpigotCommand.kt | 2 +- .../austech/betterstaffchat/spigot/commands/CommandManager.kt | 2 +- .../spigot/commands/impl/BetterStaffChatCommand.kt | 2 +- .../betterstaffchat/spigot/commands/impl/StaffChatCommand.kt | 2 +- .../spigot/commands/impl/StaffChatMuteCommand.kt | 2 +- .../spigot/commands/impl/StaffChatToggleCommand.kt | 2 +- .../austech/betterstaffchat/spigot/listeners/PlayerListener.kt | 2 +- .../dev/austech/betterstaffchat/spigot/util/PlayerUtil.kt | 2 +- .../dev/austech/betterstaffchat/spigot/util/ReflectionUtil.kt | 2 +- 30 files changed, 30 insertions(+), 30 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9de1c1f..2d4d8d4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -103,4 +103,4 @@ tasks.named("clean") { tasks.named("build") { dependsOn("shadowJar") dependsOn("copyJars") -} \ No newline at end of file +} diff --git a/bungeecord/build.gradle.kts b/bungeecord/build.gradle.kts index 4121dc3..10bdbe3 100644 --- a/bungeecord/build.gradle.kts +++ b/bungeecord/build.gradle.kts @@ -8,4 +8,4 @@ dependencies { compileOnly(project(":common")) compileOnly("net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT") compileOnly("net.kyori:adventure-platform-bungeecord:4.1.0") -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/BSCBungee.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/BSCBungee.kt index c47892c..9e63e92 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/BSCBungee.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/BSCBungee.kt @@ -52,4 +52,4 @@ class BSCBungee: Plugin(), BSCPlugin { proxy.pluginManager.registerListener(this, PlayerListener()) } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/BSCBungeeCommand.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/BSCBungeeCommand.kt index 26dad65..9183abf 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/BSCBungeeCommand.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/BSCBungeeCommand.kt @@ -57,4 +57,4 @@ abstract class BSCBungeeCommand(name: String, permission: String?, aliases: List fun warnTell(s: String) { legacyTell("&e$s") } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/CommandManager.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/CommandManager.kt index 9c6ccf2..00b1ea0 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/CommandManager.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/CommandManager.kt @@ -30,4 +30,4 @@ class CommandManager(private val plugin: BSCBungee) { plugin.proxy.pluginManager.registerCommand(plugin, it) } } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/BetterStaffChatCommand.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/BetterStaffChatCommand.kt index 7914c42..9f5582d 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/BetterStaffChatCommand.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/BetterStaffChatCommand.kt @@ -20,4 +20,4 @@ class BetterStaffChatCommand: BSCBungeeCommand("betterstaffchat", null, listOf(" return } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatCommand.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatCommand.kt index d9dbbd6..48ff20a 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatCommand.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatCommand.kt @@ -20,4 +20,4 @@ class StaffChatCommand(name: String, aliases: List): BSCBungeeCommand(na plugin.staffChatUtil.sendMessage(PlayerUtil.getReceiveAudience(), args.joinToString(separator = " "), PlayerUtil.getSenderName(sender), PlayerUtil.getServer(sender), PlayerMeta(null, null)) } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatMuteCommand.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatMuteCommand.kt index 2cb70d9..2776d79 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatMuteCommand.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatMuteCommand.kt @@ -50,4 +50,4 @@ class StaffChatMuteCommand(name: String, aliases: List): BSCBungeeComman return } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatToggleCommand.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatToggleCommand.kt index 625e31b..307f14b 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatToggleCommand.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/commands/impl/StaffChatToggleCommand.kt @@ -57,4 +57,4 @@ class StaffChatToggleCommand(name: String, aliases: List): BSCBungeeComm return } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/listeners/PlayerListener.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/listeners/PlayerListener.kt index d6b4f0e..e57737d 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/listeners/PlayerListener.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/listeners/PlayerListener.kt @@ -57,4 +57,4 @@ class PlayerListener: Listener { BSCBungee.instance.staffChatUtil.sendSwitchMessage(PlayerUtil.getReceiveAudience(), event.player.name, PlayerUtil.getServerReplacement(event.from), PlayerUtil.getServer(event.player), PlayerMeta(null, null)) } } -} \ No newline at end of file +} diff --git a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/util/PlayerUtil.kt b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/util/PlayerUtil.kt index 31dad43..a138bb0 100644 --- a/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/util/PlayerUtil.kt +++ b/bungeecord/src/main/kotlin/dev/austech/betterstaffchat/bungeecord/util/PlayerUtil.kt @@ -46,4 +46,4 @@ object PlayerUtil { return info.name } -} \ No newline at end of file +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 374aa04..4decff6 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1 +1 @@ -// Nothing needs to be in this file \ No newline at end of file +// Nothing needs to be in this file diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/BSCPlugin.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/BSCPlugin.kt index e2c68a1..9c0cef7 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/BSCPlugin.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/BSCPlugin.kt @@ -14,4 +14,4 @@ interface BSCPlugin { BUKKIT, BUNGEECORD } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/PlayerMeta.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/PlayerMeta.kt index 2fec9c0..2dba7da 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/PlayerMeta.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/PlayerMeta.kt @@ -5,4 +5,4 @@ import java.util.UUID class PlayerMeta( val prefix: String?, val suffix: String? -) {} \ No newline at end of file +) {} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/BSCLibraries.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/BSCLibraries.kt index b00790e..1478de1 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/BSCLibraries.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/libraries/BSCLibraries.kt @@ -117,4 +117,4 @@ object BSCLibraries { return libraryList } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Config.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Config.kt index d70e9a9..235a82c 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Config.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Config.kt @@ -63,4 +63,4 @@ class Config(private val plugin: BSCPlugin) { return path; } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Data.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Data.kt index 80dd2cb..0598f2c 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Data.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/Data.kt @@ -43,4 +43,4 @@ class Data(private val plugin: BSCPlugin) { return Json(dataFile) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/StaffChatUtil.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/StaffChatUtil.kt index 278fd31..b460b9b 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/StaffChatUtil.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/StaffChatUtil.kt @@ -62,4 +62,4 @@ class StaffChatUtil(private val plugin: BSCPlugin) { audience.sendMessage(TextUtil.parseText(configMessage)) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/TextUtil.kt b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/TextUtil.kt index b3de47b..50f60c7 100644 --- a/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/TextUtil.kt +++ b/common/src/main/kotlin/dev/austech/betterstaffchat/common/util/TextUtil.kt @@ -13,4 +13,4 @@ object TextUtil { fun parseText(s: String): Component { return miniMessage.deserialize(s) } -} \ No newline at end of file +} diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts index 7815745..6cf7afd 100644 --- a/spigot/build.gradle.kts +++ b/spigot/build.gradle.kts @@ -9,4 +9,4 @@ dependencies { compileOnly(project(":common")) compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT") compileOnly("net.kyori:adventure-platform-bukkit:4.1.0") -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/BSCSpigot.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/BSCSpigot.kt index ad64dea..e9f0f90 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/BSCSpigot.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/BSCSpigot.kt @@ -53,4 +53,4 @@ class BSCSpigot: JavaPlugin(), BSCPlugin { Bukkit.getPluginManager().registerEvents(PlayerListener(), this) } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/BSCSpigotCommand.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/BSCSpigotCommand.kt index fd07fe1..ca4822a 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/BSCSpigotCommand.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/BSCSpigotCommand.kt @@ -54,4 +54,4 @@ abstract class BSCSpigotCommand(name: String, description: String, usage: String fun warnTell(s: String) { legacyTell("&e$s") } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/CommandManager.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/CommandManager.kt index 61140bd..6e152f7 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/CommandManager.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/CommandManager.kt @@ -37,4 +37,4 @@ class CommandManager(private val plugin: BSCSpigot) { ReflectionUtil.registerCommand(it) } } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/BetterStaffChatCommand.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/BetterStaffChatCommand.kt index f7382b5..8e9e1b5 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/BetterStaffChatCommand.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/BetterStaffChatCommand.kt @@ -20,4 +20,4 @@ class BetterStaffChatCommand: BSCSpigotCommand("betterstaffchat", "The main comm return true; } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatCommand.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatCommand.kt index 74b1194..8d1142b 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatCommand.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatCommand.kt @@ -26,4 +26,4 @@ class StaffChatCommand(name: String, description: String, usage: String, aliases return true; } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatMuteCommand.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatMuteCommand.kt index 05b3fcb..fde5248 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatMuteCommand.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatMuteCommand.kt @@ -54,4 +54,4 @@ class StaffChatMuteCommand(name: String, description: String, usage: String, ali return true } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatToggleCommand.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatToggleCommand.kt index 27fdb5b..dd4d834 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatToggleCommand.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/commands/impl/StaffChatToggleCommand.kt @@ -61,4 +61,4 @@ class StaffChatToggleCommand(name: String, description: String, usage: String, a return true } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/listeners/PlayerListener.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/listeners/PlayerListener.kt index 47a9778..5e73f5e 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/listeners/PlayerListener.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/listeners/PlayerListener.kt @@ -48,4 +48,4 @@ class PlayerListener: Listener { BSCSpigot.instance.staffChatUtil.sendSwitchMessage(PlayerUtil.getReceiveAudience(), event.player.name, event.from.name, event.player.world.name, PlayerMeta(null, null)) } } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/PlayerUtil.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/PlayerUtil.kt index f418286..e96d8f5 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/PlayerUtil.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/PlayerUtil.kt @@ -32,4 +32,4 @@ object PlayerUtil { ) else getPermissionAudience("betterstaffchat.messages.read") } -} \ No newline at end of file +} diff --git a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/ReflectionUtil.kt b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/ReflectionUtil.kt index 632cf40..94af261 100644 --- a/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/ReflectionUtil.kt +++ b/spigot/src/main/kotlin/dev/austech/betterstaffchat/spigot/util/ReflectionUtil.kt @@ -24,4 +24,4 @@ object ReflectionUtil { throw RuntimeException("Failed to register command: " + command.name); } } -} \ No newline at end of file +}