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:
authored and GitHub committed 2021-10-09 00:20:57 +01:00
1 parent a693615e2e
commit 7d64e2298f
74 files changed
+1799 -75

No files matched your search

@@ -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<EventSubscriber<?>> 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<PluginMetaData[]> 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<PluginMetaData[]> 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<PluginMetaData[]> findPlugins(File dir) throws IOException {
Collection<PluginMetaData[]> 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<EventSubscriber<?>> getSubscribers() {
return subscribers;
}
}