Skip to content
Draft
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
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/src/main/java/org/wlosp/varo/api/APIInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.wlosp.varo.api;

public class APIInstance {

static VaroInterface instance;
}
36 changes: 36 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/Varo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.wlosp.varo.api

import org.bukkit.OfflinePlayer
import org.wlosp.varo.api.entities.VaroPlayer
import org.wlosp.varo.api.entities.VaroTeam

/**
* Converts this [OfflinePlayer] to a [VaroPlayer].
*
* @see VaroPlayerApi.get
*/
fun OfflinePlayer.toVaroPlayer(): VaroPlayer? = VaroPlayerApi[this]

/**
* A list of all [VaroPlayer]s.
*
* @see VaroPlayerApi.players
*/
val varoPlayers: List<VaroPlayer>
get() = VaroPlayerApi.players

/**
* A list of all online [VaroPlayer]s.
*
* @see VaroPlayerApi.onlinePlayers
*/
val onlineVaroPlayers: List<VaroPlayer>
get() = VaroPlayerApi.onlinePlayers

/**
* A list of all [VaroTeam]s.
*
* @see VaroTeamApi.teams
*/
val varoTeams: List<VaroTeam>
get() = VaroTeamApi.teams
14 changes: 14 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/VaroApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.wlosp.varo.api

import kotlin.properties.Delegates

/**
* Singleton for Varo API.
*
* @see VaroInterface for API documentation
*/
object VaroApi : VaroInterface by APIInstance.instance

object VaroTeamApi : VaroTeamApiInterface by VaroApi.teams

object VaroPlayerApi : VaroPlayerApiInterface by VaroApi.players
104 changes: 104 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/VaroInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.wlosp.varo.api

import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import org.wlosp.varo.api.entities.VaroPlayer
import org.wlosp.varo.api.entities.VaroTeam
import java.util.*

typealias VaroTeamApiInterface = VaroInterface.TeamApi

typealias VaroPlayerApiInterface = VaroInterface.PlayerApi

