mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-19 23:19:17 +00:00
Migrations and updates
This commit is contained in:
@@ -2,7 +2,7 @@ plugins {
|
|||||||
java
|
java
|
||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
kotlin("jvm") version "1.7.10"
|
kotlin("jvm") version "1.9.20"
|
||||||
id("com.github.johnrengelman.shadow") version "8.0.0"
|
id("com.github.johnrengelman.shadow") version "8.0.0"
|
||||||
id("com.willfp.libreforge-gradle-plugin") version "1.0.0"
|
id("com.willfp.libreforge-gradle-plugin") version "1.0.0"
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,6 @@ base {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":eco-core:core-plugin"))
|
implementation(project(":eco-core:core-plugin"))
|
||||||
implementation(project(path = ":eco-core:core-nms:v1_20_R1", configuration = "reobf"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
@@ -37,9 +36,9 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.willfp:eco:6.65.0")
|
compileOnly("com.willfp:eco:6.67.0")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
|
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.20")
|
||||||
compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.5")
|
compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.5")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("io.papermc.paperweight.userdev") version "1.5.3" apply false
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "com.willfp"
|
|
||||||
version = rootProject.version
|
|
||||||
|
|
||||||
subprojects {
|
|
||||||
dependencies {
|
|
||||||
compileOnly(project(":eco-core:core-plugin"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("io.papermc.paperweight.userdev")
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "com.willfp"
|
|
||||||
version = rootProject.version
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT")
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.willfp.ecomobs.nms.v1_20_R1
|
|
||||||
|
|
||||||
import com.willfp.eco.core.packet.Packet
|
|
||||||
import com.willfp.eco.core.packet.sendPacket
|
|
||||||
import com.willfp.ecomobs.name.DisplayNameProxy
|
|
||||||
import io.papermc.paper.adventure.PaperAdventure
|
|
||||||
import net.kyori.adventure.text.Component
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket
|
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor
|
|
||||||
import net.minecraft.network.syncher.SynchedEntityData
|
|
||||||
import net.minecraft.world.entity.Entity
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftMob
|
|
||||||
import org.bukkit.entity.Mob
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import java.util.Optional
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
class DisplayName : DisplayNameProxy {
|
|
||||||
private val displayNameAccessor = Entity::class.java
|
|
||||||
.declaredFields
|
|
||||||
.filter { it.type == EntityDataAccessor::class.java }
|
|
||||||
.toList()[2]
|
|
||||||
.apply { isAccessible = true }
|
|
||||||
.get(null) as EntityDataAccessor<Optional<net.minecraft.network.chat.Component>>
|
|
||||||
|
|
||||||
private val customNameVisibleAccessor = Entity::class.java
|
|
||||||
.declaredFields
|
|
||||||
.filter { it.type == EntityDataAccessor::class.java }
|
|
||||||
.toList()[3]
|
|
||||||
.apply { isAccessible = true }
|
|
||||||
.get(null) as EntityDataAccessor<Boolean>
|
|
||||||
|
|
||||||
override fun setDisplayName(mob: Mob, player: Player, displayName: Component, visible: Boolean) {
|
|
||||||
if (mob !is CraftMob) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val nmsComponent = PaperAdventure.asVanilla(displayName)
|
|
||||||
?: throw IllegalStateException("Display name component is null!")
|
|
||||||
|
|
||||||
val nmsEntity = mob.handle
|
|
||||||
nmsEntity.isCustomNameVisible
|
|
||||||
val entityData = SynchedEntityData(nmsEntity)
|
|
||||||
|
|
||||||
entityData.forceSet(displayNameAccessor, Optional.of(nmsComponent))
|
|
||||||
entityData.forceSet(customNameVisibleAccessor, visible)
|
|
||||||
|
|
||||||
val packet = ClientboundSetEntityDataPacket(
|
|
||||||
nmsEntity.id,
|
|
||||||
entityData.packDirty() ?: throw IllegalStateException("No packed entity data")
|
|
||||||
)
|
|
||||||
|
|
||||||
player.sendPacket(Packet(packet))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> SynchedEntityData.forceSet(
|
|
||||||
accessor: EntityDataAccessor<T>,
|
|
||||||
value: T
|
|
||||||
) {
|
|
||||||
if (!this.hasItem(accessor)) {
|
|
||||||
this.define(accessor, value)
|
|
||||||
}
|
|
||||||
this[accessor] = value
|
|
||||||
this.markDirty(accessor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,7 @@ import com.willfp.ecomobs.integrations.levelledmobs.IntegrationLevelledMobs
|
|||||||
import com.willfp.ecomobs.integrations.libsdisguises.IntegrationLibsDisguises
|
import com.willfp.ecomobs.integrations.libsdisguises.IntegrationLibsDisguises
|
||||||
import com.willfp.ecomobs.integrations.modelengine.IntegrationModelEngine
|
import com.willfp.ecomobs.integrations.modelengine.IntegrationModelEngine
|
||||||
import com.willfp.ecomobs.mob.EcoMobs
|
import com.willfp.ecomobs.mob.EcoMobs
|
||||||
|
import com.willfp.ecomobs.mob.damage.TopDamagerHandler
|
||||||
import com.willfp.libreforge.loader.LibreforgePlugin
|
import com.willfp.libreforge.loader.LibreforgePlugin
|
||||||
import com.willfp.libreforge.loader.configs.ConfigCategory
|
import com.willfp.libreforge.loader.configs.ConfigCategory
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
@@ -27,6 +28,7 @@ internal lateinit var plugin: EcoMobsPlugin
|
|||||||
|
|
||||||
class EcoMobsPlugin : LibreforgePlugin() {
|
class EcoMobsPlugin : LibreforgePlugin() {
|
||||||
val spawnPointGenerator = SpawnPointGenerator(this)
|
val spawnPointGenerator = SpawnPointGenerator(this)
|
||||||
|
val topDamagerHandler = TopDamagerHandler(this)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
plugin = this
|
plugin = this
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.willfp.ecomobs.mob.damage
|
||||||
|
|
||||||
|
import com.willfp.eco.util.savedDisplayName
|
||||||
|
import com.willfp.eco.util.tryAsPlayer
|
||||||
|
import com.willfp.ecomobs.EcoMobsPlugin
|
||||||
|
import com.willfp.libreforge.NamedValue
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.entity.Mob
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.EventPriority
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
/*
|
||||||
|
Old code mostly ported from EcoBosses, can't be bothered to write it again
|
||||||
|
*/
|
||||||
|
|
||||||
|
data class Damager(
|
||||||
|
val uuid: UUID, var damage: Double
|
||||||
|
)
|
||||||
|
|
||||||
|
private const val metaKey = "TOP_DAMAGERS"
|
||||||
|
|
||||||
|
class TopDamagerHandler(
|
||||||
|
private val plugin: EcoMobsPlugin
|
||||||
|
) : Listener {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
private var Mob.topDamagers: List<Damager>
|
||||||
|
get() = (this.getMetadata(metaKey).getOrNull(0)?.value() as? List<Damager>) ?: emptyList()
|
||||||
|
set(value) {
|
||||||
|
this.removeMetadata(metaKey, plugin)
|
||||||
|
this.setMetadata(metaKey, plugin.metadataValueFactory.create(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
|
fun handle(event: EntityDamageByEntityEvent) {
|
||||||
|
val uuid = event.damager.tryAsPlayer()?.uniqueId ?: return
|
||||||
|
val victim = event.entity as? Mob ?: return
|
||||||
|
|
||||||
|
val topDamagers = victim.topDamagers.toMutableList()
|
||||||
|
|
||||||
|
val damager = topDamagers.firstOrNull { it.uuid == uuid } ?: Damager(uuid, 0.0)
|
||||||
|
damager.damage += event.damage
|
||||||
|
topDamagers.removeIf { it.uuid == uuid }
|
||||||
|
topDamagers.add(damager)
|
||||||
|
victim.topDamagers = topDamagers.sortedByDescending { it.damage }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generatePlaceholders(mob: Mob): List<NamedValue> {
|
||||||
|
return mob.topDamagers
|
||||||
|
.mapIndexed { index, damager ->
|
||||||
|
NamedValue("top_damager_${index + 1}_name", Bukkit.getOfflinePlayer(damager.uuid).name ?: "Unknown")
|
||||||
|
NamedValue("top_damager_${index + 1}_display", Bukkit.getOfflinePlayer(damager.uuid).savedDisplayName)
|
||||||
|
NamedValue("top_damager_${index + 1}_damage", damager.damage.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ import org.bukkit.entity.Mob
|
|||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
internal class LivingMobImpl(
|
internal class LivingMobImpl(
|
||||||
plugin: EcoMobsPlugin,
|
private val plugin: EcoMobsPlugin,
|
||||||
override val mob: EcoMob,
|
override val mob: EcoMob,
|
||||||
override val entity: Mob,
|
override val entity: Mob,
|
||||||
private val deathCallback: () -> Unit
|
private val deathCallback: () -> Unit
|
||||||
@@ -70,6 +70,10 @@ internal class LivingMobImpl(
|
|||||||
trigger.addPlaceholder(NamedValue(placeholder.id, placeholder.getValue(this)))
|
trigger.addPlaceholder(NamedValue(placeholder.id, placeholder.getValue(this)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (placeholder in plugin.topDamagerHandler.generatePlaceholders(entity)) {
|
||||||
|
trigger.addPlaceholder(placeholder)
|
||||||
|
}
|
||||||
|
|
||||||
mob.handleEvent(event, trigger)
|
mob.handleEvent(event, trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.willfp.ecomobs.name
|
|
||||||
|
|
||||||
import com.willfp.eco.util.toComponent
|
|
||||||
import com.willfp.ecomobs.plugin
|
|
||||||
import net.kyori.adventure.text.Component
|
|
||||||
import org.bukkit.entity.Mob
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
|
|
||||||
interface DisplayNameProxy {
|
|
||||||
fun setDisplayName(mob: Mob, player: Player, displayName: Component, visible: Boolean)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Mob.setClientDisplayName(player: Player, name: String, visible: Boolean) =
|
|
||||||
plugin.getProxy(DisplayNameProxy::class.java).setDisplayName(this, player, name.toComponent(), visible)
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.willfp.ecomobs.tick
|
package com.willfp.ecomobs.tick
|
||||||
|
|
||||||
|
import com.willfp.eco.util.setClientsideDisplayName
|
||||||
|
import com.willfp.eco.util.toComponent
|
||||||
import com.willfp.ecomobs.mob.LivingMob
|
import com.willfp.ecomobs.mob.LivingMob
|
||||||
import com.willfp.ecomobs.name.setClientDisplayName
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
class TickHandlerDisplayName : TickHandler {
|
class TickHandlerDisplayName : TickHandler {
|
||||||
@@ -12,6 +13,6 @@ class TickHandlerDisplayName : TickHandler {
|
|||||||
|
|
||||||
mob.entity.getNearbyEntities(20.0, 20.0, 20.0)
|
mob.entity.getNearbyEntities(20.0, 20.0, 20.0)
|
||||||
.filterIsInstance<Player>()
|
.filterIsInstance<Player>()
|
||||||
.forEach { mob.entity.setClientDisplayName(it, mob.displayName, false) }
|
.forEach { mob.entity.setClientsideDisplayName(it, mob.displayName.toComponent(), false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ spawning:
|
|||||||
# none
|
# none
|
||||||
# Disables natural spawning
|
# Disables natural spawning
|
||||||
|
|
||||||
type: replace
|
type: custom
|
||||||
|
|
||||||
# Options for replace spawning
|
# Options for replace spawning
|
||||||
replace:
|
replace:
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ custom-ai:
|
|||||||
# Effects are done from the player's perspective: to treat the player as the victim,
|
# Effects are done from the player's perspective: to treat the player as the victim,
|
||||||
# either use self_as_victim in args, or use player_as_victim in mutators.
|
# either use self_as_victim in args, or use player_as_victim in mutators.
|
||||||
# You can use display name placeholders in effects
|
# You can use display name placeholders in effects
|
||||||
|
# You can also use top damager placeholders:
|
||||||
|
# %top_damager_<place>_name%, %top_damager_<place>_damage%, %top_damager_<place>_display%
|
||||||
effects:
|
effects:
|
||||||
# Effects ran when the mob spawns
|
# Effects ran when the mob spawns
|
||||||
spawn: [ ]
|
spawn: [ ]
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
name: ${pluginName}
|
|
||||||
version: ${version}
|
|
||||||
main: com.willfp.ecomobs.EcoMobsPlugin
|
|
||||||
api-version: 1.19
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
- name: eco
|
|
||||||
required: true
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
- name: libreforge
|
|
||||||
required: false
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
- name: LevelledMobs
|
|
||||||
required: false
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
- name: ModelEngine
|
|
||||||
required: false
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
- name: LibsDisguises
|
|
||||||
required: false
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
load-after:
|
|
||||||
- name: eco
|
|
||||||
bootstrap: false
|
|
||||||
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
ecomobs.*:
|
|
||||||
description: All ecomobs permissions
|
|
||||||
default: op
|
|
||||||
children:
|
|
||||||
ecomobs.command.*: true
|
|
||||||
ecomobs.command.*:
|
|
||||||
description: All ecomobs commands
|
|
||||||
default: op
|
|
||||||
children:
|
|
||||||
ecomobs.command.ecomobs: true
|
|
||||||
ecomobs.command.reload: true
|
|
||||||
ecomobs.command.spawn: true
|
|
||||||
ecomobs.command.give: true
|
|
||||||
|
|
||||||
ecomobs.command.ecomobs:
|
|
||||||
description: Allows the use of /ecomobs
|
|
||||||
default: true
|
|
||||||
|
|
||||||
ecomobs.command.give:
|
|
||||||
description: Allows the use of /ecomobs give
|
|
||||||
default: op
|
|
||||||
|
|
||||||
ecomobs.command.spawn:
|
|
||||||
description: Allows the use of /ecomobs spawn
|
|
||||||
default: op
|
|
||||||
|
|
||||||
ecomobs.command.killall:
|
|
||||||
description: Allows the use of /ecomobs killall
|
|
||||||
default: op
|
|
||||||
|
|
||||||
ecomobs.command.reload:
|
|
||||||
description: Allows the use of /ecomobs reload
|
|
||||||
default: op
|
|
||||||
@@ -13,5 +13,3 @@ rootProject.name = "EcoMobs"
|
|||||||
// Core
|
// Core
|
||||||
include(":eco-core")
|
include(":eco-core")
|
||||||
include(":eco-core:core-plugin")
|
include(":eco-core:core-plugin")
|
||||||
include(":eco-core:core-nms")
|
|
||||||
include(":eco-core:core-nms:v1_20_R1")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user