This commit is contained in:
TomTom 2024-02-18 18:23:38 +01:00
parent 869efed819
commit 6341697495
12 changed files with 77 additions and 2 deletions

View File

@ -47,6 +47,8 @@ class Config(file: File, stream: InputStream) {
@JvmStatic
fun PLACE_PERMISSION() = AxMinionsAPI.INSTANCE.getConfig().get("place-permissions", false)
@JvmStatic
fun WORK_WHEN_OWNER_OFFLINE() = AxMinionsAPI.INSTANCE.getConfig().get("work-when-owner-offline", true)
@JvmStatic
fun DEBUG(): Boolean {
if (debug === null) {
debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false)

View File

@ -109,4 +109,8 @@ interface Minion : InventoryHolder {
fun damageTool(amount: Int = 1)
fun canUseTool(): Boolean
fun isOwnerOnline(): Boolean
fun setOwnerOnline(online: Boolean)
}

View File

@ -33,6 +33,7 @@ abstract class MinionType(private val name: String, private val defaults: InputS
}
fun tick(minion: Minion) {
if (!com.artillexstudios.axminions.api.config.Config.WORK_WHEN_OWNER_OFFLINE() && !minion.isOwnerOnline()) return
if (!shouldRun(minion)) return
minion.resetAnimation()

View File

@ -20,6 +20,7 @@ import com.artillexstudios.axminions.listeners.MinionDamageListener
import com.artillexstudios.axminions.listeners.MinionDropListener
import com.artillexstudios.axminions.listeners.MinionInventoryListener
import com.artillexstudios.axminions.listeners.MinionPlaceListener
import com.artillexstudios.axminions.listeners.PlayerListener
import com.artillexstudios.axminions.listeners.WorldListener
import com.artillexstudios.axminions.minions.Minion
import com.artillexstudios.axminions.minions.MinionTicker
@ -114,6 +115,7 @@ class AxMinionsPlugin : AxPlugin() {
it.registerEvents(MinionDamageListener(), this)
it.registerEvents(WorldListener(), this)
it.registerEvents(MinionDropListener(), this)
it.registerEvents(PlayerListener(), this)
}
// Retroactively load minions for the already loaded worlds

View File

@ -0,0 +1,28 @@
package com.artillexstudios.axminions.listeners
import com.artillexstudios.axminions.minions.Minions
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
class PlayerListener : Listener {
@EventHandler
fun onPlayerJoinEvent(event: PlayerJoinEvent) {
Minions.getMinions().forEach {
if (it.getOwnerUUID() == event.player.uniqueId) {
it.setOwnerOnline(true)
}
}
}
@EventHandler
fun onPlayerJoinEvent(event: PlayerQuitEvent) {
Minions.getMinions().forEach {
if (it.getOwnerUUID() == event.player.uniqueId) {
it.setOwnerOnline(false)
}
}
}
}

View File

@ -67,10 +67,12 @@ class Minion(
private val extraData = hashMapOf<String, String>()
private var linkedInventory: Inventory? = null
internal val openInventories = mutableListOf<Inventory>()
@Volatile
private var ticking = false
private var debugHologram: Hologram? = null
private var broken = false
private var ownerOnline = false
init {
spawn()
@ -671,8 +673,8 @@ class Minion(
setTool(it)
linkedInventory?.remove(it)
return canUseTool()
}
}
}
return false
} else {
return true
@ -682,6 +684,14 @@ class Minion(
return false
}
override fun isOwnerOnline(): Boolean {
return ownerOnline
}
override fun setOwnerOnline(online: Boolean) {
ownerOnline = online
}
override fun getInventory(): Inventory {
return Bukkit.createInventory(this, 9)
}

View File

@ -45,6 +45,11 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
minion.setLinkedChest(null)
}
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
if (!minion.canUseTool()) {
Warnings.NO_TOOL.display(minion)
return

View File

@ -44,6 +44,11 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
minion.setLinkedChest(null)
}
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
var waterLocation: Location? = null
run breaking@{
LocationUtils.getAllBlocksInRadius(minion.getLocation(), 2.0, false).fastFor {

View File

@ -49,6 +49,11 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
return
}
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
Warnings.remove(minion, Warnings.NO_TOOL)
val loot = ArrayList<ItemStack>()

View File

@ -57,6 +57,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
return
}
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
Warnings.remove(minion, Warnings.NO_TOOL)
var amount = 0

View File

@ -49,6 +49,11 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour
return
}
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
Warnings.remove(minion, Warnings.NO_TOOL)
minion.getLocation().world!!.getNearbyEntities(

View File

@ -39,6 +39,9 @@ use-durability: true
# If the minion should pull new tools from the chest it's connected to
pull-tools-from-chest: false
# If the minion should work when the owner is offline (only if the chunk is loaded)
work-when-owner-offline: true
# What type of message we should send when the upgrade fails
# due to insufficient funds
# Possible options: chat, title, subtitle, actionbar
@ -95,4 +98,4 @@ gui:
debug: false
# Do not change!
config-version: 3
config-version: 4