Skip to content

Commit

Permalink
Add detailed comments for classes and functions
Browse files Browse the repository at this point in the history
JavaDoc style comments were added to different classes, methods, and functions across multiple files. These comments provide a clear explanation of what each class or function does, and include parameter descriptions for methods, helping other developers understand the code better.
  • Loading branch information
TheMeinerLP committed Dec 6, 2023
1 parent a3b3eb7 commit 4c62410
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ import org.bukkit.plugin.java.JavaPlugin
import java.nio.file.Files
import kotlin.io.path.Path

/**
* This class represents a ClipboardConnect plugin that provides functionality
* for managing the clipboard and setup process. It extends the JavaPlugin class
* and implements various methods for plugin initialization and configuration.
*
*/
@Singleton
class ClipboardConnect : JavaPlugin() {

Expand All @@ -45,8 +51,6 @@ class ClipboardConnect : JavaPlugin() {
saveDefaultConfig()
}



override fun onEnable() {
val injector = Injector.newInjector()
injector.install(BindingBuilder.create()
Expand All @@ -73,6 +77,11 @@ class ClipboardConnect : JavaPlugin() {
))
}

/**
* Initializes the command manager for the ClipboardConnect plugin.
*
* @param injector The Injector instance used for dependency injection.
*/
@Inject
@Order(10)
private fun commandManager(injector: Injector) {
Expand All @@ -87,6 +96,12 @@ class ClipboardConnect : JavaPlugin() {
injector.install(BindingBuilder.create().bind(Element.forType(commandManager.javaClass)).bindMatching(RawTypeMatcher.create(commandManager.javaClass)).toInstance(commandManager))
}

/**
* Parses the given command annotations and creates an instance of AnnotationParser.
*
* @param commandManager The PaperCommandManager instance used for command registration.
* @param injector The Injector instance used for dependency injection.
*/
@Inject
@Order(100)
private fun annotationParser(commandManager: PaperCommandManager<ClipboardSender>, injector: Injector) {
Expand All @@ -100,6 +115,11 @@ class ClipboardConnect : JavaPlugin() {
injector.install(BindingBuilder.create().bind(Element.forType(annotationParser.javaClass)).bindMatching(RawTypeMatcher.create(annotationParser.javaClass)).toInstance(annotationParser))
}

/**
* Registers event listeners and parses command annotations.
*
* @param injector The Injector instance used for dependency injection.
*/
@Inject
@Order(150)
private fun register(injector: Injector) {
Expand All @@ -124,6 +144,11 @@ class ClipboardConnect : JavaPlugin() {
}
}

/**
* Generates a configuration file based on the provided conversation context.
*
* @param conversationContext The conversation context containing the necessary data.
*/
fun generateConfig(conversationContext: ConversationContext) {
setupService.generateConfig(conversationContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,101 @@ import net.kyori.adventure.text.Component
import net.onelitefeather.clipboardconnect.conversation.*
import org.bukkit.entity.Player

/**
* This class represents a ClipboardPlayer, which is a player that can interact with the clipboard and engage in conversations.
* It extends the ClipboardSender class and implements the Conversable interface.
*
* @property player The player associated with this ClipboardPlayer
* @constructor Creates a ClipboardPlayer with the given player
*/
class ClipboardPlayer(private val player: Player) : ClipboardSender(player), Conversable {

private val conversationTracker = ConversationTracker()

/**
* Sends a message to the player associated with this ClipboardPlayer.
*
* @param source The source of the message
* @param message The message to be sent
* @param type The type of the message
*/
override fun sendMessage(source: Identified, message: Component, type: MessageType) {
player.sendMessage(source, message, type)
}

/**
* Sends a message to the player associated with this ClipboardPlayer.
*
* @param source The source of the message
* @param message The message to be sent
* @param type The type of the message
*/
override fun sendMessage(source: Identity, message: Component, type: MessageType) {
player.sendMessage(source, message, type)
}

/**
* Returns the player associated with this ClipboardPlayer as the command sender.
*
* @return The player command sender.
*/
override fun getCommandSender(): Player {
return player
}

/**
* Returns whether the object is actively engaged in a conversation.
*
* @return True if a conversation is in progress, false otherwise
*/
override fun isConversing(): Boolean {
return this.conversationTracker.isConversing
}

/**
* Accepts input into the active conversation. If no conversation is in
* progress, this method does nothing.
*
* @param input The input message into the conversation
*/
override fun acceptConversationInput(input: String) {
this.conversationTracker.acceptConversationInput(input)
}

/**
* Begins a conversation with the specified Conversation.
*
* @param conversation The Conversation to begin
* @return True if the conversation should proceed, false if it has been enqueued
*/
override fun beginConversation(conversation: Conversation): Boolean {
return this.conversationTracker.beginConversation(conversation)
}

/**
* Abandons an active conversation.
*
* @param conversation The conversation to abandon
*/
override fun abandonConversation(conversation: Conversation) {
this.conversationTracker.abandonConversation(conversation, ConversationAbandonedEvent(conversation, ManuallyAbandonedConversationCanceller()))
}

/**
* Abandons an active conversation.
*
* @param conversation The conversation to abandon
* @param details Details about why the conversation was abandoned
*/
override fun abandonConversation(conversation: Conversation, details: ConversationAbandonedEvent) {
this.conversationTracker.abandonConversation(conversation, details)
}

/**
* Sets custom suggestions for the player during a conversation.
*
* @param completions The collection of completion suggestions
*/
override fun setCustomSuggestionToPlayer(completions: Collection<String>) {
if (completions.isNotEmpty()) {
this.player.setCustomChatCompletions(completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter
import com.sk89q.worldedit.extension.platform.Actor
import org.bukkit.command.CommandSender

@Suppress("DEPRECATION")
/**
* The ClipboardSender class is responsible for managing the interactions with a CommandSender
* as it relates to clipboard functionality.
*
* @constructor Creates a ClipboardSender instance with a specified CommandSender.
* @param commandSender The CommandSender associated with the ClipboardSender.
*/
open class ClipboardSender(private val commandSender: CommandSender) {
/**
* Retrieves the CommandSender associated with the ClipboardSender.
*
* @return The CommandSender associated with the ClipboardSender.
*/
open fun getCommandSender(): CommandSender {
return commandSender
}

/**
* Retrieves the WorldEdit actor associated with the ClipboardSender.
*
* @return The WorldEdit actor associated with the ClipboardSender.
*/
fun getWorldEditPlayer(): Actor {
return BukkitAdapter.adapt(commandSender)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import net.onelitefeather.clipboardconnect.command.ClipboardPlayer
import net.onelitefeather.clipboardconnect.services.SyncService

/**
* This class represents a load command that loads a clipboard global.
*
* @param syncService The SyncService instance used for synchronization
* @param prefix The prefix component for message formatting
*/
@CommandMethod("clipboardconnect|clipcon")
class LoadCommand @Inject constructor(private val syncService: SyncService, @Named("prefix") private val prefix: Component){

/**
* Executes the load command to load a clipboard global.
*
* @param clipboardPlayer The ClipboardPlayer to execute the command for
*/
@CommandMethod("load")
@ProxiedBy("gload")
@CommandPermission("clipboardconnect.command.load")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import net.onelitefeather.clipboardconnect.command.ClipboardPlayer
import net.onelitefeather.clipboardconnect.services.SyncService

/**
* Represents a command for saving a clipboard globally.
*
* @property syncService The SyncService instance used for synchronization.
* @property prefix The prefix component used for message formatting.
* @constructor Creates a SaveCommand with the given SyncService and prefix.
*/
@CommandMethod("clipboardconnect|clipcon")
class SaveCommand @Inject constructor(private val syncService: SyncService, @Named("prefix") private val prefix: Component){

/**
* Executes the save command for a clipboard player.
*
* @param clipboardPlayer The ClipboardPlayer instance to save the clipboard for.
*/
@CommandMethod("save")
@ProxiedBy("gsave")
@CommandPermission("clipboardconnect.command.save")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import net.onelitefeather.clipboardconnect.services.SetupService
import net.onelitefeather.clipboardconnect.setup.ServerNamePrompt


/**
* The SetupCommand class represents a command for starting the setup procedure.
*
* @param setupService The SetupService instance for handling setup operations.
*/
@CommandMethod("clipboardconnect|clipcon")
class SetupCommand
@Inject constructor(private val setupService: SetupService) {

/**
* Executes the setup procedure for the given [ClipboardPlayer].
*
* @param clipboardPlayer The [ClipboardPlayer] initiating the setup.
*/
@CommandMethod("setup")
@CommandPermission("clipboardconnect.command.setup")
@CommandDescription("Starts the beginning of setup procedure")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerQuitEvent

/**
* Listener class that handles the 'PlayerQuitEvent' when a player quits the server.
*
* @property syncService The SyncService instance used for syncing player data.
* @property plugin The ClipboardConnect plugin instance.
*/
class PlayerQuitListener
@Inject constructor(private val syncService: SyncService, private val plugin: ClipboardConnect) : Listener {

/**
* Handles the 'PlayerQuitEvent' when a player quits the server.
*
* @param event The PlayerQuitEvent object.
*/
@EventHandler
fun playerQuit(event: PlayerQuitEvent) {
val player = event.player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ import net.onelitefeather.clipboardconnect.services.SetupService
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener

/**
* This class represents a SetupListener, which is responsible for listening to chat events and performing setup-related actions.
*
* @param setupService The SetupService instance used for setup operations.
*/
class SetupListener @Inject constructor(private val setupService: SetupService) : Listener {

/**
* Listens to chat events and performs setup-related actions.
*
* @param event The AsyncChatEvent to be handled
*/
@EventHandler
fun chatListening(event: AsyncChatEvent) {
event.viewers().removeIf(setupService::removeSetupPlayers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonTypeInfo
import java.util.*

/**
* Represents a message that is sent or received through the redis queue.
*
* @property userId The unique identifier of the user associated with the message.
* @property fromServer The identifier of the server from which the message is sent or received.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class")
data class ClipboardMessage(
@JsonProperty("userId")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package net.onelitefeather.clipboardconnect.model

/**
* Represents a library configuration for a Paper plugin.
*
* @property repositories A map of repository names to their corresponding URLs, used for resolving dependencies.
* @property dependencies A list of Maven-style dependency strings that specify the required libraries for the plugin.
*/
data class PaperLib(val repositories: Map<String, String>, val dependencies: List<String>) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ import org.bukkit.entity.Player
import java.nio.file.Files
import kotlin.time.Duration

/**
* This class represents a SetupService, which is responsible for managing the setup process
* for ClipboardConnect. It provides methods to start and manage the setup conversation,
* find a ClipboardPlayer, remove setup players, and generate the configuration.
*
* @property javaPlugin The instance of the ClipboardConnect plugin
* @property prefix The prefix component for messages
* @constructor Creates a SetupService with the given ClipboardConnect instance and prefix component
*/
@Singleton
class SetupService @Inject constructor(private val javaPlugin: ClipboardConnect, @Named("prefix") private val prefix: Component) {

private val clipboardPlayers: MutableList<ClipboardPlayer> = mutableListOf()
private val redisFileName = "redis.yml"

/**
* Starts the setup procedure for the given `ClipboardPlayer` using the specified `Prompt`.
*
* @param player The `ClipboardPlayer` initiating the setup.
* @param prompt The `Prompt` to use for the setup procedure.
* @return void
*/
fun startSetup(player: ClipboardPlayer, prompt: Prompt) {
ConversationFactory(javaPlugin).withFirstPrompt(prompt).withPrefix { prefix }.addConversationAbandonedListener(this::remove).buildConversation(player).begin()
clipboardPlayers.add(player)
Expand All @@ -34,15 +50,32 @@ class SetupService @Inject constructor(private val javaPlugin: ClipboardConnect,
}
}

/**
* Finds the `ClipboardPlayer` associated with the specified `Player`.
*
* @param player The `Player` object for which to find the `ClipboardPlayer`.
* @return The `ClipboardPlayer` associated with the specified `Player`, or null if not found.
*/
fun findClipboardPlayer(player: Player): ClipboardPlayer? {
return this.clipboardPlayers.firstOrNull { clipboardPlayer: ClipboardPlayer -> clipboardPlayer.getCommandSender().uniqueId == player.uniqueId }
}


/**
* Removes the setup players from the audience.
*
* @param audience The audience from which to remove the setup players.
* @return True if any setup player was removed from the audience, false otherwise.
*/
fun removeSetupPlayers(audience: Audience): Boolean {
return clipboardPlayers.any { clipboardPlayer: ClipboardPlayer -> clipboardPlayer.getCommandSender() == audience }
}

/**
* Generates a configuration file based on the provided conversation context.
*
* @param conversationContext The conversation context containing the necessary data.
*/
fun generateConfig(conversationContext: ConversationContext) {
javaPlugin.saveResource(redisFileName, false)
if(conversationContext.getSessionData(SetupKey.DOCKER_COMPOSE) != null) {
Expand Down
Loading

0 comments on commit 4c62410

Please sign in to comment.