mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-29 12:45:18 +01:00
Island recalculate
This commit is contained in:
parent
ac503fe71a
commit
d28f4b9880
@ -78,6 +78,8 @@ class Messages(file: File, stream: InputStream) {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
|
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
fun RECALC() = AxMinionsAPI.INSTANCE.getMessages().get<String>("recalc")
|
||||||
|
@JvmStatic
|
||||||
fun LOCATION_FORMAT() = AxMinionsAPI.INSTANCE.getMessages().get<String>("location-format")
|
fun LOCATION_FORMAT() = AxMinionsAPI.INSTANCE.getMessages().get<String>("location-format")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ interface DataHandler {
|
|||||||
|
|
||||||
fun islandBreak(island: String)
|
fun islandBreak(island: String)
|
||||||
|
|
||||||
|
fun islandReset(island: String)
|
||||||
|
|
||||||
fun getIsland(island: String): Int
|
fun getIsland(island: String): Int
|
||||||
|
|
||||||
fun disable()
|
fun disable()
|
||||||
|
@ -13,19 +13,14 @@ import com.artillexstudios.axminions.converter.LitMinionsConverter
|
|||||||
import com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration
|
import com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration
|
||||||
import com.artillexstudios.axminions.minions.Minions
|
import com.artillexstudios.axminions.minions.Minions
|
||||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI
|
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
|
||||||
|
import org.bukkit.Chunk
|
||||||
import org.bukkit.World.Environment
|
import org.bukkit.World.Environment
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import revxrsal.commands.annotation.AutoComplete
|
import revxrsal.commands.annotation.*
|
||||||
import revxrsal.commands.annotation.Command
|
|
||||||
import revxrsal.commands.annotation.Default
|
|
||||||
import revxrsal.commands.annotation.Description
|
|
||||||
import revxrsal.commands.annotation.Range
|
|
||||||
import revxrsal.commands.annotation.Subcommand
|
|
||||||
import revxrsal.commands.bukkit.annotation.CommandPermission
|
import revxrsal.commands.bukkit.annotation.CommandPermission
|
||||||
|
import java.util.concurrent.CompletableFuture
|
||||||
|
|
||||||
@Command("axminions", "minion", "minions")
|
@Command("axminions", "minion", "minions")
|
||||||
class AxMinionsCommand {
|
class AxMinionsCommand {
|
||||||
@ -143,32 +138,35 @@ class AxMinionsCommand {
|
|||||||
fun recalc(player: Player) {
|
fun recalc(player: Player) {
|
||||||
val islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandAt(player.location)
|
val islandId = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandAt(player.location)
|
||||||
AxMinionsPlugin.dataQueue.submit {
|
AxMinionsPlugin.dataQueue.submit {
|
||||||
|
var original = 0
|
||||||
if (islandId.isNotBlank()) {
|
if (islandId.isNotBlank()) {
|
||||||
val islandPlaced = AxMinionsAPI.INSTANCE.getDataHandler().getIsland(islandId)
|
original = AxMinionsAPI.INSTANCE.getDataHandler().getIsland(islandId)
|
||||||
if (Config.DEBUG()) {
|
|
||||||
player.sendMessage("Placed: $islandPlaced")
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i in islandPlaced downTo 0) {
|
AxMinionsPlugin.dataHandler.islandReset(islandId)
|
||||||
AxMinionsPlugin.dataHandler.islandBreak(islandId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()
|
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()
|
||||||
if (integration is SuperiorSkyBlock2Integration) {
|
if (integration is SuperiorSkyBlock2Integration) {
|
||||||
val island = SuperiorSkyblockAPI.getIslandAt(player.location)
|
val island = SuperiorSkyblockAPI.getIslandAt(player.location) ?: return@submit
|
||||||
if (island == null) return@submit
|
|
||||||
|
|
||||||
val minions = Minions.getMinions()
|
val minions = Minions.getMinions()
|
||||||
Environment.entries.forEach { entry ->
|
Environment.entries.forEach { entry ->
|
||||||
try {
|
try {
|
||||||
island.getAllChunksAsync(entry, true) { }.forEach { chunk ->
|
val futures = arrayListOf<CompletableFuture<Chunk>>()
|
||||||
|
island.getAllChunksAsync(entry, true) { }.forEach { future ->
|
||||||
|
futures.add(future)
|
||||||
|
future.thenAccept { chunk ->
|
||||||
minions.forEach { minion ->
|
minions.forEach { minion ->
|
||||||
if (minion.getLocation().chunk == chunk) {
|
val ch = minion.getLocation().chunk
|
||||||
|
if (ch.x == chunk.x && ch.z == chunk.z && ch.world == chunk.world) {
|
||||||
AxMinionsPlugin.dataHandler.islandPlace(islandId)
|
AxMinionsPlugin.dataHandler.islandPlace(islandId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
CompletableFuture.allOf(*futures.toTypedArray()).thenRun {
|
||||||
|
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.RECALC(), Placeholder.unparsed("from", original.toString()), Placeholder.unparsed("to", futures.size.toString())))
|
||||||
|
}
|
||||||
} catch (_: NullPointerException) {
|
} catch (_: NullPointerException) {
|
||||||
// SuperiorSkyBlock api does it this way aswell
|
// SuperiorSkyBlock api does it this way aswell
|
||||||
}
|
}
|
||||||
|
@ -385,6 +385,15 @@ class H2DataHandler : DataHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun islandReset(island: String) {
|
||||||
|
dataSource.connection.use { connection ->
|
||||||
|
connection.prepareStatement("UPDATE `axminions_island_counter` SET `placed` = 0 WHERE `island` = ?;").use { statement ->
|
||||||
|
statement.setString(1, island)
|
||||||
|
statement.executeUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun islandBreak(island: String) {
|
override fun islandBreak(island: String) {
|
||||||
dataSource.connection.use { connection ->
|
dataSource.connection.use { connection ->
|
||||||
connection.prepareStatement("UPDATE `axminions_island_counter` SET `placed` = `placed` - 1 WHERE `island` = ?;").use { statement ->
|
connection.prepareStatement("UPDATE `axminions_island_counter` SET `placed` = `placed` - 1 WHERE `island` = ?;").use { statement ->
|
||||||
|
@ -5,6 +5,7 @@ import com.bgsoftware.superiorskyblock.api.events.IslandDisbandEvent
|
|||||||
import org.bukkit.World.Environment
|
import org.bukkit.World.Environment
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class SuperiorSkyBlock2Listener : Listener {
|
class SuperiorSkyBlock2Listener : Listener {
|
||||||
|
|
||||||
@ -14,13 +15,16 @@ class SuperiorSkyBlock2Listener : Listener {
|
|||||||
|
|
||||||
Environment.entries.forEach { entry ->
|
Environment.entries.forEach { entry ->
|
||||||
try {
|
try {
|
||||||
event.island.getAllChunksAsync(entry, true) { }.forEach { chunk ->
|
event.island.getAllChunksAsync(entry, true) { }.forEach { future ->
|
||||||
|
future.thenAccept { chunk ->
|
||||||
minions.forEach { minion ->
|
minions.forEach { minion ->
|
||||||
if (minion.getLocation().chunk == chunk) {
|
val ch = minion.getLocation().chunk
|
||||||
|
if (ch.x == chunk.x && ch.z == chunk.z && ch.world == chunk.world) {
|
||||||
minion.remove()
|
minion.remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (_: NullPointerException) {
|
} catch (_: NullPointerException) {
|
||||||
// SuperiorSkyBlock api does it this way aswell
|
// SuperiorSkyBlock api does it this way aswell
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,9 @@ charge:
|
|||||||
tools:
|
tools:
|
||||||
wrong-tool: "<red>You can't place this item as the tool if this minion!"
|
wrong-tool: "<red>You can't place this item as the tool if this minion!"
|
||||||
|
|
||||||
|
recalc: "<green>Recalculated island minion count! <from> -> <to>"
|
||||||
|
|
||||||
location-format: "<world>;<x>;<y>;<z>"
|
location-format: "<world>;<x>;<y>;<z>"
|
||||||
|
|
||||||
# Do not change!
|
# Do not change!
|
||||||
config-version: 7
|
config-version: 8
|
Loading…
Reference in New Issue
Block a user