Add Folia support & fixes to some other stuff, prepare for release

This commit is contained in:
TomTom 2023-10-21 21:57:20 +02:00
parent d916079c3a
commit c781bf0587
15 changed files with 126 additions and 45 deletions

View File

@ -78,9 +78,15 @@ object MinionUtils {
FACES.fastFor {
val relative = block.getRelative(it)
if (!visited.contains(relative)) {
if (visited.add(relative)) {
queue.add(relative)
}
}
} else if (type.endsWith("_LEAVES")) {
FACES.fastFor {
val relative = block.getRelative(it)
if (visited.add(relative)) {
queue.add(relative)
visited.add(relative)
}
}
}

View File

@ -44,7 +44,7 @@ class AxMinionsPlugin : AxPlugin() {
}
init {
val manager = BukkitLibraryManager(this, "../../libraries")
val manager = BukkitLibraryManager(this)
val stdLib = Library.builder().groupId("org{}jetbrains{}kotlin").artifactId("kotlin-stdlib").version("1.9.0")
.relocate("org{}jetbrains{}kotlin", "com{}artillexstudios{}axminions{}libs{}kotlin").build()
val h2 = Library.builder().groupId("com{}h2database").artifactId("h2").version("2.2.220")

View File

@ -1,5 +1,6 @@
package com.artillexstudios.axminions.integrations.stacker
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axminions.api.integrations.types.StackerIntegration
import org.bukkit.Location
import org.bukkit.entity.Item
@ -17,7 +18,9 @@ class DefaultStackerIntegration : StackerIntegration {
}
override fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location) {
location.world!!.dropItem(location, itemStack)
Scheduler.get().runAt(location) {
location.world!!.dropItem(location, itemStack)
}
}
override fun register() {

View File

@ -12,9 +12,10 @@ import org.bukkit.event.Listener
class MinionDamageListener : Listener {
@EventHandler
fun onPreMinionDamageEntityEvent(event: MinionKillEntityEvent) {
fun onMinionKillEntityEvent(event: MinionKillEntityEvent) {
val entitySize = AxMinionsPlugin.integrations.getStackerIntegration().getStackSize(event.target)
event.minion.setActions(event.minion.getActionAmount() + entitySize)
event.minion.setStorage(event.minion.getStorage() + ThreadLocalRandom.current().nextInt(1, 4) * entitySize)
event.target.location.world!!.getNearbyEntities(event.target.location, 4.0, 4.0, 4.0).filterIsInstance<Item>().fastFor { item ->

View File

@ -71,7 +71,12 @@ class Minion(
init {
spawn()
Minions.load(this)
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
if (linkedChest != null) {
Scheduler.get().runAt(linkedChest) {
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
}
}
}
override fun getType(): MinionType {
@ -140,7 +145,9 @@ class Minion(
debugHologram?.setLine(0, StringUtils.format("Ticking: $ticking"))
}
type.tick(this)
Scheduler.get().runAt(location) {
type.tick(this)
}
animate()
}
@ -362,8 +369,13 @@ class Minion(
override fun setLinkedChest(location: Location?) {
this.linkedChest = location?.clone()
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
updateInventories()
if (linkedChest != null) {
Scheduler.get().runAt(linkedChest) {
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
updateInventories()
}
}
AxMinionsPlugin.dataQueue.submit {
AxMinionsPlugin.dataHandler.saveMinion(this)

View File

@ -19,7 +19,7 @@ object MinionTicker {
fun startTicking() {
Scheduler.get().runTimer({ _ ->
tickAll()
}, 0, 0)
}, 1, 1)
}
fun getTick(): Long {

View File

@ -3,11 +3,11 @@ package com.artillexstudios.axminions.minions.miniontype
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
import com.artillexstudios.axminions.minions.MinionTicker
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.minions.MinionTicker
import kotlin.math.roundToInt
import org.bukkit.Material
import org.bukkit.block.data.Ageable
@ -46,6 +46,7 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
Warnings.remove(minion, Warnings.NO_TOOL)
var size = 0
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
val block = location.block
val drops = arrayListOf<ItemStack>()
@ -53,20 +54,32 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
when (block.type) {
Material.CACTUS, Material.SUGAR_CANE, Material.BAMBOO -> {
MinionUtils.getPlant(block).fastFor {
drops.addAll(it.getDrops(minion.getTool()))
val blockDrops = it.getDrops(minion.getTool())
blockDrops.forEach { itemStack ->
size += itemStack.amount
}
drops.addAll(blockDrops)
it.type = Material.AIR
}
}
Material.MELON, Material.PUMPKIN -> {
drops.addAll(block.getDrops(minion.getTool()))
val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack ->
size += itemStack.amount
}
drops.addAll(blockDrops)
block.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
if (ageable.age != ageable.maximumAge) return@fastFor
drops.addAll(block.getDrops(minion.getTool()))
val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack ->
size += itemStack.amount
}
drops.addAll(blockDrops)
ageable.age = 0
block.blockData = ageable
}
@ -74,7 +87,11 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
Material.SWEET_BERRY_BUSH -> {
val ageable = block.blockData as Ageable
if (ageable.age != ageable.maximumAge) return@fastFor
drops.addAll(block.getDrops(minion.getTool()))
val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack ->
size += itemStack.amount
}
drops.addAll(blockDrops)
ageable.age = 1
block.blockData = ageable
}
@ -83,9 +100,8 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
}
minion.addToContainerOrDrop(drops)
val dropsSize = drops.size
minion.damageTool(dropsSize)
minion.setActions(minion.getActionAmount() + dropsSize)
minion.damageTool(size)
minion.setActions(minion.getActionAmount() + size)
}
}
}
}

View File

@ -40,7 +40,7 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
}
var waterLocation: Location? = null
run breaking@ {
run breaking@{
LocationUtils.getAllBlocksInRadius(minion.getLocation(), 2.0, false).fastFor {
if (it.block.type != Material.WATER) return@fastFor
@ -67,5 +67,6 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
minion.addToContainerOrDrop(loot)
minion.setStorage(minion.getStorage() + xp)
minion.damageTool()
}
}

View File

@ -1,5 +1,6 @@
package com.artillexstudios.axminions.minions.miniontype
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
@ -88,10 +89,7 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
Material.SPRUCE_SAPLING
}
else -> {
println("Material: $material")
Material.OAK_SAPLING
}
else -> Material.OAK_SAPLING
}
}
}

