This commit is contained in:
AverageGithub 2024-01-29 15:29:51 +01:00
parent c086eb36a3
commit aadf5ebeb4
6 changed files with 245 additions and 187 deletions

View File

@ -20,6 +20,7 @@ repositories {
dependencies {
implementation project(path: ":api")
implementation project(path: ":common")
implementation project(path: ":nms:v1_19_R3", configuration: "reobf")
implementation project(path: ":nms:v1_20_R1", configuration: "reobf")
implementation project(path: ":nms:v1_20_R2", configuration: "reobf")
implementation project(path: ":nms:v1_20_R3", configuration: "reobf")
@ -120,8 +121,9 @@ allprojects {
compileOnly 'com.intellectualsites.plotsquared:plotsquared-core:7.0.0-rc.4'
compileOnly 'com.intellectualsites.plotsquared:plotsquared-bukkit:7.0.0-rc.4'
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
implementation("com.artillexstudios.axapi:axapi:1.4.10")
implementation("com.artillexstudios.axapi:axapi:1.4.22")
implementation("net.byteflux:libby-bukkit:1.3.0")
implementation("com.zaxxer:HikariCP:5.1.0")
compileOnly files('../libs/CMI-API9.5.0.8.jar')
compileOnly files('../libs/IridiumSkyblock-3.2.12.jar')
compileOnly files('../libs/KingdomsX-1.16.12.jar')
@ -131,6 +133,7 @@ allprojects {
relocate("com.artillexstudios.axapi", "com.artillexstudios.axminions.libs.axapi")
relocate("org.h2", "com.artillexstudios.axminions.libs.h2")
relocate("org.jetbrains.kotlin", "com.artillexstudios.axminions.libs.kotlin")
relocate("com.zaxxer", "com.artillexstudios.axminions.libs.hikaricp")
}
}

View File

@ -5,6 +5,8 @@ import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.data.DataHandler
import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
@ -17,52 +19,68 @@ import java.util.Properties
import java.util.UUID
class H2DataHandler : DataHandler {
private lateinit var connection: JdbcConnection
private lateinit var dataSource: HikariDataSource
override fun getType(): String {
return "H2"
}
override fun setup() {
Class.forName("org.h2.Driver")
connection =
JdbcConnection("jdbc:h2:./${AxMinionsPlugin.INSTANCE.dataFolder}/data", Properties(), null, null, false)
val config = HikariConfig()
config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource")
config.addDataSourceProperty("url", "jdbc:h2:async:./${AxMinionsPlugin.INSTANCE.dataFolder}/data")
config.setAutoCommit(true)
dataSource = HikariDataSource(config)
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_types`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));")
.use {
it.executeUpdate()
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_users`(`uuid` UUID PRIMARY KEY, `name` VARCHAR(16));")
.use {
it.executeUpdate()
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_worlds`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));")
.use {
it.executeUpdate()
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_locations`(`id` INT AUTO_INCREMENT PRIMARY KEY, `x` INT, `y` INT, `z` INT, `world_id` INT, FOREIGN KEY(world_id) REFERENCES `axminions_worlds`(`id`));")
.use {
it.executeUpdate()
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_minions`(`id` INT AUTO_INCREMENT PRIMARY KEY, `location_id` INT, `chest_location_id` INT, `owner_id` UUID, `type_id` TINYINT, `direction` TINYINT, `level` SMALLINT, `storage` DOUBLE, `actions` BIGINT, `tool` CLOB, FOREIGN KEY(`location_id`) REFERENCES `axminions_locations`(id), FOREIGN KEY(`chest_location_id`) REFERENCES `axminions_locations`(`id`), FOREIGN KEY(`owner_id`) REFERENCES `axminions_users`(`uuid`), FOREIGN KEY(`type_id`) REFERENCES `axminions_types`(`id`));")
.use {
it.executeUpdate()
}
}
}
override fun insertType(minionType: MinionType) {
dataSource.connection.use { connection ->
connection.prepareStatement("MERGE INTO `axminions_types`(`name`) KEY(`name`) VALUES(?);").use {
it.setString(1, minionType.getName())
it.executeUpdate()
}
}
}
override fun loadMinionsForWorld(minionType: MinionType, world: World) {
var typeId = 0
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT `id` FROM `axminions_types` WHERE `name` = ?;").use { statement ->
statement.setString(1, minionType.getName())
statement.executeQuery().use { resultSet ->
@ -71,7 +89,9 @@ class H2DataHandler : DataHandler {
}
}
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT `minions`.* FROM `axminions_minions` AS `minions` JOIN `axminions_locations` AS `location` ON `minions`.`location_id` = `location`.`id` WHERE `location`.`world_id` = (SELECT `id` FROM `axminions_worlds` WHERE `name` = ?) AND `type_id` = ?;").use { statement ->
statement.setString(1, world.name)
statement.setInt(2, typeId)
@ -115,9 +135,11 @@ class H2DataHandler : DataHandler {
}
}
}
}
override fun getLocationID(location: Location): Int {
var worldId = 0
dataSource.connection.use { connection ->
connection.prepareStatement(
"MERGE INTO `axminions_worlds`(`name`) KEY(`name`) VALUES(?);",
Statement.RETURN_GENERATED_KEYS
@ -131,7 +153,9 @@ class H2DataHandler : DataHandler {
}
}
}
}
dataSource.connection.use { connection ->
connection.prepareStatement(
"MERGE INTO `axminions_locations`(`x`, `y`, `z`, `world_id`) KEY(`x`, `y`, `z`, `world_id`) VALUES (?, ?, ?, ?);",
Statement.RETURN_GENERATED_KEYS
@ -148,11 +172,13 @@ class H2DataHandler : DataHandler {
}
}
}
}
return 0
}
override fun getLocation(locationId: Int): Location? {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT * FROM `axminions_locations` WHERE `id` = ?;").use { statement ->
statement.setInt(1, locationId)
statement.executeQuery().use { resultSet ->
@ -169,8 +195,10 @@ class H2DataHandler : DataHandler {
}
}
}
}
override fun getWorld(worldId: Int): World? {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT `name` FROM `axminions_worlds` WHERE `id` = ?;").use { statement ->
statement.setInt(1, worldId)
statement.executeQuery().use { resultSet ->
@ -182,6 +210,7 @@ class H2DataHandler : DataHandler {
}
}
}
}
override fun saveMinion(minion: com.artillexstudios.axminions.api.minions.Minion) {
val locationId = getLocationID(minion.getLocation())
@ -189,6 +218,7 @@ class H2DataHandler : DataHandler {
var userId: UUID? = null
var minionTypeId = 0
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT * FROM `axminions_types` WHERE `name` = ?;").use {
it.setString(1, minion.getType().getName())
it.executeQuery().use { resultSet ->
@ -197,11 +227,13 @@ class H2DataHandler : DataHandler {
}
}
}
}
if (minion.getLinkedChest() != null) {
linkedChestId = getLocationID(minion.getLinkedChest()!!)
}
dataSource.connection.use { connection ->
connection.prepareStatement(
"MERGE INTO `axminions_users`(`uuid`, `name`) KEY(`uuid`) VALUES (?,?);",
Statement.RETURN_GENERATED_KEYS
@ -216,11 +248,13 @@ class H2DataHandler : DataHandler {
}
}
}
}
if (userId == null) {
return
}
dataSource.connection.use { connection ->
connection.prepareStatement("MERGE INTO `axminions_minions`(`location_id`, `chest_location_id`, `owner_id`, `type_id`, `direction`, `level`, `storage`, `actions`, `tool`) KEY(`location_id`) VALUES(?,?,?,?,?,?,?,?,?)")
.use { statement ->
statement.setInt(1, locationId)
@ -243,14 +277,18 @@ class H2DataHandler : DataHandler {
statement.executeUpdate()
}
}
}
override fun deleteMinion(minion: com.artillexstudios.axminions.api.minions.Minion) {
dataSource.connection.use { connection ->
connection.prepareStatement("DELETE FROM `axminions_minions` WHERE `location_id` = ?;")
.use { preparedStatement ->
preparedStatement.setInt(1, minion.getLocationId())
preparedStatement.executeUpdate()
}
}
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `location_id` = ?;").use { statement ->
statement.setInt(1, minion.getLocationId())
statement.executeQuery().use { resultSet ->
@ -262,8 +300,10 @@ class H2DataHandler : DataHandler {
}
}
}
}
if (minion.getChestLocationId() != 0) {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `chest_location_id` = ?;")
.use { statement ->
statement.setInt(1, minion.getChestLocationId())
@ -278,8 +318,10 @@ class H2DataHandler : DataHandler {
}
}
}
}
override fun getMinionAmount(uuid: UUID): Int {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT COUNT(`owner_id`) FROM `axminions_minions` WHERE `owner_id` = ?;")
.use { statement ->
statement.setObject(1, uuid)
@ -289,11 +331,13 @@ class H2DataHandler : DataHandler {
}
}
}
}
return 0
}
override fun isMinion(location: Location): Boolean {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `location_id` = (SELECT `id` FROM `axminions_locations` WHERE x = ? AND y = ? AND z = ? AND `world_id` = (SELECT `id` FROM `axminions_worlds` WHERE `name` = ?));")
.use { statement ->
statement.setInt(1, location.blockX)
@ -306,11 +350,14 @@ class H2DataHandler : DataHandler {
}
}
}
}
return false
}
override fun disable() {
dataSource.connection.use { connection ->
connection.prepareStatement("SHUTDOWN DEFRAG;").executeUpdate()
}
}
}

View File

@ -12,7 +12,7 @@ class SuperiorSkyBlock2Integration : ProtectionIntegration {
val island = SuperiorSkyblockAPI.getIslandAt(location) ?: return true
return island.isMember(localPlayer)
return island.isMember(localPlayer) || localPlayer.hasBypassModeEnabled()
}
override fun register() {

View File

@ -34,7 +34,7 @@ class MinionPlaceListener : Listener {
event.isCancelled = true
val item = event.item ?: return
val meta = item.itemMeta ?: return
var meta = item.itemMeta ?: return
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
@ -81,7 +81,8 @@ class MinionPlaceListener : Listener {
0
)
minion.setTicking(true)
Scheduler.get().run {
Scheduler.get().run { task ->
meta = item.itemMeta!!
meta.persistentDataContainer.remove(Keys.PLACED)
item.itemMeta = meta
item.amount = item.amount.minus(1)

View File

@ -566,6 +566,12 @@ class Minion(
override fun setTicking(ticking: Boolean) {
this.ticking = ticking
if (ticking && linkedChest != null) {
Scheduler.get().runAt(linkedChest) {
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
}
}
}
override fun setRange(range: Double) {

View File

@ -13,6 +13,7 @@ rootProject.name = 'AxMinions'
include 'api'
include 'common'
include 'nms'
include 'nms:v1_19_R3'
include 'nms:v1_20_R1'
include 'nms:v1_20_R2'
include 'nms:v1_20_R3'