diff --git a/README.md b/README.md index dad1336..1d9d8a5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Get the artifact under /target folder ## How to Contribute #### Translations -Clone this project and create a new language file in the /common/src/main/resources/translations directory. \ +Clone this project and create a new language file in the /backend/src/main/resources/translations directory. \ Once your changes are ready, open a pull request for review. We appreciate your works! ## Support the Developer diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 11aaa7d..e9af732 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,5 +1,4 @@ plugins { - id("io.github.goooler.shadow") version "8.1.8" id("maven-publish") } @@ -10,21 +9,32 @@ repositories { } dependencies { - implementation(project(":common")) // Adventure implementation("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}") compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}") compileOnly("net.kyori:adventure-text-serializer-gson:${rootProject.properties["adventure_bundle_version"]}") + compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}") + compileOnly("net.kyori:adventure-text-serializer-gson:${rootProject.properties["adventure_bundle_version"]}") // YAML implementation(files("libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar")) // Cache compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}") // Netty - compileOnly("io.netty:netty-all:4.1.113.Final") + compileOnly("io.netty:netty-all:4.1.117.Final") // GSON compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}") // Fast util compileOnly("it.unimi.dsi:fastutil:${rootProject.properties["fastutil_version"]}") + // Command + compileOnly("org.incendo:cloud-core:${rootProject.properties["cloud_core_version"]}") + compileOnly("org.incendo:cloud-minecraft-extras:${rootProject.properties["cloud_minecraft_extras_version"]}") + // Logger + compileOnly("org.slf4j:slf4j-api:${rootProject.properties["slf4j_version"]}") + compileOnly("org.apache.logging.log4j:log4j-core:${rootProject.properties["log4j_version"]}") + // Expression + compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}") + // code generator + compileOnly("net.bytebuddy:byte-buddy:${rootProject.properties["byte_buddy_version"]}") } java { @@ -34,7 +44,6 @@ java { languageVersion = JavaLanguageVersion.of(17) } withSourcesJar() - withJavadocJar() } tasks.withType { @@ -45,7 +54,7 @@ tasks.withType { tasks { shadowJar { -// archiveClassifier.set("") + archiveClassifier.set("") archiveFileName = "custom-nameplates-${rootProject.properties["project_version"]}.jar" relocate ("net.kyori", "net.momirealms.customnameplates.libraries") relocate("dev.dejvokep", "net.momirealms.customnameplates.libraries") @@ -73,10 +82,18 @@ publishing { groupId = "net.momirealms" artifactId = "custom-nameplates" version = rootProject.properties["project_version"].toString() - from(components["java"]) + artifact(tasks["sourcesJar"]) + from(components["shadow"]) pom { name = "CustomNameplates API" - url = "https://momirealms.net" + url = "https://github.com/Xiao-MoMi/Custom-Nameplates" + licenses { + license { + name = "GNU General Public License v3.0" + url = "https://www.gnu.org/licenses/gpl-3.0.html" + distribution = "repo" + } + } } } } diff --git a/api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java b/api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java new file mode 100644 index 0000000..83f93e2 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java @@ -0,0 +1,161 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.command; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; +import net.momirealms.customnameplates.common.sender.SenderFactory; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.context.CommandContext; + +/** + * Abstract base class for command feature implementations within the Custom Nameplates command system. + * This class provides utility methods for command registration, feedback handling, and configuration. + * + * @param The type of the sender (e.g., a player or console sender) for the command. + */ +public abstract class AbstractCommandFeature implements CommandFeature { + /** + * The command manager + */ + protected final CustomNameplatesCommandManager commandManager; + /** + * The command config + */ + protected CommandConfig commandConfig; + + /** + * Constructs an AbstractCommandFeature instance with the given command manager. + * + * @param commandManager The command manager to manage the commands associated with this feature. + */ + public AbstractCommandFeature(CustomNameplatesCommandManager commandManager) { + this.commandManager = commandManager; + } + + /** + * Abstract method to retrieve the sender factory for the command. + * Implementations must provide the logic for creating senders of type C. + * + * @return The sender factory for the command. + */ + protected abstract SenderFactory getSenderFactory(); + + /** + * Abstract method to assemble the command builder with the given manager. + * Implementations must define how to build the command. + * + * @param manager The command manager responsible for managing the command. + * @param builder The builder used to construct the command. + * @return A command builder ready to be built. + */ + public abstract Command.Builder assembleCommand(CommandManager manager, Command.Builder builder); + + /** + * Registers the command with the provided command manager. + * This method builds the command and registers it with the command manager. + * + * @param manager The command manager to register the command with. + * @param builder The builder used to create the command. + * @return The registered command. + */ + @Override + @SuppressWarnings("unchecked") + public Command registerCommand(CommandManager manager, Command.Builder builder) { + Command command = (Command) assembleCommand(manager, builder).build(); + manager.command(command); + return command; + } + + /** + * Registers any related functions or hooks. This method is a no-op by default + * and can be overridden in subclasses to register additional functionality. + */ + @Override + public void registerRelatedFunctions() { + // empty + } + + /** + * Unregisters any related functions or hooks. This method is a no-op by default + * and can be overridden in subclasses to unregister additional functionality. + */ + @Override + public void unregisterRelatedFunctions() { + // empty + } + + /** + * Handles feedback for the command execution, sending a translation message to the sender. + * The feedback is suppressed if the "silent" flag is present in the command context. + * + * @param context The command context containing information about the sender and flags. + * @param key The key for the translation component to be used as feedback. + * @param args The arguments to be passed to the translation. + */ + @Override + @SuppressWarnings("unchecked") + public void handleFeedback(CommandContext context, TranslatableComponent.Builder key, Component... args) { + if (context.flags().hasFlag("silent")) { + return; + } + commandManager.handleCommandFeedback((C) context.sender(), key, args); + } + + /** + * Handles feedback for the command execution, sending a translation message to the sender. + * + * @param sender The sender to receive the feedback. + * @param key The key for the translation component to be used as feedback. + * @param args The arguments to be passed to the translation. + */ + @Override + public void handleFeedback(C sender, TranslatableComponent.Builder key, Component... args) { + commandManager.handleCommandFeedback(sender, key, args); + } + + /** + * Retrieves the command manager associated with this feature. + * + * @return The command manager. + */ + @Override + public CustomNameplatesCommandManager getCustomNameplatesCommandManager() { + return commandManager; + } + + /** + * Retrieves the configuration associated with the command. + * + * @return The command configuration. + */ + @Override + public CommandConfig getCommandConfig() { + return commandConfig; + } + + /** + * Sets the configuration for the command. + * + * @param commandConfig The configuration to set for the command. + */ + public void setCommandConfig(CommandConfig commandConfig) { + this.commandConfig = commandConfig; + } +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java b/api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java similarity index 88% rename from common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java rename to api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java index 587a796..06d7f4d 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandManager.java @@ -49,17 +49,39 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +/** + * An abstract implementation of the {@link CustomNameplatesCommandManager} that handles the management and registration of command features, + * exception handling, and feedback handling within the Custom Nameplates plugin. + * + * @param The type of the sender (e.g., player, console) for the commands. + */ public abstract class AbstractCommandManager implements CustomNameplatesCommandManager { - + /** + * Registered commands + */ protected final HashSet> registeredRootCommandComponents = new HashSet<>(); + /** + * Registered features + */ protected final HashSet> registeredFeatures = new HashSet<>(); + /** + * The command manager + */ protected final CommandManager commandManager; + /** + * The NameplatesPlugin + */ protected final NameplatesPlugin plugin; private final CustomNameplatesCaptionFormatter captionFormatter = new CustomNameplatesCaptionFormatter(); private final MinecraftExceptionHandler.Decorator decorator = (formatter, ctx, msg) -> msg; - private TriConsumer feedbackConsumer; + /** + * Constructs an AbstractCommandManager instance with the provided plugin and command manager. + * + * @param plugin The plugin instance managing this command manager. + * @param commandManager The command manager instance that handles the command registration. + */ public AbstractCommandManager(NameplatesPlugin plugin, CommandManager commandManager) { this.commandManager = commandManager; this.plugin = plugin; @@ -86,6 +108,12 @@ public abstract class AbstractCommandManager implements CustomNameplatesComma }); } + /** + * Wraps a sender base on platform + * + * @param c sender + * @return the wrapped sender + */ protected abstract Sender wrapSender(C c); private void inject() { @@ -108,7 +136,7 @@ public abstract class AbstractCommandManager implements CustomNameplatesComma } @Override - public CommandConfig getCommandConfig(YamlDocument document, String featureID) { + public CommandConfig getCommandConfig(YamlDocument document, String featureID) { Section section = document.getSection(featureID); if (section == null) return null; return new CommandConfig.Builder() @@ -119,7 +147,7 @@ public abstract class AbstractCommandManager implements CustomNameplatesComma } @Override - public Collection> buildCommandBuilders(CommandConfig config) { + public Collection> buildCommandBuilders(CommandConfig config) { ArrayList> list = new ArrayList<>(); for (String usage : config.getUsages()) { if (!usage.startsWith("/")) continue; @@ -135,7 +163,7 @@ public abstract class AbstractCommandManager implements CustomNameplatesComma } @Override - public void registerFeature(CommandFeature feature, CommandConfig config) { + public void registerFeature(CommandFeature feature, CommandConfig config) { if (!config.isEnable()) throw new RuntimeException("Registering a disabled command feature is not allowed"); for (Command.Builder builder : buildCommandBuilders(config)) { Command command = feature.registerCommand(commandManager, builder); @@ -155,7 +183,7 @@ public abstract class AbstractCommandManager implements CustomNameplatesComma throw new RuntimeException(e); } this.getFeatures().values().forEach(feature -> { - CommandConfig config = getCommandConfig(document, feature.getFeatureID()); + CommandConfig config = getCommandConfig(document, feature.getFeatureID()); if (config.isEnable()) { registerFeature(feature, config); } diff --git a/api/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java new file mode 100644 index 0000000..7dae7f3 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.command; + +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; + +/** + * A builder interface for constructing commands with configurable parameters. + * This interface allows setting permissions, command nodes (subcommands), and + * building the final {@link Command.Builder} object. + */ +public interface CommandBuilder { + + /** + * Sets the permission required to execute the command. + * + * @param permission the permission string required for executing the command. + * @return the current {@link CommandBuilder} instance for method chaining. + */ + CommandBuilder setPermission(String permission); + + /** + * Sets the subcommands (nodes) for the command. + * This allows defining a hierarchy of commands. + * + * @param subNodes the subcommands or nodes to add to the command. + * @return the current {@link CommandBuilder} instance for method chaining. + */ + CommandBuilder setCommandNode(String... subNodes); + + /** + * Retrieves the fully constructed {@link Command.Builder} instance. + * This method returns the builder object that can be used to further configure + * and register the command. + * + * @return the built {@link Command.Builder} instance. + */ + Command.Builder getBuiltCommandBuilder(); + + /** + * Basic implementation of the {@link CommandBuilder} interface. + * This class provides a default implementation for constructing a command + * with the given root node, permission, and subcommand nodes. + * + * @param The type of context or object associated with the command. + */ + class BasicCommandBuilder implements CommandBuilder { + + /** + * The actual command builder used to construct the command. + */ + private Command.Builder commandBuilder; + + /** + * Constructs a new {@link BasicCommandBuilder} for building a command. + * + * @param commandManager the {@link CommandManager} instance used for creating the command builder. + * @param rootNode the root node for the command. + */ + public BasicCommandBuilder(CommandManager commandManager, String rootNode) { + this.commandBuilder = commandManager.commandBuilder(rootNode); + } + + /** + * Sets the permission for the command. + * + * @param permission the permission required for executing the command. + * @return the current {@link CommandBuilder} instance for method chaining. + */ + @Override + public CommandBuilder setPermission(String permission) { + this.commandBuilder = this.commandBuilder.permission(permission); + return this; + } + + /** + * Sets the subcommands (nodes) for the command. + * + * @param subNodes the subcommands to add to the command. + * @return the current {@link CommandBuilder} instance for method chaining. + */ + @Override + public CommandBuilder setCommandNode(String... subNodes) { + for (String sub : subNodes) { + this.commandBuilder = this.commandBuilder.literal(sub); + } + return this; + } + + /** + * Retrieves the built {@link Command.Builder} instance. + * + * @return the built {@link Command.Builder} instance. + */ + @Override + public Command.Builder getBuiltCommandBuilder() { + return commandBuilder; + } + } +} diff --git a/api/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java new file mode 100644 index 0000000..14468ca --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.command; + +import java.util.ArrayList; +import java.util.List; + +/** + * A configuration class for setting up command-related options such as enabling/disabling, + * command usages, and required permissions. + *

