mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-02 16:49:03 +00:00
Plugins Fixup / Conversion(#511)
* Server: Ripped PluginService From Astreaus-V2 This Removes The Need For Plugin MetaData * Plugins: Handle Emote Tab Run Buttons * Add Some Settings Button Plugins Brightness Buttons Music Volume Buttons Walk/Run Buttons Toggle SplitPrivate-Chat * Fix Player Still Running With 0 Energy Fixes Players Continuing To Run For The Rest Of Their Current Movement Task Even If They Run Out Of Energy
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package plugin.buttons.gameframe
|
||||
|
||||
import com.rs2.event.SubscribesTo
|
||||
import com.rs2.event.impl.ButtonActionEvent
|
||||
import com.rs2.game.items.impl.LightSources
|
||||
import com.rs2.game.players.Player
|
||||
import plugin.buttons.ButtonClick
|
||||
|
||||
@SubscribesTo(ButtonActionEvent::class)
|
||||
class BrightnessButtons : ButtonClick() {
|
||||
|
||||
override fun execute(player: Player, event: ButtonActionEvent) {
|
||||
when (event.button) {
|
||||
3138 -> LightSources.brightness1(player)
|
||||
3140 -> LightSources.brightness2(player)
|
||||
3142 -> LightSources.brightness3(player)
|
||||
3144 -> LightSources.brightness4(player)
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: ButtonActionEvent): Boolean {
|
||||
return event.button == 3138 || event.button == 3140 || event.button == 3142 || event.button == 912
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class LogoutButton : ButtonClick() {
|
||||
}
|
||||
|
||||
override fun test(event: ButtonActionEvent): Boolean {
|
||||
return event.button == 9154;
|
||||
return event.button == 9154
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package plugin.buttons.gameframe
|
||||
|
||||
import com.rs2.event.SubscribesTo
|
||||
import com.rs2.event.impl.ButtonActionEvent
|
||||
import com.rs2.game.content.music.Music
|
||||
import com.rs2.game.players.Player
|
||||
import plugin.buttons.ButtonClick
|
||||
|
||||
@SubscribesTo(ButtonActionEvent::class)
|
||||
class MusicVolumeButtons : ButtonClick() {
|
||||
|
||||
override fun execute(player: Player, event: ButtonActionEvent) {
|
||||
when (event.button) {
|
||||
3162 -> {
|
||||
if (player.musicOn) {
|
||||
player.musicOn = false
|
||||
} else {
|
||||
player.packetSender.sendMessage("Your music is already turned off.")
|
||||
}
|
||||
}
|
||||
3163,3164,3165,3166 -> {
|
||||
Music.playMusic(player)
|
||||
player.musicOn = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: ButtonActionEvent): Boolean {
|
||||
return event.button == 3162 || event.button == 3163 || event.button == 3164 || event.button == 3165 || event.button == 3166
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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 ToggleRunButtons : ButtonClick() {
|
||||
|
||||
override fun execute(player: Player, event: ButtonActionEvent) {
|
||||
when (event.button) {
|
||||
152 -> {
|
||||
player.packetSender.sendConfig(173, 0)
|
||||
player.isRunning = false
|
||||
player.isRunning2 = false
|
||||
|
||||
}
|
||||
|
||||
153 -> {
|
||||
if (player.tutorialProgress == 11) {
|
||||
player.dialogueHandler.sendDialogues(3041, 0)
|
||||
}
|
||||
player.packetSender.sendConfig(173, 1)
|
||||
player.isRunning = true
|
||||
player.isRunning2 = true
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun test(event: ButtonActionEvent): Boolean {
|
||||
return event.button == 152 || event.button == 153
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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 ToggleSplitChatButtons : ButtonClick() {
|
||||
|
||||
override fun execute(player: Player, event: ButtonActionEvent) {
|
||||
when (event.button) {
|
||||
3189 -> {
|
||||
player.packetSender.sendConfig(502, 1)
|
||||
player.packetSender.sendConfig(287, 1)
|
||||
player.splitChat = true
|
||||
}
|
||||
|
||||
3190 -> {
|
||||
player.packetSender.sendConfig(502, 0)
|
||||
player.packetSender.sendConfig(287, 0)
|
||||
player.splitChat = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: ButtonActionEvent): Boolean {
|
||||
return event.button == 3189 || event.button == 3190
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
[
|
||||
{
|
||||
"name": "Logout Button",
|
||||
"description": "The button for logging a player out.",
|
||||
"group": "button",
|
||||
"base": "plugin.buttons.gameframe.LogoutButton",
|
||||
"authors": [
|
||||
"Vult-R"
|
||||
],
|
||||
"version": 1.0
|
||||
}
|
||||
]
|
||||
@@ -1,62 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
@@ -1,12 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
@@ -1,32 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
@@ -1,42 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
@@ -939,6 +939,7 @@ public abstract class Player {
|
||||
lastIncrease = System.currentTimeMillis();
|
||||
}
|
||||
if (playerEnergy <= 0 && isRunning2) {
|
||||
isRunning = false;
|
||||
isRunning2 = false;
|
||||
getPacketSender().sendConfig(504, 0);
|
||||
getPacketSender().sendConfig(173, 0);
|
||||
|
||||
@@ -592,22 +592,6 @@ public class ClickingButtons implements PacketType {
|
||||
break;
|
||||
/** End of Hairdresser buttons */
|
||||
|
||||
case 3166:
|
||||
case 3165:
|
||||
case 3164:
|
||||
case 3163:
|
||||
Music.playMusic(player);
|
||||
player.musicOn = true;
|
||||
break;
|
||||
|
||||
case 3162:
|
||||
if (player.musicOn) {
|
||||
player.musicOn = false;
|
||||
} else {
|
||||
player.getPacketSender().sendMessage("Your music is already turned off.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 8198:
|
||||
PartyRoom.accept(player);
|
||||
break;
|
||||
@@ -1183,19 +1167,6 @@ public class ClickingButtons implements PacketType {
|
||||
player.usingMagic = false;
|
||||
break;
|
||||
|
||||
case 153:
|
||||
if (player.tutorialProgress == 11) {
|
||||
player.getDialogueHandler().sendDialogues(3041, 0);
|
||||
}
|
||||
player.getPacketSender().sendConfig(173, 1);
|
||||
player.isRunning2 = true;
|
||||
break;
|
||||
|
||||
case 152:
|
||||
player.isRunning2 = false;
|
||||
player.getPacketSender().sendConfig(173, 0);
|
||||
break;
|
||||
|
||||
case 21010:
|
||||
if (player.isBanking) {
|
||||
player.takeAsNote = true;
|
||||
@@ -1500,17 +1471,6 @@ public class ClickingButtons implements PacketType {
|
||||
player.getPacketSender().sendConfig(170, 0);
|
||||
}
|
||||
break;
|
||||
case 3189:
|
||||
if (player.splitChat == false) {
|
||||
player.getPacketSender().sendConfig(502, 1);
|
||||
player.getPacketSender().sendConfig(287, 1);
|
||||
player.splitChat = true;
|
||||
} else if (player.splitChat) {
|
||||
player.getPacketSender().sendConfig(502, 0);
|
||||
player.getPacketSender().sendConfig(287, 0);
|
||||
player.splitChat = false;
|
||||
}
|
||||
break;
|
||||
case 74180:
|
||||
if (!player.chatEffects) {
|
||||
player.chatEffects = true;
|
||||
@@ -1544,26 +1504,6 @@ public class ClickingButtons implements PacketType {
|
||||
player.getPacketSender().sendConfig(173, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
//case 74201:// brightness1
|
||||
case 3138:
|
||||
LightSources.brightness1(player);
|
||||
break;
|
||||
|
||||
//case 74203:// brightness2
|
||||
case 3140:
|
||||
LightSources.brightness2(player);
|
||||
break;
|
||||
|
||||
//case 74204:// brightness3
|
||||
case 3142:
|
||||
LightSources.brightness3(player);
|
||||
break;
|
||||
|
||||
//case 74205:// brightness4
|
||||
case 3144:
|
||||
LightSources.brightness4(player);
|
||||
break;
|
||||
|
||||
case 74206:// area1
|
||||
player.getPacketSender().sendConfig(509, 1);
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
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.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
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;
|
||||
@@ -32,20 +27,15 @@ public final class PluginService {
|
||||
* 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));
|
||||
Collection<EventSubscriber<?>> 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);
|
||||
}
|
||||
@@ -55,10 +45,9 @@ public final class PluginService {
|
||||
/**
|
||||
* Finds plugins in a given directory.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private Collection<PluginMetaData[]> findPlugins() throws IOException {
|
||||
return findPlugins(new File("./plugins/"));
|
||||
private Collection<EventSubscriber<?>> findPlugins() throws IOException {
|
||||
return findPlugins(new File("./plugins"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,64 +56,51 @@ public final class PluginService {
|
||||
* @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));
|
||||
private Collection<EventSubscriber<?>> findPlugins(File dir) {
|
||||
Collection<EventSubscriber<?>> plugins = new ArrayList<>();
|
||||
for (File file : Objects.requireNonNull(dir.listFiles())) {
|
||||
String base = file.getPath();
|
||||
|
||||
base = base.replace("\\", ".");
|
||||
|
||||
base = base.replace("..plugins.", "");
|
||||
|
||||
base = base.replace(".kt", "");
|
||||
|
||||
base = base.replace(".java", "");
|
||||
|
||||
if (!file.isDirectory()) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(base);
|
||||
|
||||
if (EventSubscriber.class.isAssignableFrom(clazz) && !Modifier.isInterface(clazz.getModifiers()) && !Modifier.isAbstract(clazz.getModifiers())) {
|
||||
final EventSubscriber<?> sub = (EventSubscriber<?>) clazz.newInstance();
|
||||
|
||||
plugins.add(sub);
|
||||
}
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} 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();
|
||||
private void register(EventSubscriber<?> subscriber) {
|
||||
|
||||
Class<?> clazz;
|
||||
Player.provideSubscriber(subscriber);
|
||||
|
||||
try {
|
||||
subscribers.add(subscriber);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user