diff --git a/2006Scape Server/libs/google-collect-1.0.jar b/2006Scape Server/libs/google-collect-1.0.jar new file mode 100644 index 00000000..a7abdbbd Binary files /dev/null and b/2006Scape Server/libs/google-collect-1.0.jar differ diff --git a/2006Scape Server/plugins/plugin/buttons/ButtonClick.kt b/2006Scape Server/plugins/plugin/buttons/ButtonClick.kt new file mode 100644 index 00000000..e66b89ce --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/ButtonClick.kt @@ -0,0 +1,17 @@ +package plugin.buttons + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.impl.ButtonActionEvent +import com.rs2.game.players.Player + + +abstract class ButtonClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ButtonActionEvent) { + execute(player, event) + } + + abstract fun execute(player : Player, event : ButtonActionEvent); + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/LogoutButton.kt b/2006Scape Server/plugins/plugin/buttons/gameframe/LogoutButton.kt new file mode 100644 index 00000000..e38bd1eb --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/LogoutButton.kt @@ -0,0 +1,20 @@ +package plugin.buttons.gameframe + +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ButtonActionEvent + +import com.rs2.game.players.Player +import plugin.buttons.ButtonClick + +@SubscribesTo(ButtonActionEvent::class) +class LogoutButton : ButtonClick() { + + override fun execute(player: Player, event: ButtonActionEvent) { + player.logout() + } + + override fun test(event: ButtonActionEvent): Boolean { + return event.button == 9154; + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/plugins.json b/2006Scape Server/plugins/plugin/buttons/gameframe/plugins.json new file mode 100644 index 00000000..9deacd8b --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/plugins.json @@ -0,0 +1,12 @@ +[ +{ + "name": "Logout Button", + "description": "The button for logging a player out.", + "group": "button", + "base": "plugin.buttons.gameframe.LogoutButton", + "authors": [ + "Vult-R" + ], + "version": 1.0 +} +] diff --git a/2006Scape Server/plugins/plugin/click/item/ItemFirstClick.kt b/2006Scape Server/plugins/plugin/click/item/ItemFirstClick.kt new file mode 100644 index 00000000..28425bda --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemFirstClick.kt @@ -0,0 +1,28 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemFirstClickEvent +import com.rs2.game.players.Player + + +@SubscribesTo(ItemFirstClickEvent::class) +class ItemFirstClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemFirstClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemClick#1] - Item: ${event.item}") + } + + when(event.item) { + + 4079 -> player.startAnimation(1457) // yo-yo + + } + + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/ItemOnItem.kt b/2006Scape Server/plugins/plugin/click/item/ItemOnItem.kt new file mode 100644 index 00000000..76e10611 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemOnItem.kt @@ -0,0 +1,25 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemOnItemEvent +import com.rs2.game.players.Player + +@SubscribesTo(ItemOnItemEvent::class) +class ItemOnItem : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemOnItemEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemOnItem] - used: ${event.used} with: ${event.usedWith}") + } + + if (event.used == 38 && event.usedWith == 590) { + player.itemAssistant.addItem(32, 1) + player.itemAssistant.deleteItem(38, 1) + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/ItemOnNpc.kt b/2006Scape Server/plugins/plugin/click/item/ItemOnNpc.kt new file mode 100644 index 00000000..b1b673a4 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemOnNpc.kt @@ -0,0 +1,21 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemOnNpcEvent +import com.rs2.game.npcs.NpcHandler +import com.rs2.game.players.Player + +@SubscribesTo(ItemOnNpcEvent::class) +class ItemOnNpc : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemOnNpcEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemOnNpc] - itemId: ${event.item} npcId: ${event.npc}") + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/ItemOnObject.kt b/2006Scape Server/plugins/plugin/click/item/ItemOnObject.kt new file mode 100644 index 00000000..b8e05364 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemOnObject.kt @@ -0,0 +1,30 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemOnObjectEvent +import com.rs2.game.items.impl.Fillables +import com.rs2.game.players.Player + + +@SubscribesTo(ItemOnObjectEvent::class) +class ItemOnObject : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemOnObjectEvent) { + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemOnObject] - itemId: ${event.item} objectId: ${event.gameObject} Location: x: ${player.objectX}, x: ${player.objectY}") + } + + if (Fillables.canFill(event.item, event.gameObject) && player.itemAssistant.playerHasItem(event.item)) { + //val amount = player.itemAssistant.getItemAmount(event.item) + player.itemAssistant.deleteItem(event.item, 1) + player.itemAssistant.addItem(Fillables.counterpart(event.item), 1) + player.packetSender.sendMessage(Fillables.fillMessage(event.item, event.gameObject)) + player.startAnimation(832) + return + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/ItemSecondClick.kt b/2006Scape Server/plugins/plugin/click/item/ItemSecondClick.kt new file mode 100644 index 00000000..c9be4e07 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemSecondClick.kt @@ -0,0 +1,27 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemSecondClickEvent +import com.rs2.game.players.Player + +@SubscribesTo(ItemSecondClickEvent::class) +class ItemSecondClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemSecondClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemClick#2] - ItemId: ${event.id}") + } + + when(event.id) { + + 4079 -> player.startAnimation(1459) //yo-yo + + } + + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/ItemThirdClick.kt b/2006Scape Server/plugins/plugin/click/item/ItemThirdClick.kt new file mode 100644 index 00000000..63600f00 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/ItemThirdClick.kt @@ -0,0 +1,28 @@ +package plugin.click.item + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ItemThirdClickEvent +import com.rs2.game.players.Player + +@SubscribesTo(ItemThirdClickEvent::class) +class ItemThirdClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ItemThirdClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[ItemClick#3] - ItemId: ${event.id}") + } + + when(event.id) { + + 4079 -> player.startAnimation(1460) //yo-yo + + + } + + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/item/plugins.json b/2006Scape Server/plugins/plugin/click/item/plugins.json new file mode 100644 index 00000000..c03e82fd --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/item/plugins.json @@ -0,0 +1,62 @@ +[ +{ + "name": "Item First Click", + "description": "The plugin for handling the first option of an item.", + "group": "click", + "base": "plugin.click.item.ItemFirstClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Item Second Click", + "description": "The plugin for handling the second option of an item.", + "group": "click", + "base": "plugin.click.item.ItemSecondClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Item Third Click", + "description": "The plugin for handling the third option of an item.", + "group": "click", + "base": "plugin.click.item.ItemThirdClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Item On Item", + "description": "The plugin for handling using an item on another item.", + "group": "item", + "base": "plugin.click.item.ItemOnItem", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Item On Npc", + "description": "The plugin for handling using an item on an npc.", + "group": "item", + "base": "plugin.click.item.ItemOnNpc", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Item On Object", + "description": "The plugin for handling using an item on a game object.", + "group": "item", + "base": "plugin.click.item.ItemOnObject", + "authors": [ + "Vult-R" + ], + "version": 1.0 +} +] \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/magic/MagicOnItem.kt b/2006Scape Server/plugins/plugin/click/magic/MagicOnItem.kt new file mode 100644 index 00000000..56ec141f --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/magic/MagicOnItem.kt @@ -0,0 +1,26 @@ +package plugin.click.magic + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.MagicOnItemEvent +import com.rs2.game.content.skills.smithing.Superheat +import com.rs2.game.players.Player + +@SubscribesTo(MagicOnItemEvent::class) +class MagicOnItem : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: MagicOnItemEvent) { + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[MagicOnItem] - ItemId: ${event.itemId} Slot: ${event.slot} SpellId: ${event.spellId}"); + } + + when(event.spellId) { + 1173 -> if (!Superheat.superHeatItem(player, event.itemId)) { + return; + } + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/magic/plugins.json b/2006Scape Server/plugins/plugin/click/magic/plugins.json new file mode 100644 index 00000000..f4d92d2b --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/magic/plugins.json @@ -0,0 +1,12 @@ +[ +{ + "name": "Magic On Item", + "description": "The plugin for handling using spells on items.", + "group": "magic", + "base": "plugin.click.magic.MagicOnItem", + "authors": [ + "Vult-R" + ], + "version": 1.0 +} +] \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/npc/NpcFirstClick.kt b/2006Scape Server/plugins/plugin/click/npc/NpcFirstClick.kt new file mode 100644 index 00000000..60cbb8f1 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/npc/NpcFirstClick.kt @@ -0,0 +1,35 @@ +package plugin.click.npc + +import com.rs2.GameConstants +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.NpcFirstClickEvent +import com.rs2.game.npcs.Npc +import com.rs2.game.players.Player +import com.rs2.util.Misc + + +@SubscribesTo(NpcFirstClickEvent::class) +class NpcFirstClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: NpcFirstClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= npc], [type = first], [id= ${event.npc}], [Type= ${event.npc}]"); + } + + when(event.npc) { + + 1,2,3,4,5,6 -> if (Misc.random(10) <= 5) { + player.dialogueHandler.sendDialogues(3869, player.npcType) + } else { + player.dialogueHandler.sendDialogues(3872, player.npcType) + } + + //else -> + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/npc/NpcSecondClick.kt b/2006Scape Server/plugins/plugin/click/npc/NpcSecondClick.kt new file mode 100644 index 00000000..75a77468 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/npc/NpcSecondClick.kt @@ -0,0 +1,30 @@ +package plugin.click.npc + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.NpcSecondClickEvent +import com.rs2.game.content.skills.thieving.Pickpocket +import com.rs2.game.players.Player + +@SubscribesTo(NpcSecondClickEvent::class) +class NpcSecondClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: NpcSecondClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= npc], [type = second], [id= ${event.npc}], [Type= ${event.npc}]"); + } + + if (Pickpocket.isNPC(player, player.npcType)) { + Pickpocket.attemptPickpocket(player, player.npcType) + return + } + + when(event.npc) { + + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/npc/NpcThirdClick.kt b/2006Scape Server/plugins/plugin/click/npc/NpcThirdClick.kt new file mode 100644 index 00000000..59304133 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/npc/NpcThirdClick.kt @@ -0,0 +1,24 @@ +package plugin.click.npc + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.NpcThirdClickEvent +import com.rs2.game.players.Player + +@SubscribesTo(NpcThirdClickEvent::class) +class NpcThirdClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: NpcThirdClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= npc], [type = third], [id= ${event.npc}], [Type= ${event.npc}]"); + } + + when(event.npc) { + + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/npc/plugins.json b/2006Scape Server/plugins/plugin/click/npc/plugins.json new file mode 100644 index 00000000..9e18cbad --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/npc/plugins.json @@ -0,0 +1,32 @@ +[ + { + "name": "Npc First Click", + "description": "The plugin for handling the first option of an npc.", + "group": "click", + "base": "plugin.click.npc.NpcFirstClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 + }, + { + "name": "Npc Second Click", + "description": "The plugin for handling the second option of an npc.", + "group": "click", + "base": "plugin.click.npc.NpcSecondClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 + }, + { + "name": "Npc Third Click", + "description": "The plugin for handling the third option of an npc.", + "group": "click", + "base": "plugin.click.npc.NpcThirdClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 + } +] \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/obj/ObjectFirstClick.kt b/2006Scape Server/plugins/plugin/click/obj/ObjectFirstClick.kt new file mode 100644 index 00000000..57ccda36 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/obj/ObjectFirstClick.kt @@ -0,0 +1,31 @@ +package plugin.click.obj + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ObjectFirstClickEvent +import com.rs2.game.content.skills.core.Mining +import com.rs2.game.players.Player + +@SubscribesTo(ObjectFirstClickEvent::class) +class ObjectFirstClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ObjectFirstClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= object], [type= first], [id= ${player.objectId}], [location= x:${player.objectX} y:${player.objectY} ]") + } + + // if its a rock we can mine, mine it + if (Mining.rockExists(event.gameObject)) { + player.mining.startMining(player, event.gameObject, player.objectX, player.objectY, player.clickObjectType) + return + } + + when (event.gameObject) { + + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/obj/ObjectFourthClick.kt b/2006Scape Server/plugins/plugin/click/obj/ObjectFourthClick.kt new file mode 100644 index 00000000..37e454e0 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/obj/ObjectFourthClick.kt @@ -0,0 +1,31 @@ +package plugin.click.obj + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ObjectFourthClickEvent +import com.rs2.game.content.skills.farming.Farming +import com.rs2.game.players.Player +import com.rs2.world.clip.Region + +@SubscribesTo(ObjectFourthClickEvent::class) +class ObjectFourthClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ObjectFourthClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= object], [type= fourth], [id= ${player.objectId}], [location= x:${player.objectX} y:${player.objectY} ], [PLUGIN]"); + } + + if (!Region.objectExists(player.objectId, player.objectX, player.objectY, player.heightLevel)) { + return + } + + Farming.guide(player, player.objectX, player.objectY) + + when (event.gameObject) { + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/obj/ObjectSecondClick.kt b/2006Scape Server/plugins/plugin/click/obj/ObjectSecondClick.kt new file mode 100644 index 00000000..fd95ac9e --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/obj/ObjectSecondClick.kt @@ -0,0 +1,30 @@ +package plugin.click.obj + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ObjectSecondClickEvent +import com.rs2.game.content.skills.thieving.Stalls +import com.rs2.game.players.Player + +@SubscribesTo(ObjectSecondClickEvent::class) +class ObjectSecondClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ObjectSecondClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= object], [type= second], [id= ${player.objectId}], [location= x:${player.objectX} y:${player.objectY} ]"); + } + + if (Stalls.isObject(event.gameObject)) { + Stalls.attemptStall(player, event.gameObject, player.objectX, player.objectY) + return + } + + when (event.gameObject) { + + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/obj/ObjectThirdClick.kt b/2006Scape Server/plugins/plugin/click/obj/ObjectThirdClick.kt new file mode 100644 index 00000000..418235f9 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/obj/ObjectThirdClick.kt @@ -0,0 +1,30 @@ +package plugin.click.obj + +import com.rs2.event.EventContext +import com.rs2.event.EventSubscriber +import com.rs2.event.SubscribesTo +import com.rs2.event.impl.ObjectThirdClickEvent +import com.rs2.game.content.skills.thieving.Stalls +import com.rs2.game.players.Player + +@SubscribesTo(ObjectThirdClickEvent::class) +class ObjectThirdClick : EventSubscriber { + + override fun subscribe(context: EventContext, player: Player, event: ObjectThirdClickEvent) { + + if (player.playerRights >= 3) { + player.packetSender.sendMessage("[click= object], [type= third], [id= ${player.objectId}], [location= x:${player.objectX} y:${player.objectY} ], [PLUGIN]"); + } + + if (Stalls.isObject(event.gameObject)) { + Stalls.attemptStall(player, event.gameObject, player.objectX, player.objectY) + return + } + + when (event.gameObject) { + 10177 -> player.playerAssistant.movePlayer(1798, 4407, 3); + } + + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/click/obj/plugins.json b/2006Scape Server/plugins/plugin/click/obj/plugins.json new file mode 100644 index 00000000..4e7946d0 --- /dev/null +++ b/2006Scape Server/plugins/plugin/click/obj/plugins.json @@ -0,0 +1,42 @@ +[ +{ + "name": "Object First Click", + "description": "The plugin for handling the first option of an object.", + "group": "click", + "base": "plugin.click.obj.ObjectFirstClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Object Second Click", + "description": "The plugin for handling the second option of an object.", + "group": "click", + "base": "plugin.click.obj.ObjectSecondClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Object Third Click", + "description": "The plugin for handling the third option of an object.", + "group": "click", + "base": "plugin.click.obj.ObjectThirdClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +}, +{ + "name": "Object Fourth Click", + "description": "The plugin for handling the fourth option of an object.", + "group": "click", + "base": "plugin.click.obj.ObjectFourthClick", + "authors": [ + "Vult-R" + ], + "version": 1.0 +} +] \ No newline at end of file diff --git a/2006Scape Server/pom.xml b/2006Scape Server/pom.xml index bd2d866b..b6e7b888 100644 --- a/2006Scape Server/pom.xml +++ b/2006Scape Server/pom.xml @@ -145,6 +145,11 @@ system ${project.basedir}/libs/everythingrs-api.jar + + com.google.collections + google-collections + 1.0 + diff --git a/2006Scape Server/src/main/java/com/rs2/GameEngine.java b/2006Scape Server/src/main/java/com/rs2/GameEngine.java index c576ae13..21b3e1f2 100644 --- a/2006Scape Server/src/main/java/com/rs2/GameEngine.java +++ b/2006Scape Server/src/main/java/com/rs2/GameEngine.java @@ -201,6 +201,11 @@ public class GameEngine { startMinutesCounter(); setMinutesCounter(minutesCounter); + /** + * Load Plugins + */ + Player.getPluginService().load(); + /** * Server Successfully Loaded */ diff --git a/2006Scape Server/src/main/java/com/rs2/event/Event.java b/2006Scape Server/src/main/java/com/rs2/event/Event.java new file mode 100644 index 00000000..595fd58c --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/Event.java @@ -0,0 +1,15 @@ +package com.rs2.event; + +/** + * Something that happens; an occurrence. + * + *

+ * An event is characterized by having a type and relative information about + * each occurrence of the event. + *

+ * + * @author Ryley Kimmel + */ +public interface Event { + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/EventContext.java b/2006Scape Server/src/main/java/com/rs2/event/EventContext.java new file mode 100644 index 00000000..97c54609 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/EventContext.java @@ -0,0 +1,28 @@ +package com.rs2.event; + +/** + * Represents the context of an {@link Event} + * + * @author Ryley Kimmel + */ +public interface EventContext { + + /** + * Breaks the chain of subscribers. + */ + void breakSubscriberChain(); + + /** + * Repairs the chain of subscribers. + */ + void repairSubscriberChain(); + + /** + * Checks whether or not the subscriber chain is broken. + * + * @return {@code true} if and only if the chain is broken, otherwise + * {@code false}. + */ + boolean isChainBroken(); + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/EventProvider.java b/2006Scape Server/src/main/java/com/rs2/event/EventProvider.java new file mode 100644 index 00000000..97049c5f --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/EventProvider.java @@ -0,0 +1,36 @@ +package com.rs2.event; + +import com.rs2.game.players.Player; + +/** + * An event provider provides support for dynamic {@link Event} posting, + * depriving and providing {@link EventSubscriber}s + * + * @author Ryley Kimmel + */ +public interface EventProvider { + + /** + * Provides an {@link EventSubscriber} for the specified event. + * + * @param subscriber The subscriber to provide. + */ + void provideSubscriber(EventSubscriber subscriber); + + /** + * Deprives an {@link EventSubscriber} for the specified event. + * + * @param subscriber The subscriber to deprive. + */ + void depriveSubscriber(EventSubscriber subscriber); + + /** + * Posts an {@link Event}, notifying all provided subscribers. + * + * @param The event type reference. + * @param player The player to post the event for. + * @param event The event to post. + */ + void post(Player player, E event); + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/EventSubscriber.java b/2006Scape Server/src/main/java/com/rs2/event/EventSubscriber.java new file mode 100644 index 00000000..765aa6bf --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/EventSubscriber.java @@ -0,0 +1,32 @@ +package com.rs2.event; + +import com.rs2.game.players.Player; + +import java.util.function.Predicate; + +/** + * Represents a single subscriber for some {@link Event}. + * + * @author Ryley Kimmel + * + * @param The type of event to the subscriber. + */ +@FunctionalInterface +public interface EventSubscriber extends Predicate { + + /** + * A handler method which executes event specific logic if and only if + * {@link #test(Event)} returns {@code true}. + * + * @param context The context of the event. + * @param player The player to subscribe the event for. + * @param event The event to subscribe. + */ + void subscribe(EventContext context, Player player, E event); + + @Override + default boolean test(E event) { + return true; + } + +} \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/event/SubscribesTo.java b/2006Scape Server/src/main/java/com/rs2/event/SubscribesTo.java new file mode 100644 index 00000000..99e3d010 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/SubscribesTo.java @@ -0,0 +1,30 @@ +package com.rs2.event; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicates that types annotated are an {@link EventSubscriber} and subscribe + * to one specific {@link Event}. {@link #value()} enforces that the specified + * event value is indeed an event. All event subscribers MUST be annotated + * otherwise {@link EventProvider}s will be unable to provide and deprive + * subscribers. + * + * @author Ryley Kimmel + */ +@Documented +@Retention(RUNTIME) +@Target(TYPE) +public @interface SubscribesTo { + + /** + * Returns the event class that the annotated {@link EventSubscriber} + * subscribes to. + */ + Class value(); + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/UniversalEventContext.java b/2006Scape Server/src/main/java/com/rs2/event/UniversalEventContext.java new file mode 100644 index 00000000..18acf92b --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/UniversalEventContext.java @@ -0,0 +1,30 @@ +package com.rs2.event; + +/** + * An universal implementation of an {@link EventContext}. + * + * @author Ryley Kimmel + */ +public final class UniversalEventContext implements EventContext { + + /** + * A flag denoting whether or not the subscriber chain is broken. + */ + private boolean chainBroken; + + @Override + public void breakSubscriberChain() { + chainBroken = true; + } + + @Override + public void repairSubscriberChain() { + chainBroken = false; + } + + @Override + public boolean isChainBroken() { + return chainBroken; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/UniversalEventProvider.java b/2006Scape Server/src/main/java/com/rs2/event/UniversalEventProvider.java new file mode 100644 index 00000000..13c3f1cd --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/UniversalEventProvider.java @@ -0,0 +1,71 @@ +package com.rs2.event; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.rs2.game.players.Player; +import com.rs2.util.ClassUtils; + +import java.util.Collection; +import java.util.Optional; +import java.util.function.Consumer; + +/** + * A universal event provider which posts, provides and deprives subscribers. + * + * @author Ryley Kimmel + */ +public final class UniversalEventProvider implements EventProvider { + + /** + * A {@link Multimap} of {@link Event} classes to subscribers. + */ + private final Multimap, EventSubscriber> events = ArrayListMultimap.create(); + + /** + * The universal context of this event provider. + */ + private final EventContext context = new UniversalEventContext(); + + @SuppressWarnings("unchecked") + @Override + public void provideSubscriber(EventSubscriber subscriber) { + checkSubscriber(subscriber, annotation -> events.put(annotation.value(), (EventSubscriber) subscriber)); + } + + @SuppressWarnings("unchecked") + @Override + public void depriveSubscriber(EventSubscriber subscriber) { + checkSubscriber(subscriber, annotation -> events.remove(annotation.value(), (EventSubscriber) subscriber)); + } + + private void checkSubscriber(EventSubscriber subscriber, Consumer consumer) { + Optional optional = ClassUtils.getAnnotation(subscriber.getClass(), SubscribesTo.class); + Preconditions.checkArgument(optional.isPresent(), String.format("%s is not annotated with @SubscribesTo", subscriber.getClass())); + consumer.accept(optional.get()); + } + + @Override + public void post(Player player, E event) { + Collection> subscribers = events.get(event.getClass()); + + for (EventSubscriber subscriber : subscribers) { + /* Check to be sure we can subscribe to the event. */ + if (subscriber.test(event)) { + subscriber.subscribe(context, player, event); + + /* If the chain is broken, don't continue parsing subscribers. */ + if (context.isChainBroken()) { + break; + } + } + } + + context.repairSubscriberChain(); + } + + public Multimap, EventSubscriber> getEvents() { + return events; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ButtonActionEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ButtonActionEvent.java new file mode 100644 index 00000000..3176bf0d --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ButtonActionEvent.java @@ -0,0 +1,34 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; + +/** + * An event which manages button actions. + * + * @author Ryley Kimmel + */ +public final class ButtonActionEvent implements Event { + + /** + * The id of the button. + */ + private final int button; + + /** + * Constructs a new {@link ButtonActionEvent} with the specified button id. + * + * @param button The buttons id. + */ + public ButtonActionEvent(int button) { + this.button = button; + } + + /** + * Returns the buttons id. + */ + public int getButton() { + return button; + } + +} \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/CommandEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/CommandEvent.java new file mode 100644 index 00000000..45bf1181 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/CommandEvent.java @@ -0,0 +1,43 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +/** + * Represents a command event. + * + * @author Vult-R + */ +public final class CommandEvent implements Event { + + /** + * The name for this command. + */ + private final String name; + + /** + * The input for this command. + */ + private final String input; + + /** + * Creates the command. + */ + public CommandEvent(String name, String input) { + this.name = name; + this.input = input; + } + + /** + * Gets the name of this command. + */ + public String getName() { + return name; + } + + /** + * Gets the input for this command. + */ + public String getInput() { + return input; + } +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/DialogueEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/DialogueEvent.java new file mode 100644 index 00000000..0ae0f423 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/DialogueEvent.java @@ -0,0 +1,7 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public class DialogueEvent implements Event { + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/DoorEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/DoorEvent.java new file mode 100644 index 00000000..a1c9bb2d --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/DoorEvent.java @@ -0,0 +1,18 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class DoorEvent implements Event { + + private GameObject door; + + public DoorEvent(GameObject door) { + this.door = door; + } + + public GameObject getDoor() { + return door; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemFirstClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemFirstClickEvent.java new file mode 100644 index 00000000..f0715cbd --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemFirstClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.game.items.Item; + +public final class ItemFirstClickEvent implements Event { + + private final int item; + + public ItemFirstClickEvent(int item) { + this.item = item; + } + + public int getItem() { + return item; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnGroundItemEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnGroundItemEvent.java new file mode 100644 index 00000000..4e00166e --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnGroundItemEvent.java @@ -0,0 +1,34 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.game.items.Item; +import com.rs2.game.players.Position; + +public final class ItemOnGroundItemEvent implements Event { + + private final Item used; + + private final Item groundItem; + + private final Position position; + + public ItemOnGroundItemEvent(Item used, Item groundItem, Position position) { + this.used = used; + this.groundItem = groundItem; + this.position = position; + } + + public Item getUsed() { + return used; + } + + public Item getGroundItem() { + return groundItem; + } + + public Position getPosition() { + return position; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnItemEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnItemEvent.java new file mode 100644 index 00000000..e8ad53a0 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnItemEvent.java @@ -0,0 +1,25 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.game.items.Item; + +public final class ItemOnItemEvent implements Event { + + private final int used; + + private final int with; + + public ItemOnItemEvent(int used, int with) { + this.used = used; + this.with = with; + } + + public int getUsed() { + return used; + } + + public int getUsedWith() { + return with; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnNpcEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnNpcEvent.java new file mode 100644 index 00000000..4e73034a --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnNpcEvent.java @@ -0,0 +1,33 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.game.items.Item; +import com.rs2.game.npcs.Npc; + +public final class ItemOnNpcEvent implements Event { + + private final int item; + + private final int npc; + + private final int clicked; + + public ItemOnNpcEvent(int item, int npc, int clicked) { + this.item = item; + this.npc = npc; + this.clicked = clicked; + } + + public int getItem() { + return item; + } + + public int getNpc() { + return npc; + } + + public int getNpcClicked() { + return clicked; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnObjectEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnObjectEvent.java new file mode 100644 index 00000000..4c9dd75e --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnObjectEvent.java @@ -0,0 +1,26 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.game.items.Item; +import com.rs2.world.GameObject; + +public final class ItemOnObjectEvent implements Event { + + private final int item; + + private final int gameObject; + + public ItemOnObjectEvent(int item, int gameObject) { + this.item = item; + this.gameObject = gameObject; + } + + public int getItem() { + return item; + } + + public int getGameObject() { + return gameObject; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnPlayerEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnPlayerEvent.java new file mode 100644 index 00000000..f060a044 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemOnPlayerEvent.java @@ -0,0 +1,26 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.game.items.Item; +import com.rs2.game.players.Player; + +public final class ItemOnPlayerEvent implements Event { + + private final Item used; + + private final Player usedWith; + + public ItemOnPlayerEvent(Item used, Player usedWith) { + this.used = used; + this.usedWith = usedWith; + } + + public Item getUsed() { + return used; + } + + public Player getUsedWith() { + return usedWith; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemSecondClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemSecondClickEvent.java new file mode 100644 index 00000000..8336a298 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemSecondClickEvent.java @@ -0,0 +1,18 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class ItemSecondClickEvent implements Event { + + + private final int id; + + public ItemSecondClickEvent(int id) { + this.id = id; + } + + public int getId() { + return id; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ItemThirdClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemThirdClickEvent.java new file mode 100644 index 00000000..230a3111 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ItemThirdClickEvent.java @@ -0,0 +1,17 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class ItemThirdClickEvent implements Event { + + private final int id; + + public ItemThirdClickEvent(int id) { + this.id = id; + } + + public int getId() { + return id; + } + +} \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/MagicOnItemEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/MagicOnItemEvent.java new file mode 100644 index 00000000..44c1df1e --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/MagicOnItemEvent.java @@ -0,0 +1,32 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class MagicOnItemEvent implements Event { + + private final int itemId; + + private final int slot; + + + private final int spellId; + + public MagicOnItemEvent(int itemId, int slot, int spellId) { + this.itemId = itemId; + this.slot = slot; + this.spellId = spellId; + } + + public int getItemId() { + return itemId; + } + + public int getSlot() { + return slot; + } + + public int getSpellId() { + return spellId; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java new file mode 100644 index 00000000..54a3699b --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcFirstClickEvent.java @@ -0,0 +1,16 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class NpcFirstClickEvent implements Event { + private final int npc; + + public NpcFirstClickEvent(int npc) { + this.npc = npc; + } + + public int getNpc() { + return npc; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/NpcSecondClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcSecondClickEvent.java new file mode 100644 index 00000000..925b0f7c --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcSecondClickEvent.java @@ -0,0 +1,18 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.game.npcs.Npc; + +public final class NpcSecondClickEvent implements Event { + + private final int npc; + + public NpcSecondClickEvent(int npc) { + this.npc = npc; + } + + public int getNpc() { + return npc; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/NpcThirdClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcThirdClickEvent.java new file mode 100644 index 00000000..873b6d29 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/NpcThirdClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.game.npcs.Npc; + +public final class NpcThirdClickEvent implements Event { + + private final int npc; + + public NpcThirdClickEvent(int npc) { + this.npc = npc; + } + + public int getNpc() { + return npc; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFifthClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFifthClickEvent.java new file mode 100644 index 00000000..b0a205ed --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFifthClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class ObjectFifthClickEvent implements Event { + + private final GameObject gameObject; + + public ObjectFifthClickEvent(GameObject gameObject) { + this.gameObject = gameObject; + } + + public GameObject getGameObject() { + return gameObject; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFirstClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFirstClickEvent.java new file mode 100644 index 00000000..b4365acc --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFirstClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class ObjectFirstClickEvent implements Event { + + private final int gameObject; + + public ObjectFirstClickEvent(int gameObject) { + this.gameObject = gameObject; + } + + public int getGameObject() { + return gameObject; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFourthClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFourthClickEvent.java new file mode 100644 index 00000000..61015c38 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectFourthClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class ObjectFourthClickEvent implements Event { + + private final int gameObject; + + public ObjectFourthClickEvent(int gameObject) { + this.gameObject = gameObject; + } + + public int getGameObject() { + return gameObject; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectSecondClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectSecondClickEvent.java new file mode 100644 index 00000000..bdb583a9 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectSecondClickEvent.java @@ -0,0 +1,19 @@ +package com.rs2.event.impl; + + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class ObjectSecondClickEvent implements Event { + + private final int gameObject; + + public ObjectSecondClickEvent(int gameObject) { + this.gameObject = gameObject; + } + + public int getGameObject() { + return gameObject; + } + +} \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectThirdClickEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectThirdClickEvent.java new file mode 100644 index 00000000..750de353 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/ObjectThirdClickEvent.java @@ -0,0 +1,18 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; +import com.rs2.world.GameObject; + +public final class ObjectThirdClickEvent implements Event { + + private final int gameObject; + + public ObjectThirdClickEvent(int gameObject) { + this.gameObject = gameObject; + } + + public int getGameObject() { + return gameObject; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFirstOptionEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFirstOptionEvent.java new file mode 100644 index 00000000..f3fed6a1 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFirstOptionEvent.java @@ -0,0 +1,31 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class WidgetContainerFirstOptionEvent implements Event { + + private final int widgetId; + + private final int itemSlot; + + private final int itemId; + + public WidgetContainerFirstOptionEvent(int widgetId, int itemId, int itemSlot) { + this.widgetId = widgetId; + this.itemId = itemId; + this.itemSlot = itemSlot; + } + + public int getWidgetId() { + return widgetId; + } + + public int getItemSlot() { + return itemSlot; + } + + public int getItemId() { + return itemId; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFourthOptionEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFourthOptionEvent.java new file mode 100644 index 00000000..dba38f32 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerFourthOptionEvent.java @@ -0,0 +1,31 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class WidgetContainerFourthOptionEvent implements Event { + + private final int widgetId; + + private final int itemSlot; + + private final int itemId; + + public WidgetContainerFourthOptionEvent(int widgetId, int itemId, int itemSlot) { + this.widgetId = widgetId; + this.itemId = itemId; + this.itemSlot = itemSlot; + } + + public int getWidgetId() { + return widgetId; + } + + public int getItemSlot() { + return itemSlot; + } + + public int getItemId() { + return itemId; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerSecondOptionEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerSecondOptionEvent.java new file mode 100644 index 00000000..dff7b464 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerSecondOptionEvent.java @@ -0,0 +1,31 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class WidgetContainerSecondOptionEvent implements Event { + + private final int widgetId; + + private final int itemSlot; + + private final int itemId; + + public WidgetContainerSecondOptionEvent(int widgetId, int itemId, int itemSlot) { + this.widgetId = widgetId; + this.itemId = itemId; + this.itemSlot = itemSlot; + } + + public int getWidgetId() { + return widgetId; + } + + public int getItemSlot() { + return itemSlot; + } + + public int getItemId() { + return itemId; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerThirdOptionEvent.java b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerThirdOptionEvent.java new file mode 100644 index 00000000..16471c80 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/event/impl/WidgetContainerThirdOptionEvent.java @@ -0,0 +1,31 @@ +package com.rs2.event.impl; + +import com.rs2.event.Event; + +public final class WidgetContainerThirdOptionEvent implements Event { + + private final int widgetId; + + private final int itemSlot; + + private final int itemId; + + public WidgetContainerThirdOptionEvent(int widgetId, int itemId, int itemSlot) { + this.widgetId = widgetId; + this.itemId = itemId; + this.itemSlot = itemSlot; + } + + public int getWidgetId() { + return widgetId; + } + + public int getItemSlot() { + return itemSlot; + } + + public int getItemId() { + return itemId; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/game/items/UseItem.java b/2006Scape Server/src/main/java/com/rs2/game/items/UseItem.java index f575154e..ea2b9c0a 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/items/UseItem.java +++ b/2006Scape Server/src/main/java/com/rs2/game/items/UseItem.java @@ -1,5 +1,6 @@ package com.rs2.game.items; +import com.rs2.event.impl.ItemOnItemEvent; import com.rs2.GameConstants; import com.rs2.game.content.skills.cooking.Cooking; import com.rs2.game.content.skills.crafting.BattleStaffs; @@ -121,6 +122,8 @@ public class UseItem { } public static void itemOnItem(Player player, int itemUsed, int useWith) { + player.post(new ItemOnItemEvent(itemUsed, useWith)); + player.post(new ItemOnItemEvent(useWith, itemUsed)); LogCuttingInterface.handleItemOnItem(player, itemUsed, useWith); ArrowMaking.makeArrow(player, itemUsed, useWith); Stringing.StringBow(player, itemUsed, useWith); @@ -218,11 +221,11 @@ public class UseItem { player.getItemAssistant().deleteItem(327, 1); player.getItemAssistant().addItem(1552, 1); } - if (itemUsed == 38 && useWith == 590 || useWith == 38 + /*f (itemUsed == 38 && useWith == 590 || useWith == 38 && itemUsed == 590) {// player.getItemAssistant().addItem(32, 1); player.getItemAssistant().deleteItem(38, 1); - } + }*/ if (itemUsed == 36 && useWith == 590 || useWith == 36 && itemUsed == 590) { player.getItemAssistant().addItem(33, 1); diff --git a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java index f9562466..5ad15959 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java +++ b/2006Scape Server/src/main/java/com/rs2/game/npcs/NpcActions.java @@ -40,20 +40,6 @@ public class NpcActions { } } switch (npcType) { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: //1-3 Man, 4-6 Woman - We are playing random dialogues here - if (Misc.random(10) <= 5) - { - player.getDialogueHandler().sendDialogues(3869, npcType); - } - else { - player.getDialogueHandler().sendDialogues(3872, npcType); - } - break; case 389 : //thormac player.getDialogueHandler().sendDialogues(3574, npcType); break; @@ -1064,10 +1050,6 @@ public class NpcActions { player.rememberNpcIndex = player.npcClickIndex; player.npcClickIndex = 0; Shops.openShop(player, npcType); - if (Pickpocket.isNPC(player, npcType)) { - Pickpocket.attemptPickpocket(player, npcType); - return; - } if (Fishing.fishingNPC(player, npcType)) { Fishing.fishingNPC(player, 2, npcType); } @@ -1083,13 +1065,9 @@ public class NpcActions { player.getFarmingTools().loadInterfaces(); break; - case 3: - player.getDialogueHandler().sendDialogues(5, npcType); - break; - - case 209: + /*case 209: player.getShopAssistant().openShop(144); - break; + break;*/ case 2437: diff --git a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java index b3f0b182..2c65002c 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java +++ b/2006Scape Server/src/main/java/com/rs2/game/objects/ObjectsActions.java @@ -115,10 +115,7 @@ public class ObjectsActions { PassDoor.processDoor(player, objectType); AbyssalHandler.handleAbyssalTeleport(player, objectType); OpenObject.interactObject(player, objectType); - // if its a rock we can mine, mine it - if (Mining.rockExists(objectType)) - player.getMining().startMining(player, objectType, player.objectX, player.objectY, player.clickObjectType); - if (Stalls.isObject(objectType)) { + if (Stalls.isObject(objectType)) { Stalls.attemptStall(player, objectType, objectX, objectY); return; } @@ -2775,10 +2772,6 @@ public class ObjectsActions { if (!Region.objectExists(objectType, obX, obY, player.heightLevel)) { return; } - if (Stalls.isObject(objectType)) { - Stalls.attemptStall(player, objectType, obX, obY); - return; - } if (Farming.inspectObject(player, obX, obY)) { return; } @@ -3052,10 +3045,6 @@ public class ObjectsActions { if (!Region.objectExists(objectType, obX, obY, player.heightLevel)) { return; } - if (Stalls.isObject(objectType)) { - Stalls.attemptStall(player, objectType, obX, obY); - return; - } OpenObject.interactObject(player, objectType); switch (objectType) { case 6: @@ -3073,9 +3062,6 @@ public class ObjectsActions { Climbing.climbDown(player); } break; - case 10177: - player.getPlayerAssistant().movePlayer(1798, 4407, 3); - break; case 11890: Climbing.handleClimbing(player); break; @@ -3098,6 +3084,5 @@ public class ObjectsActions { if (!Region.objectExists(objectType, obX, obY, player.heightLevel)) { return; } - Farming.guide(player, obX, obY); } } diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java index f584f640..348e603b 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/Player.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/Player.java @@ -9,12 +9,11 @@ import java.util.Map; import java.util.Queue; import com.everythingrs.hiscores.Hiscores; +import com.rs2.event.*; +import com.rs2.plugin.PluginService; import org.apache.mina.common.IoSession; import com.rs2.GameConstants; import com.rs2.GameEngine; -import com.rs2.event.CycleEvent; -import com.rs2.event.CycleEventContainer; -import com.rs2.event.CycleEventHandler; import com.rs2.game.content.BankPin; import com.rs2.game.content.EmoteHandler; import com.rs2.game.content.combat.CombatAssistant; @@ -166,7 +165,7 @@ public abstract class Player { private SingleGates singleGates = new SingleGates(); private DoubleGates doubleGates = new DoubleGates(); public int lastMainFrameInterface = -1; //Possibly used in future to prevent packet exploits - + public boolean isPreaching() { return preaching; } @@ -742,6 +741,68 @@ public abstract class Player { } } + /** + * This worlds event provider. + */ + private static final UniversalEventProvider eventProvider = new UniversalEventProvider(); + + /** + * The service for plugins. + */ + private static final PluginService pluginService = new PluginService(); + + /** + * Posts an event to this worlds event provider. + * + * @param player + * The player to post the event for. + * @param event + * The event to post. + */ + public void post(Player player, E event) { + eventProvider.post(player, event); + } + + /** + * Posts an event to this world's event provider. + * + * @param event + * The event to post. + */ + public void post(E event) { + post(this, event); + } + + /** + * Provides an event subscriber to this worlds event provider. + * + * @param subscriber + * The event subscriber. + */ + public static void provideSubscriber(EventSubscriber subscriber) { + eventProvider.provideSubscriber(subscriber); + } + + /** + * Deprives an event subscriber to this worlds event provider. + * + * @param subscriber + * The event subscriber. + */ + public void depriveSubscriber(EventSubscriber subscriber) { + eventProvider.depriveSubscriber(subscriber); + } + + /** + * Gets the service for plugins. + */ + public static PluginService getPluginService() { + return pluginService; + } + + public UniversalEventProvider getSubscribers() { + return eventProvider; + } public int packetSize = 0, packetType = -1; public boolean wildernessWarning; diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java index 1875467c..c2f89f4b 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java @@ -1227,12 +1227,6 @@ public class PlayerAssistant { } break; - case 1173: - if (!Superheat.superHeatItem(player, itemId)) { - return; - } - break; - case 1155: // Lvl-1 enchant sapphire case 1165: // Lvl-2 enchant emerald case 1176: // Lvl-3 enchant ruby diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickItem.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickItem.java index cd8062b3..f1ef35a2 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickItem.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickItem.java @@ -2,6 +2,7 @@ package com.rs2.net.packets.impl; import com.rs2.GameConstants; import com.rs2.GameEngine; +import com.rs2.event.impl.ItemFirstClickEvent; import com.rs2.game.content.consumables.Beverages; import com.rs2.game.content.consumables.Kebabs; import com.rs2.game.content.consumables.Beverages.beverageData; @@ -37,6 +38,7 @@ public class ClickItem implements PacketType { if(!player.getItemAssistant().playerHasItem(itemId, 1)) { return; } + player.post(new ItemFirstClickEvent(itemId)); GodBooks.sendPreachOptions(player, itemId); if (itemId == 6) { player.getCannon().placeCannon(); diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java index 9c02144b..9dc57b90 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickNPC.java @@ -3,6 +3,9 @@ package com.rs2.net.packets.impl; import com.rs2.event.CycleEvent; import com.rs2.event.CycleEventContainer; import com.rs2.event.CycleEventHandler; +import com.rs2.event.impl.NpcFirstClickEvent; +import com.rs2.event.impl.NpcSecondClickEvent; +import com.rs2.event.impl.NpcThirdClickEvent; import com.rs2.game.content.combat.CombatConstants; import com.rs2.game.content.combat.magic.MagicData; import com.rs2.game.content.combat.range.RangeData; @@ -229,6 +232,7 @@ public class ClickNPC implements PacketType { case FIRST_CLICK: player.npcClickIndex = player.inStream.readSignedWordBigEndian(); player.npcType = NpcHandler.npcs[player.npcClickIndex].npcType; + if (player.goodDistance(NpcHandler.npcs[player.npcClickIndex].getX(), NpcHandler.npcs[player.npcClickIndex].getY(), player.getX(), player.getY(), 2)) { @@ -236,6 +240,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); player.getNpcs().firstClickNpc(player.npcType); + player.post(new NpcFirstClickEvent(player.npcType)); } else { player.clickNpcType = 1; CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { @@ -252,6 +257,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex] .facePlayer(player.playerId); player.getNpcs().firstClickNpc(player.npcType); + player.post(new NpcFirstClickEvent(player.npcType)); container.stop(); } } @@ -277,6 +283,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); player.getNpcs().secondClickNpc(player.npcType); + player.post(new NpcSecondClickEvent(player.npcType)); } else { player.clickNpcType = 2; CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { @@ -293,6 +300,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex] .facePlayer(player.playerId); player.getNpcs().secondClickNpc(player.npcType); + player.post(new NpcSecondClickEvent(player.npcType)); container.stop(); } } @@ -319,6 +327,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); player.getNpcs().thirdClickNpc(player.npcType); + player.post(new NpcThirdClickEvent(player.npcType)); } else { player.clickNpcType = 3; CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() { @@ -335,6 +344,7 @@ public class ClickNPC implements PacketType { NpcHandler.npcs[player.npcClickIndex] .facePlayer(player.playerId); player.getNpcs().thirdClickNpc(player.npcType); + player.post(new NpcThirdClickEvent(player.npcType)); container.stop(); } } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickObject.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickObject.java index 4a33f04f..a633f0c5 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickObject.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickObject.java @@ -5,6 +5,10 @@ import com.rs2.GameEngine; import com.rs2.event.CycleEvent; import com.rs2.event.CycleEventContainer; import com.rs2.event.CycleEventHandler; +import com.rs2.event.impl.ObjectFirstClickEvent; +import com.rs2.event.impl.ObjectFourthClickEvent; +import com.rs2.event.impl.ObjectSecondClickEvent; +import com.rs2.event.impl.ObjectThirdClickEvent; import com.rs2.game.content.minigames.castlewars.CastleWarObjects; import com.rs2.game.content.minigames.castlewars.CastleWars; import com.rs2.game.content.skills.woodcutting.Woodcutting; @@ -410,6 +414,7 @@ public class ClickObject implements PacketType { break; } player.getObjects().firstClickObject(player.objectId, player.objectX, player.objectY); + player.post(new ObjectFirstClickEvent(player.objectId)); break; case 2: @@ -417,6 +422,7 @@ public class ClickObject implements PacketType { player.getPacketSender().sendMessage("ObjectId: " + player.objectId + " ObjectX: " + player.objectX + " ObjectY: " + player.objectY + " Objectclick = 2, Xoff: " + (player.getX() - player.objectX) + " Yoff: " + (player.getY() - player.objectY)); } player.getObjects().secondClickObject(player.objectId, player.objectX, player.objectY); + player.post(new ObjectSecondClickEvent(player.objectId)); break; case 3: // 'F' @@ -425,6 +431,7 @@ public class ClickObject implements PacketType { } player.getObjects().thirdClickObject(player.objectId, player.objectX, player.objectY); + player.post(new ObjectThirdClickEvent(player.objectId)); break; @@ -434,6 +441,7 @@ public class ClickObject implements PacketType { } player.getObjects().fourthClickObject(player.objectId, player.objectX, player.objectY); + player.post(new ObjectFourthClickEvent(player.objectId)); break; } } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java index 2251778c..5927a108 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ClickingButtons.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.ButtonActionEvent; import com.rs2.GameConstants; import com.rs2.game.content.combat.CombatConstants; import com.rs2.game.content.combat.Specials; @@ -81,6 +82,8 @@ public class ClickingButtons implements PacketType { if (player.isAutoButton(actionButtonId)) { player.assignAutocast(actionButtonId); } + player.post(new ButtonActionEvent(actionButtonId)); + switch (actionButtonId) { case 23132: player.getPlayerAssistant().unMorphPlayer(); @@ -1193,10 +1196,6 @@ public class ClickingButtons implements PacketType { player.getPacketSender().sendConfig(173, 0); break; - case 9154: - player.logout(); - break; - case 21010: if (player.isBanking) { player.takeAsNote = true; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2.java index 76b33dcf..ca3b6216 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick2.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.ItemSecondClickEvent; import com.rs2.game.items.impl.HandleEmpty; import com.rs2.game.players.Player; import com.rs2.net.packets.PacketType; @@ -20,16 +21,10 @@ public class ItemClick2 implements PacketType { } player.endCurrentTask(); + player.post(new ItemSecondClickEvent(itemId)); if (HandleEmpty.canEmpty(player, itemId)) { HandleEmpty.handleEmptyItem(player, itemId, HandleEmpty.filledToEmpty(player, itemId)); - return; - } - - switch (itemId) { - case 4079: - player.startAnimation(1459); - break; } } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick3.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick3.java index a30a7c74..bd4061d0 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick3.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemClick3.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.ItemThirdClickEvent; import com.rs2.game.content.skills.runecrafting.Runecrafting; import com.rs2.game.items.impl.HandleEmpty; import com.rs2.game.items.impl.Teles; @@ -23,6 +24,7 @@ public class ItemClick3 implements PacketType { if (!player.getItemAssistant().playerHasItem(itemId, 1)) { return; } + player.post(new ItemThirdClickEvent(itemId)); if (HandleEmpty.canEmpty(player, itemId)) { HandleEmpty.handleEmptyItem(player, itemId, HandleEmpty.filledToEmpty(player, itemId)); return; @@ -52,9 +54,6 @@ public class ItemClick3 implements PacketType { case 1448:// Mind Talisman Runecrafting.locate(player, 2982, 3514); break; - case 4079: - player.startAnimation(1460); - break; case 2552: case 2554: diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnNpc.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnNpc.java index 452f31a6..31492b89 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnNpc.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnNpc.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.ItemOnNpcEvent; import com.rs2.game.content.skills.SkillHandler; import com.rs2.game.items.UseItem; import com.rs2.game.npcs.NpcHandler; @@ -27,6 +28,7 @@ public class ItemOnNpc implements PacketType { return; } player.faceNpc(i); + player.post(new ItemOnNpcEvent(itemId,npcId, i)); switch(npcId) { case 3021: if (player.getFarmingTools().noteItem(itemId)) { diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnObject.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnObject.java index 486c130b..735058ca 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnObject.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnObject.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.ItemOnObjectEvent; import com.rs2.GameConstants; import com.rs2.game.content.combat.range.DwarfCannon; import com.rs2.game.content.skills.cooking.Cooking; @@ -49,6 +50,7 @@ public class ItemOnObject implements PacketType { "Object Id:" + objectId + " ObjectX: " + objectX + " ObjectY: " + objectY + "."); } + player.post(new ItemOnObjectEvent(itemId, objectId)); switch (objectId) { case 3044: if (itemId == 438 || itemId == 436) { @@ -213,15 +215,6 @@ public class ItemOnObject implements PacketType { player.getPlayerAssistant().movePlayer(2510, 3096, 0); } - if (Fillables.canFill(itemId, objectId) && player.getItemAssistant().playerHasItem(itemId)) { - int amount = player.getItemAssistant().getItemAmount(itemId); - player.getItemAssistant().deleteItem(itemId, amount); - player.getItemAssistant().addItem(Fillables.counterpart(itemId), amount); - player.getPacketSender().sendMessage(Fillables.fillMessage(itemId, objectId)); - player.startAnimation(832); - return; - } - UseItem.itemOnObject(player, objectId, objectX, objectY, itemId); } diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnItems.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnItems.java index 83ecbebb..f975c809 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnItems.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/MagicOnItems.java @@ -1,5 +1,6 @@ package com.rs2.net.packets.impl; +import com.rs2.event.impl.MagicOnItemEvent; import com.rs2.game.players.Player; import com.rs2.net.packets.PacketType; @@ -21,6 +22,7 @@ public class MagicOnItems implements PacketType { } player.usingMagic = true; player.getPlayerAssistant().magicOnItems(slot, itemId, spellId); + player.post(new MagicOnItemEvent(itemId, slot, spellId)); player.usingMagic = false; } diff --git a/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java b/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java new file mode 100644 index 00000000..1b9d593a --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java @@ -0,0 +1,50 @@ +package com.rs2.plugin; + +public final class PluginMetaData { + + private final String name; + + private final String description; + + private final String group; + + private final String base; + + private final String[] authors; + + private final double version; + + public PluginMetaData(String name, String description, String group, String base, String[] authors, double version) { + this.name = name; + this.description = description; + this.group = group; + this.base = base; + this.authors = authors; + this.version = version; + } + + public String getName() { + return name; + } + + public String[] getAuthors() { + return authors; + } + + public String getDescription() { + return description; + } + + public String getGroup() { + return group; + } + + public String getBase() { + return base; + } + + public double getVersion() { + return version; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java b/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java new file mode 100644 index 00000000..4318a532 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java @@ -0,0 +1,144 @@ +package com.rs2.plugin; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.rs2.event.EventSubscriber; +import com.rs2.game.players.Player; +import com.rs2.util.LoggerUtils; + +/** + * The service that services plugins. + * + * @author Vult-R + */ +public final class PluginService { + + /** + * The single logger for this class. + */ + private static final Logger logger = LoggerUtils.getLogger(PluginService.class); + + /** + * The list of subscribers registered to the server. + */ + private static final List> subscribers = new ArrayList<>(); + + /** + * The single instance of gson to deserialize the plugin meta data. + */ + private static final Gson gson = new GsonBuilder().create(); + + /** + * Loads the plugins. + */ + public void load() { + try { + Collection plugins = findPlugins(); + + plugins.stream().forEach($it -> register($it)); + } catch (IOException e) { + logger.log(Level.SEVERE, "A problem was encountered while trying to load plugins.", e); + } + logger.info("Loaded: " + subscribers.size() + " plugins."); + } + + /** + * Finds plugins in a given directory. + * + * @throws IOException + */ + private Collection findPlugins() throws IOException { + return findPlugins(new File("./plugins/")); + } + + /** + * Finds plugins in a specified directory. + * + * @param dir + * The directory to check for plugins. + * + * @throws IOException + * + * @return The collection of plugin data. + */ + private Collection findPlugins(File dir) throws IOException { + Collection plugins = new ArrayList<>(); + for(File file : dir.listFiles()) { + if (file.isDirectory()) { + + File json = new File(file, "plugins.json"); + + if (json.exists()) { + PluginMetaData[] meta = gson.fromJson(new FileReader(json), PluginMetaData[].class); + + plugins.add(meta); + } else { + plugins.addAll(findPlugins(file)); + } + + } + } + return Collections.unmodifiableCollection(plugins); + } + + /** + * Assigns a plugin to a subscriber + * + * @param metas + * The meta deta for each plugin. + */ + private void register(PluginMetaData[] metas) { + for(PluginMetaData meta : metas) { + String base = meta.getBase(); + + Class clazz; + + try { + + clazz = Class.forName(base); + + } catch (Exception ex) { + logger.warning(base + " could not be found."); + continue; + } + + if (EventSubscriber.class.isAssignableFrom(clazz)) { + try { + final EventSubscriber subscriber = (EventSubscriber) clazz.newInstance(); + + Player.provideSubscriber(subscriber); + + subscribers.add(subscriber); + } catch (Exception ex) { + logger.warning(base + " could not be created."); + continue; + } + } + } + } + + /** + * Reloads plugins. + */ + public void reload() { + throw new UnsupportedOperationException("This is currently not supported."); + } + + /** + * Gets the list of subscriber registered to the server. + */ + public List> getSubscribers() { + return subscribers; + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/util/ClassUtils.java b/2006Scape Server/src/main/java/com/rs2/util/ClassUtils.java new file mode 100644 index 00000000..22593237 --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/util/ClassUtils.java @@ -0,0 +1,40 @@ +package com.rs2.util; + +import java.lang.annotation.Annotation; +import java.util.Optional; + +/** + * A static-utility class containing extension or helper methods for + * {@link Class}es or generic objects. + * + * @author Ryley Kimmel + */ +public final class ClassUtils { + + /** + * Returns the specified {@link T annotation} for the potentially annotated + * {@link Class class} if it exists. + * + * @param clazz The class to test contains the specified {@code annotation}. + * @param annotation The annotation to check the specified {@code class} + * for. + * @return The {@code annotation} if and only if it exists otherwise + * {@link Optional#empty()}. + */ + public static Optional getAnnotation(Class clazz, Class annotation) { + return Optional.ofNullable(clazz.getAnnotation(annotation)); + } + + /** + * Suppresses the default-public constructor preventing this class from + * being instantiated by other classes, instantiating this class from within + * itself will throw an {@link UnsupportedOperationException}. + * + * @throws UnsupportedOperationException If this class is instantiated from + * within itself. + */ + private ClassUtils() { + throw new UnsupportedOperationException("static-utility classes may not be instantiated."); + } + +} diff --git a/2006Scape Server/src/main/java/com/rs2/util/LoggerUtils.java b/2006Scape Server/src/main/java/com/rs2/util/LoggerUtils.java new file mode 100644 index 00000000..5c10632b --- /dev/null +++ b/2006Scape Server/src/main/java/com/rs2/util/LoggerUtils.java @@ -0,0 +1,11 @@ +package com.rs2.util; + +import java.util.logging.Logger; + +public final class LoggerUtils { + + public static Logger getLogger(Class clazz) { + return Logger.getLogger(clazz.getName()); + } + +}