Fixes, integrations work

This commit is contained in:
TomTom 2023-10-10 20:09:59 +02:00
parent 6789d80d47
commit 0b5716820e
15 changed files with 178 additions and 11 deletions

View File

@ -0,0 +1,6 @@
package com.artillexstudios.axminions.api.integrations
interface Integration {
fun register()
}

View File

@ -0,0 +1,23 @@
package com.artillexstudios.axminions.api.integrations
import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration
import com.artillexstudios.axminions.api.integrations.types.PricesIntegration
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations
import com.artillexstudios.axminions.api.integrations.types.StackerIntegration
interface Integrations {
fun getStackerIntegration(): StackerIntegration
fun getPricesIntegration(): PricesIntegration
fun getEconomyIntegration(): EconomyIntegration
fun getProtectionIntegration(): ProtectionIntegrations
fun reload()
fun register(integration: Integration)
fun deregister(integration: Integration)
}

View File

@ -0,0 +1,13 @@
package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.entity.Player
interface EconomyIntegration : Integration {
fun getBalance(player: Player): Double
fun giveBalance(player: Player, amount: Double)
fun takeBalance(player: Player, amount: Double)
}

View File

@ -0,0 +1,9 @@
package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.inventory.ItemStack
interface PricesIntegration : Integration {
fun getPrice(itemStack: ItemStack): Double
}

View File

@ -0,0 +1,10 @@
package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.Location
import org.bukkit.entity.Player
interface ProtectionIntegration : Integration {
fun canBuildAt(player: Player, location: Location): Boolean
}

View File

@ -0,0 +1,11 @@
package com.artillexstudios.axminions.api.integrations.types
import org.bukkit.Location
import org.bukkit.entity.Player
interface ProtectionIntegrations {
fun getProtectionIntegrations(): List<ProtectionIntegration>
fun canBuildAt(player: Player, location: Location): Boolean
}

View File

@ -0,0 +1,16 @@
package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.Location
import org.bukkit.entity.Item
import org.bukkit.entity.LivingEntity
import org.bukkit.inventory.ItemStack
interface StackerIntegration : Integration {
fun getStackSize(entity: LivingEntity): Long
fun getStackSize(item: Item): Long
fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location)
}

View File

@ -97,4 +97,8 @@ interface Minion : InventoryHolder {
fun isTicking(): Boolean
fun setTicking(ticking: Boolean)
fun setRange(range: Double)
fun setNextAction(nextAction: Int)
}

View File

@ -15,9 +15,10 @@ abstract class Warning(private val name: String) {
fun display(minion: Minion) {
if (minion.getWarning() == null) {
val hologram = HologramFactory.get()
.spawnHologram(minion.getLocation().clone().add(0.0, 1.5, 0.0), minion.getLocation().toString())
.spawnHologram(minion.getLocation().clone().add(0.0, 1.15, 0.0), minion.getLocation().toString())
hologram.addLine(getContent())
minion.setWarning(this)
minion.setWarningHologram(hologram)
}
}
}

View File

