From 7462266756194ead3460f236fb2fe037cb6ad906 Mon Sep 17 00:00:00 2001 From: Byte Date: Sat, 22 Oct 2022 04:10:38 +0000 Subject: [PATCH] Updated SwampHoleRope plugin to listener (applies to Lumbridge swamp hole) --- .../item/withobject/SwampHoleRopePlugin.java | 48 ------------------- .../item/withobject/SwampHoleRopeListener.kt | 33 +++++++++++++ 2 files changed, 33 insertions(+), 48 deletions(-) delete mode 100644 Server/src/main/java/core/game/interaction/item/withobject/SwampHoleRopePlugin.java create mode 100644 Server/src/main/kotlin/rs09/game/interaction/item/withobject/SwampHoleRopeListener.kt diff --git a/Server/src/main/java/core/game/interaction/item/withobject/SwampHoleRopePlugin.java b/Server/src/main/java/core/game/interaction/item/withobject/SwampHoleRopePlugin.java deleted file mode 100644 index 9496efc4c..000000000 --- a/Server/src/main/java/core/game/interaction/item/withobject/SwampHoleRopePlugin.java +++ /dev/null @@ -1,48 +0,0 @@ -package core.game.interaction.item.withobject; - -import core.game.interaction.NodeUsageEvent; -import core.game.interaction.UseWithHandler; -import core.game.node.item.Item; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Represents the swamp hole rope plugin. - * @author 'Vexia - * @date 01/12/2013 - */ -@Initializable -public class SwampHoleRopePlugin extends UseWithHandler { - - /** - * Represents the rope item. - */ - private static final Item ROPE = new Item(954); - - /** - * Constructs a new {@code SwampHoleRopePlugin.java} {@code Object}. - */ - public SwampHoleRopePlugin() { - super(954); - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - addHandler(5947, OBJECT_TYPE, this); - return this; - } - - @Override - public boolean handle(NodeUsageEvent event) { - if (!event.getPlayer().getSavedData().getGlobalData().hasTiedLumbridgeRope()) { - if (event.getPlayer().getInventory().remove(ROPE)) { - event.getPlayer().getDialogueInterpreter().sendItemMessage(954, "You tie the rope to the top of the entrance and throw it down."); - event.getPlayer().getSavedData().getGlobalData().setLumbridgeRope(true); - } - } else { - event.getPlayer().getDialogueInterpreter().sendDialogue("There is already a rope tied to the entrance."); - } - return true; - } - -} diff --git a/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SwampHoleRopeListener.kt b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SwampHoleRopeListener.kt new file mode 100644 index 000000000..924366edb --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SwampHoleRopeListener.kt @@ -0,0 +1,33 @@ +package rs09.game.interaction.item.withobject + +import api.* +import org.rs09.consts.Items +import org.rs09.consts.Scenery +import rs09.game.interaction.IntType +import rs09.game.interaction.InteractionListener + +/** + * Listener for using rope on Lumbridge swamp hole + * @author Byte + */ +@Suppress("unused") +class SwampHoleRopeListener : InteractionListener { + + override fun defineListeners() { + onUseWith(IntType.SCENERY, Items.ROPE_954, Scenery.DARK_HOLE_5947) { player, used, _ -> + if (player.savedData.globalData.hasTiedLumbridgeRope()) { + sendDialogue(player, "There is already a rope tied to the entrance.") + return@onUseWith true + } + + if (!removeItem(player, used)) { + return@onUseWith false + } + + sendItemDialogue(player, used, "You tie the rope to the top of the entrance and throw it down.") + player.savedData.globalData.setLumbridgeRope(true) + + return@onUseWith true + } + } +}