Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master into feat branch #82

Merged
merged 105 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
26ad822
Added SQL Support#
kotlinsyntax Feb 13, 2024
5feaa7b
Add support for multiple WHERE and JOIN clauses
kotlinsyntax Feb 13, 2024
886968a
Added Date & Time Utils
kotlinsyntax Feb 13, 2024
8691c5b
Some Cleanup
kotlinsyntax Feb 13, 2024
2a9858c
Added SQL Test
kotlinsyntax Feb 14, 2024
5df8c23
Updated README for SQL
kotlinsyntax Feb 14, 2024
be523c2
Changed SQLSerializable to an Interface
kotlinsyntax Feb 14, 2024
383fa21
Added POJO to Table Methods
kotlinsyntax Feb 14, 2024
d274459
Added a way to exclude fields
kotlinsyntax Feb 14, 2024
7b8b6ed
Forgot MySQL doesnt have the REAL type
kotlinsyntax Feb 14, 2024
7df2a12
Updated QueryBuilder & Readme
kotlinsyntax Feb 15, 2024
854416e
Update Readme
kotlinsyntax Feb 15, 2024
2db3f41
Added objects to readme
kotlinsyntax Feb 15, 2024
79b38c4
Merge branch 'master' into master
kotlinsyntax Feb 15, 2024
d54b7a8
Merge pull request #48 from kotlinsyntax/master
joshbker Feb 17, 2024
ea61636
chore: bump ver 1.1.7
joshbker Feb 17, 2024
7ad6317
chore: revert dotenv, mongo-sync & gson to be api rather than impl
joshbker Feb 17, 2024
acc2ef2
refactor: clean up db test
joshbker Feb 17, 2024
ff1e5b3
refactor: formatting & imports
joshbker Feb 17, 2024
ba61e99
Merge pull request #53 from flytegg/clone/master
joshbker Feb 17, 2024
c84930a
Update README.md
Dawsson Feb 20, 2024
10eb279
Added Extension Functions To Entity.kt
Dawsson Feb 20, 2024
ad0b983
Merge remote-tracking branch 'origin/master'
CodedRedGIT Feb 23, 2024
7046ad6
Added freeze() and unfreeze()
abstractabuser Feb 23, 2024
8bbf5d1
Updated freeze system with metadatas.
abstractabuser Feb 24, 2024
f4e690e
Added support for both players and entities.
abstractabuser Feb 24, 2024
f26c300
Added Extension Functions To Entity.kt
itay64 Feb 24, 2024
702ad20
Added Extension Functions To Entity.kt
itay64 Feb 24, 2024
4150c20
Merge pull request #58 from staticabuser/master
joshbker Mar 12, 2024
2976e91
feat: add Entity#frozen to check if an Entity is frozen
joshbker Mar 13, 2024
7e2db04
feat: use Entity#frozen to check if an Entity is frozen
joshbker Mar 13, 2024
2986191
refactor: newline
joshbker Mar 13, 2024
473af04
feat: add ServerSoftware to identify which software is running
joshbker Mar 13, 2024
ce658ee
feat: init ServerSoftware and add software boolean convenience method…
joshbker Mar 13, 2024
4be44d7
refactor: MoveEvent to EntityMoveEventListener
joshbker Mar 13, 2024
7f85449
feat: add software boolean convenience extension methods to Bukkit Se…
joshbker Mar 13, 2024
a46c60b
feat: register EntityMoveEventListener as a customEventListener
joshbker Mar 13, 2024
e073296
chore: bump ver v1.1.8
joshbker Mar 13, 2024
77f68b2
refactor: parking spaces for an-225 mriya aircraft (at request of ste…
joshbker Mar 13, 2024
84d6985
feat: add support to recognise Folia (and #isFolia)
joshbker Mar 13, 2024
442c8a1
refactor: my fault he only wanted to fit a boeing 777 in the spaces
joshbker Mar 13, 2024
906e1af
Merge pull request #60 from flytegg/feat/freeze
joshbker Mar 13, 2024
97ad548
Merge branch 'feat/entity-extensions' into master
joshbker Mar 13, 2024
494d74e
Merge pull request #59 from itay64/master
joshbker Mar 13, 2024
8aeff63
chore: bump ver v1.1.9
joshbker Mar 13, 2024
d850588
Merge pull request #61 from flytegg/feat/entity-extensions
joshbker Mar 13, 2024
eb571a9
Added a Redis system that lets you do the following things:
itay64 Mar 17, 2024
574b26f
Added a Redis system that lets you do the following things:
itay64 Mar 17, 2024
6f7b523
Fixed a small issue, made the sync publish method private in Redis
itay64 Mar 17, 2024
d8bc03a
Update README.md
itay64 Mar 17, 2024
326dd9f
Update README.md
itay64 Mar 17, 2024
7f39e04
Update README.md
itay64 Mar 17, 2024
552bb5e
Update README.md
itay64 Mar 17, 2024
34a62ac
Added to the Redis System:
itay64 Mar 18, 2024
16bc150
Merge remote-tracking branch 'origin/master'
itay64 Mar 18, 2024
00bc8bd
Update README.md
itay64 Mar 18, 2024
041804a
Specified Return Types
itay64 Mar 18, 2024
1a7ef58
Update README.md
itay64 Mar 18, 2024
bcfd28c
Update README.md
itay64 Mar 18, 2024
f84b162
Update README.md
itay64 Mar 18, 2024
34971fa
Merge remote-tracking branch 'origin/master'
itay64 Mar 18, 2024
916020e
Update README.md
itay64 Mar 18, 2024
9fd4ce1
Update README.md
itay64 Mar 18, 2024
22be4e7
Added Username/Password Options To Redis
itay64 Mar 18, 2024
8a8df0d
Merge remote-tracking branch 'origin/master'
itay64 Mar 18, 2024
3d33db3
Update README.md
itay64 Mar 18, 2024
59ab047
Update README.md
stephendotgg Mar 29, 2024
831ad69
Merge pull request #63 from itay64/master
joshbker Apr 5, 2024
b0db89f
refactor: move redis to data package
joshbker Apr 5, 2024
d5295a4
chore: bump ver v1.1.10
joshbker Apr 5, 2024
e3c8852
Merge pull request #64 from flytegg/pr/redis
joshbker Apr 5, 2024
36b23db
- Fixed The Listener Registering By Initiating A New Client To Regist…
itay64 Apr 12, 2024
1f925bc
Merge pull request #65 from itay64/master
joshbker May 1, 2024
fcf5abf
chore: bump ver v1.1.11
joshbker May 1, 2024
61f6734
feat: add metadata extensions
May 16, 2024
5cc0c06
Merge pull request #67 from flytegg/fix/redis
joshbker May 19, 2024
c72cf3f
Merge pull request #68 from akkkih/master
joshbker May 19, 2024
a84575f
chore: bump ver v1.1.12
joshbker May 19, 2024
65ced5e
Merge pull request #69 from flytegg/pr/metadata
joshbker May 19, 2024
f911607
Created nice GUI builder :)
slohth Sep 9, 2024
1d62add
Merge pull request #70 from flytegg/gui-builder
stephendotgg Sep 9, 2024
8fa421d
Bump version
stephendotgg Sep 9, 2024
b9e42ba
Implemented TwilightRunnable and chaining runnables.
slohth Oct 8, 2024
dae48c5
Fixed behaviour
slohth Oct 8, 2024
6d67cb9
Merge pull request #73 from flytegg/feat/on-complete-unit
joshbker Oct 8, 2024
5b1760e
Bump version README
joshbker Oct 8, 2024
404bc82
Bump version gradle
joshbker Oct 8, 2024
9d967f1
Merge pull request #74 from flytegg/pr/scheduler
joshbker Oct 8, 2024
7ca737d
feat: allow for duration specified and infinite actionbars through Tw…
joshbker Oct 8, 2024
9a85c75
chore: bump ver 1.1.15
joshbker Oct 8, 2024
893c6cb
fix(event): store type of TwilightRunnable for runnables rather than …
joshbker Oct 8, 2024
f2d0cf8
GUI builder slot action filters click events in player inventory
Pan-nav Nov 17, 2024
c4b2b35
Merge pull request #75 from Pan-nav/master
joshbker Nov 17, 2024
709b5be
chore: bump ver 1.1.16
joshbker Nov 17, 2024
bd5a3a1
Merge pull request #76 from flytegg/pr/panav-gui-fix
joshbker Nov 17, 2024
935a6b9
Use firstOrNull in NameCacheService to not throw for uncached players
KingsMMA Dec 5, 2024
13c1930
Added the option to use a default click event
KingsMMA Dec 7, 2024
e1f2865
Added javadoc, changed to all clicks while open
KingsMMA Dec 7, 2024
9169639
Updated README to reflect change
KingsMMA Dec 7, 2024
dfcaf7c
Merge pull request #77 from KingsMMA/master
stephendotgg Dec 16, 2024
0392266
Merge pull request #78 from KingsMMA/cancel-by-default
stephendotgg Dec 16, 2024
7c16e0a
PR readme update
stephendotgg Dec 16, 2024
484d147
Bump ver
stephendotgg Dec 16, 2024
a94665c
Readme improvements
stephendotgg Dec 16, 2024
e5c712f
Fix typos
stephendotgg Dec 16, 2024
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
320 changes: 293 additions & 27 deletions README.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "gg.flyte"
version = "1.1.6"
version = "1.1.17"

repositories {
mavenLocal()
Expand All @@ -27,7 +27,10 @@ dependencies {
api("io.github.cdimascio:dotenv-kotlin:6.4.1")
api("org.mongodb:mongodb-driver-kotlin-sync:4.11.0")
api("com.google.code.gson:gson:2.10.1")
api("redis.clients:jedis:5.1.2")


implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0-RC2")
implementation(kotlin("reflect"))

// api("com.github.okkero:Skedule:v1.2.6")
Expand Down Expand Up @@ -73,6 +76,4 @@ publishing {
}
}
}
}


}
13 changes: 12 additions & 1 deletion src/main/kotlin/gg/flyte/twilight/Twilight.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package gg.flyte.twilight