@ -34,7 +34,7 @@ class AxMinionsPlugin : AxPlugin() {
}
init {
val manager = BukkitLibraryManager(this)
val manager = BukkitLibraryManager(this, "../../libraries")
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").relocate("org{}h2", "com{}artillexstudios{}axminions{}libs{}h2").build()
manager.addMavenCentral()

View File

@ -0,0 +1,60 @@
package com.artillexstudios.axminions.integrations
import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration
import com.artillexstudios.axminions.api.integrations.Integration
import com.artillexstudios.axminions.api.integrations.Integrations
import com.artillexstudios.axminions.api.integrations.types.PricesIntegration
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations
import com.artillexstudios.axminions.api.integrations.types.StackerIntegration
class Integrations : Integrations {
private lateinit var stackerIntegration: StackerIntegration
private lateinit var pricesIntegration: PricesIntegration
private lateinit var economyIntegration: EconomyIntegration
private lateinit var protectionIntegrations: ProtectionIntegrations
override fun getStackerIntegration(): StackerIntegration {
return stackerIntegration
}
override fun getPricesIntegration(): PricesIntegration {
return pricesIntegration
}
override fun getEconomyIntegration(): EconomyIntegration {
return economyIntegration
}
override fun getProtectionIntegration(): ProtectionIntegrations {
return protectionIntegrations
}
override fun reload() {
TODO("Not yet implemented")
}
override fun register(integration: Integration) {
when (integration) {
is StackerIntegration -> {
stackerIntegration = integration
}
is ProtectionIntegration -> {
// Hook into protection
}
is EconomyIntegration -> {
economyIntegration = integration
}
is PricesIntegration -> {
pricesIntegration = integration
}
}
}
override fun deregister(integration: Integration) {
TODO("Not yet implemented")
}
}

View File

@ -11,6 +11,7 @@ import com.artillexstudios.axapi.utils.EquipmentSlot
import com.artillexstudios.axapi.utils.ItemBuilder
import com.artillexstudios.axapi.utils.RotationType
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.config.Messages
@ -50,8 +51,8 @@ class Minion(
private var chestLocationId: Int
) : Minion {
private lateinit var entity: PacketArmorStand
internal var nextAction = 0
internal var range = 0.0
private var nextAction = 0
private var range = 0.0
private var dirty = true
private var armTick = 2.0
private var warning: Warning? = null
@ -59,7 +60,6 @@ class Minion(
private val extraData = hashMapOf<String, String>()
private var linkedInventory: Inventory? = null
private val openInventories = mutableListOf<Inventory>()
@Volatile
private var ticking = false
init {
@ -136,7 +136,8 @@ class Minion(
item = ItemBuilder(type.getConfig().getSection("gui.$it"), level, nextLevel, range, nextRange, extra, nextExtra, speed, nextSpeed, price, requiredActions, stored, actions).storePersistentData(
MinionTypes.getGuiKey(), PersistentDataType.STRING, it).get()
} else if (it.equals("item")) {
item = ItemBuilder(tool?.clone() ?: ItemStack(Material.AIR)).get()
println("Setting item! $tool")
item = tool?.clone() ?: ItemStack(Material.AIR)
} else {
val rotation = Placeholder.unparsed("direction", Messages.ROTATION_NAME(direction))
val linked = Placeholder.unparsed("linked", when (linkedChest) {
@ -213,6 +214,10 @@ class Minion(
} else {
entity.setItem(EquipmentSlot.MAIN_HAND, tool)
}
AxMinionsPlugin.dataQueue.submit {
AxMinionsPlugin.dataHandler.saveMinion(this)
}
}
override fun getTool(): ItemStack? {
@ -264,7 +269,7 @@ class Minion(
override fun setLinkedChest(location: Location?) {
this.linkedChest = location?.clone()
linkedInventory = (linkedChest?.block?.blockData as? Container)?.inventory
linkedInventory = (linkedChest?.block?.state as? Container)?.inventory
updateInventories()
}
@ -348,6 +353,14 @@ class Minion(
this.ticking = ticking
}
override fun setRange(range: Double) {
this.range = range
}
override fun setNextAction(nextAction: Int) {
this.nextAction = nextAction
}
override fun getInventory(): Inventory {
return Bukkit.createInventory(this, 9)
}

View File

@ -18,9 +18,9 @@ class CollectorMinionType : MinionType("collector", AxMinionsPlugin.INSTANCE.get
override fun onToolDirty(minion: Minion) {
val minionImpl = minion as com.artillexstudios.axminions.minions.Minion
minionImpl.range = getDouble("range", minion.getLevel())
minionImpl.setRange(getDouble("range", minion.getLevel()))
val efficiency = 1.0 - (minion.getTool()?.getEnchantmentLevel(Enchantment.DIG_SPEED)?.div(10.0) ?: 0.1)
minionImpl.nextAction = (getLong("speed", minion.getLevel()) * efficiency).roundToInt()
minionImpl.setNextAction((getLong("speed", minion.getLevel()) * efficiency).roundToInt())
}
override fun run(minion: Minion) {

View File

@ -20,12 +20,13 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
override fun onToolDirty(minion: Minion) {
val minionImpl = minion as com.artillexstudios.axminions.minions.Minion
minionImpl.range = getDouble("range", minion.getLevel())
minionImpl.setRange(getDouble("range", minion.getLevel()))
val efficiency = 1.0 - (minion.getTool()?.getEnchantmentLevel(Enchantment.DIG_SPEED)?.div(10.0) ?: 0.1)
minionImpl.nextAction = (getLong("speed", minion.getLevel()) * efficiency).roundToInt()
minionImpl.setNextAction((getLong("speed", minion.getLevel()) * efficiency).roundToInt())
}
override fun run(minion: Minion) {
minion.resetAnimation()
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
val block = location.block
val drops = arrayListOf<ItemStack>()

Binary file not shown.