Updated CrystalKeyCreate plugin to listener

This commit is contained in:
Byte
2022-10-17 17:15:50 -06:00
committed by Ryan
parent 7b1a9f1efa
commit 32931ef85c
2 changed files with 33 additions and 46 deletions
@@ -1,46 +0,0 @@
package core.game.interaction.item.withitem;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used to handle the creation of a crystal key.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class CrystalKeyCreatePlugin extends UseWithHandler {
/**
* Represents the crystal key item.
*/
private static final Item KEY = new Item(989, 1);
/**
* Constructs a new {@code CrystalKeyCreatePlugin} {@code Object}.
*/
public CrystalKeyCreatePlugin() {
super(985);
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
if (player.getInventory().remove(event.getBaseItem(), event.getUsedItem())) {
player.getInventory().add(KEY);
player.getPacketDispatch().sendMessage("You join the loop half of a key and the tooth half of a key to make a crystal key.");
}
return true;
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
addHandler(987, ITEM_TYPE, this);
return this;
}
}
@@ -0,0 +1,33 @@
package rs09.game.interaction.item.withitem
import api.addItem
import api.removeItem
import api.sendMessage
import org.rs09.consts.Items
import rs09.game.interaction.IntType
import rs09.game.interaction.InteractionListener
/**
* Listener for creating a crystal key
* @author Byte
*/
@Suppress("unused")
class CrystalKeyCreateListener : InteractionListener {
override fun defineListeners() {
onUseWith(IntType.ITEM, Items.LOOP_HALF_OF_A_KEY_987, Items.TOOTH_HALF_OF_A_KEY_985) { player, used, with ->
if (!removeItem(player, used)) {
return@onUseWith false
}
if (!removeItem(player, with)) {
return@onUseWith false
}
addItem(player, Items.CRYSTAL_KEY_989)
sendMessage(player, "You join the loop half of a key and the tooth half of a key to make a crystal key.")
return@onUseWith true
}
}
}