View File

@ -1,6 +1,7 @@
package com.artillexstudios.axminions.minions.miniontype
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axapi.scheduler.impl.FoliaScheduler
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
@ -51,34 +52,60 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
Warnings.remove(minion, Warnings.NO_TOOL)
var amount = 0
when (getConfig().getString("mode").lowercase(Locale.ENGLISH)) {
"sphere" -> {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
if (isStoneGenerator) {
minion.addToContainerOrDrop(location.block.getDrops(minion.getTool()))
val drops = location.block.getDrops(minion.getTool())
drops.forEach {
amount += it.amount
}
minion.addToContainerOrDrop(drops)
location.block.type = Material.AIR
}
}
}
"asphere" -> {
if (asyncExecutor == null) {
asyncExecutor = Executors.newFixedThreadPool(3)
}
if (Scheduler.get() !is FoliaScheduler) {
if (asyncExecutor == null) {
asyncExecutor = Executors.newFixedThreadPool(3)
}
asyncExecutor!!.execute {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
asyncExecutor!!.execute {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
.fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
if (isStoneGenerator) {
Scheduler.get().run {
minion.addToContainerOrDrop(location.block.getDrops(minion.getTool()))
if (isStoneGenerator) {
Scheduler.get().run {
val drops = location.block.getDrops(minion.getTool())
drops.forEach {
amount += it.amount
}
minion.addToContainerOrDrop(drops)
location.block.type = Material.AIR
}
}
}
}
} else {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
.fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
if (isStoneGenerator) {
val drops = location.block.getDrops(minion.getTool())
drops.forEach {
amount += it.amount
}
minion.addToContainerOrDrop(drops)
location.block.type = Material.AIR
}
}
}
}
}
@ -88,7 +115,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
if (isStoneGenerator) {
minion.addToContainerOrDrop(location.block.getDrops(minion.getTool()))
val drops = location.block.getDrops(minion.getTool())
drops.forEach {
amount += it.amount
}
minion.addToContainerOrDrop(drops)
location.block.type = Material.AIR
}
}
@ -96,15 +127,22 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
"face" -> {
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing).fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing)
.fastFor { location ->
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
if (isStoneGenerator) {
minion.addToContainerOrDrop(location.block.getDrops(minion.getTool()))
location.block.type = Material.AIR
if (isStoneGenerator) {
val drops = location.block.getDrops(minion.getTool())
drops.forEach {
amount += it.amount
}
minion.addToContainerOrDrop(drops)
location.block.type = Material.AIR
}
}
}
}
}
minion.damageTool(amount)
}
}

View File

@ -75,7 +75,7 @@ class SellerMinionType : MinionType("seller", AxMinionsPlugin.INSTANCE.getResour
}
minion.setActions(minion.getActionAmount() + it.amount)
minion.damageTool()
minion.damageTool(it.amount)
minion.setStorage(minion.getStorage() + price)
it.amount = 0
}

View File

@ -46,7 +46,12 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour
Warnings.remove(minion, Warnings.NO_TOOL)
minion.getLocation().world!!.getNearbyEntities(minion.getLocation(), minion.getRange(), minion.getRange(), minion.getRange()).filterIsInstance<LivingEntity>().fastFor {
minion.getLocation().world!!.getNearbyEntities(
minion.getLocation(),
minion.getRange(),
minion.getRange(),
minion.getRange()
).filterIsInstance<LivingEntity>().fastFor {
if (it is Player) return@fastFor
if (!getConfig().getBoolean("damage-animals") && NMSHandler.get().isAnimal(it)) {

View File

@ -1,7 +1,8 @@
name: "AxMinions"
main: "com.artillexstudios.axminions.AxMinionsPlugin"
version: "1.0"
api-version: 1.19
api-version: 1.18
folia-supported: true
softdepend:
- RoseStacker
- WildStacker

Binary file not shown.

Binary file not shown.