From 4f7e07436b65b42d7b4d2c0bfeaddf2314483101 Mon Sep 17 00:00:00 2001 From: Byte Date: Wed, 26 Oct 2022 09:41:47 +0000 Subject: [PATCH] Updated SandSource plugin to listener --- .../item/withobject/SandSourcePlugin.java | 83 ------------------- .../item/withobject/SandSourceListener.kt | 49 +++++++++++ 2 files changed, 49 insertions(+), 83 deletions(-) delete mode 100644 Server/src/main/java/core/game/interaction/item/withobject/SandSourcePlugin.java create mode 100644 Server/src/main/kotlin/rs09/game/interaction/item/withobject/SandSourceListener.kt diff --git a/Server/src/main/java/core/game/interaction/item/withobject/SandSourcePlugin.java b/Server/src/main/java/core/game/interaction/item/withobject/SandSourcePlugin.java deleted file mode 100644 index a1e8fc329..000000000 --- a/Server/src/main/java/core/game/interaction/item/withobject/SandSourcePlugin.java +++ /dev/null @@ -1,83 +0,0 @@ -package core.game.interaction.item.withobject; - -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.game.system.task.Pulse; -import core.game.world.update.flag.context.Animation; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Represents the sand source plugin. - * @author 'Vexia - * @version 1.0 - */ -@Initializable -public final class SandSourcePlugin extends UseWithHandler { - - /** - * Represents the ids to use. - */ - private static final int[] IDS = new int[] { 2645, 10814 }; - - /** - * Represents the bucket to use. - */ - private static final Item BUCKET = new Item(1925); - - /** - * Represents the sand item. - */ - private static final Item SAND = new Item(1783); - - /** - * Represents the animation to use. - */ - private static final Animation ANIMATION = new Animation(832); - - /** - * Constructs a new {@code SandSourcePlugin} {@code Object}. - */ - public SandSourcePlugin() { - super(1925); - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - for (int i : IDS) { - addHandler(i, OBJECT_TYPE, this); - } - return this; - } - - @Override - public boolean handle(NodeUsageEvent event) { - handle(event.getPlayer()); - return true; - } - - /** - * Method used to handle the interaction. - * @param player the player. - */ - public final void handle(final Player player) { - player.getPulseManager().run(new Pulse(2, player) { - @Override - public boolean pulse() { - if (player.getInventory().remove(BUCKET)) { - player.animate(ANIMATION); - player.getPacketDispatch().sendMessage("You fill the bucket with sand."); - player.getInventory().add(SAND); - } - return !player.getInventory().containsItem(BUCKET); - } - - @Override - public void stop() { - super.stop(); - } - }); - } -} diff --git a/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SandSourceListener.kt b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SandSourceListener.kt new file mode 100644 index 000000000..c6b63006a --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/SandSourceListener.kt @@ -0,0 +1,49 @@ +package rs09.game.interaction.item.withobject + +import api.* +import core.game.system.task.Pulse +import core.game.world.update.flag.context.Animation +import org.rs09.consts.Items +import org.rs09.consts.Scenery +import rs09.game.interaction.IntType +import rs09.game.interaction.InteractionListener + +/** + * Listener for collecting buckets of sand from a sand pit + * @author Byte + */ +@Suppress("unused") +class SandSourceListener : InteractionListener { + + companion object { + private val ANIMATION = Animation(895) + + private val SAND_PITS = intArrayOf( + Scenery.SAND_PIT_2645, + Scenery.SAND_PIT_4373, + Scenery.SANDPIT_10814 + ) + } + + override fun defineListeners() { + onUseWith(IntType.SCENERY, Items.BUCKET_1925, *SAND_PITS) { player, used, _ -> + val numEmptyBuckets = amountInInventory(player, used.id) + + var animationTrigger = 0 + runTask(player, 2, numEmptyBuckets) { + if (removeItem(player, used)) { + if (animationTrigger % 2 == 0) { + animate(player, ANIMATION) + } + + sendMessage(player, "You fill the bucket with sand.") + addItem(player, Items.BUCKET_OF_SAND_1783) + } + + animationTrigger++ + } + + return@onUseWith true + } + } +}