Plugins System (#510)

* Started Ripping Plugin System From Astraeus

*Currently only ClickingButtons Support
*Also Started Using The Logout Button Plugin From Astraeus

* NpcFirstClickEvent setup for plugins

also made Man & Women chat work through this

* Server: Add Google Collect Lib

* Server: NpcSecondClickEvent setup for plugins

also handle pickpocketing npc clicking through plugin

* Server: NpcThirdClickEvent setup for plugins

* Server: Remove conflicting action for Secondclicking npc id 3

* Server: ItemFirstClickEvent setup for plugins

Also Handle Yo-Yo First Click Through This

* Server: ItemOnItemEvent setup for plugins

Also Handle Black Candle Lighting With Tinderbox Through this

* Server: ItemOnNpcEvent setup for plugins

* Server: ItemOnObjectEvent setup for plugins

Also Handle Fillable Items Through This

* Server: ItemSecondClickEvent & ItemThirdClickEvent setup for plugins

Also Handle Yo-Yo Actions Through This

* Server: ObjectFirstClickEvent setup for plugins

Also Handle FirstClick Mining Actions Through This

* Server: ObjectSecondClickEvent setup for plugins

Also Handle Stall Thieving Actions Through This

* Server: ObjectThirdClickEvent setup for plugins

* Server: ObjectFourthClickEvent setup for plugins

Also Handle Fourth Click Farming Object Actions Through This

* Server: MagicOnItemEvent setup for plugins

Also Handle SuperHeat Through This

* More mage training arena (#509)

* Fixup points display

* Only allow players to deposit up to 12k at one time

* Apple damage and play animation

* Update order or prices

* Update Telekinetic.java

(cherry picked from commit ab3b1e9731)

Co-authored-by: RedSparr0w <RedSparr0w@users.noreply.github.com>
Co-authored-by: Danial <admin@redsparr0w.com>
This commit is contained in:
Josh Shippam
2021-10-09 00:20:57 +01:00
committed by GitHub
parent a693615e2e
commit 7d64e2298f
74 changed files with 1799 additions and 75 deletions
@@ -0,0 +1,15 @@
package com.rs2.event;
/**
* Something that happens; an occurrence.
*
* <p>
* An event is characterized by having a type and relative information about
* each occurrence of the event.
* </p>
*
* @author Ryley Kimmel <ryley.kimmel@live.com>
*/
public interface Event {
}
@@ -0,0 +1,28 @@
package com.rs2.event;
/**
* Represents the context of an {@link Event}
*
* @author Ryley Kimmel <ryley.kimmel@live.com>
*/
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();
}
@@ -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 <ryley.kimmel@live.com>
*/
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 <E> The event type reference.
* @param player The player to post the event for.
* @param event The event to post.
*/
<E extends Event> void post(Player player, E event);
}
@@ -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 <ryley.kimmel@live.com>
*
* @param <E> The type of event to the subscriber.
*/
@FunctionalInterface
public interface EventSubscriber<E extends Event> extends Predicate<E> {
/**
* 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;
}
}
@@ -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 <ryley.kimmel@live.com>
*/
@Documented
@Retention(RUNTIME)
@Target(TYPE)
public @interface SubscribesTo {
/**
* Returns the event class that the annotated {@link EventSubscriber}
* subscribes to.
*/
Class<? extends Event> value();
}
@@ -0,0 +1,30 @@
package com.rs2.event;
/**
* An universal implementation of an {@link EventContext}.
*
* @author Ryley Kimmel <ryley.kimmel@live.com>
*/
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;
}
}
@@ -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 <ryley.kimmel@live.com>
*/
public final class UniversalEventProvider implements EventProvider {
/**
* A {@link Multimap} of {@link Event} classes to subscribers.
*/
private final Multimap<Class<? extends Event>, EventSubscriber<? super Event>> 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<? super Event>) subscriber));
}
@SuppressWarnings("unchecked")
@Override
public void depriveSubscriber(EventSubscriber<?> subscriber) {
checkSubscriber(subscriber, annotation -> events.remove(annotation.value(), (EventSubscriber<? super Event>) subscriber));
}
private void checkSubscriber(EventSubscriber<?> subscriber, Consumer<SubscribesTo> consumer) {
Optional<SubscribesTo> 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 <E extends Event> void post(Player player, E event) {
Collection<EventSubscriber<? super Event>> subscribers = events.get(event.getClass());
for (EventSubscriber<? super Event> 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<Class<? extends Event>, EventSubscriber<? super Event>> getEvents() {
return events;
}
}
@@ -0,0 +1,34 @@
package com.rs2.event.impl;
import com.rs2.event.Event;
/**
* An event which manages button actions.
*
* @author Ryley Kimmel <ryley.kimmel@live.com>
*/
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;
}
}
@@ -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;
}
}
@@ -0,0 +1,7 @@
package com.rs2.event.impl;
import com.rs2.event.Event;
public class DialogueEvent implements Event {
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}