This commit is contained in:
TomTom 2024-06-13 20:33:52 +02:00
parent 912bea3f69
commit c638876aa2
7 changed files with 94 additions and 49 deletions

View File

@ -30,5 +30,11 @@ interface DataHandler {
fun isMinion(location: Location): Boolean
fun islandPlace(island: String)
fun islandBreak(island: String)
fun getIsland(island: String): Int
fun disable()
}

View File

@ -1,12 +1,12 @@
package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.entity.Player
interface IslandIntegration : Integration {
fun getIslandPlaced(player: Player): Int
fun getIslandAt(location: Location): String
fun handleBlockBreak(block: Block)
}

View File

@ -2,6 +2,7 @@ package com.artillexstudios.axminions.data
import com.artillexstudios.axapi.serializers.Serializers
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.data.DataHandler
import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
@ -73,6 +74,15 @@ class H2DataHandler : DataHandler {
it.executeUpdate()
}
}
if (Config.ISLAND_LIMIT() > 0) {
dataSource.connection.use { connection ->
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `axminions_island_counter`(`island` VARCHAR(256) PRIMARY KEY, `placed` INT);")
.use {
it.executeUpdate()
}
}
}
}
override fun insertType(minionType: MinionType) {
@ -364,6 +374,38 @@ class H2DataHandler : DataHandler {
return false
}
override fun islandPlace(island: String) {
dataSource.connection.use { connection ->
connection.prepareStatement("UPDATE `axminions_island_counter` SET `placed` = `placed` + 1 WHERE `island` = ?;").use { statement ->
statement.setString(1, island)
statement.executeUpdate()
}
}
}
override fun islandBreak(island: String) {
dataSource.connection.use { connection ->
connection.prepareStatement("UPDATE `axminions_island_counter` SET `placed` = `placed` - 1 WHERE `island` = ?;").use { statement ->
statement.setString(1, island)
statement.executeUpdate()
}
}
}
override fun getIsland(island: String): Int {
dataSource.connection.use { connection ->
connection.prepareStatement("SELECT `placed` FROM `axminions_island_counter` WHERE `island` = ?").use { statement ->
statement.executeQuery().use { resultSet ->
if (resultSet.next()) {
return resultSet.getInt("placed")
}
}
}
}
return 0
}
override fun disable() {
dataSource.connection.prepareStatement("SHUTDOWN DEFRAG;").executeUpdate()
}

View File

@ -1,29 +1,23 @@
package com.artillexstudios.axminions.integrations.island
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.integrations.types.IslandIntegration
import com.artillexstudios.axminions.api.utils.fastFor
import com.iridium.iridiumskyblock.IridiumSkyblock
import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.entity.Player
class IridiumSkyBlockIntegration : IslandIntegration {
override fun getIslandPlaced(player: Player): Int {
val island = IridiumSkyblockAPI.getInstance().getUser(player).island
if (island.isEmpty) {
return 0
override fun getIslandAt(location: Location): String {
val island = IridiumSkyblockAPI.getInstance().getIslandViaLocation(location)
if (island.isPresent) {
return island.get().id.toString()
}
var amount = 0
IridiumSkyblock.getInstance().teamManager.getTeamMembers(island.get()).fastFor {
amount += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uuid)
}
return amount
return ""
}
override fun handleBlockBreak(block: Block) {
}

View File

@ -1,28 +1,15 @@
package com.artillexstudios.axminions.integrations.island
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.integrations.types.IslandIntegration
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.entity.Player
class SuperiorSkyBlock2Integration : IslandIntegration {
override fun getIslandPlaced(player: Player): Int {
var placed = 0
SuperiorSkyblockAPI.getPlayer(player.uniqueId).island?.getIslandMembers(true)?.forEach {
val a = AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uniqueId)
placed += a
if (Config.DEBUG()) {
println("Member: ${it.name} - $a")
}
}
if (Config.DEBUG()) {
println("Placed total: $placed")
}
return placed
override fun getIslandAt(location: Location): String {
return SuperiorSkyblockAPI.getIslandAt(location)?.uniqueId?.toString() ?: ""
}
override fun handleBlockBreak(block: Block) {

View File

@ -6,22 +6,22 @@ import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.events.PreMinionPlaceEvent
import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
import com.artillexstudios.axminions.api.utils.Keys
import com.artillexstudios.axminions.minions.Minion
import com.artillexstudios.axminions.minions.Minions
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import org.bukkit.event.block.BlockPlaceEvent
import com.artillexstudios.axminions.api.events.PreMinionPlaceEvent
import org.bukkit.Bukkit
class MinionPlaceListener : Listener {
@ -77,24 +77,28 @@ class MinionPlaceListener : Listener {
val islandLimit = Config.ISLAND_LIMIT()
var islandPlaced = 0
var islandId = ""
if (islandLimit > 0 && AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() != null) {
islandPlaced = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandPlaced(event.player)
islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandAt(location)
if (islandId.isNotBlank()) {
islandPlaced = AxMinionsAPI.INSTANCE.getDataHandler().getIsland(islandId)
if (islandPlaced >= islandLimit && !event.player.hasPermission("axminions.limit.*")) {
event.player.sendMessage(
StringUtils.formatToString(
Messages.PREFIX() + Messages.ISLAND_LIMIT_REACHED(),
Placeholder.unparsed("placed", islandPlaced.toString()),
Placeholder.unparsed("max", islandLimit.toString())
if (islandPlaced >= islandLimit && !event.player.hasPermission("axminions.limit.*")) {
event.player.sendMessage(
StringUtils.formatToString(
Messages.PREFIX() + Messages.ISLAND_LIMIT_REACHED(),
Placeholder.unparsed("placed", islandPlaced.toString()),
Placeholder.unparsed("max", islandLimit.toString())
)
)
)
Scheduler.get().run { _ ->
meta = item.itemMeta!!
meta.persistentDataContainer.remove(Keys.PLACED)
item.itemMeta = meta
Scheduler.get().run { _ ->
meta = item.itemMeta!!
meta.persistentDataContainer.remove(Keys.PLACED)
item.itemMeta = meta
}
return@submit
}
return@submit
}
}
@ -125,7 +129,7 @@ class MinionPlaceListener : Listener {
}
return@submit
}
val locationId = AxMinionsPlugin.dataHandler.getLocationID(location)
val minion = Minion(
location,
@ -144,6 +148,7 @@ class MinionPlaceListener : Listener {
)
Minions.startTicking(chunk)
Scheduler.get().run { _ ->
meta = item.itemMeta!!
meta.persistentDataContainer.remove(Keys.PLACED)
@ -164,6 +169,10 @@ class MinionPlaceListener : Listener {
minion.setOwnerOnline(true)
AxMinionsPlugin.dataHandler.saveMinion(minion)
if (islandId.isNotBlank()) {
AxMinionsPlugin.dataHandler.islandPlace(islandId)
}
event.player.sendMessage(
StringUtils.formatToString(
Messages.PREFIX() + Messages.PLACE_SUCCESS(),

View File

@ -550,6 +550,13 @@ class Minion(
AxMinionsPlugin.dataQueue.submit {
AxMinionsPlugin.dataHandler.deleteMinion(this)
if (AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() != null) {
val islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandAt(location)
if (islandId.isNotBlank()) {
AxMinionsPlugin.dataHandler.islandBreak(islandId)
}
}
}
}