Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target/**/*
out/
build/
.gradle/

output/
### IntelliJ IDEA ###
/.idea/*
!/.idea/runConfigurations
Expand Down
19 changes: 0 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import dev.slne.surf.surfapi.gradle.util.slnePublic
import dev.slne.surf.surfapi.gradle.util.slneReleases

buildscript {
repositories {
gradlePluginPortal()
Expand All @@ -11,23 +8,7 @@ buildscript {
}
}

plugins {
java
}


allprojects {
group = "dev.slne.surf"
version = findProperty("version") as String
}

subprojects {
apply(plugin = "java")
repositories {
slnePublic()
slneReleases()
}
dependencies {
implementation(platform("dev.slne.surf.cloud:surf-cloud-bom:1.21.7+"))
}
}
5 changes: 0 additions & 5 deletions gradle/libs.versions.toml

This file was deleted.

14 changes: 3 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}

val projects: List<Pair<String, String>> = listOf(
"surf-transaction-api" to "SurfTransactionApi",
"surf-transaction-paper" to "SurfTransactionBukkit",
"surf-transaction-velocity" to "SurfTransactionVelocity",
// "surf-transaction-fallback" to "SurfTransactionFallback"
)

projects.forEach { (path, _) ->
include(path)
}

include("surf-transaction-api")
include("surf-transaction-paper")
include("surf-transaction-velocity")
include("surf-transaction-core:surf-transaction-core-common")
include("surf-transaction-core:surf-transaction-core-client")
include("surf-transaction-server")
4 changes: 2 additions & 2 deletions surf-transaction-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
id("dev.slne.surf.surfapi.gradle.core")
}

dependencies {
compileOnly("dev.slne.surf.cloud:surf-cloud-api-common:1.21.7+")
surfCoreApi {
withCloudCommon()
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.slne.surf.transaction.api.account

import dev.slne.surf.cloud.api.common.player.OfflineCloudPlayer
import dev.slne.surf.transaction.api.user.HasTransactions
import dev.slne.surf.transaction.api.util.InternalTransactionApi
import kotlinx.serialization.Serializable
import net.kyori.adventure.text.Component
import java.util.*

@OptIn(InternalTransactionApi::class)
@Serializable(with = AccountSerializer::class)
interface Account : HasTransactions {

/**
* Unique identifier for the account.
*/
val accountId: UUID

/**
* The name of the account.
*/
val name: String

/**
* The owner of the account.
*/
val owner: OfflineCloudPlayer

/**
* Indicates whether this account is the default account for the owner.
*/
val defaultAccount: Boolean

/**
* Converts the account information into a [Component] for display purposes.
*
* @return A [Component] representing the account information, suitable for use in user interfaces.
*/
suspend fun asComponent(): Component