+ * This class provides a builder pattern implementation to easily create and configure + * a {@link CommandConfig} object with a fluent API. + */ +public class CommandConfig { + + /** + * Flag indicating whether the command is enabled. + */ + private boolean enable = false; + + /** + * List of command usage examples or syntax hints. + */ + private List usages = new ArrayList<>(); + + /** + * Permission required to execute the command. + */ + private String permission = null; + + /** + * Private constructor to prevent direct instantiation. + * Use the {@link Builder} class to construct an instance. + */ + private CommandConfig() { + } + + /** + * Constructs a new {@link CommandConfig} with the specified values. + * + * @param enable whether the command is enabled. + * @param usages the list of command usages. + * @param permission the permission required to execute the command. + */ + public CommandConfig(boolean enable, List usages, String permission) { + this.enable = enable; + this.usages = usages; + this.permission = permission; + } + + /** + * Gets whether the command is enabled. + * + * @return true if the command is enabled, false otherwise. + */ + public boolean isEnable() { + return enable; + } + + /** + * Gets the list of command usages or syntax examples. + * + * @return the list of command usages. + */ + public List getUsages() { + return usages; + } + + /** + * Gets the permission required to execute the command. + * + * @return the permission string. + */ + public String getPermission() { + return permission; + } + + /** + * Builder class for constructing a {@link CommandConfig} object with customizable options. + * This allows setting values for enabling the command, defining usages, and setting permissions. + * + * @param the context type associated with the command. + */ + public static class Builder { + + /** + * The {@link CommandConfig} object being built. + */ + private final CommandConfig config; + + /** + * Constructs a new {@link Builder} for {@link CommandConfig}. + * Initializes the config object to default values. + */ + public Builder() { + this.config = new CommandConfig(); + } + + /** + * Sets the list of command usages (examples or syntax hints). + * + * @param usages the list of command usages. + * @return the current {@link Builder} instance for method chaining. + */ + public Builder usages(List usages) { + config.usages = usages; + return this; + } + + /** + * Sets the permission required to execute the command. + * + * @param permission the permission string. + * @return the current {@link Builder} instance for method chaining. + */ + public Builder permission(String permission) { + config.permission = permission; + return this; + } + + /** + * Sets whether the command is enabled. + * + * @param enable true to enable the command, false to disable it. + * @return the current {@link Builder} instance for method chaining. + */ + public Builder enable(boolean enable) { + config.enable = enable; + return this; + } + + /** + * Builds and returns the constructed {@link CommandConfig} object. + * + * @return the {@link CommandConfig} object. + */ + public CommandConfig build() { + return config; + } + } +} diff --git a/api/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java new file mode 100644 index 0000000..9594534 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.command; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.context.CommandContext; + +/** + * Represents the contract for a feature that provides a command in the Custom Nameplates system. + * This interface defines methods for registering commands, handling feedback, and managing related functionality. + * + * @param The type of the sender (e.g., player, console) for the command. + */ +public interface CommandFeature { + + /** + * Registers the command with the provided command manager and builder. + * + * @param cloudCommandManager The command manager responsible for managing commands. + * @param builder The command builder used to create the command. + * @return The registered command. + */ + Command registerCommand(CommandManager cloudCommandManager, Command.Builder builder); + + /** + * Retrieves a unique identifier for this feature. + * The feature ID is used to identify the feature within the system. + * + * @return A unique identifier for this command feature. + */ + String getFeatureID(); + + /** + * Registers any related functions or hooks that this feature may require. + * This method may be used to register additional functionality necessary for the feature. + */ + void registerRelatedFunctions(); + + /** + * Unregisters any related functions or hooks that were previously registered. + * This method is used for cleaning up after the feature when it's no longer needed. + */ + void unregisterRelatedFunctions(); + + /** + * Handles feedback for the command execution, sending a translation message to the sender. + * The feedback may be affected by the flags in the command context (e.g., silent mode). + * + * @param context The command context containing information about the sender and flags. + * @param key The key for the translation component to be used as feedback. + * @param args The arguments to be passed to the translation. + */ + void handleFeedback(CommandContext context, TranslatableComponent.Builder key, Component... args); + + /** + * Handles feedback for the command execution, sending a translation message to the sender. + * + * @param sender The sender to receive the feedback. + * @param key The key for the translation component to be used as feedback. + * @param args The arguments to be passed to the translation. + */ + void handleFeedback(C sender, TranslatableComponent.Builder key, Component... args); + + /** + * Retrieves the command manager associated with this feature. + * + * @return The command manager. + */ + CustomNameplatesCommandManager getCustomNameplatesCommandManager(); + + /** + * Retrieves the configuration associated with the command. + * + * @return The command configuration. + */ + CommandConfig getCommandConfig(); +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java b/api/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java new file mode 100644 index 0000000..5a63245 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.command; + +import dev.dejvokep.boostedyaml.YamlDocument; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.util.Index; +import net.momirealms.customnameplates.common.util.TriConsumer; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * Interface for managing commands within the Custom Nameplates plugin. This interface defines methods for + * registering features, handling feedback, and interacting with the command manager and configurations. + * + * @param The type of the sender (e.g., player, console) for the commands. + */ +public interface CustomNameplatesCommandManager { + + /** + * The default configuration file name for commands + */ + String commandsFile = "commands.yml"; + + /** + * Unregisters all previously registered command features. + */ + void unregisterFeatures(); + + /** + * Registers a command feature with the provided configuration. + * + * @param feature The command feature to register. + * @param config The configuration for the feature. + */ + void registerFeature(CommandFeature feature, CommandConfig config); + + /** + * Registers all default features based on the plugin configuration. + */ + void registerDefaultFeatures(); + + /** + * Retrieves all registered command features in the form of an index. + * + * @return The index of registered command features. + */ + Index> getFeatures(); + + /** + * Sets a custom feedback consumer that handles the feedback sent to the command sender. + * + * @param feedbackConsumer The custom feedback consumer. + */ + void setFeedbackConsumer(@NotNull TriConsumer feedbackConsumer); + + /** + * Provides the default feedback consumer for sending feedback messages. + * + * @return The default feedback consumer. + */ + TriConsumer defaultFeedbackConsumer(); + + /** + * Retrieves the command configuration from a YAML document and a given feature ID. + * + * @param document The YAML document containing the configuration. + * @param featureID The ID of the feature to retrieve configuration for. + * @return The command configuration for the specified feature, or null if not found. + */ + CommandConfig getCommandConfig(YamlDocument document, String featureID); + + /** + * Builds a collection of command builders based on the given configuration. + * + * @param config The command configuration. + * @return A collection of command builders. + */ + Collection> buildCommandBuilders(CommandConfig config); + + /** + * Retrieves the command manager associated with this command manager. + * + * @return The command manager. + */ + CommandManager getCommandManager(); + + /** + * Sends feedback to the sender based on the provided key and arguments. + * + * @param sender The sender of the command. + * @param key The key used to retrieve the feedback message. + * @param args The arguments to be included in the feedback message. + */ + void handleCommandFeedback(C sender, TranslatableComponent.Builder key, Component... args); + + /** + * Sends feedback to the sender based on the provided node and component. + * + * @param sender The sender of the command. + * @param node The feedback node. + * @param component The component containing the feedback message. + */ + void handleCommandFeedback(C sender, String node, Component component); +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java similarity index 80% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java index 7046e12..53fc848 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/dependency/Dependency.java @@ -1,26 +1,18 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright (C) <2024> * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package net.momirealms.customnameplates.common.dependency; @@ -356,10 +348,27 @@ public enum Dependency { private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar"; + /** + * Constructs a Dependency with the given group ID, artifact ID, repository, and custom artifact ID. + * + * @param groupId the group ID of the dependency + * @param artifactId the artifact ID of the dependency + * @param repo the repository for the dependency + * @param customArtifactID the custom artifact ID for the dependency + */ Dependency(String groupId, String artifactId, String repo, String customArtifactID) { this(groupId, artifactId, repo, customArtifactID, new Relocation[0]); } + /** + * Constructs a Dependency with the given group ID, artifact ID, repository, custom artifact ID, and relocations. + * + * @param groupId the group ID of the dependency + * @param artifactId the artifact ID of the dependency + * @param repo the repository for the dependency + * @param customArtifactID the custom artifact ID for the dependency + * @param relocations any relocations associated with the dependency + */ Dependency(String groupId, String artifactId, String repo, String customArtifactID, Relocation... relocations) { this.artifactId = artifactId; this.artifactIdSuffix = ""; @@ -369,6 +378,16 @@ public enum Dependency { this.customArtifactID = customArtifactID; } + /** + * Constructs a Dependency with the given group ID, artifact ID, repository, custom artifact ID, and relocations. + * + * @param groupId the group ID of the dependency + * @param artifactId the artifact ID of the dependency + * @param repo the repository for the dependency + * @param customArtifactID the custom artifact ID for the dependency + * @param artifactIdSuffix the custom artifact suffix + * @param relocations any relocations associated with the dependency + */ Dependency(String groupId, String artifactId, String repo, String customArtifactID, String artifactIdSuffix, Relocation... relocations) { this.artifactId = artifactId; this.artifactIdSuffix = artifactIdSuffix; @@ -378,10 +397,20 @@ public enum Dependency { this.customArtifactID = customArtifactID; } + /** + * Sets the artifact suffix + * + * @param artifactIdSuffix the artifact suffix + */ public void setArtifactIdSuffix(String artifactIdSuffix) { this.artifactIdSuffix = artifactIdSuffix; } + /** + * Returns the version of the dependency based on the custom artifact ID. + * + * @return the version of the dependency + */ public String getVersion() { return CustomNameplatesProperties.getValue(customArtifactID); } @@ -390,6 +419,12 @@ public enum Dependency { return s.replace("{}", "."); } + /** + * Returns the filename for the dependency's JAR file, optionally with a classifier. + * + * @param classifier the classifier for the JAR (e.g., "sources" or "javadoc") + * @return the filename for the JAR + */ public String getFileName(String classifier) { String name = customArtifactID.toLowerCase(Locale.ROOT).replace('_', '-'); String extra = classifier == null || classifier.isEmpty() @@ -398,6 +433,11 @@ public enum Dependency { return name + "-" + this.getVersion() + extra + ".jar"; } + /** + * Returns the Maven repository path for the dependency. + * + * @return the Maven repository path + */ String getMavenRepoPath() { return String.format(MAVEN_FORMAT, rewriteEscaping(groupId).replace(".", "/"), @@ -408,6 +448,11 @@ public enum Dependency { ); } + /** + * Returns the list of relocations for the dependency. + * + * @return a list of {@link Relocation} objects + */ public List getRelocations() { return this.relocations; } @@ -426,6 +471,11 @@ public enum Dependency { } } + /** + * Gets the repo + * + * @return the repo + */ @Nullable public String getRepo() { return repo; diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java similarity index 79% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java index 679517c..76f5c18 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyDownloadException.java @@ -30,18 +30,20 @@ package net.momirealms.customnameplates.common.dependency; */ public class DependencyDownloadException extends Exception { - public DependencyDownloadException() { - - } - + /** + * Constructs a new DependencyDownloadException with the specified detail message. + * + * @param message the detail message, which provides additional information about the error + */ public DependencyDownloadException(String message) { super(message); } - public DependencyDownloadException(String message, Throwable cause) { - super(message, cause); - } - + /** + * Constructs a new DependencyDownloadException with the specified cause. + * + * @param cause the cause of the exception, which can be retrieved later with {@link Throwable#getCause()} + */ public DependencyDownloadException(Throwable cause) { super(cause); } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManager.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManager.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManager.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManager.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java similarity index 98% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java index 43a4d37..19d89e6 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyManagerImpl.java @@ -61,6 +61,11 @@ public class DependencyManagerImpl implements DependencyManager { private final Executor loadingExecutor; private final NameplatesPlugin plugin; + /** + * Constructs a DependencyManagerImpl instance + * + * @param plugin plugin + */ public DependencyManagerImpl(NameplatesPlugin plugin) { this.plugin = plugin; this.registry = new DependencyRegistry(); diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java similarity index 89% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java index e5e5489..01419c9 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRegistry.java @@ -32,6 +32,12 @@ import com.google.gson.JsonElement; */ public class DependencyRegistry { + /** + * Check if the dependency should be automatically loaded + * + * @param dependency dependency + * @return should be automatically loaded or not + */ public boolean shouldAutoLoad(Dependency dependency) { return switch (dependency) { // all used within 'isolated' classloaders, and are therefore not @@ -41,6 +47,11 @@ public class DependencyRegistry { }; } + /** + * Checks if gson is relocated + * + * @return relocated or not + */ @SuppressWarnings("ConstantConditions") public static boolean isGsonRelocated() { return JsonElement.class.getName().startsWith("net.momirealms"); @@ -58,5 +69,4 @@ public class DependencyRegistry { private static boolean slf4jPresent() { return classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory"); } - } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java similarity index 98% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java index 646499f..b775f69 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/dependency/DependencyRepository.java @@ -66,6 +66,11 @@ public enum DependencyRepository { this.id = id; } + /** + * Gets the url of this repo + * + * @return the url + */ public String getUrl() { return url; } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/classloader/IsolatedClassLoader.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/classloader/IsolatedClassLoader.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/classloader/IsolatedClassLoader.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/classloader/IsolatedClassLoader.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/Relocation.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/Relocation.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/Relocation.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/Relocation.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHandler.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHandler.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHandler.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHandler.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHelper.java b/api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHelper.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHelper.java rename to api/src/main/java/net/momirealms/customnameplates/common/dependency/relocation/RelocationHelper.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java b/api/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java similarity index 55% rename from common/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java index 87a600d..75ac8a8 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java @@ -17,16 +17,23 @@ package net.momirealms.customnameplates.common.event; -import net.kyori.adventure.text.Component; +/** + * Interface representing an event or task that can be cancelled. + * This interface defines methods to check and set the cancellation state of the event or task. + */ +public interface Cancellable { -public interface CommandFeedbackEvent extends NameplatesEvent, Cancellable { + /** + * Gets the current cancelled state of the event or task. + * + * @return true if the event or task has been cancelled, false otherwise. + */ + boolean cancelled(); - @Param(0) - C sender(); - - @Param(1) - String key(); - - @Param(2) - Component message(); + /** + * Sets the cancelled state of the event or task. + * + * @param cancelled a boolean indicating whether the event is cancelled + */ + void cancelled(final boolean cancelled); } diff --git a/api/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java b/api/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java new file mode 100644 index 0000000..49899b6 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/CommandFeedbackEvent.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.event; + +import net.kyori.adventure.text.Component; + +/** + * An event that represents feedback generated by a command execution. + * This event contains the sender of the command, the associated key, and the feedback message. + */ +public interface CommandFeedbackEvent extends NameplatesEvent, Cancellable { + + /** + * Gets the sender of the command that triggered this event. + * + * @return the sender (e.g., player or entity) of the command. + */ + @Param(0) + C sender(); + + /** + * Gets the key associated with the feedback message. + * This key may be used to identify the context or specific type of feedback. + * + * @return the key for the feedback message. + */ + @Param(1) + String key(); + + /** + * Gets the feedback message that will be sent in response to the command. + * The message is represented by a {@link Component}, which allows for rich text formatting. + * + * @return the feedback message to be displayed or logged. + */ + @Param(2) + Component message(); +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventConfig.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventConfig.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventConfig.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventConfig.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventConfigImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventConfigImpl.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventConfigImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventConfigImpl.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventConsumer.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventConsumer.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventConsumer.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventConsumer.java diff --git a/api/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java new file mode 100644 index 0000000..95b5ff4 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.event; + +import net.momirealms.customnameplates.common.event.bus.EventBus; +import net.momirealms.customnameplates.common.plugin.NameplatesPlugin; + +import java.util.OptionalInt; + +/** + * Interface for managing and dispatching events within the Nameplates plugin system. + *

+ * This interface provides methods to subscribe to events, dispatch events, and interact with the underlying + * {@link EventBus}. It allows plugins to register subscribers for specific events and manage the event lifecycle. + *

+ */ +public interface EventManager { + + /** + * A static inner class that holds the singleton instance of {@link EventManager}. + * This ensures that the {@link EventManager} is initialized only once. + */ + class SingletonHolder { + private static EventManager INSTANCE = null; + } + + /** + * Creates and returns the singleton instance of {@link EventManager}. + *

+ * This method ensures that only one instance of the {@link EventManager} is created during the lifecycle + * of the plugin. If the instance does not exist, it initializes the {@link EventManager} using the provided + * {@link NameplatesPlugin}. + *

+ * + * @param plugin the {@link NameplatesPlugin} instance to be used for initializing the event manager + * @return the singleton instance of {@link EventManager} + */ + static EventManager create(NameplatesPlugin plugin) { + if (SingletonHolder.INSTANCE == null) { + SingletonHolder.INSTANCE = new EventManagerImpl(plugin); + } + return SingletonHolder.INSTANCE; + } + + /** + * Subscribes a {@link EventSubscriber} to an event type. + *

+ * This method allows subscribing a listener (subscriber) to a specific event type. The subscriber will be notified + * whenever the event is dispatched. + *

+ * + * @param the type of event to subscribe to + * @param event the {@link Class} object representing the event type + * @param subscriber the {@link EventSubscriber} that will handle the event + * @return an {@link EventSubscription} representing the subscription + */ + EventSubscription subscribe(Class event, EventSubscriber subscriber); + + /** + * Subscribes a {@link EventSubscriber} to an event type with a custom event configuration. + *

+ * This method allows subscribing a listener (subscriber) to a specific event type with additional configuration + * settings for the event. The subscriber will be notified based on the provided configuration when the event is + * dispatched. + *

+ * + * @param the type of event to subscribe to + * @param event the {@link Class} object representing the event type + * @param config the {@link EventConfig} containing additional event configuration + * @param subscriber the {@link EventSubscriber} that will handle the event + * @return an {@link EventSubscription} representing the subscription + */ + EventSubscription subscribe(Class event, EventConfig config, EventSubscriber subscriber); + + /** + * Dispatches an event of the specified class with the provided parameters. + *

+ * This method triggers the event, notifying all subscribers of the event. The event is dispatched synchronously + * to all registered subscribers. + *

+ * + * @param eventClass the {@link Class} object representing the event type + * @param params the parameters to pass to the event + * @return the dispatched {@link NameplatesEvent} + */ + NameplatesEvent dispatch(Class eventClass, Object... params); + + /** + * Dispatches an event of the specified class with the provided order and parameters. + *

+ * This method allows dispatching the event with an optional order. The order is used to prioritize events, + * allowing certain events to be processed before others. If the order is not provided, the event will be dispatched + * without any specific order. + *

+ * + * @param eventClass the {@link Class} object representing the event type + * @param order the optional {@link OptionalInt} specifying the order of the event + * @param params the parameters to pass to the event + * @return the dispatched {@link NameplatesEvent} + */ + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + NameplatesEvent dispatch(Class eventClass, OptionalInt order, Object... params); + + /** + * Retrieves the underlying event bus that handles event dispatching and subscriptions. + *

+ * The {@link EventBus} is responsible for managing the lifecycle of events, including dispatching and subscribing + * to events. This method allows direct access to the {@link EventBus}. + *

+ * + * @return the underlying {@link EventBus} used by the event manager + */ + EventBus getEventBus(); +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventManagerImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventManagerImpl.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventManagerImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventManagerImpl.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventSubscriber.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventSubscriber.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventSubscriber.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventSubscriber.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventSubscription.java b/api/src/main/java/net/momirealms/customnameplates/common/event/EventSubscription.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/EventSubscription.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/EventSubscription.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java b/api/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java similarity index 85% rename from common/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java index ba12348..7c36615 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/NameplatesEvent.java @@ -3,10 +3,15 @@ package net.momirealms.customnameplates.common.event; import net.momirealms.customnameplates.common.plugin.NameplatesPlugin; import org.jetbrains.annotations.NotNull; +/** + * Interface for Nameplates Event + */ public interface NameplatesEvent { /** * Get the plugin instance this event was dispatched from + * + * @return the plugin instance */ @NotNull NameplatesPlugin plugin(); diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/Param.java b/api/src/main/java/net/momirealms/customnameplates/common/event/Param.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/Param.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/Param.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/bus/EventBus.java b/api/src/main/java/net/momirealms/customnameplates/common/event/bus/EventBus.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/bus/EventBus.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/bus/EventBus.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/bus/SimpleEventBus.java b/api/src/main/java/net/momirealms/customnameplates/common/event/bus/SimpleEventBus.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/bus/SimpleEventBus.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/bus/SimpleEventBus.java diff --git a/api/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java b/api/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java new file mode 100644 index 0000000..b80fb76 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.event.gen; + +import net.momirealms.customnameplates.common.event.NameplatesEvent; +import net.momirealms.customnameplates.common.plugin.NameplatesPlugin; +import org.jetbrains.annotations.NotNull; + +import java.lang.invoke.MethodHandles; + +/** + * Abstract base class for events in the Nameplates plugin system. + */ +public abstract class AbstractNameplatesEvent implements NameplatesEvent { + + private final NameplatesPlugin plugin; + + /** + * Constructs an instance of {@code AbstractNameplatesEvent} with the given {@link NameplatesPlugin}. + * + * @param plugin the {@link NameplatesPlugin} instance associated with this event + */ + protected AbstractNameplatesEvent(NameplatesPlugin plugin) { + this.plugin = plugin; + } + + /** + * Returns the {@link NameplatesPlugin} instance associated with this event. + * + * @return the plugin instance + */ + @NotNull + @Override + public NameplatesPlugin plugin() { + return plugin; + } + + /** + * Returns a {@link MethodHandles.Lookup} instance for dynamic method invocation. + *

+ * This method is currently unsupported and will throw an {@link UnsupportedOperationException} if invoked. + * It may be overridden in subclasses to provide custom logic for dynamic method handles. + *

+ * + * @return the {@link MethodHandles.Lookup} instance + * @throws UnsupportedOperationException if the method is not overridden in a subclass + */ + public MethodHandles.Lookup mhl() { + throw new UnsupportedOperationException(); + } +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java b/api/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java similarity index 99% rename from common/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java index f4531cb..df7452d 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/event/gen/EventGenerator.java @@ -51,6 +51,9 @@ import java.util.Map; import static net.bytebuddy.matcher.ElementMatchers.*; +/** + * A class for generating event class + */ public class EventGenerator { /** diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/registry/EventRegistry.java b/api/src/main/java/net/momirealms/customnameplates/common/event/registry/EventRegistry.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/registry/EventRegistry.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/registry/EventRegistry.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/registry/Internals.java b/api/src/main/java/net/momirealms/customnameplates/common/event/registry/Internals.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/registry/Internals.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/registry/Internals.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/registry/SimpleEventRegistry.java b/api/src/main/java/net/momirealms/customnameplates/common/event/registry/SimpleEventRegistry.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/event/registry/SimpleEventRegistry.java rename to api/src/main/java/net/momirealms/customnameplates/common/event/registry/SimpleEventRegistry.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java similarity index 95% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java index 14b7c51..db9c19c 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionFormatter.java @@ -25,6 +25,10 @@ import org.incendo.cloud.minecraft.extras.caption.ComponentCaptionFormatter; import java.util.List; +/** + * CustomNameplatesCaptionFormatter + * @param sender + */ public class CustomNameplatesCaptionFormatter implements ComponentCaptionFormatter { @Override diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java similarity index 55% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java index 91ffab9..75fe1b2 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionKeys.java @@ -19,9 +19,29 @@ package net.momirealms.customnameplates.common.locale; import org.incendo.cloud.caption.Caption; +/** + * A utility class that defines keys for various captions used in the Custom Nameplates plugin. + *

+ * This class provides static final constants for common caption keys that are used for + * error messages, argument parsing failures, and other localized messages in the plugin. + * These keys can be used with a captioning system to retrieve appropriate translations + * based on the user's locale. + *

+ */ public final class CustomNameplatesCaptionKeys { - + /** + * Caption key for a failure when parsing a time argument. + * This key is used for error messages related to time arguments that failed to parse. + */ public static final Caption ARGUMENT_PARSE_FAILURE_TIME = Caption.of("argument.parse.failure.time"); + /** + * Caption key for a failure when parsing a URL argument. + * This key is used for error messages related to URL arguments that failed to parse. + */ public static final Caption ARGUMENT_PARSE_FAILURE_URL = Caption.of("argument.parse.failure.url"); + /** + * Caption key for a failure when parsing a named text color argument. + * This key is used for error messages related to named text color arguments that failed to parse. + */ public static final Caption ARGUMENT_PARSE_FAILURE_NAMEDTEXTCOLOR = Caption.of("argument.parse.failure.namedtextcolor"); } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java similarity index 76% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java index 6d6b84b..ae2407b 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/locale/CustomNameplatesCaptionProvider.java @@ -21,6 +21,16 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.caption.CaptionProvider; import org.incendo.cloud.caption.DelegatingCaptionProvider; +/** + * A custom implementation of a {@link CaptionProvider} for the Custom Nameplates plugin. + *

+ * This class provides a caption provider that delegates to a constant provider which includes + * predefined captions for argument parsing failure messages. It ensures that specific caption keys, + * such as those related to parsing time, URL, and named text color arguments, are available for use. + *

+ * + * @param the context type associated with the captions + */ public final class CustomNameplatesCaptionProvider extends DelegatingCaptionProvider { private static final CaptionProvider PROVIDER = CaptionProvider.constantProvider() diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/MessageConstants.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/MessageConstants.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/MessageConstants.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/MessageConstants.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistry.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistry.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistry.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistry.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistryImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistryImpl.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistryImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslationRegistryImpl.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslator.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslator.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslator.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslator.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslatorImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslatorImpl.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslatorImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/MiniMessageTranslatorImpl.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/locale/TranslationManager.java b/api/src/main/java/net/momirealms/customnameplates/common/locale/TranslationManager.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/locale/TranslationManager.java rename to api/src/main/java/net/momirealms/customnameplates/common/locale/TranslationManager.java diff --git a/api/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java new file mode 100644 index 0000000..4391953 --- /dev/null +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customnameplates.common.plugin; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * A utility class for loading and retrieving properties from a custom properties file. + *

+ * This class loads the properties from the {@code custom-nameplates.properties} file + * located in the classpath and provides a way to retrieve property values by key. + * The properties are loaded and stored in a singleton instance to ensure only + * one loading of the properties file throughout the lifetime of the application. + *

+ */ +public class CustomNameplatesProperties { + + /** + * A map that holds the key-value pairs of properties. + */ + private final HashMap propertyMap; + + /** + * Private constructor that initializes the property map. + * + * @param propertyMap the map holding the property key-value pairs + */ + private CustomNameplatesProperties(HashMap propertyMap) { + this.propertyMap = propertyMap; + } + + /** + * Retrieves the value of a property based on the provided key. + *

+ * This method throws a {@link RuntimeException} if the key is not found in the properties file. + *

+ * + * @param key the property key to retrieve + * @return the value associated with the given key + * @throws RuntimeException if the key is unknown or not found in the properties file + */ + public static String getValue(String key) { + if (!SingletonHolder.INSTANCE.propertyMap.containsKey(key)) { + throw new RuntimeException("Unknown key: " + key); + } + return SingletonHolder.INSTANCE.propertyMap.get(key); + } + + /** + * A static inner class to hold the singleton instance of {@link CustomNameplatesProperties}. + * This class is used to lazily load the properties file and ensure only one instance is created. + */ + private static class SingletonHolder { + + /** + * The singleton instance of {@link CustomNameplatesProperties}. + */ + private static final CustomNameplatesProperties INSTANCE = getInstance(); + + /** + * Loads the properties file and creates an instance of {@link CustomNameplatesProperties}. + * + * @return an instance of {@link CustomNameplatesProperties} containing the loaded properties + * @throws RuntimeException if there is an error reading the properties file + */ + private static CustomNameplatesProperties getInstance() { + try (InputStream inputStream = CustomNameplatesProperties.class.getClassLoader().getResourceAsStream("custom-nameplates.properties")) { + HashMap versionMap = new HashMap<>(); + Properties properties = new Properties(); + properties.load(inputStream); + for (Map.Entry entry : properties.entrySet()) { + if (entry.getKey() instanceof String key && entry.getValue() instanceof String value) { + versionMap.put(key, value); + } + } + return new CustomNameplatesProperties(versionMap); + } catch (IOException e) { + throw new RuntimeException("Error loading properties file", e); + } + } + } +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/NameplatesPlugin.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/NameplatesPlugin.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/NameplatesPlugin.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/NameplatesPlugin.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java similarity index 87% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java index 30d2643..9721c40 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ClassPathAppender.java @@ -32,6 +32,12 @@ import java.nio.file.Path; */ public interface ClassPathAppender extends AutoCloseable { + /** + * Adds a JAR file to the classpath. + * + * @param file the {@link Path} to the JAR file to be added to the classpath. + * @throws IllegalArgumentException if the provided file is not a valid JAR file. + */ void addJarToClasspath(Path file); @Override diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ReflectionClassPathAppender.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ReflectionClassPathAppender.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ReflectionClassPathAppender.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/ReflectionClassPathAppender.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/URLClassLoaderAccess.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/URLClassLoaderAccess.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/URLClassLoaderAccess.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/classpath/URLClassLoaderAccess.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java similarity index 75% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java index f23d09e..8b7f293 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/config/ConfigLoader.java @@ -47,6 +47,20 @@ public interface ConfigLoader { */ YamlDocument loadConfig(String filePath, char routeSeparator); + /** + * Loads a YAML configuration file from the specified file path with custom settings. + *

+ * This method allows loading a YAML file with various settings, including general, + * loader, dumper, and updater settings, providing more flexibility in how the file is processed. + *

+ * + * @param filePath the path to the configuration file. + * @param generalSettings the general settings to use for loading the configuration. + * @param loaderSettings the loader-specific settings to be applied. + * @param dumperSettings the dumper-specific settings to be applied. + * @param updaterSettings the updater-specific settings to be applied. + * @return the loaded {@link YamlDocument} representing the YAML data. + */ YamlDocument loadConfig(String filePath, GeneralSettings generalSettings, LoaderSettings loaderSettings, DumperSettings dumperSettings, UpdaterSettings updaterSettings); /** diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java similarity index 72% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java index 5ee6cca..69e7259 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/feature/Reloadable.java @@ -17,19 +17,34 @@ package net.momirealms.customnameplates.common.plugin.feature; +/** + * Interface for objects that can be reloaded, unloaded, and loaded again. + */ public interface Reloadable { + /** + * Reloads the feature or component by first unloading it and then loading it again. + */ default void reload() { unload(); load(); } + /** + * Unloads the feature or component. + */ default void unload() { } + /** + * Loads the feature or component. + */ default void load() { } + /** + * Disables the feature or component by unloading it. + */ default void disable() { unload(); } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/JavaPluginLogger.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/JavaPluginLogger.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/JavaPluginLogger.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/JavaPluginLogger.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Log4jPluginLogger.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Log4jPluginLogger.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Log4jPluginLogger.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Log4jPluginLogger.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/PluginLogger.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/PluginLogger.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/PluginLogger.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/PluginLogger.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Slf4jPluginLogger.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Slf4jPluginLogger.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Slf4jPluginLogger.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/logging/Slf4jPluginLogger.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java similarity index 98% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java index b94cd82..71b4e3e 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AbstractJavaScheduler.java @@ -45,6 +45,10 @@ public abstract class AbstractJavaScheduler implements SchedulerAdapter { private final ScheduledThreadPoolExecutor scheduler; private final ForkJoinPool worker; + /** + * Constructs an AbstractJavaScheduler + * @param plugin plugin + */ public AbstractJavaScheduler(NameplatesPlugin plugin) { this.plugin = plugin; diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java similarity index 55% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java index 34ab060..1b7aa7d 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/AsyncTask.java @@ -19,19 +19,45 @@ package net.momirealms.customnameplates.common.plugin.scheduler; import java.util.concurrent.ScheduledFuture; +/** + * Represents an asynchronous task that is scheduled to run at a later time. + * This class wraps a {@link ScheduledFuture} and provides methods to cancel + * the task and check if it has been cancelled. + */ public class AsyncTask implements SchedulerTask { + /** + * The {@link ScheduledFuture} representing the scheduled task. + * This is used to interact with the task, such as cancelling it. + */ private final ScheduledFuture future; + /** + * Constructs an {@link AsyncTask} using the provided {@link ScheduledFuture}. + * + * @param future the {@link ScheduledFuture} representing the scheduled task. + */ public AsyncTask(ScheduledFuture future) { this.future = future; } + /** + * Cancels the scheduled task. The task will not run if it has not started yet, + * or it will stop if it is currently running. + * + * @see ScheduledFuture#cancel(boolean) + */ @Override public void cancel() { future.cancel(false); } + /** + * Checks if the task has been cancelled. + * + * @return true if the task has been cancelled, false otherwise. + * @see ScheduledFuture#isCancelled() + */ @Override public boolean cancelled() { return future.isCancelled(); diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/DummyTask.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/DummyTask.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/DummyTask.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/DummyTask.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/RegionExecutor.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/RegionExecutor.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/RegionExecutor.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/RegionExecutor.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java similarity index 97% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java index dd23011..d7b7d75 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerAdapter.java @@ -60,6 +60,7 @@ public interface SchedulerAdapter { * Executes a task sync * * @param task the task + * @param location the location */ default void executeSync(Runnable task, T location) { sync().run(task, location); @@ -83,6 +84,7 @@ public interface SchedulerAdapter { * Executes the given task repeatedly at a given interval. * * @param task the task + * @param delay the delay * @param interval the interval * @param unit the unit of interval * @return the resultant task instance diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java similarity index 94% rename from common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java rename to api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java index 5e37781..02b4e8b 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/plugin/scheduler/SchedulerTask.java @@ -35,5 +35,10 @@ public interface SchedulerTask { */ void cancel(); + /** + * Check if the task is cancelled + * + * @return cancelled or not + */ boolean cancelled(); } diff --git a/common/src/main/java/net/momirealms/customnameplates/common/sender/AbstractSender.java b/api/src/main/java/net/momirealms/customnameplates/common/sender/AbstractSender.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/sender/AbstractSender.java rename to api/src/main/java/net/momirealms/customnameplates/common/sender/AbstractSender.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/sender/DummyConsoleSender.java b/api/src/main/java/net/momirealms/customnameplates/common/sender/DummyConsoleSender.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/sender/DummyConsoleSender.java rename to api/src/main/java/net/momirealms/customnameplates/common/sender/DummyConsoleSender.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java b/api/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java similarity index 98% rename from common/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java rename to api/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java index 795dd4c..3013b91 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/sender/Sender.java @@ -110,7 +110,7 @@ public interface Sender { boolean isConsole(); /** - * Gets whether this sender is still valid & receiving messages. + * Gets whether this sender is still valid and receiving messages. * * @return if this sender is valid */ diff --git a/common/src/main/java/net/momirealms/customnameplates/common/sender/SenderFactory.java b/api/src/main/java/net/momirealms/customnameplates/common/sender/SenderFactory.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/sender/SenderFactory.java rename to api/src/main/java/net/momirealms/customnameplates/common/sender/SenderFactory.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java similarity index 52% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java index 865da28..2d43b02 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/util/Architecture.java @@ -19,30 +19,95 @@ package net.momirealms.customnameplates.common.util; import java.util.Locale; +/** + * Enum representing the supported system architectures. + * This enum helps determine the architecture of the current system + * and provides utility methods for architecture-related operations. + *

+ * The possible architectures include: + * - X64 (64-bit x86) + * - X86 (32-bit x86) + * - ARM64 (64-bit ARM) + * - ARM32 (32-bit ARM) + * - PPC64LE (64-bit PowerPC, Little Endian) + * - RISCV64 (64-bit RISC-V) + *

+ * It also provides a utility method to get the native path representation of the architecture + * and a method to retrieve the current architecture of the system. + */ public enum Architecture { + /** + * Represents a 64-bit x86 architecture. + */ X64(true), + + /** + * Represents a 32-bit x86 architecture. + */ X86(false), + + /** + * Represents a 64-bit ARM architecture. + */ ARM64(true), + + /** + * Represents a 32-bit ARM architecture. + */ ARM32(false), + + /** + * Represents a 64-bit PowerPC Little Endian architecture. + * Only 'ppc64le' is supported in this case. + */ PPC64LE(true), + + /** + * Represents a 64-bit RISC-V architecture. + * Only 'riscv64' is supported in this case. + */ RISCV64(true); + /** + * The current architecture of the system, determined during class initialization. + */ static final Architecture current; + + /** + * A boolean flag indicating if the architecture is 64-bit. + */ final boolean is64Bit; + /** + * Constructor to initialize the architecture with its 64-bit flag. + * + * @param is64Bit a boolean indicating if the architecture is 64-bit. + */ Architecture(boolean is64Bit) { this.is64Bit = is64Bit; } + /** + * Returns the native path representation of the architecture. + * The name is returned in lowercase using English locale. + * + * @return the native path for the architecture (e.g., "x64", "arm64"). + */ public String getNativePath() { return name().toLowerCase(Locale.ENGLISH); } + /** + * Retrieves the current architecture of the system. + * + * @return the current system architecture as an {@link Architecture} enum. + */ public static Architecture get() { return current; } + // Static block to determine the current system architecture based on system properties. static { String osArch = System.getProperty("os.arch"); boolean is64Bit = osArch.contains("64") || osArch.startsWith("armv8"); @@ -64,4 +129,4 @@ public enum Architecture { current = is64Bit ? ARM64 : ARM32; } } -} \ No newline at end of file +} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/ArrayUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/ArrayUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/ArrayUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/ArrayUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/ClassUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/ClassUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/ClassUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/ClassUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Either.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Either.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Either.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Either.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/EitherImpl.java b/api/src/main/java/net/momirealms/customnameplates/common/util/EitherImpl.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/EitherImpl.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/EitherImpl.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Key.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Key.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Key.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Key.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/ListUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/ListUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/ListUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/ListUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/MoonPhase.java b/api/src/main/java/net/momirealms/customnameplates/common/util/MoonPhase.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/MoonPhase.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/MoonPhase.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Pair.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Pair.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Pair.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Pair.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Platform.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Platform.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Platform.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Platform.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/RandomUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/RandomUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/RandomUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/RandomUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/ReflectionUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/ReflectionUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/ReflectionUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/ReflectionUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/SerializationUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/SerializationUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/SerializationUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/SerializationUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/ThrowableFunction.java b/api/src/main/java/net/momirealms/customnameplates/common/util/ThrowableFunction.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/ThrowableFunction.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/ThrowableFunction.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/TriConsumer.java b/api/src/main/java/net/momirealms/customnameplates/common/util/TriConsumer.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/TriConsumer.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/TriConsumer.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/TriFunction.java b/api/src/main/java/net/momirealms/customnameplates/common/util/TriFunction.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/TriFunction.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/TriFunction.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java similarity index 52% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java index e01271a..554db8c 100644 --- a/common/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java +++ b/api/src/main/java/net/momirealms/customnameplates/common/util/Tristate.java @@ -1,26 +1,18 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright (C) <2024> * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ package net.momirealms.customnameplates.common.util; @@ -28,15 +20,7 @@ package net.momirealms.customnameplates.common.util; import org.jetbrains.annotations.NotNull; /** - * Represents three different states of a setting. - * - *

Possible values:

- *

- *
    - *
  • {@link #TRUE} - a positive setting
  • - *
  • {@link #FALSE} - a negative (negated) setting
  • - *
  • {@link #UNDEFINED} - a non-existent setting
  • - *
+ * Tristate */ public enum Tristate { diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/Tuple.java b/api/src/main/java/net/momirealms/customnameplates/common/util/Tuple.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/Tuple.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/Tuple.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/UUIDUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/UUIDUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/UUIDUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/UUIDUtils.java diff --git a/common/src/main/java/net/momirealms/customnameplates/common/util/WeightUtils.java b/api/src/main/java/net/momirealms/customnameplates/common/util/WeightUtils.java similarity index 100% rename from common/src/main/java/net/momirealms/customnameplates/common/util/WeightUtils.java rename to api/src/main/java/net/momirealms/customnameplates/common/util/WeightUtils.java diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index c3bfd30..9cdf301 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -1,13 +1,8 @@ -plugins { - id("io.github.goooler.shadow") version "8.1.8" -} - repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") } dependencies { - compileOnly(project(":common")) compileOnly(project(":api")) // YAML compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}") diff --git a/common/src/main/resources/custom-nameplates.properties b/backend/src/main/resources/custom-nameplates.properties similarity index 100% rename from common/src/main/resources/custom-nameplates.properties rename to backend/src/main/resources/custom-nameplates.properties diff --git a/common/src/main/resources/translations/en.yml b/backend/src/main/resources/translations/en.yml similarity index 100% rename from common/src/main/resources/translations/en.yml rename to backend/src/main/resources/translations/en.yml diff --git a/common/src/main/resources/translations/zh_cn.yml b/backend/src/main/resources/translations/zh_cn.yml similarity index 100% rename from common/src/main/resources/translations/zh_cn.yml rename to backend/src/main/resources/translations/zh_cn.yml diff --git a/build.gradle.kts b/build.gradle.kts index bf59103..5388e97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,7 @@ import java.io.ByteArrayOutputStream plugins { id("java") + id("com.gradleup.shadow") version "9.0.0-beta6" } val git : String = versionBanner() @@ -11,9 +12,8 @@ ext["git_version"] = git ext["builder"] = builder subprojects { - apply(plugin = "java") - apply(plugin = "java-library") + apply(plugin = "com.gradleup.shadow") repositories { mavenCentral() diff --git a/common/.gitignore b/common/.gitignore deleted file mode 100644 index b63da45..0000000 --- a/common/.gitignore +++ /dev/null @@ -1,42 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts deleted file mode 100644 index b7fdb2d..0000000 --- a/common/build.gradle.kts +++ /dev/null @@ -1,37 +0,0 @@ -repositories { - maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") -} - -dependencies { - compileOnly("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}") { - exclude(module = "adventure-bom") - exclude(module = "checker-qual") - exclude(module = "annotations") - } - compileOnly("org.incendo:cloud-core:${rootProject.properties["cloud_core_version"]}") - compileOnly("org.incendo:cloud-minecraft-extras:${rootProject.properties["cloud_minecraft_extras_version"]}") - compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}") - compileOnly("org.jetbrains:annotations:${rootProject.properties["jetbrains_annotations_version"]}") - compileOnly("org.slf4j:slf4j-api:${rootProject.properties["slf4j_version"]}") - compileOnly("org.apache.logging.log4j:log4j-core:${rootProject.properties["log4j_version"]}") - compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}") - compileOnly("net.kyori:adventure-text-serializer-gson:${rootProject.properties["adventure_bundle_version"]}") - compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}") - compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}") - compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}") - compileOnly("net.bytebuddy:byte-buddy:${rootProject.properties["byte_buddy_version"]}") -} - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } -} - -tasks.withType { - options.encoding = "UTF-8" - options.release.set(17) - dependsOn(tasks.clean) -} \ No newline at end of file diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java b/common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java deleted file mode 100644 index ae77ea1..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/AbstractCommandFeature.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.command; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TranslatableComponent; -import net.momirealms.customnameplates.common.sender.SenderFactory; -import org.incendo.cloud.Command; -import org.incendo.cloud.CommandManager; -import org.incendo.cloud.context.CommandContext; - -public abstract class AbstractCommandFeature implements CommandFeature { - - protected final CustomNameplatesCommandManager commandManager; - protected CommandConfig commandConfig; - - public AbstractCommandFeature(CustomNameplatesCommandManager commandManager) { - this.commandManager = commandManager; - } - - protected abstract SenderFactory getSenderFactory(); - - public abstract Command.Builder assembleCommand(CommandManager manager, Command.Builder builder); - - @Override - @SuppressWarnings("unchecked") - public Command registerCommand(CommandManager manager, Command.Builder builder) { - Command command = (Command) assembleCommand(manager, builder).build(); - manager.command(command); - return command; - } - - @Override - public void registerRelatedFunctions() { - // empty - } - - @Override - public void unregisterRelatedFunctions() { - // empty - } - - @Override - @SuppressWarnings("unchecked") - public void handleFeedback(CommandContext context, TranslatableComponent.Builder key, Component... args) { - if (context.flags().hasFlag("silent")) { - return; - } - commandManager.handleCommandFeedback((C) context.sender(), key, args); - } - - @Override - public void handleFeedback(C sender, TranslatableComponent.Builder key, Component... args) { - commandManager.handleCommandFeedback(sender, key, args); - } - - @Override - public CustomNameplatesCommandManager getCustomNameplatesCommandManager() { - return commandManager; - } - - @Override - public CommandConfig getCommandConfig() { - return commandConfig; - } - - public void setCommandConfig(CommandConfig commandConfig) { - this.commandConfig = commandConfig; - } -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java b/common/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java deleted file mode 100644 index 566822c..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.command; - -import org.incendo.cloud.Command; -import org.incendo.cloud.CommandManager; - -public interface CommandBuilder { - - CommandBuilder setPermission(String permission); - - CommandBuilder setCommandNode(String... subNodes); - - Command.Builder getBuiltCommandBuilder(); - - class BasicCommandBuilder implements CommandBuilder { - - private Command.Builder commandBuilder; - - public BasicCommandBuilder(CommandManager commandManager, String rootNode) { - this.commandBuilder = commandManager.commandBuilder(rootNode); - } - - @Override - public CommandBuilder setPermission(String permission) { - this.commandBuilder = this.commandBuilder.permission(permission); - return this; - } - - @Override - public CommandBuilder setCommandNode(String... subNodes) { - for (String sub : subNodes) { - this.commandBuilder = this.commandBuilder.literal(sub); - } - return this; - } - - @Override - public Command.Builder getBuiltCommandBuilder() { - return commandBuilder; - } - } -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java b/common/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java deleted file mode 100644 index e4a85cb..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandConfig.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.command; - -import java.util.ArrayList; -import java.util.List; - -public class CommandConfig { - - private boolean enable = false; - private List usages = new ArrayList<>(); - private String permission = null; - - private CommandConfig() { - } - - public CommandConfig(boolean enable, List usages, String permission) { - this.enable = enable; - this.usages = usages; - this.permission = permission; - } - - public boolean isEnable() { - return enable; - } - - public List getUsages() { - return usages; - } - - public String getPermission() { - return permission; - } - - public static class Builder { - - private final CommandConfig config; - - public Builder() { - this.config = new CommandConfig<>(); - } - - public Builder usages(List usages) { - config.usages = usages; - return this; - } - - public Builder permission(String permission) { - config.permission = permission; - return this; - } - - public Builder enable(boolean enable) { - config.enable = enable; - return this; - } - - public CommandConfig build() { - return config; - } - } -} \ No newline at end of file diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java b/common/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java deleted file mode 100644 index 39bba14..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/CommandFeature.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.command; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TranslatableComponent; -import org.incendo.cloud.Command; -import org.incendo.cloud.CommandManager; -import org.incendo.cloud.context.CommandContext; - -public interface CommandFeature { - - Command registerCommand(CommandManager cloudCommandManager, Command.Builder builder); - - String getFeatureID(); - - void registerRelatedFunctions(); - - void unregisterRelatedFunctions(); - - void handleFeedback(CommandContext context, TranslatableComponent.Builder key, Component... args); - - void handleFeedback(C sender, TranslatableComponent.Builder key, Component... args); - - CustomNameplatesCommandManager getCustomNameplatesCommandManager(); - - CommandConfig getCommandConfig(); -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java b/common/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java deleted file mode 100644 index 68a4843..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/command/CustomNameplatesCommandManager.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.command; - -import dev.dejvokep.boostedyaml.YamlDocument; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TranslatableComponent; -import net.kyori.adventure.util.Index; -import net.momirealms.customnameplates.common.util.TriConsumer; -import org.incendo.cloud.Command; -import org.incendo.cloud.CommandManager; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -public interface CustomNameplatesCommandManager { - - String commandsFile = "commands.yml"; - - void unregisterFeatures(); - - void registerFeature(CommandFeature feature, CommandConfig config); - - void registerDefaultFeatures(); - - Index> getFeatures(); - - void setFeedbackConsumer(@NotNull TriConsumer feedbackConsumer); - - TriConsumer defaultFeedbackConsumer(); - - CommandConfig getCommandConfig(YamlDocument document, String featureID); - - Collection> buildCommandBuilders(CommandConfig config); - - CommandManager getCommandManager(); - - void handleCommandFeedback(C sender, TranslatableComponent.Builder key, Component... args); - - void handleCommandFeedback(C sender, String node, Component component); -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java b/common/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java deleted file mode 100644 index cee9be6..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/Cancellable.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.momirealms.customnameplates.common.event; - -public interface Cancellable { - - /** - * Gets the cancelled state. - */ - boolean cancelled(); - - /** - * Sets the cancelled state. - */ - void cancelled(final boolean cancelled); -} \ No newline at end of file diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java b/common/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java deleted file mode 100644 index 02d515f..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/EventManager.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.momirealms.customnameplates.common.event; - -import net.momirealms.customnameplates.common.event.bus.EventBus; -import net.momirealms.customnameplates.common.plugin.NameplatesPlugin; - -import java.util.OptionalInt; - -public interface EventManager { - - class SingletonHolder { - private static EventManager INSTANCE = null; - } - - static EventManager create(NameplatesPlugin plugin) { - if (SingletonHolder.INSTANCE == null) { - SingletonHolder.INSTANCE = new EventManagerImpl(plugin); - } - return SingletonHolder.INSTANCE; - } - - EventSubscription subscribe(Class event, EventSubscriber subscriber); - - EventSubscription subscribe(Class event, EventConfig config, EventSubscriber subscriber); - - NameplatesEvent dispatch(Class eventClass, Object... params); - - @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - NameplatesEvent dispatch(Class eventClass, OptionalInt order, Object... params); - - EventBus getEventBus(); -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java b/common/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java deleted file mode 100644 index 835d1e0..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/event/gen/AbstractNameplatesEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.momirealms.customnameplates.common.event.gen; - -import net.momirealms.customnameplates.common.event.NameplatesEvent; -import net.momirealms.customnameplates.common.plugin.NameplatesPlugin; -import org.jetbrains.annotations.NotNull; - -import java.lang.invoke.MethodHandles; - -public abstract class AbstractNameplatesEvent implements NameplatesEvent { - - private final NameplatesPlugin plugin; - - protected AbstractNameplatesEvent(NameplatesPlugin plugin) { - this.plugin = plugin; - } - - @NotNull - @Override - public NameplatesPlugin plugin() { - return plugin; - } - - public MethodHandles.Lookup mhl() { - throw new UnsupportedOperationException(); - } -} diff --git a/common/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java b/common/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java deleted file mode 100644 index 25e16ed..0000000 --- a/common/src/main/java/net/momirealms/customnameplates/common/plugin/CustomNameplatesProperties.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) <2024> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customnameplates.common.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -public class CustomNameplatesProperties { - - private final HashMap propertyMap; - - private CustomNameplatesProperties(HashMap propertyMap) { - this.propertyMap = propertyMap; - } - - public static String getValue(String key) { - if (!SingletonHolder.INSTANCE.propertyMap.containsKey(key)) { - throw new RuntimeException("Unknown key: " + key); - } - return SingletonHolder.INSTANCE.propertyMap.get(key); - } - - private static class SingletonHolder { - - private static final CustomNameplatesProperties INSTANCE = getInstance(); - - private static CustomNameplatesProperties getInstance() { - try (InputStream inputStream = CustomNameplatesProperties.class.getClassLoader().getResourceAsStream("custom-nameplates.properties")) { - HashMap versionMap = new HashMap<>(); - Properties properties = new Properties(); - properties.load(inputStream); - for (Map.Entry entry : properties.entrySet()) { - if (entry.getKey() instanceof String key && entry.getValue() instanceof String value) { - versionMap.put(key, value); - } - } - return new CustomNameplatesProperties(versionMap); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b36119d..c608c99 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 98ae628..c0b48db 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -1,7 +1,3 @@ -plugins { - id("io.github.goooler.shadow") version "8.1.8" -} - repositories { maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // papi maven("https://libraries.minecraft.net") // brigadier @@ -15,7 +11,6 @@ dependencies { implementation(project(":api")) { exclude("dev.dejvokep", "boosted-yaml") } - implementation(project(":common")) implementation(project(":backend")) implementation(project(":platforms:bukkit:compatibility")) @@ -41,7 +36,7 @@ dependencies { compileOnly("org.incendo:cloud-minecraft-extras:${rootProject.properties["cloud_minecraft_extras_version"]}") compileOnly("org.incendo:cloud-paper:${rootProject.properties["cloud_paper_version"]}") // Netty - compileOnly("io.netty:netty-all:4.1.113.Final") + compileOnly("io.netty:netty-all:4.1.117.Final") } tasks { diff --git a/platforms/bukkit/compatibility/build.gradle.kts b/platforms/bukkit/compatibility/build.gradle.kts index b5eee94..098ec52 100644 --- a/platforms/bukkit/compatibility/build.gradle.kts +++ b/platforms/bukkit/compatibility/build.gradle.kts @@ -16,7 +16,6 @@ repositories { dependencies { compileOnly(project(":api")) - compileOnly(project(":common")) compileOnly(project(":backend")) compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}") // WorldGuard diff --git a/settings.gradle.kts b/settings.gradle.kts index ee9ff0d..adcc32e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,5 @@ rootProject.name = "CustomNameplates" include(":api") -include(":common") include(":backend") include(":platforms:bukkit") include(":platforms:bukkit:compatibility")