/**
* API for WLOSP Varo plugin.
*
* @see VaroApi
*/
interface VaroInterface {

/**
* API for Varo teams.
*
* @see TeamApi
*/
val teams: TeamApi

/**
* API for Varo players.
*
* @see PlayerApi
*/
val players: PlayerApi

/**
* Teams related API.
*/
interface TeamApi {
/**
* An unmodifiable list of all [VaroTeam]s.
*/
val teams: List<VaroTeam>

/**
* Retrieves a [VaroTeam] by its [name] or `null` if it does not exist.
*/
operator fun get(name: String): VaroTeam?
}

/**
* Player related API.
*/
interface PlayerApi {

/**
* An unmodifiable list of all [VaroPlayer].
*/
val players: List<VaroPlayer>

/**
* An unmodifiable list of all [VaroPlayer], that are currently online.
*/
val onlinePlayers: List<VaroPlayer>

/**
* Retrieves a [VaroPlayer] by it's [UUID].
*
* @throws IllegalArgumentException if the player does not participate in the currently running Varo project
*/
operator fun get(uuid: UUID): VaroPlayer?

/**
* Retrieves the [VaroPlayer] corresponding to this [player].
*
* @throws IllegalArgumentException if the player does not participate in the currently running Varo project
* @see get(UUID)
*/
operator fun get(player: OfflinePlayer): VaroPlayer? = get(player.uniqueId)

/**
* This method only exists to tell players who don't know that [Player] extends [OfflinePlayer] to use the normal get method
* as they cannot read docs.
*
* @see get(OfflinePlayer)
*/
@Deprecated(
"Player extends OfflinePlayer so just use the normal get method",
ReplaceWith("get"),
DeprecationLevel.ERROR
)
fun getByPlayer(player: Player): VaroPlayer? = get(player)

/**
* Finds the [VaroPlayer] corresponding to its [name].
*
* @throws IllegalArgumentException when the player is not online
*/
operator fun get(name: String): VaroPlayer? {
val player = Bukkit.getPlayer(name)
requireNotNull(player) { "The player has to be online" }
return get(player)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.wlosp.varo.api.entities

enum class StrikeAction {
PUBLISH_COORDINATES,
DELETE_INVENTORY_AND_CHEST,
BAN
}
35 changes: 35 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/entities/VaroPlayer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.wlosp.varo.api.entities

import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import java.util.*

/**
* Representation of a Player in this Varo.
*
* @property uuid the [UUID] of the player
* @property team the [VaroTeam] the player is in
* @property spawnLocation the [Location] at which the player will spawn when Varo starts.
*/
interface VaroPlayer {
val uuid: UUID
val team: VaroTeam
val spawnLocation: Location
val isAlive: Boolean

/**
* Returns the corresponding [Player] or `null` if the player is not online.
*
* @see Bukkit.getPlayer
*/
fun toPlayer(): Player? = Bukkit.getPlayer(uuid)

/**
* Returns the corresponding [OfflinePlayer].
*
* @see Bukkit.getOfflinePlayer
*/
fun toOfflinePlayer(): OfflinePlayer = Bukkit.getOfflinePlayer(uuid)
}
21 changes: 21 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/entities/VaroTeam.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.wlosp.varo.api.entities

import org.bukkit.ChatColor

/**
* Representation of a Varo team.
*
* @property name the name of the team
* @property color the color of the team (used for Discord and Scoreboard)
* @property players an unmodifiable list of [VaroPlayer]s which are in this team
* @property isAlive whether the team is still alive or not
*/
interface VaroTeam {
val name: String
val color: ChatColor

val players: List<VaroPlayer>

val isAlive: Boolean
get() = players.any(VaroPlayer::isAlive)
}
18 changes: 18 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/events/VaroEndEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.wlosp.varo.api.events

import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.wlosp.varo.api.entities.VaroTeam

class VaroEndEvent(
val winningTeam: VaroTeam
) : Event() {

override fun getHandlers(): HandlerList = HANDLERS

companion object {
@JvmStatic
@get:JvmName("getHandlersList")
val HANDLERS: HandlerList = HandlerList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.wlosp.varo.api.events

import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.wlosp.varo.api.entities.VaroPlayer
import org.wlosp.varo.api.entities.VaroTeam

class VaroPlayerDiedEvent(
val player: Player,
val varoPlayer: VaroPlayer
) : Event() {

val varoTeam: VaroTeam by lazy { varoPlayer.team }

override fun getHandlers(): HandlerList {
return HANDLERS
}

companion object {
@JvmStatic
@get:JvmName("getHandlersList")
val HANDLERS: HandlerList = HandlerList()
}
}
22 changes: 22 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/events/VaroStrikeEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.wlosp.varo.api.events

import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.wlosp.varo.api.entities.StrikeAction
import org.wlosp.varo.api.entities.VaroTeam

class VaroStrikeEvent(
val team: VaroTeam,
val action: StrikeAction?,
val reason: String?,
val amount: Int
) : Event() {

override fun getHandlers(): HandlerList = HANDLERS

companion object {
@JvmStatic
@get:JvmName("getHandlersList")
val HANDLERS: HandlerList = HandlerList()
}
}
28 changes: 28 additions & 0 deletions api/src/main/kotlin/org/wlosp/varo/api/events/VaroTeamDiedEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.wlosp.varo.api.events

import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.wlosp.varo.api.entities.VaroPlayer
import org.wlosp.varo.api.entities.VaroTeam

class VaroTeamDiedEvent(
val team: VaroTeam,
val cause: Cause
) : Event() {
override fun getHandlers(): HandlerList = HANDLERS

val players: List<VaroPlayer>
get() = team.players


enum class Cause {
STRIKE,
DEATH
}

companion object {
@JvmStatic
@get:JvmName("getHandlersList")
val HANDLERS: HandlerList = HandlerList()
}
}
16 changes: 15 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@ repositories {
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
maven("https://dl.bintray.com/johnnyjayjay/spiglin")
maven("https://repo.byteflux.net/repository/maven-releases/")
maven("https://jitpack.io")
jcenter()
mavenCentral()
}

dependencies {
implementation(project(":api"))

compileOnly("org.spigotmc", "spigot-api", "1.16.1-R0.1-SNAPSHOT")
compileOnly("com.github.johnnyjayjay", "spiglin", "2.0.3")
compileOnly("com.github.johnnyjayjay", "spiglin", "develop-SNAPSHOT")
implementation("net.byteflux", "libby-bukkit", "0.0.1")

// Database
compileOnly("org.jetbrains.exposed", "exposed-core", "0.25.1")
compileOnly("org.jetbrains.exposed", "exposed-dao", "0.25.1")
compileOnly("org.jetbrains.exposed", "exposed-jdbc", "0.25.1")
compileOnly("com.zaxxer", "HikariCP", "3.4.5")

// HTTP
compileOnly("com.squareup.okhttp3", "okhttp", "4.8.0")

compileOnly("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8", "1.3.4")
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
}

tasks {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = "varo"

include("api")
Loading