mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-02-18 01:31:40 +01:00
Started optimizing by caching
This commit is contained in:
parent
aadf5ebeb4
commit
9962cd4683
@ -13,6 +13,7 @@
|
||||
<option value="$PROJECT_DIR$/nms" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R1" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R2" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R3" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.0" />
|
||||
<option name="version" value="1.9.22" />
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,10 +1,9 @@
|
||||
package com.artillexstudios.axminions.api.minions.utils
|
||||
package com.artillexstudios.axminions.api.utils
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.api.utils.fastFor
|
||||
import org.bukkit.World
|
||||
|
||||
data class ChunkPos(val world: World, var x: Int, var z: Int) {
|
||||
data class ChunkPos(val world: World, val x: Int, val z: Int) {
|
||||
val minions = arrayListOf<Minion>()
|
||||
val worldUUID = world.uid
|
||||
|
@ -41,8 +41,10 @@ object MinionUtils {
|
||||
var lava = false
|
||||
var water = false
|
||||
|
||||
val locBlock = location.block
|
||||
|
||||
FACES.fastFor {
|
||||
val relative = location.block.getRelative(it)
|
||||
val relative = locBlock.getRelative(it)
|
||||
val type = relative.type
|
||||
if (!lava) {
|
||||
lava = type == Material.LAVA
|
||||
|
15
build.gradle
15
build.gradle
@ -3,11 +3,11 @@ plugins {
|
||||
id 'com.github.johnrengelman.shadow' version "8.1.1"
|
||||
id 'maven-publish'
|
||||
id 'java'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.9.0'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.9.22'
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axminions'
|
||||
version = '1.0.0'
|
||||
version = '1.0.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -20,7 +20,6 @@ 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")
|
||||
@ -46,6 +45,10 @@ allprojects {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
||||
}
|
||||
@ -107,7 +110,6 @@ allprojects {
|
||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:3.0.0'
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.9.0'
|
||||
compileOnly 'com.h2database:h2:2.2.220'
|
||||
compileOnly 'dev.rosewood:rosestacker:1.5.9'
|
||||
compileOnly 'com.bgsoftware:WildStackerAPI:2023.2'
|
||||
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
|
||||
compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.6.0'
|
||||
@ -120,13 +122,12 @@ allprojects {
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:6.29.12'
|
||||
compileOnly 'com.intellectualsites.plotsquared:plotsquared-core:7.0.0-rc.4'
|
||||
compileOnly 'com.intellectualsites.plotsquared:plotsquared-bukkit:7.0.0-rc.4'
|
||||
compileOnly 'org.black_ixx:playerpoints:3.2.6'
|
||||
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
|
||||
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')
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
@ -9,4 +9,8 @@ processResources {
|
||||
|
||||
dependencies {
|
||||
implementation project(':api')
|
||||
compileOnly files('../libs/CMI-API9.5.0.8.jar')
|
||||
compileOnly files('../libs/IridiumSkyblock-4.0.9.jar')
|
||||
compileOnly files('../libs/KingdomsX-1.16.12.jar')
|
||||
compileOnly files('../libs/KGenerators-7.3-b161.jar')
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.artillexstudios.axminions
|
||||
|
||||
import com.artillexstudios.axapi.AxPlugin
|
||||
import com.artillexstudios.axapi.data.ThreadedQueue
|
||||
import com.artillexstudios.axapi.scheduler.Scheduler
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPIImpl
|
||||
import com.artillexstudios.axminions.api.config.Config
|
||||
@ -10,9 +11,12 @@ import com.artillexstudios.axminions.api.data.DataHandler
|
||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
|
||||
import com.artillexstudios.axminions.api.utils.fastFor
|
||||
import com.artillexstudios.axminions.cache.Caches
|
||||
import com.artillexstudios.axminions.cache.ChunkCache
|
||||
import com.artillexstudios.axminions.commands.AxMinionsCommand
|
||||
import com.artillexstudios.axminions.data.H2DataHandler
|
||||
import com.artillexstudios.axminions.integrations.Integrations
|
||||
import com.artillexstudios.axminions.listeners.CacheListener
|
||||
import com.artillexstudios.axminions.listeners.ChunkListener
|
||||
import com.artillexstudios.axminions.listeners.LinkingListener
|
||||
import com.artillexstudios.axminions.listeners.MinionDamageListener
|
||||
@ -107,6 +111,7 @@ class AxMinionsPlugin : AxPlugin() {
|
||||
// Retroactively load minions for the already loaded worlds
|
||||
dataQueue.submit {
|
||||
Bukkit.getWorlds().fastFor { world ->
|
||||
Caches.add(ChunkCache(world))
|
||||
MinionTypes.getMinionTypes().fastFor { _, v ->
|
||||
dataHandler.loadMinionsForWorld(v, world)
|
||||
}
|
||||
@ -121,29 +126,34 @@ class AxMinionsPlugin : AxPlugin() {
|
||||
it.registerEvents(MinionDamageListener(), this)
|
||||
it.registerEvents(WorldListener(), this)
|
||||
it.registerEvents(MinionDropListener(), this)
|
||||
it.registerEvents(CacheListener(), this)
|
||||
}
|
||||
|
||||
MinionTicker.startTicking()
|
||||
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate({
|
||||
Scheduler.get().runTimer({
|
||||
dataQueue.submit {
|
||||
Minions.get().fastFor { pos ->
|
||||
pos.minions.fastFor { minion ->
|
||||
dataHandler.saveMinion(minion)
|
||||
Minions.get {
|
||||
it.fastFor { pos ->
|
||||
pos.minions.fastFor { minion ->
|
||||
dataHandler.saveMinion(minion)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},0, Config.AUTO_SAVE_MINUTES(), TimeUnit.MINUTES)
|
||||
}, 0, Config.AUTO_SAVE_MINUTES() * 20 * 60)
|
||||
}
|
||||
|
||||
override fun disable() {
|
||||
Minions.get().fastFor { pos ->
|
||||
pos.minions.fastFor { minion ->
|
||||
val minionImp = minion as Minion
|
||||
Minions.get {
|
||||
it.fastFor { pos ->
|
||||
pos.minions.fastFor { minion ->
|
||||
val minionImp = minion as Minion
|
||||
|
||||
minionImp.openInventories.fastFor { inventory ->
|
||||
inventory.viewers.fastFor { player ->
|
||||
player.closeInventory()
|
||||
minionImp.openInventories.fastFor { inventory ->
|
||||
inventory.viewers.fastFor { player ->
|
||||
player.closeInventory()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
common/src/main/kotlin/com/artillexstudios/axminions/cache/Caches.kt
vendored
Normal file
21
common/src/main/kotlin/com/artillexstudios/axminions/cache/Caches.kt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
package com.artillexstudios.axminions.cache
|
||||
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import org.bukkit.World
|
||||
|
||||
object Caches {
|
||||
private val map = ConcurrentHashMap<UUID, ChunkCache>()
|
||||
|
||||
fun add(cache: ChunkCache) {
|
||||
map[cache.world.uid] = cache
|
||||
}
|
||||
|
||||
fun remove(world: World) {
|
||||
map.remove(world.uid)
|
||||
}
|
||||
|
||||
fun get(world: World): ChunkCache? {
|
||||
return map[world.uid]
|
||||
}
|
||||
}
|
44
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkCache.kt
vendored
Normal file
44
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkCache.kt
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
package com.artillexstudios.axminions.cache
|
||||
|
||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import me.kryniowesegryderiusz.kgenerators.Main
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.World
|
||||
|
||||
class ChunkCache(val world: World) {
|
||||
private val map = ConcurrentHashMap<ChunkLoc, HashMap<Int, ChunkLayer>>()
|
||||
|
||||
fun get(x: Int, y: Int, z: Int): Any {
|
||||
val pos = ChunkLoc(x shr 4, z shr 4)
|
||||
val layerMap = map[pos] ?: HashMap()
|
||||
val layer = layerMap[y] ?: ChunkLayer()
|
||||
layerMap[y] = layer
|
||||
|
||||
val worldBlock: Any
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
|
||||
val loc = Location(world, x.toDouble(), y.toDouble(), z.toDouble())
|
||||
if (!Main.getPlacedGenerators().isChunkFullyLoaded(loc)) {
|
||||
worldBlock = world.getBlockAt(x, y, z).type
|
||||
} else {
|
||||
val gen = Main.getPlacedGenerators().getLoaded(loc) ?: world.getBlockAt(x, y, z).type
|
||||
worldBlock = gen
|
||||
}
|
||||
} else {
|
||||
worldBlock = world.getBlockAt(x, y, z).type
|
||||
}
|
||||
|
||||
val block = layer.get(x, z) ?: layer.set(x, z, worldBlock)
|
||||
map[pos] = layerMap
|
||||
|
||||
return block
|
||||
}
|
||||
|
||||
fun invalidate(x: Int, z: Int) {
|
||||
map.remove(ChunkLoc(x, z))
|
||||
}
|
||||
|
||||
fun update(x: Int, y: Int, z: Int) {
|
||||
get(x, y, z)
|
||||
}
|
||||
}
|
20
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkLayer.kt
vendored
Normal file
20
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkLayer.kt
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
package com.artillexstudios.axminions.cache
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class ChunkLayer {
|
||||
private val map = ConcurrentHashMap<Int, Any>()
|
||||
|
||||
fun set(x: Int, z: Int, to: Any): Any {
|
||||
val key = (x shl 16) or z
|
||||
|
||||
map[key] = to
|
||||
return to
|
||||
}
|
||||
|
||||
fun get(x: Int, z: Int): Any? {
|
||||
val key = (x shl 16) or z
|
||||
|
||||
return map[key]
|
||||
}
|
||||
}
|
21
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkLoc.kt
vendored
Normal file
21
common/src/main/kotlin/com/artillexstudios/axminions/cache/ChunkLoc.kt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
package com.artillexstudios.axminions.cache
|
||||
|
||||
@JvmRecord
|
||||
data class ChunkLoc(val x: Int, val z: Int) {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is ChunkLoc) return false
|
||||
|
||||
if (x != other.x) return false
|
||||
if (z != other.z) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = x
|
||||
result = 31 * result + z
|
||||
return result
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ class Integrations : Integrations {
|
||||
private var pricesIntegration: PricesIntegration? = null
|
||||
private var economyIntegration: EconomyIntegration? = null
|
||||
private val protectionIntegrations = com.artillexstudios.axminions.integrations.protection.ProtectionIntegrations()
|
||||
internal var kGeneratorsIntegration = false
|
||||
|
||||
override fun getStackerIntegration(): StackerIntegration {
|
||||
return stackerIntegration
|
||||
@ -94,7 +95,7 @@ class Integrations : Integrations {
|
||||
}
|
||||
|
||||
"economyshopgui" -> {
|
||||
if (isPluginLoaded("EconomoyShopGUI")) {
|
||||
if (isPluginLoaded("EconomyShopGUI")) {
|
||||
register(EconomyShopGUIIntegration())
|
||||
}
|
||||
}
|
||||
@ -157,6 +158,12 @@ class Integrations : Integrations {
|
||||
Bukkit.getConsoleSender()
|
||||
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into KingdomsX!"))
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("KGenerators") != null) {
|
||||
kGeneratorsIntegration = true
|
||||
Bukkit.getConsoleSender()
|
||||
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into KGenerators!"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun register(integration: Integration) {
|
||||
|
@ -1,24 +1,24 @@
|
||||
package com.artillexstudios.axminions.integrations.economy
|
||||
|
||||
import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration
|
||||
import org.black_ixx.playerpoints.PlayerPoints
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class PlayerPointsIntegration : EconomyIntegration {
|
||||
|
||||
override fun getBalance(player: OfflinePlayer): Double {
|
||||
TODO("Not yet implemented")
|
||||
return PlayerPoints.getInstance().api.look(player.uniqueId).toDouble()
|
||||
}
|
||||
|
||||
override fun giveBalance(player: OfflinePlayer, amount: Double) {
|
||||
TODO("Not yet implemented")
|
||||
PlayerPoints.getInstance().api.give(player.uniqueId, amount.toInt())
|
||||
}
|
||||
|
||||
override fun takeBalance(player: OfflinePlayer, amount: Double) {
|
||||
TODO("Not yet implemented")
|
||||
PlayerPoints.getInstance().api.take(player.uniqueId, amount.toInt())
|
||||
}
|
||||
|
||||
override fun register() {
|
||||
TODO("Not yet implemented")
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.artillexstudios.axminions.integrations.protection
|
||||
|
||||
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
|
||||
import com.iridium.iridiumskyblock.IridiumSkyblock
|
||||
import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.entity.Player
|
||||
@ -10,7 +11,7 @@ class IridiumSkyBlockIntegration : ProtectionIntegration {
|
||||
override fun canBuildAt(player: Player, location: Location): Boolean {
|
||||
val island = IridiumSkyblockAPI.getInstance().getIslandViaLocation(location)
|
||||
|
||||
return island.map { IridiumSkyblockAPI.getInstance().getUser(player) in it.members }.orElse(true)
|
||||
return island.map { IridiumSkyblockAPI.getInstance().getUser(player) in IridiumSkyblock.getInstance().teamManager.getMembersOnIsland(it) }.orElse(true) || IridiumSkyblockAPI.getInstance().getUser(player).isBypassing
|
||||
}
|
||||
|
||||
override fun register() {
|
||||
|
@ -0,0 +1,78 @@
|
||||
package com.artillexstudios.axminions.listeners
|
||||
|
||||
import com.artillexstudios.axminions.cache.Caches
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.BlockBreakEvent
|
||||
import org.bukkit.event.block.BlockBurnEvent
|
||||
import org.bukkit.event.block.BlockExplodeEvent
|
||||
import org.bukkit.event.block.BlockFadeEvent
|
||||
import org.bukkit.event.block.BlockFormEvent
|
||||
import org.bukkit.event.block.BlockFromToEvent
|
||||
import org.bukkit.event.block.BlockGrowEvent
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent
|
||||
import org.bukkit.event.block.BlockPlaceEvent
|
||||
|
||||
class CacheListener : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onBlockBreakEvent(event: BlockBreakEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockPlaceEvent(event: BlockPlaceEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockFromToEvent(event: BlockFromToEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockBurnEvent(event: BlockBurnEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockExplodeEvent(event: BlockExplodeEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockFadeEvent(event: BlockFadeEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockFormEvent(event: BlockFormEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockGrowEvent(event: BlockGrowEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockPistonExtendEvent(event: BlockPistonExtendEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onBlockPistonRetractEvent(event: BlockPistonRetractEvent) {
|
||||
val block = event.block
|
||||
Caches.get(block.world)?.update(block.x, block.y, block.z)
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.artillexstudios.axminions.listeners
|
||||
|
||||
import com.artillexstudios.axminions.cache.Caches
|
||||
import com.artillexstudios.axminions.minions.Minions
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
@ -15,6 +16,9 @@ class ChunkListener : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onChunkUnloadEvent(event: ChunkUnloadEvent) {
|
||||
Minions.removeTicking(event.chunk)
|
||||
val chunk = event.chunk
|
||||
Minions.removeTicking(chunk)
|
||||
|
||||
Caches.get(event.world)?.invalidate(chunk.x, chunk.z)
|
||||
}
|
||||
}
|
@ -2,9 +2,12 @@ package com.artillexstudios.axminions.listeners
|
||||
|
||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
|
||||
import com.artillexstudios.axminions.cache.Caches
|
||||
import com.artillexstudios.axminions.cache.ChunkCache
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.world.WorldLoadEvent
|
||||
import org.bukkit.event.world.WorldUnloadEvent
|
||||
|
||||
class WorldListener : Listener {
|
||||
|
||||
@ -13,5 +16,12 @@ class WorldListener : Listener {
|
||||
AxMinionsPlugin.dataQueue.submit {
|
||||
MinionTypes.loadForWorld(event.world)
|
||||
}
|
||||
|
||||
Caches.add(ChunkCache(event.world))
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onWorldUnloadEvent(event: WorldUnloadEvent) {
|
||||
Caches.remove(event.world)
|
||||
}
|
||||
}
|
@ -7,9 +7,11 @@ object MinionTicker {
|
||||
private var tick = 0L
|
||||
|
||||
private inline fun tickAll() {
|
||||
Minions.get().fastFor { pos ->
|
||||
pos.minions.fastFor {
|
||||
it.tick()
|
||||
Minions.get { minions ->
|
||||
minions.fastFor { pos ->
|
||||
pos.minions.fastFor {
|
||||
it.tick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.artillexstudios.axminions.minions
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.api.minions.utils.ChunkPos
|
||||
import com.artillexstudios.axminions.api.utils.ChunkPos
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
@ -9,8 +9,8 @@ import kotlin.concurrent.write
|
||||
import org.bukkit.Chunk
|
||||
|
||||
object Minions {
|
||||
private val lock = ReentrantReadWriteLock()
|
||||
private val minions = arrayListOf<ChunkPos>()
|
||||
val lock = ReentrantReadWriteLock()
|
||||
val minions = arrayListOf<ChunkPos>()
|
||||
|
||||
fun addTicking(chunk: Chunk) {
|
||||
val chunkX = chunk.x
|
||||
@ -120,9 +120,9 @@ object Minions {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun get(): ArrayList<ChunkPos> {
|
||||
internal inline fun get(use: (ArrayList<ChunkPos>) -> Unit) {
|
||||
lock.read {
|
||||
return minions
|
||||
use(minions)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.artillexstudios.axminions.api.utils.LocationUtils
|
||||
import com.artillexstudios.axminions.api.utils.MinionUtils
|
||||
import com.artillexstudios.axminions.api.utils.fastFor
|
||||
import com.artillexstudios.axminions.api.warnings.Warnings
|
||||
import com.artillexstudios.axminions.cache.Caches
|
||||
import com.artillexstudios.axminions.minions.MinionTicker
|
||||
import kotlin.math.roundToInt
|
||||
import org.bukkit.Material
|
||||
@ -53,12 +54,14 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
|
||||
|
||||
var size = 0
|
||||
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
|
||||
val block = location.block
|
||||
val block = Caches.get(location.world!!)?.get(location.x.toInt(), location.y.toInt(), location.z.toInt())
|
||||
if (block !is Material) return@fastFor
|
||||
val locationBlock = location.block
|
||||
val drops = arrayListOf<ItemStack>()
|
||||
|
||||
when (block.type) {
|
||||
when (block) {
|
||||
Material.CACTUS, Material.SUGAR_CANE, Material.BAMBOO -> {
|
||||
MinionUtils.getPlant(block).fastFor {
|
||||
MinionUtils.getPlant(locationBlock).fastFor {
|
||||
val blockDrops = it.getDrops(minion.getTool())
|
||||
blockDrops.forEach { itemStack ->
|
||||
size += itemStack.amount
|
||||
@ -69,36 +72,36 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
|
||||
}
|
||||
|
||||
Material.MELON, Material.PUMPKIN -> {
|
||||
val blockDrops = block.getDrops(minion.getTool())
|
||||
val blockDrops = locationBlock.getDrops(minion.getTool())
|
||||
blockDrops.forEach { itemStack ->
|
||||
size += itemStack.amount
|
||||
}
|
||||
drops.addAll(blockDrops)
|
||||
block.type = Material.AIR
|
||||
locationBlock.type = Material.AIR
|
||||
}
|
||||
|
||||
Material.COCOA_BEANS, Material.COCOA, Material.NETHER_WART, Material.WHEAT, Material.CARROTS, Material.BEETROOTS, Material.POTATOES -> {
|
||||
val ageable = block.blockData as Ageable
|
||||
val ageable = locationBlock.blockData as Ageable
|
||||
if (ageable.age != ageable.maximumAge) return@fastFor
|
||||
val blockDrops = block.getDrops(minion.getTool())
|
||||
val blockDrops = locationBlock.getDrops(minion.getTool())
|
||||
blockDrops.forEach { itemStack ->
|
||||
size += itemStack.amount
|
||||
}
|
||||
drops.addAll(blockDrops)
|
||||
ageable.age = 0
|
||||
block.blockData = ageable
|
||||
locationBlock.blockData = ageable
|
||||
}
|
||||
|
||||
Material.SWEET_BERRY_BUSH -> {
|
||||
val ageable = block.blockData as Ageable
|
||||
val ageable = locationBlock.blockData as Ageable
|
||||
if (ageable.age != ageable.maximumAge) return@fastFor
|
||||
val blockDrops = block.getDrops(minion.getTool())
|
||||
val blockDrops = locationBlock.getDrops(minion.getTool())
|
||||
blockDrops.forEach { itemStack ->
|
||||
size += itemStack.amount
|
||||
}
|
||||
drops.addAll(blockDrops)
|
||||
ageable.age = 1
|
||||
block.blockData = ageable
|
||||
locationBlock.blockData = ageable
|
||||
}
|
||||
|
||||
else -> return@fastFor
|
||||
|
@ -9,11 +9,14 @@ import com.artillexstudios.axminions.api.utils.LocationUtils
|
||||
import com.artillexstudios.axminions.api.utils.MinionUtils
|
||||
import com.artillexstudios.axminions.api.utils.fastFor
|
||||
import com.artillexstudios.axminions.api.warnings.Warnings
|
||||
import com.artillexstudios.axminions.integrations.Integrations
|
||||
import com.artillexstudios.axminions.minions.MinionTicker
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.roundToInt
|
||||
import me.kryniowesegryderiusz.kgenerators.Main
|
||||
import me.kryniowesegryderiusz.kgenerators.api.KGeneratorsAPI
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.block.BlockFace
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
@ -83,6 +86,16 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
asyncExecutor!!.execute {
|
||||
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
|
||||
.fastFor { location ->
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators().isChunkFullyLoaded(location)) {
|
||||
val gen = Main.getPlacedGenerators().getLoaded(location)
|
||||
val possible = gen?.isBlockPossibleToMine(location) ?: false
|
||||
|
||||
if (possible) {
|
||||
gen?.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
}
|
||||
}
|
||||
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
@ -100,6 +113,16 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
} else {
|
||||
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
|
||||
.fastFor { location ->
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators().isChunkFullyLoaded(location)) {
|
||||
val gen = Main.getPlacedGenerators().getLoaded(location)
|
||||
val possible = gen?.isBlockPossibleToMine(location) ?: false
|
||||
|
||||
if (possible) {
|
||||
gen?.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
}
|
||||
}
|
||||
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
@ -117,6 +140,16 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
"line" -> {
|
||||
faces.fastFor {
|
||||
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), it).fastFor { location ->
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators().isChunkFullyLoaded(location)) {
|
||||
val gen = Main.getPlacedGenerators().getLoaded(location)
|
||||
val possible = gen?.isBlockPossibleToMine(location) ?: false
|
||||
|
||||
if (possible) {
|
||||
gen?.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
}
|
||||
}
|
||||
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
@ -134,6 +167,16 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
"face" -> {
|
||||
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing)
|
||||
.fastFor { location ->
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators().isChunkFullyLoaded(location)) {
|
||||
val gen = Main.getPlacedGenerators().getLoaded(location)
|
||||
val possible = gen?.isBlockPossibleToMine(location) ?: false
|
||||
|
||||
if (possible) {
|
||||
gen?.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
}
|
||||
}
|
||||
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
|
@ -18,4 +18,5 @@ softdepend:
|
||||
- Lands
|
||||
- SuperiorSkyBlock2
|
||||
- WorldGuard
|
||||
- PlotSquared
|
||||
- PlotSquared
|
||||
- KGenerators
|
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.5.4" apply false
|
||||
id("io.papermc.paperweight.userdev") version "1.5.10" apply false
|
||||
}
|
||||
|
||||
group = "com.artillexstudios.axminions"
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,6 @@ 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'
|
||||
|
Loading…
Reference in New Issue
Block a user