mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-25 12:05:56 +01:00
Fixes
This commit is contained in:
parent
869efed819
commit
6341697495
@ -47,6 +47,8 @@ class Config(file: File, stream: InputStream) {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun PLACE_PERMISSION() = AxMinionsAPI.INSTANCE.getConfig().get("place-permissions", false)
|
fun PLACE_PERMISSION() = AxMinionsAPI.INSTANCE.getConfig().get("place-permissions", false)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
fun WORK_WHEN_OWNER_OFFLINE() = AxMinionsAPI.INSTANCE.getConfig().get("work-when-owner-offline", true)
|
||||||
|
@JvmStatic
|
||||||
fun DEBUG(): Boolean {
|
fun DEBUG(): Boolean {
|
||||||
if (debug === null) {
|
if (debug === null) {
|
||||||
debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false)
|
debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false)
|
||||||
|
@ -109,4 +109,8 @@ interface Minion : InventoryHolder {
|
|||||||
fun damageTool(amount: Int = 1)
|
fun damageTool(amount: Int = 1)
|
||||||
|
|
||||||
fun canUseTool(): Boolean
|
fun canUseTool(): Boolean
|
||||||
|
|
||||||
|
fun isOwnerOnline(): Boolean
|
||||||
|
|
||||||
|
fun setOwnerOnline(online: Boolean)
|
||||||
}
|
}
|
@ -33,6 +33,7 @@ abstract class MinionType(private val name: String, private val defaults: InputS
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick(minion: Minion) {
|
fun tick(minion: Minion) {
|
||||||
|
if (!com.artillexstudios.axminions.api.config.Config.WORK_WHEN_OWNER_OFFLINE() && !minion.isOwnerOnline()) return
|
||||||
if (!shouldRun(minion)) return
|
if (!shouldRun(minion)) return
|
||||||
|
|
||||||
minion.resetAnimation()
|
minion.resetAnimation()
|
||||||
|
@ -20,6 +20,7 @@ import com.artillexstudios.axminions.listeners.MinionDamageListener
|
|||||||
import com.artillexstudios.axminions.listeners.MinionDropListener
|
import com.artillexstudios.axminions.listeners.MinionDropListener
|
||||||
import com.artillexstudios.axminions.listeners.MinionInventoryListener
|
import com.artillexstudios.axminions.listeners.MinionInventoryListener
|
||||||
import com.artillexstudios.axminions.listeners.MinionPlaceListener
|
import com.artillexstudios.axminions.listeners.MinionPlaceListener
|
||||||
|
import com.artillexstudios.axminions.listeners.PlayerListener
|
||||||
import com.artillexstudios.axminions.listeners.WorldListener
|
import com.artillexstudios.axminions.listeners.WorldListener
|
||||||
import com.artillexstudios.axminions.minions.Minion
|
import com.artillexstudios.axminions.minions.Minion
|
||||||
import com.artillexstudios.axminions.minions.MinionTicker
|
import com.artillexstudios.axminions.minions.MinionTicker
|
||||||
@ -114,6 +115,7 @@ class AxMinionsPlugin : AxPlugin() {
|
|||||||
it.registerEvents(MinionDamageListener(), this)
|
it.registerEvents(MinionDamageListener(), this)
|
||||||
it.registerEvents(WorldListener(), this)
|
it.registerEvents(WorldListener(), this)
|
||||||
it.registerEvents(MinionDropListener(), this)
|
it.registerEvents(MinionDropListener(), this)
|
||||||
|
it.registerEvents(PlayerListener(), this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retroactively load minions for the already loaded worlds
|
// Retroactively load minions for the already loaded worlds
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -67,10 +67,12 @@ class Minion(
|
|||||||
private val extraData = hashMapOf<String, String>()
|
private val extraData = hashMapOf<String, String>()
|
||||||
private var linkedInventory: Inventory? = null
|
private var linkedInventory: Inventory? = null
|
||||||
internal val openInventories = mutableListOf<Inventory>()
|
internal val openInventories = mutableListOf<Inventory>()
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var ticking = false
|
private var ticking = false
|
||||||
private var debugHologram: Hologram? = null
|
private var debugHologram: Hologram? = null
|
||||||
private var broken = false
|
private var broken = false
|
||||||
|
private var ownerOnline = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
spawn()
|
spawn()
|
||||||
@ -671,8 +673,8 @@ class Minion(
|
|||||||
setTool(it)
|
setTool(it)
|
||||||
linkedInventory?.remove(it)
|
linkedInventory?.remove(it)
|
||||||
return canUseTool()
|
return canUseTool()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
@ -682,6 +684,14 @@ class Minion(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isOwnerOnline(): Boolean {
|
||||||
|
return ownerOnline
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setOwnerOnline(online: Boolean) {
|
||||||
|
ownerOnline = online
|
||||||
|
}
|
||||||
|
|
||||||
override fun getInventory(): Inventory {
|
override fun getInventory(): Inventory {
|
||||||
return Bukkit.createInventory(this, 9)
|
return Bukkit.createInventory(this, 9)
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,11 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
minion.setLinkedChest(null)
|
minion.setLinkedChest(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||||
|
Warnings.CONTAINER_FULL.display(minion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!minion.canUseTool()) {
|
if (!minion.canUseTool()) {
|
||||||
Warnings.NO_TOOL.display(minion)
|
Warnings.NO_TOOL.display(minion)
|
||||||
return
|
return
|
||||||
|
@ -44,6 +44,11 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
minion.setLinkedChest(null)
|
minion.setLinkedChest(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||||
|
Warnings.CONTAINER_FULL.display(minion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var waterLocation: Location? = null
|
var waterLocation: Location? = null
|
||||||
run breaking@{
|
run breaking@{
|
||||||
LocationUtils.getAllBlocksInRadius(minion.getLocation(), 2.0, false).fastFor {
|
LocationUtils.getAllBlocksInRadius(minion.getLocation(), 2.0, false).fastFor {
|
||||||
|
@ -49,6 +49,11 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||||
|
Warnings.CONTAINER_FULL.display(minion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Warnings.remove(minion, Warnings.NO_TOOL)
|
Warnings.remove(minion, Warnings.NO_TOOL)
|
||||||
|
|
||||||
val loot = ArrayList<ItemStack>()
|
val loot = ArrayList<ItemStack>()
|
||||||
|
@ -57,6 +57,11 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||||
|
Warnings.CONTAINER_FULL.display(minion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Warnings.remove(minion, Warnings.NO_TOOL)
|
Warnings.remove(minion, Warnings.NO_TOOL)
|
||||||
|
|
||||||
var amount = 0
|
var amount = 0
|
||||||
|
@ -49,6 +49,11 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||||
|
Warnings.CONTAINER_FULL.display(minion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Warnings.remove(minion, Warnings.NO_TOOL)
|
Warnings.remove(minion, Warnings.NO_TOOL)
|
||||||
|
|
||||||
minion.getLocation().world!!.getNearbyEntities(
|
minion.getLocation().world!!.getNearbyEntities(
|
||||||
|
@ -39,6 +39,9 @@ use-durability: true
|
|||||||
# If the minion should pull new tools from the chest it's connected to
|
# If the minion should pull new tools from the chest it's connected to
|
||||||
pull-tools-from-chest: false
|
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
|
# What type of message we should send when the upgrade fails
|
||||||
# due to insufficient funds
|
# due to insufficient funds
|
||||||
# Possible options: chat, title, subtitle, actionbar
|
# Possible options: chat, title, subtitle, actionbar
|
||||||
@ -95,4 +98,4 @@ gui:
|
|||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
# Do not change!
|
# Do not change!
|
||||||
config-version: 3
|
config-version: 4
|
Loading…
Reference in New Issue
Block a user