From 86a25dd76f9a30b4da9da51e2b3a4a00458caf47 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Mon, 14 Aug 2023 14:14:38 +0000 Subject: [PATCH] Fixed issue where unequip listeners did not fire on death --- .../core/game/node/entity/player/Player.java | 9 +++++++ Server/src/test/kotlin/content/EquipTests.kt | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Server/src/main/core/game/node/entity/player/Player.java b/Server/src/main/core/game/node/entity/player/Player.java index 53c59f883..f65720d82 100644 --- a/Server/src/main/core/game/node/entity/player/Player.java +++ b/Server/src/main/core/game/node/entity/player/Player.java @@ -11,6 +11,7 @@ import core.game.container.impl.EquipmentContainer; import core.game.container.impl.InventoryListener; import core.game.dialogue.DialogueInterpreter; import core.game.interaction.InteractPlugin; +import core.game.interaction.InteractionListeners; import core.game.node.entity.Entity; import core.game.node.entity.combat.BattleState; import core.game.node.entity.combat.CombatStyle; @@ -54,6 +55,7 @@ import core.net.packet.context.SkillContext; import core.net.packet.out.BuildDynamicScene; import core.net.packet.out.SkillLevel; import core.net.packet.out.UpdateSceneGraph; +import core.plugin.Plugin; import core.tools.*; import kotlin.Unit; import kotlin.jvm.functions.Function1; @@ -654,6 +656,13 @@ public class Player extends Entity { GroundItemManager.create(new Item(526), getLocation(), k); final Container[] c = DeathTask.getContainers(this); + for (Item i : getEquipment().toArray()) { + if (i == null) continue; + InteractionListeners.run(i.getId(), this, i, false); + Plugin equipPlugin = i.getDefinition().getConfiguration("equipment", null); + if (equipPlugin != null) equipPlugin.fireEvent("unequip"); + } + boolean canCreateGrave = GraveController.allowGenerate(this); if (canCreateGrave) { Grave g = GraveController.produceGrave(GraveController.getGraveType(this)); diff --git a/Server/src/test/kotlin/content/EquipTests.kt b/Server/src/test/kotlin/content/EquipTests.kt index 83a781638..96a903a8a 100644 --- a/Server/src/test/kotlin/content/EquipTests.kt +++ b/Server/src/test/kotlin/content/EquipTests.kt @@ -2,6 +2,8 @@ package content import TestUtils import core.api.EquipmentSlot +import core.api.addItem +import core.api.impact import core.game.node.entity.skill.Skills import core.game.node.item.Item import org.junit.jupiter.api.Assertions @@ -11,6 +13,7 @@ import core.game.global.action.EquipHandler import core.game.interaction.InteractionListener import core.game.interaction.IntType import core.game.interaction.InteractionListeners +import core.game.node.entity.player.info.Rights class EquipTests { companion object { @@ -141,4 +144,26 @@ class EquipTests { Assertions.assertEquals(p.inventory.getSlot(Item(Items.ABYSSAL_WHIP_4151)), 25) Assertions.assertEquals(p.inventory.getSlot(Item(Items.RUNE_DEFENDER_8850)), 0) } + + @Test fun graveDeathWithEquippedItemShouldFireUnequipHooks() { + TestUtils.getMockPlayer("graveunequip").use {p -> + var hookFired = false + val tempHook = object : InteractionListener { + override fun defineListeners() { + onUnequip(Items.ABYSSAL_WHIP_4151) { player, node -> + hookFired = true + return@onUnequip true + } + } + } + + tempHook.defineListeners() + p.details.rights = Rights.REGULAR_PLAYER + addItem(p, Items.ABYSSAL_WHIP_4151, 28) + p.equipment.replace(Item(Items.ABYSSAL_WHIP_4151), EquipmentSlot.WEAPON.ordinal) + impact(p, p.skills.lifepoints) + TestUtils.advanceTicks(25, false) + Assertions.assertEquals(true, hookFired) + } + } }