So much work

This commit is contained in:
TomTom 2023-10-19 20:22:55 +02:00
parent 2bb47ffae7
commit 2069ced74f
22 changed files with 161 additions and 80 deletions

View File

@ -0,0 +1,19 @@
package com.artillexstudios.axminions.api.events
import com.artillexstudios.axminions.api.minions.Minion
import org.bukkit.entity.LivingEntity
import org.bukkit.event.HandlerList
import org.bukkit.inventory.ItemStack
class MinionKillEntityEvent(minion: Minion, val target: LivingEntity, val loot: List<ItemStack>) : MinionEvent(minion) {
companion object {
private val handlerList = HandlerList()
@JvmStatic
fun getHandlerList(): HandlerList = handlerList
}
override fun getHandlers(): HandlerList {
return handlerList
}
}

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.LivingEntity
import org.bukkit.event.Cancellable
import org.bukkit.event.HandlerList
class MinionDamageEntityEvent(minion: Minion, val target: LivingEntity, val damage: Double) : MinionEvent(minion), Cancellable {
class PreMinionDamageEntityEvent(minion: Minion, val target: LivingEntity, val damage: Double) : MinionEvent(minion), Cancellable {
companion object {
private val handlerList = HandlerList()

View File

@ -2,7 +2,7 @@ package com.artillexstudios.axminions.api.minions.miniontype
import com.artillexstudios.axapi.config.Config
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section
import com.artillexstudios.axapi.libs.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import com.artillexstudios.axapi.utils.ItemBuilder
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.minions.Minion

View File

@ -1,7 +1,7 @@
package com.artillexstudios.axminions.api.warnings
import com.artillexstudios.axapi.hologram.HologramFactory
import com.artillexstudios.axapi.libs.kyori.adventure.text.Component
import net.kyori.adventure.text.Component
import com.artillexstudios.axminions.api.minions.Minion
abstract class Warning(private val name: String) {

View File

@ -1,6 +1,6 @@
package com.artillexstudios.axminions.api.warnings.impl
import com.artillexstudios.axapi.libs.kyori.adventure.text.Component
import net.kyori.adventure.text.Component
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.warnings.Warning

View File

@ -1,6 +1,6 @@
package com.artillexstudios.axminions.api.warnings.impl
import com.artillexstudios.axapi.libs.kyori.adventure.text.Component
import net.kyori.adventure.text.Component
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.warnings.Warning

View File

@ -1,6 +1,6 @@
package com.artillexstudios.axminions.api.warnings.impl
import com.artillexstudios.axapi.libs.kyori.adventure.text.Component
import net.kyori.adventure.text.Component
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.warnings.Warning

View File

@ -1,6 +1,6 @@
package com.artillexstudios.axminions.api.warnings.impl
import com.artillexstudios.axapi.libs.kyori.adventure.text.Component
import net.kyori.adventure.text.Component
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.warnings.Warning

View File

@ -2,7 +2,6 @@ package com.artillexstudios.axminions
import com.artillexstudios.axapi.AxPlugin
import com.artillexstudios.axapi.data.ThreadedQueue
import com.artillexstudios.axapi.libs.lamp.bukkit.BukkitCommandHandler
import com.artillexstudios.axapi.libs.libby.libby.BukkitLibraryManager
import com.artillexstudios.axapi.libs.libby.libby.Library
import com.artillexstudios.axminions.api.AxMinionsAPI
@ -28,8 +27,9 @@ import com.artillexstudios.axminions.minions.miniontype.LumberMinionType
import com.artillexstudios.axminions.minions.miniontype.MinerMinionType
import com.artillexstudios.axminions.minions.miniontype.SellerMinionType
import com.artillexstudios.axminions.minions.miniontype.SlayerMinionType
import org.bukkit.Bukkit
import java.io.File
import org.bukkit.Bukkit
import revxrsal.commands.bukkit.BukkitCommandHandler
class AxMinionsPlugin : AxPlugin() {
companion object {
@ -43,8 +43,10 @@ class AxMinionsPlugin : AxPlugin() {
init {
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()
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()
manager.loadLibrary(stdLib)
manager.loadLibrary(h2)
@ -101,6 +103,7 @@ class AxMinionsPlugin : AxPlugin() {
Bukkit.getPluginManager().registerEvents(ChunkListener(), this)
Bukkit.getPluginManager().registerEvents(MinionDamageListener(), this)
MinionTicker.startTicking()
}

View File

@ -1,13 +1,6 @@
package com.artillexstudios.axminions.commands
import com.artillexstudios.axapi.libs.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import com.artillexstudios.axapi.libs.lamp.annotation.AutoComplete
import com.artillexstudios.axapi.libs.lamp.annotation.Command
import com.artillexstudios.axapi.libs.lamp.annotation.Default
import com.artillexstudios.axapi.libs.lamp.annotation.Description
import com.artillexstudios.axapi.libs.lamp.annotation.Range
import com.artillexstudios.axapi.libs.lamp.annotation.Subcommand
import com.artillexstudios.axapi.libs.lamp.bukkit.annotation.CommandPermission
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
@ -17,6 +10,13 @@ import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
import com.artillexstudios.axminions.api.utils.fastFor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import revxrsal.commands.annotation.AutoComplete
import revxrsal.commands.annotation.Command
import revxrsal.commands.annotation.Default
import revxrsal.commands.annotation.Description
import revxrsal.commands.annotation.Range
import revxrsal.commands.annotation.Subcommand
import revxrsal.commands.bukkit.annotation.CommandPermission
@Command("axminions", "minion", "minions")
class AxMinionsCommand {

View File

@ -1,21 +1,22 @@
package com.artillexstudios.axminions.integrations.prices
import com.Zrips.CMI.CMI
//import com.Zrips.CMI.CMI
import com.artillexstudios.axminions.api.integrations.types.PricesIntegration
import org.bukkit.inventory.ItemStack
class CMIIntegration : PricesIntegration {
private lateinit var manager: CMI
// private lateinit var manager: CMI
override fun getPrice(itemStack: ItemStack): Double {
val worth = manager.worthManager.getWorth(itemStack) ?: return -1.0
return if (worth.sellPrice == 0.0) -1.0 else worth.sellPrice
// val worth = manager.worthManager.getWorth(itemStack) ?: return -1.0
//
// return if (worth.sellPrice == 0.0) -1.0 else worth.sellPrice
return -1.0
}
override fun register() {
manager = CMI.getInstance();
// manager = CMI.getInstance();
}
}

View File

@ -1,16 +1,16 @@
package com.artillexstudios.axminions.integrations.protection
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI
import org.bukkit.Location
import org.bukkit.entity.Player
class IridiumSkyBlockIntegration : ProtectionIntegration {
override fun canBuildAt(player: Player, location: Location): Boolean {
val island = IridiumSkyblockAPI.getInstance().getIslandViaLocation(location)
/* 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 it.members }.orElse(true)*/
return true
}
override fun register() {

View File

@ -3,16 +3,15 @@ package com.artillexstudios.axminions.integrations.protection
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
import org.bukkit.Location
import org.bukkit.entity.Player
import org.kingdoms.constants.land.Land
import org.kingdoms.constants.player.KingdomPlayer
class KingdomsXIntegration : ProtectionIntegration {
override fun canBuildAt(player: Player, location: Location): Boolean {
val localPlayer = KingdomPlayer.getKingdomPlayer(player.uniqueId);
val land = Land.getLand(location) ?: return true
return land.kingdom.isMember(localPlayer);
// val localPlayer = KingdomPlayer.getKingdomPlayer(player.uniqueId);
// val land = Land.getLand(location) ?: return true
//
// return land.kingdom.isMember(localPlayer);
return true
}
override fun register() {

View File

@ -1,19 +1,35 @@
package com.artillexstudios.axminions.listeners
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.events.MinionDamageEntityEvent
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.utils.fastFor
import com.artillexstudios.axminions.api.warnings.Warnings
import java.util.concurrent.ThreadLocalRandom
import org.bukkit.entity.Item
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
class MinionDamageListener : Listener {
@EventHandler
fun onMinionDamageEntityEvent(event: MinionDamageEntityEvent) {
if (event.damage < event.target.health) return
fun onPreMinionDamageEntityEvent(event: MinionKillEntityEvent) {
println("MINION KILL ENTITY EVENT")
val entitySize = AxMinionsPlugin.integrations.getStackerIntegration().getStackSize(event.target)
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 ->
if (event.minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(event.minion)
return
}
val amount = AxMinionsPlugin.integrations.getStackerIntegration().getStackSize(item)
val stack = item.itemStack
stack.amount = amount.toInt()
event.minion.addToContainerOrDrop(stack)
item.remove()
}
}
}

View File

@ -1,15 +1,16 @@
package com.artillexstudios.axminions.listeners
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.minions.Direction
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
import com.artillexstudios.axminions.api.utils.CoolDown
import com.artillexstudios.axminions.api.utils.Keys
import com.artillexstudios.axminions.api.utils.fastFor
import java.util.UUID
import java.util.concurrent.TimeUnit
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
@ -117,6 +118,43 @@ class MinionInventoryListener : Listener {
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_START()))
LinkingListener.linking[player.uniqueId] = minion
}
"upgrade" -> {
val money = minion.getType().getDouble("requirements.money", minion.getLevel() + 1)
val actions = minion.getType().getDouble("requirements.actions", minion.getLevel() + 1)
if (minion.getType().hasReachedMaxLevel(minion)) {
return
}
if (minion.getActionAmount() < actions) {
return
}
AxMinionsPlugin.integrations.getEconomyIntegration()?.let {
if (it.getBalance(player) < money) {
return
}
it.takeBalance(player, money)
}
minion.setLevel(minion.getLevel() + 1)
}
"statistics" -> {
val stored = minion.getStorage()
if (stored == 0.0) {
return
}
if (minion.getType() == MinionTypes.getMinionTypes()["seller"]) {
// TODO: Give money
} else {
player.giveExp(stored.toInt())
}
}
}
minion.updateInventories()

View File

@ -1,6 +1,6 @@
package com.artillexstudios.axminions.listeners
import com.artillexstudios.axapi.libs.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin

View File

@ -6,7 +6,7 @@ import com.artillexstudios.axapi.entity.impl.PacketEntity
import com.artillexstudios.axapi.events.PacketEntityInteractEvent
import com.artillexstudios.axapi.hologram.Hologram
import com.artillexstudios.axapi.hologram.HologramFactory
import com.artillexstudios.axapi.libs.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axapi.serializers.Serializers
import com.artillexstudios.axapi.utils.EquipmentSlot
@ -57,6 +57,7 @@ class Minion(
private lateinit var entity: PacketArmorStand
private var nextAction = 0
private var range = 0.0
@Volatile
private var dirty = true
private var armTick = 2.0
private var warning: Warning? = null
@ -84,6 +85,24 @@ class Minion(
entity.setHasBasePlate(false)
entity.setSmall(true)
entity.setHasArms(true)
entity.onClick { event ->
println("bbbbbbbbbbbbbb")
if (event.isAttack) {
if (ownerUUID == event.player.uniqueId && Config.ONLY_OWNER_BREAK()) {
breakMinion(event)
} else if (AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location)) {
breakMinion(event)
}
} else {
if (ownerUUID == event.player.uniqueId || AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location)) {
Scheduler.get().run {
openInventory(event.player)
}
}
}
}
entity.name = StringUtils.format(
type.getConfig().get("entity.name"),
Placeholder.unparsed("owner", owner.name ?: "???"),
@ -98,23 +117,6 @@ class Minion(
setDirection(direction)
updateArmour()
entity.onClick { event ->
if (event.isAttack) {
// if (ownerUUID == event.player.uniqueId && Config.ONLY_OWNER_BREAK()) {
// breakMinion(event)
// } else if (AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location)) {
breakMinion(event)
// }
} else {
/* if (ownerUUID == event.player.uniqueId || AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.packetEntity.location)) {
}*/
Scheduler.get().run {
openInventory(event.player)
}
}
}
}
private fun breakMinion(event: PacketEntityInteractEvent) {
@ -235,8 +237,9 @@ class Minion(
inventory.setItem(i, filler)
}
updateInventory(inventory)
println("aaaaa")
player.openInventory(inventory)
updateInventory(inventory)
openInventories.add(inventory)
}
@ -291,6 +294,7 @@ class Minion(
}
AxMinionsPlugin.dataQueue.submit {
println("Saving minion!")
AxMinionsPlugin.dataHandler.saveMinion(this)
}
}
@ -375,6 +379,7 @@ class Minion(
entity.teleport(location)
AxMinionsPlugin.dataQueue.submit {
println("Saving minion!")
AxMinionsPlugin.dataHandler.saveMinion(this)
}
}

View File

@ -66,7 +66,6 @@ object Minions {
if (pos === null) {
pos = ChunkPos(chunkX, chunkZ)
println("Adding new pos! $pos")
minions.add(pos!!)
}

View File

@ -10,7 +10,6 @@ import com.artillexstudios.axminions.nms.NMSHandler
import kotlin.math.roundToInt
import org.bukkit.Material
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Item
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.entity.Tameable
@ -63,19 +62,6 @@ class SlayerMinionType : MinionType("slayer", AxMinionsPlugin.INSTANCE.getResour
}
NMSHandler.get().attack(minion, it)
it.location.world!!.getNearbyEntities(it.location, 2.0, 2.0, 2.0).filterIsInstance<Item>().fastFor { item ->
if (minion.getLinkedInventory()?.firstEmpty() == -1) {
Warnings.CONTAINER_FULL.display(minion)
return
}
val amount = AxMinionsPlugin.integrations.getStackerIntegration().getStackSize(item)
val stack = item.itemStack
stack.amount = amount.toInt()
minion.addToContainerOrDrop(stack)
item.remove()
}
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,7 @@
package com.artillexstudios.axminions.nms.v1_20_R1
import com.artillexstudios.axminions.api.events.MinionDamageEntityEvent
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
import com.artillexstudios.axminions.api.minions.Minion
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.server.level.ServerLevel
@ -85,7 +86,7 @@ object DamageHandler {
}
}
val event = MinionDamageEntityEvent(source, entity as org.bukkit.entity.LivingEntity, f.toDouble())
val event = PreMinionDamageEntityEvent(source, entity as org.bukkit.entity.LivingEntity, f.toDouble())
Bukkit.getPluginManager().callEvent(event)
if (event.isCancelled) {
return
@ -94,6 +95,11 @@ object DamageHandler {
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().magic(), f.toFloat())
if (flag5) {
if ((nmsEntity as LivingEntity).isDeadOrDying) {
val killEvent = MinionKillEntityEvent(source, entity, nmsEntity.drops)
Bukkit.getPluginManager().callEvent(killEvent)
}
if (i > 0) {
if (nmsEntity is LivingEntity) {
(nmsEntity).knockback(
@ -120,11 +126,16 @@ object DamageHandler {
while (iterator.hasNext()) {
val entityliving: LivingEntity = iterator.next() as LivingEntity
if ((entityliving !is ArmorStand || !(entityliving).isMarker) && source.getLocation().distanceSquared(
(entity as Entity).location
) < 9.0
if ((entityliving !is ArmorStand || !(entityliving).isMarker) && source.getLocation()
.distanceSquared(
(entity as Entity).location
) < 9.0
) {
val damageEvent = MinionDamageEntityEvent(source, entityliving.bukkitEntity as org.bukkit.entity.LivingEntity, f4.toDouble())
val damageEvent = PreMinionDamageEntityEvent(
source,
entityliving.bukkitEntity as org.bukkit.entity.LivingEntity,
f4.toDouble()
)
Bukkit.getPluginManager().callEvent(damageEvent)
if (event.isCancelled) {
return
@ -132,6 +143,10 @@ object DamageHandler {
// CraftBukkit start - Only apply knockback if the damage hits
if (entityliving.hurt(nmsEntity.damageSources().magic(), f4)) {
if (entityliving.isDeadOrDying) {
val killEvent = MinionKillEntityEvent(source, entity, entityliving.drops)
Bukkit.getPluginManager().callEvent(killEvent)
}
entityliving.knockback(
0.4000000059604645,
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),