Updated SwampHoleRope plugin to listener (applies to Lumbridge swamp hole)

This commit is contained in:
Byte
2022-10-22 04:10:38 +00:00
committed by Ryan
parent bb0ae3ad8d
commit 7462266756
2 changed files with 33 additions and 48 deletions
@@ -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<Object> 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;
}
}
@@ -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
}
}
}