import gg.flyte.twilight.builders.item.ItemBuilder
import gg.flyte.twilight.data.MongoDB
import gg.flyte.twilight.data.service.NameCacheService
import gg.flyte.twilight.environment.Environment
import gg.flyte.twilight.event.custom.chat.command.ChatClickCommand
import gg.flyte.twilight.event.customEventListeners
import gg.flyte.twilight.extension.applyForEach
import gg.flyte.twilight.itembuilder.ItemBuilder
import gg.flyte.twilight.data.Redis
import gg.flyte.twilight.server.ServerSoftware
import org.bukkit.plugin.java.JavaPlugin

class Twilight(javaPlugin: JavaPlugin) {

init {
plugin = javaPlugin
run {
ServerSoftware
customEventListeners
ItemBuilder.Companion
ChatClickCommand.register()
Expand All @@ -24,15 +27,23 @@ class Twilight(javaPlugin: JavaPlugin) {
lateinit var plugin: JavaPlugin
var usingEnv = false
val internalPdc by lazy { "_twilight_${plugin.name.lowercase()}" }

fun isFolia(): Boolean = ServerSoftware.isFolia()
fun isPaper(): Boolean = ServerSoftware.isPaper()
fun isSpigot(): Boolean = ServerSoftware.isSpigot()
fun isCraftBukkit(): Boolean = ServerSoftware.isCraftBukkit()
}

fun env(init: Environment.Settings.() -> Unit = {}) {
usingEnv = true
Environment.env(Environment.Settings().apply(init))

}

fun mongo(init: MongoDB.Settings.() -> Unit = {}) = MongoDB.mongo(MongoDB.Settings().apply(init))

fun redis(init: Redis.Settings.() -> Unit = {}) = Redis.redis(Redis.Settings().apply(init))

fun nameCache(init: NameCacheService.Settings.() -> Unit = {}) = NameCacheService.nameCache(NameCacheService.Settings().apply(init))

fun terminate() = customEventListeners.applyForEach { unregister() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gg.flyte.twilight.itembuilder
package gg.flyte.twilight.builders.item

import gg.flyte.twilight.Twilight
import gg.flyte.twilight.event.event
import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.attribute.Attribute
Expand All @@ -15,6 +14,9 @@ import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet

class ItemBuilder(
var type: Material,
Expand All @@ -24,7 +26,7 @@ class ItemBuilder(
var unbreakable: Boolean = false,
val enchantments: MutableMap<Enchantment, Int> = HashMap(),
var customModelData: Int? = null,
var attributes: MutableMap<Attribute, AttributeModifier> = HashMap(),
var attributes: MutableMap<Attribute, AttributeModifier> = EnumMap(org.bukkit.attribute.Attribute::class.java),

val persistentStrings: MutableMap<String, String> = HashMap<String, String>().apply {
put(INTERACTION_UUID_KEY, uuidPdc())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gg.flyte.twilight.itembuilder
package gg.flyte.twilight.builders.item

enum class ItemInteraction {
RIGHT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gg.flyte.twilight.itembuilder
package gg.flyte.twilight.builders.item

import org.bukkit.persistence.PersistentDataType
import java.util.*
Expand Down
43 changes: 43 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/builders/recipe/RecipeBuilder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gg.flyte.twilight.builders.recipe

import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ShapedRecipe
import org.bukkit.plugin.java.JavaPlugin

class RecipeBuilder(result: ItemStack, plugin: JavaPlugin, key: String) {
private val recipe: ShapedRecipe = ShapedRecipe(NamespacedKey(plugin, key), result)
private val ingredients: MutableMap<Char, RecipeIngredient> = HashMap()

fun setShape(vararg shape: String): RecipeBuilder {
recipe.shape(*shape)
return this
}

fun setIngredient(key: Char, material: Material, amount: Int): RecipeBuilder {
val recipeIngredient = RecipeIngredient(ItemStack(material, amount))
recipe.setIngredient(key, recipeIngredient.materialData)
ingredients[key] = recipeIngredient
return this
}

fun setIngredient(key: Char, itemStack: ItemStack, amount: Int): RecipeBuilder {
val recipeIngredient = RecipeIngredient(itemStack.clone(), amount)
recipe.setIngredient(key, recipeIngredient.materialData)
ingredients[key] = recipeIngredient
return this
}

fun build(): ShapedRecipe {
ingredients.forEach { (key, value) ->
recipe.setIngredient(key, value.materialData)
}
return recipe
}

private inner class RecipeIngredient(private val itemStack: ItemStack, private val amount: Int = 1) {
val materialData: ItemStack
get() = itemStack.clone().apply { this.amount = amount }
}
}
93 changes: 93 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/data/Redis.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package gg.flyte.twilight.data

import gg.flyte.twilight.Twilight
import gg.flyte.twilight.environment.Environment
import redis.clients.jedis.DefaultJedisClientConfig
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisPubSub
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
import java.util.concurrent.Executors

object Redis {
private lateinit var jedis: Jedis
private lateinit var settings: Settings
private val executor: Executor = Executors.newCachedThreadPool()
fun redis(redis: Settings) {
jedis = getClient(redis)
settings = redis
}

private fun getClient(redis: Settings): Jedis = when (redis.authentication){
Authentication.NONE -> Jedis(redis.host, redis.port)
Authentication.USERNAME_PASSWORD -> Jedis(redis.host, redis.port, DefaultJedisClientConfig.builder().user(redis.username).password(redis.password).timeoutMillis(redis.timeout).build())
Authentication.URL -> Jedis(redis.url)
}

private fun publishSync(channel: String, message: String) = jedis.publish(channel, message)
fun publish(channel: String, message: String): CompletableFuture<Long> = CompletableFuture.supplyAsync({ publishSync(channel, message) }, executor)
private fun setSync(key: String, value: String) = jedis.set(key, value)
fun set(key: String, value: String): CompletableFuture<String> = CompletableFuture.supplyAsync({ setSync(key, value) }, executor)
private fun getSync(key: String) = jedis.get(key)
fun get(key: String): CompletableFuture<String> = CompletableFuture.supplyAsync({ getSync(key) }, executor)
private fun deleteSync(key: String) = jedis.del(key)
fun delete(key: String): CompletableFuture<Long> = CompletableFuture.supplyAsync({ deleteSync(key) }, executor)

fun addListener(listener: TwilightRedisListener): TwilightRedisListener {
val client = getClient(settings)
client.subscribe(listener, listener.channel)
client.close()
return listener
}
fun addListener(channel: String, block: RedisMessage.() -> Unit): TwilightRedisListener {
val client = getClient(settings)
val listener = RedisListener(channel, block)
client.subscribe(listener, channel)
client.close()
return listener
}
class Settings {
var authentication = if (Twilight.usingEnv) Authentication.fromString(Environment.get("REDIS_AUTHENTICATION")) else Authentication.NONE
var host: String = if (Twilight.usingEnv) Environment.get("REDIS_HOST") else "localhost"
var port: Int = if (Twilight.usingEnv) Environment.get("REDIS_PORT").toInt() else 6379
var timeout: Int = if (Twilight.usingEnv) Environment.get("REDIS_TIMEOUT").toInt() else 0
val username: String = if (Twilight.usingEnv && authentication == Authentication.USERNAME_PASSWORD) Environment.get("REDIS_USERNAME") else ""
var password: String = if (Twilight.usingEnv && authentication == Authentication.USERNAME_PASSWORD) Environment.get("REDIS_PASSWORD") else ""
var url: String = if (Twilight.usingEnv && authentication == Authentication.URL) Environment.get("REDIS_URL") else ""
}

enum class Authentication {
NONE,
USERNAME_PASSWORD,
URL;

companion object {
fun fromString(value: String): Authentication = when (value.uppercase()) {
"NONE" -> NONE
"USERNAME_PASSWORD" -> USERNAME_PASSWORD
"URL" -> URL
else -> throw IllegalArgumentException("Invalid authentication type: $value")
}
}

}

}

data class RedisMessage(val channel: String, val message: String, val listener: TwilightRedisListener)

abstract class TwilightRedisListener(val channel: String) : JedisPubSub() {
override fun onMessage(channel: String?, message: String?) {
channel ?: return
message?: return
if (channel == this.channel) onMessage(message)
}
abstract fun onMessage(message: String)
fun unregister() = unsubscribe()
}

class RedisListener(channel: String, val block: RedisMessage.() -> Unit): TwilightRedisListener(channel) {
override fun onMessage(message: String) {
block(RedisMessage(channel, message, this))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ object NameCacheService {

private fun queryMongoNameByUUID(uuid: UUID): String? {
mongoCache.let {
mongoCache.find(Filters.eq("_id", uuid.toString())).first()
mongoCache.find(Filters.eq("_id", uuid.toString())).firstOrNull()
?.let {
val name =
it.getString("name") ?: throw MongoException("Document with '_id' '$uuid' has no field 'name'.")
cache[uuid] = name
return name
} ?: return null
}
}
return null
}

private fun queryMojangNameByUUID(uuid: UUID): String {
Expand Down Expand Up @@ -78,13 +79,14 @@ object NameCacheService {
"name",
Pattern.compile("^$name$", Pattern.CASE_INSENSITIVE)
)
).first()?.let {
).firstOrNull()?.let {
val uuid = UUID.fromString(it.getString("_id"))
?: throw MongoException("Document with 'name' '$name' has no valid UUID at '_id'.")
cache[uuid] = name
return uuid
} ?: return null
}
}
return null
}

private fun queryMojangUUIDByName(name: String): UUID {
Expand Down
61 changes: 61 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/data/sql/AsyncSQLWrapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gg.flyte.twilight.data.sql

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement
import java.sql.Statement

class AsyncSQLWrapper(private val url: String, private val user: String, private val password: String) {

private var connection: Connection? = null

suspend fun connect() {
coroutineScope {
connection = DriverManager.getConnection(url, user, password)
}
}

suspend fun executeQuery(query: String): Results? {
return coroutineScope {
val resultSet = async(Dispatchers.IO) {
val statement: Statement? = connection?.createStatement()
statement?.executeQuery(query)
}
val rs = resultSet.await()
rs?.toResults()
}
}

suspend fun execute(sql: String): Boolean {
return coroutineScope {
var result = false
try {
val statement: Statement? = connection?.createStatement()
statement?.execute(sql)
result = true
} catch (e: Exception) {
e.printStackTrace()
}
result
}
}

suspend fun executeUpdate(query: String): Int {
return coroutineScope {
val rowsAffected = async(Dispatchers.IO) {
val statement: PreparedStatement? = connection?.prepareStatement(query)
statement?.executeUpdate() ?: 0
}
rowsAffected.await()
}
}

suspend fun close() {
coroutineScope {
connection?.close()
}
}
}
Loading
Loading