diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/BrightnessButtons.kt b/2006Scape Server/plugins/plugin/buttons/gameframe/BrightnessButtons.kt new file mode 100644 index 00000000..2989580b --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/BrightnessButtons.kt @@ -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 + } + +} \ 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 index e38bd1eb..123c45b9 100644 --- a/2006Scape Server/plugins/plugin/buttons/gameframe/LogoutButton.kt +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/LogoutButton.kt @@ -14,7 +14,7 @@ class LogoutButton : ButtonClick() { } override fun test(event: ButtonActionEvent): Boolean { - return event.button == 9154; + return event.button == 9154 } } \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/MusicVolumeButtons.kt b/2006Scape Server/plugins/plugin/buttons/gameframe/MusicVolumeButtons.kt new file mode 100644 index 00000000..950d4e0b --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/MusicVolumeButtons.kt @@ -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 + } + +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleRunButtons.kt b/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleRunButtons.kt new file mode 100644 index 00000000..62f9c791 --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleRunButtons.kt @@ -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 + } +} \ No newline at end of file diff --git a/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleSplitChatButtons.kt b/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleSplitChatButtons.kt new file mode 100644 index 00000000..706f265b --- /dev/null +++ b/2006Scape Server/plugins/plugin/buttons/gameframe/ToggleSplitChatButtons.kt @@ -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 + } + +} \ 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 deleted file mode 100644 index 9deacd8b..00000000 --- a/2006Scape Server/plugins/plugin/buttons/gameframe/plugins.json +++ /dev/null @@ -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 -} -] diff --git a/2006Scape Server/plugins/plugin/click/item/plugins.json b/2006Scape Server/plugins/plugin/click/item/plugins.json deleted file mode 100644 index c03e82fd..00000000 --- a/2006Scape Server/plugins/plugin/click/item/plugins.json +++ /dev/null @@ -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 -} -] \ 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 deleted file mode 100644 index f4d92d2b..00000000 --- a/2006Scape Server/plugins/plugin/click/magic/plugins.json +++ /dev/null @@ -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 -} -] \ 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 deleted file mode 100644 index 9e18cbad..00000000 --- a/2006Scape Server/plugins/plugin/click/npc/plugins.json +++ /dev/null @@ -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 - } -] \ 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 deleted file mode 100644 index 4e7946d0..00000000 --- a/2006Scape Server/plugins/plugin/click/obj/plugins.json +++ /dev/null @@ -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 -} -] \ No newline at end of file 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 348e603b..ee715d6d 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 @@ -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); 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 5927a108..50228c2e 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 @@ -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); diff --git a/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java b/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java deleted file mode 100644 index 1b9d593a..00000000 --- a/2006Scape Server/src/main/java/com/rs2/plugin/PluginMetaData.java +++ /dev/null @@ -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; - } - -} diff --git a/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java b/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java index 4318a532..554c5bf2 100644 --- a/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java +++ b/2006Scape Server/src/main/java/com/rs2/plugin/PluginService.java @@ -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> 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)); + 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); } @@ -55,10 +45,9 @@ public final class PluginService { /** * Finds plugins in a given directory. * - * @throws IOException */ - private Collection findPlugins() throws IOException { - return findPlugins(new File("./plugins/")); + private Collection> 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 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)); + private Collection> findPlugins(File dir) { + Collection> 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; - } - } - } } /**