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 { dependencies {
implementation project(path: ":api") implementation project(path: ":api")
implementation project(path: ":common") 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_R1", configuration: "reobf")
implementation project(path: ":nms:v1_20_R2", configuration: "reobf") implementation project(path: ":nms:v1_20_R2", configuration: "reobf")
implementation project(path: ":nms:v1_20_R3", 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-core:7.0.0-rc.4'
compileOnly 'com.intellectualsites.plotsquared:plotsquared-bukkit: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 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("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/CMI-API9.5.0.8.jar')
compileOnly files('../libs/IridiumSkyblock-3.2.12.jar') compileOnly files('../libs/IridiumSkyblock-3.2.12.jar')
compileOnly files('../libs/KingdomsX-1.16.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("com.artillexstudios.axapi", "com.artillexstudios.axminions.libs.axapi")
relocate("org.h2", "com.artillexstudios.axminions.libs.h2") relocate("org.h2", "com.artillexstudios.axminions.libs.h2")
relocate("org.jetbrains.kotlin", "com.artillexstudios.axminions.libs.kotlin") 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.data.DataHandler
import com.artillexstudios.axminions.api.minions.Direction import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.miniontype.MinionType 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.Bukkit
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.Material import org.bukkit.Material
@ -17,100 +19,119 @@ import java.util.Properties
import java.util.UUID import java.util.UUID
class H2DataHandler : DataHandler { class H2DataHandler : DataHandler {
private lateinit var connection: JdbcConnection private lateinit var dataSource: HikariDataSource
override fun getType(): String { override fun getType(): String {
return "H2" return "H2"
} }
override fun setup() { override fun setup() {
Class.forName("org.h2.Driver") val config = HikariConfig()
connection = config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource")
JdbcConnection("jdbc:h2:./${AxMinionsPlugin.INSTANCE.dataFolder}/data", Properties(), null, null, false) config.addDataSourceProperty("url", "jdbc:h2:async:./${AxMinionsPlugin.INSTANCE.dataFolder}/data")
config.setAutoCommit(true)
dataSource = HikariDataSource(config)
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_types`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));") dataSource.connection.use { connection ->
.use { connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_types`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));")
it.executeUpdate() .use {
} it.executeUpdate()
}
}
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_users`(`uuid` UUID PRIMARY KEY, `name` VARCHAR(16));") dataSource.connection.use { connection ->
.use { connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_users`(`uuid` UUID PRIMARY KEY, `name` VARCHAR(16));")
it.executeUpdate() .use {
} it.executeUpdate()
}
}
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_worlds`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));") dataSource.connection.use { connection ->
.use { connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_worlds`(`id` INT AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(64));")
it.executeUpdate() .use {
} it.executeUpdate()
}
}
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()
}
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`));") dataSource.connection.use { connection ->
.use { 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`));")
it.executeUpdate() .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) { override fun insertType(minionType: MinionType) {
connection.prepareStatement("MERGE INTO `axminions_types`(`name`) KEY(`name`) VALUES(?);").use { dataSource.connection.use { connection ->
it.setString(1, minionType.getName()) connection.prepareStatement("MERGE INTO `axminions_types`(`name`) KEY(`name`) VALUES(?);").use {
it.executeUpdate() it.setString(1, minionType.getName())
it.executeUpdate()
}
} }
} }
override fun loadMinionsForWorld(minionType: MinionType, world: World) { override fun loadMinionsForWorld(minionType: MinionType, world: World) {
var typeId = 0 var typeId = 0
connection.prepareStatement("SELECT `id` FROM `axminions_types` WHERE `name` = ?;").use { statement -> dataSource.connection.use { connection ->
statement.setString(1, minionType.getName()) connection.prepareStatement("SELECT `id` FROM `axminions_types` WHERE `name` = ?;").use { statement ->
statement.executeQuery().use { resultSet -> statement.setString(1, minionType.getName())
if (resultSet.next()) { statement.executeQuery().use { resultSet ->
typeId = resultSet.getInt("id") if (resultSet.next()) {
typeId = resultSet.getInt("id")
}
} }
} }
} }
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 -> dataSource.connection.use { connection ->
statement.setString(1, world.name) 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.setInt(2, typeId) statement.setString(1, world.name)
statement.executeQuery().use { resultSet -> statement.setInt(2, typeId)
while (resultSet.next()) { statement.executeQuery().use { resultSet ->
val locationId = resultSet.getInt("location_id") while (resultSet.next()) {
val chestLocationId = resultSet.getInt("chest_location_id") val locationId = resultSet.getInt("location_id")
val ownerId = resultSet.getObject("owner_id") as UUID val chestLocationId = resultSet.getInt("chest_location_id")
val direction = Direction.entries[resultSet.getByte("direction").toInt()] val ownerId = resultSet.getObject("owner_id") as UUID
val level = resultSet.getShort("level") val direction = Direction.entries[resultSet.getByte("direction").toInt()]
val storage = resultSet.getDouble("storage") val level = resultSet.getShort("level")
val actions = resultSet.getLong("actions") val storage = resultSet.getDouble("storage")
val tool = resultSet.getString("tool") val actions = resultSet.getLong("actions")
val tool = resultSet.getString("tool")
val location = getLocation(locationId) val location = getLocation(locationId)
var chestLocation: Location? = null var chestLocation: Location? = null
if (chestLocationId != 0) { if (chestLocationId != 0) {
chestLocation = getLocation(chestLocationId) chestLocation = getLocation(chestLocationId)
}
var itemStack = ItemStack(Material.AIR)
if (tool != null) {
itemStack = Serializers.ITEM_STACK.deserialize(tool)
}
com.artillexstudios.axminions.minions.Minion(
location!!,
ownerId,
Bukkit.getOfflinePlayer(ownerId),
minionType,
level.toInt(),
itemStack,
chestLocation,
direction,
actions,
storage,
locationId,
chestLocationId
)
} }
var itemStack = ItemStack(Material.AIR)
if (tool != null) {
itemStack = Serializers.ITEM_STACK.deserialize(tool)
}
com.artillexstudios.axminions.minions.Minion(
location!!,
ownerId,
Bukkit.getOfflinePlayer(ownerId),
minionType,
level.toInt(),
itemStack,
chestLocation,
direction,
actions,
storage,
locationId,
chestLocationId
)
} }
} }
} }
@ -118,33 +139,37 @@ class H2DataHandler : DataHandler {
override fun getLocationID(location: Location): Int { override fun getLocationID(location: Location): Int {
var worldId = 0 var worldId = 0
connection.prepareStatement( dataSource.connection.use { connection ->
"MERGE INTO `axminions_worlds`(`name`) KEY(`name`) VALUES(?);", connection.prepareStatement(
Statement.RETURN_GENERATED_KEYS "MERGE INTO `axminions_worlds`(`name`) KEY(`name`) VALUES(?);",
).use { statement -> Statement.RETURN_GENERATED_KEYS
statement.setString(1, location.world?.name) ).use { statement ->
statement.executeUpdate() statement.setString(1, location.world?.name)
statement.executeUpdate()
statement.generatedKeys.use { resultSet -> statement.generatedKeys.use { resultSet ->
if (resultSet.next()) { if (resultSet.next()) {
worldId = resultSet.getInt(1) worldId = resultSet.getInt(1)
}
} }
} }
} }
connection.prepareStatement( dataSource.connection.use { connection ->
"MERGE INTO `axminions_locations`(`x`, `y`, `z`, `world_id`) KEY(`x`, `y`, `z`, `world_id`) VALUES (?, ?, ?, ?);", connection.prepareStatement(
Statement.RETURN_GENERATED_KEYS "MERGE INTO `axminions_locations`(`x`, `y`, `z`, `world_id`) KEY(`x`, `y`, `z`, `world_id`) VALUES (?, ?, ?, ?);",
).use { statement -> Statement.RETURN_GENERATED_KEYS
statement.setInt(1, location.blockX) ).use { statement ->
statement.setInt(2, location.blockY) statement.setInt(1, location.blockX)
statement.setInt(3, location.blockZ) statement.setInt(2, location.blockY)
statement.setInt(4, worldId) statement.setInt(3, location.blockZ)
statement.executeUpdate() statement.setInt(4, worldId)
statement.executeUpdate()
statement.generatedKeys.use { resultSet -> statement.generatedKeys.use { resultSet ->
if (resultSet.next()) { if (resultSet.next()) {
return resultSet.getInt(1) return resultSet.getInt(1)
}
} }
} }
} }
@ -153,32 +178,36 @@ class H2DataHandler : DataHandler {
} }
override fun getLocation(locationId: Int): Location? { override fun getLocation(locationId: Int): Location? {
connection.prepareStatement("SELECT * FROM `axminions_locations` WHERE `id` = ?;").use { statement -> dataSource.connection.use { connection ->
statement.setInt(1, locationId) connection.prepareStatement("SELECT * FROM `axminions_locations` WHERE `id` = ?;").use { statement ->
statement.executeQuery().use { resultSet -> statement.setInt(1, locationId)
if (resultSet.next()) { statement.executeQuery().use { resultSet ->
val worldId = resultSet.getInt("world_id") if (resultSet.next()) {
val x = resultSet.getInt("x") val worldId = resultSet.getInt("world_id")
val y = resultSet.getInt("y") val x = resultSet.getInt("x")
val z = resultSet.getInt("z") val y = resultSet.getInt("y")
val z = resultSet.getInt("z")
return Location(getWorld(worldId), x.toDouble(), y.toDouble(), z.toDouble()) return Location(getWorld(worldId), x.toDouble(), y.toDouble(), z.toDouble())
}
return null
} }
return null
} }
} }
} }
override fun getWorld(worldId: Int): World? { override fun getWorld(worldId: Int): World? {
connection.prepareStatement("SELECT `name` FROM `axminions_worlds` WHERE `id` = ?;").use { statement -> dataSource.connection.use { connection ->
statement.setInt(1, worldId) connection.prepareStatement("SELECT `name` FROM `axminions_worlds` WHERE `id` = ?;").use { statement ->
statement.executeQuery().use { resultSet -> statement.setInt(1, worldId)
if (resultSet.next()) { statement.executeQuery().use { resultSet ->
return Bukkit.getWorld(resultSet.getString("name")) if (resultSet.next()) {
} return Bukkit.getWorld(resultSet.getString("name"))
}
return null return null
}
} }
} }
} }
@ -189,11 +218,13 @@ class H2DataHandler : DataHandler {
var userId: UUID? = null var userId: UUID? = null
var minionTypeId = 0 var minionTypeId = 0
connection.prepareStatement("SELECT * FROM `axminions_types` WHERE `name` = ?;").use { dataSource.connection.use { connection ->
it.setString(1, minion.getType().getName()) connection.prepareStatement("SELECT * FROM `axminions_types` WHERE `name` = ?;").use {
it.executeQuery().use { resultSet -> it.setString(1, minion.getType().getName())
if (resultSet.next()) { it.executeQuery().use { resultSet ->
minionTypeId = resultSet.getInt("id") if (resultSet.next()) {
minionTypeId = resultSet.getInt("id")
}
} }
} }
} }
@ -202,17 +233,19 @@ class H2DataHandler : DataHandler {
linkedChestId = getLocationID(minion.getLinkedChest()!!) linkedChestId = getLocationID(minion.getLinkedChest()!!)
} }
connection.prepareStatement( dataSource.connection.use { connection ->
"MERGE INTO `axminions_users`(`uuid`, `name`) KEY(`uuid`) VALUES (?,?);", connection.prepareStatement(
Statement.RETURN_GENERATED_KEYS "MERGE INTO `axminions_users`(`uuid`, `name`) KEY(`uuid`) VALUES (?,?);",
).use { statement -> Statement.RETURN_GENERATED_KEYS
statement.setObject(1, minion.getOwnerUUID()) ).use { statement ->
statement.setString(2, minion.getOwner()?.name ?: "---") statement.setObject(1, minion.getOwnerUUID())
statement.executeUpdate() statement.setString(2, minion.getOwner()?.name ?: "---")
statement.executeUpdate()
statement.generatedKeys.use { resultSet -> statement.generatedKeys.use { resultSet ->
if (resultSet.next()) { if (resultSet.next()) {
userId = resultSet.getObject(1) as UUID userId = resultSet.getObject(1) as UUID
}
} }
} }
} }
@ -221,96 +254,110 @@ class H2DataHandler : DataHandler {
return return
} }
connection.prepareStatement("MERGE INTO `axminions_minions`(`location_id`, `chest_location_id`, `owner_id`, `type_id`, `direction`, `level`, `storage`, `actions`, `tool`) KEY(`location_id`) VALUES(?,?,?,?,?,?,?,?,?)") dataSource.connection.use { connection ->
.use { statement -> connection.prepareStatement("MERGE INTO `axminions_minions`(`location_id`, `chest_location_id`, `owner_id`, `type_id`, `direction`, `level`, `storage`, `actions`, `tool`) KEY(`location_id`) VALUES(?,?,?,?,?,?,?,?,?)")
statement.setInt(1, locationId) .use { statement ->
if (linkedChestId == null) { statement.setInt(1, locationId)
statement.setNull(2, Types.INTEGER) if (linkedChestId == null) {
} else { statement.setNull(2, Types.INTEGER)
statement.setInt(2, linkedChestId) } else {
statement.setInt(2, linkedChestId)
}
statement.setObject(3, userId!!)
statement.setInt(4, minionTypeId)
statement.setByte(5, minion.getDirection().ordinal.toByte())
statement.setInt(6, minion.getLevel())
statement.setDouble(7, minion.getStorage())
statement.setLong(8, minion.getActionAmount())
if (minion.getTool() == null || minion.getTool()?.type == Material.AIR) {
statement.setNull(9, Types.CLOB)
} else {
statement.setString(9, Serializers.ITEM_STACK.serialize(minion.getTool()))
}
statement.executeUpdate()
} }
statement.setObject(3, userId!!) }
statement.setInt(4, minionTypeId)
statement.setByte(5, minion.getDirection().ordinal.toByte())
statement.setInt(6, minion.getLevel())
statement.setDouble(7, minion.getStorage())
statement.setLong(8, minion.getActionAmount())
if (minion.getTool() == null || minion.getTool()?.type == Material.AIR) {
statement.setNull(9, Types.CLOB)
} else {
statement.setString(9, Serializers.ITEM_STACK.serialize(minion.getTool()))
}
statement.executeUpdate()
}
} }
override fun deleteMinion(minion: com.artillexstudios.axminions.api.minions.Minion) { override fun deleteMinion(minion: com.artillexstudios.axminions.api.minions.Minion) {
connection.prepareStatement("DELETE FROM `axminions_minions` WHERE `location_id` = ?;") dataSource.connection.use { connection ->
.use { preparedStatement -> connection.prepareStatement("DELETE FROM `axminions_minions` WHERE `location_id` = ?;")
preparedStatement.setInt(1, minion.getLocationId()) .use { preparedStatement ->
preparedStatement.executeUpdate() preparedStatement.setInt(1, minion.getLocationId())
} preparedStatement.executeUpdate()
}
}
connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `location_id` = ?;").use { statement -> dataSource.connection.use { connection ->
statement.setInt(1, minion.getLocationId()) connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `location_id` = ?;").use { statement ->
statement.executeQuery().use { resultSet -> statement.setInt(1, minion.getLocationId())
if (!resultSet.next()) { statement.executeQuery().use { resultSet ->
connection.prepareStatement("DELETE FROM `axminions_locations` WHERE `id` = ?").use { if (!resultSet.next()) {
it.setInt(1, minion.getLocationId()) connection.prepareStatement("DELETE FROM `axminions_locations` WHERE `id` = ?").use {
it.executeUpdate() it.setInt(1, minion.getLocationId())
it.executeUpdate()
}
} }
} }
} }
} }
if (minion.getChestLocationId() != 0) { if (minion.getChestLocationId() != 0) {
connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `chest_location_id` = ?;") dataSource.connection.use { connection ->
.use { statement -> connection.prepareStatement("SELECT * FROM `axminions_minions` WHERE `chest_location_id` = ?;")
statement.setInt(1, minion.getChestLocationId()) .use { statement ->
statement.executeQuery().use { resultSet -> statement.setInt(1, minion.getChestLocationId())
if (!resultSet.next()) { statement.executeQuery().use { resultSet ->
connection.prepareStatement("DELETE FROM `axminions_locations` WHERE `id` = ?").use { if (!resultSet.next()) {
it.setInt(1, minion.getLocationId()) connection.prepareStatement("DELETE FROM `axminions_locations` WHERE `id` = ?").use {
it.executeUpdate() it.setInt(1, minion.getLocationId())
it.executeUpdate()
}
} }
} }
} }
} }
} }
} }
override fun getMinionAmount(uuid: UUID): Int { override fun getMinionAmount(uuid: UUID): Int {
connection.prepareStatement("SELECT COUNT(`owner_id`) FROM `axminions_minions` WHERE `owner_id` = ?;") dataSource.connection.use { connection ->
.use { statement -> connection.prepareStatement("SELECT COUNT(`owner_id`) FROM `axminions_minions` WHERE `owner_id` = ?;")
statement.setObject(1, uuid) .use { statement ->
statement.executeQuery().use { resultSet -> statement.setObject(1, uuid)
if (resultSet.next()) { statement.executeQuery().use { resultSet ->
return resultSet.getInt(1) if (resultSet.next()) {
return resultSet.getInt(1)
}
} }
} }
} }
return 0 return 0
} }
override fun isMinion(location: Location): Boolean { override fun isMinion(location: Location): Boolean {
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` = ?));") dataSource.connection.use { connection ->
.use { statement -> 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` = ?));")
statement.setInt(1, location.blockX) .use { statement ->
statement.setInt(2, location.blockY) statement.setInt(1, location.blockX)
statement.setInt(3, location.blockZ) statement.setInt(2, location.blockY)
statement.setString(4, location.world?.name ?: "---") statement.setInt(3, location.blockZ)
statement.executeQuery().use { resultSet -> statement.setString(4, location.world?.name ?: "---")
if (resultSet.next()) { statement.executeQuery().use { resultSet ->
return true if (resultSet.next()) {
return true
}
} }
} }
} }
return false return false
} }
override fun disable() { override fun disable() {
connection.prepareStatement("SHUTDOWN DEFRAG;").executeUpdate() 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 val island = SuperiorSkyblockAPI.getIslandAt(location) ?: return true
return island.isMember(localPlayer) return island.isMember(localPlayer) || localPlayer.hasBypassModeEnabled()
} }
override fun register() { override fun register() {

View File

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

View File

@ -498,7 +498,7 @@ class Minion(
} }
override fun addToContainerOrDrop(itemStack: ItemStack) { override fun addToContainerOrDrop(itemStack: ItemStack) {
if (linkedInventory == null) { if (linkedInventory == null) {
AxMinionsPlugin.integrations.getStackerIntegration().dropItemAt(itemStack, itemStack.amount, location) AxMinionsPlugin.integrations.getStackerIntegration().dropItemAt(itemStack, itemStack.amount, location)
return return
} }
@ -566,6 +566,12 @@ class Minion(
override fun setTicking(ticking: Boolean) { override fun setTicking(ticking: Boolean) {
this.ticking = ticking this.ticking = ticking
if (ticking && linkedChest != null) {
Scheduler.get().runAt(linkedChest) {
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
}
}
} }
override fun setRange(range: Double) { override fun setRange(range: Double) {

View File

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