companion object {
/**
* Retrieves an account by its unique identifier.
*
* @param accountId The unique identifier of the account to retrieve.
* @return The [Account] associated with the given [accountId], or null if no such account exists.
*/
suspend operator fun get(accountId: UUID?): Account? =
accountId?.let { InternalAccountBridge.instance.getAccountByAccountId(it) }

/**
* Creates a new account with the specified owner and name.
*
* @param owner The owner of the account.
* @param name The name of the account.
* @return An [AccountCreationResult] indicating the success or failure of the account creation.
*/
suspend fun create(
owner: OfflineCloudPlayer,
name: String
): AccountCreationResult = InternalAccountBridge.instance.createAccount(owner, name)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.slne.surf.transaction.api.account

import kotlinx.serialization.Serializable

/**
* Represents the result of an account creation operation.
* This sealed class encapsulates both successful and failed account creation attempts.
*
* @property message A message describing the result of the account creation attempt.
*/
@Serializable
sealed class AccountCreationResult(val message: String) {

/**
* Represents a successful account creation result.
*
* @property account The newly created account.
*/
@Serializable
data class Success(val account: Account) :
AccountCreationResult("Dein Account wurde erfolgreich erstellt.")

/**
* Represents a failure in account creation.
*
* This class includes a reason for the failure, which can be one of several predefined reasons.
* @property reason The reason for the failure, represented by a [FailureReason] enum.
*/
@Serializable
data class Failure(val reason: FailureReason) :
AccountCreationResult("Fehler beim Erstellen des Accounts: $reason")

/**
* Enum representing the possible reasons for a failure in account creation.
*/
@Serializable
enum class FailureReason {
/**
* The account name already exists.
*/
NAME_ALREADY_EXISTS,

/**
* The account name is too long.
*/
NAME_TOO_LONG,

/**
* The account name is too short.
*/
NAME_TOO_SHORT,

/**
* The account name matches a UUID format.
*/
NAME_IS_UUID
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.slne.surf.transaction.api.account

import kotlinx.serialization.Serializable

/**
* Represents the result of an account deletion operation.
* This sealed class encapsulates both successful and failed account deletion attempts.
*
* @property message A message describing the result of the account deletion attempt.
*/
@Serializable
sealed class AccountDeleteResult(val message: String) {

/**
* Represents a successful account deletion result.
*
* @property account The account that was successfully deleted.
*/
@Serializable
data class Success(val account: Account) :
AccountDeleteResult("Dein Account wurde erfolgreich gelöscht.")

/**
* Represents a failure in account deletion.
* This class includes a reason for the failure, which can be one of several predefined reasons.
*
* @property reason The reason for the failure, represented by a [FailureReason] enum
*/
@Serializable
data class Failure(val reason: FailureReason) :
AccountDeleteResult("Fehler beim Löschen des Accounts: $reason")

/**
* Represents the possible reasons for a failure in account deletion.
*/
@Serializable
enum class FailureReason {
/**
* The account could not be found.
*/
ACCOUNT_NOT_FOUND,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.slne.surf.transaction.api.account

import dev.slne.surf.transaction.api.util.InternalTransactionApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@OptIn(InternalTransactionApi::class)
object AccountSerializer : KSerializer<Account> {
override val descriptor get() = InternalAccountBridge.instance.descriptor

override fun serialize(
encoder: Encoder,
value: Account
) {
InternalAccountBridge.instance.serialize(encoder, value)
}

override fun deserialize(decoder: Decoder): Account {
return InternalAccountBridge.instance.deserialize(decoder)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.slne.surf.transaction.api.account

import dev.slne.surf.cloud.api.common.player.OfflineCloudPlayer
import dev.slne.surf.transaction.api.util.InternalTransactionApi

@OptIn(InternalTransactionApi::class)
interface HasAccounts {

/**
* Represents the cloud player associated with this account holder.
*/
val cloudPlayer: OfflineCloudPlayer

/**
* Retrieves the default account for this player.
*
* @return the default [Account] associated with this player
*/
suspend fun getDefaultAccount() =
InternalAccountBridge.instance.getDefaultAccount(cloudPlayer)

/**
* Retrieves all accounts associated with this player.
*
* @return a set of [Account]s owned by this player
*/
suspend fun getAllAccounts() =
InternalAccountBridge.instance.getAccounts(cloudPlayer)

/**
* Creates a new account for this player with the specified [name].
*
* @param name the name of the new account; must be non-empty
* @return the newly created [Account]
*/
suspend fun createAccount(name: String) =
InternalAccountBridge.instance.createAccount(cloudPlayer, name)

/**
* Retrieves the account with the specified [accountName] for this player.
*
* @param accountName the name of the account to retrieve; must be non-empty
* @return the [Account] matching [accountName], or `null` if not found
*/
suspend fun getAccountByName(accountName: String) =
InternalAccountBridge.instance.getAccountByName(accountName)

/**
* Deletes the specified [account] from this player's accounts.
*
* @param account the account to delete; must be non-null
* @return an [AccountDeleteResult] indicating success or failure
*/
suspend fun deleteAccount(account: Account) =
InternalAccountBridge.instance.deleteAccount(account)

}
Loading