diff options
| author | Ritabrata Das <[email protected]> | 2025-02-15 06:58:20 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-02-15 06:58:20 +0530 |
| commit | 1474f8174ca6d0718963ec018f1acef9e43b5be4 (patch) | |
| tree | 4f78af3df923b45b8dd5814818a83005a56f0670 /plugins | |
| parent | 2db93027372bd1b13794f3ab6fc8441eb3e51ebc (diff) | |
| parent | 2d16176ba18901ded88419d3ac24a104d575e2e3 (diff) | |
Merge pull request #6 from Skipper-is/plugin_manager
Added custom aircraft list plugin
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/custom_aircraft_list/Plugin.py | 42 | ||||
| -rw-r--r-- | plugins/custom_aircraft_list/__init__.py | 2 | ||||
| -rw-r--r-- | plugins/custom_aircraft_list/custom_list.json | 14 |
3 files changed, 58 insertions, 0 deletions
diff --git a/plugins/custom_aircraft_list/Plugin.py b/plugins/custom_aircraft_list/Plugin.py new file mode 100644 index 0000000..0fc1bd0 --- /dev/null +++ b/plugins/custom_aircraft_list/Plugin.py @@ -0,0 +1,42 @@ +"""TThis plugin will cause the aircraft to emit smoke if it's health is below a certain threshold. +It is also an example of a plugin as a folder/module. +This can be used as a basis for more complex plugins that may need multiple files.""" +from lib.PacketManager.packets import List_Constructor +from json import load +from struct import pack +from logging import error +ENABLED = False +custom_list_file = "plugins\\custom_aircraft_list\\custom_list.json" + +class Plugin: + def __init__(self): + self.plugin_manager = None + self.aircraft_list = [] + + def register(self, plugin_manager): + self.plugin_manager = plugin_manager + with open(custom_list_file, 'r', encoding='utf-8') as f: + json_file = load(f) + if isinstance(json_file,list): + self.aircraft_list = json_file + else: + error(f"Invalid JSON file {custom_list_file}. Must be a list of aircraft.") + self.plugin_manager.register_hook('on_list', self.on_list) + self.plugin_manager.register_hook('on_list_server', self.on_list_server) + + def on_list(self, packet, player, message_to_client, message_to_server): + if ENABLED: + return False + + def on_list_server(self, packet, player, message_to_client, message_to_server): + if ENABLED: + #Send the packet straight back to the server, and prevent it being passed to the client. + packet = pack("I",len(packet)) + packet + message_to_server.append(packet) + if not hasattr(player, 'custom_packet_sent'): + player.custom_packet_sent=True + #Send the custom list packets. + lc = List_Constructor(self.aircraft_list).get_packets() + for packet in lc: + message_to_client.append(packet) + return False diff --git a/plugins/custom_aircraft_list/__init__.py b/plugins/custom_aircraft_list/__init__.py new file mode 100644 index 0000000..425d2ad --- /dev/null +++ b/plugins/custom_aircraft_list/__init__.py @@ -0,0 +1,2 @@ +from .Plugin import Plugin +from .Plugin import ENABLED
\ No newline at end of file diff --git a/plugins/custom_aircraft_list/custom_list.json b/plugins/custom_aircraft_list/custom_list.json new file mode 100644 index 0000000..987350d --- /dev/null +++ b/plugins/custom_aircraft_list/custom_list.json @@ -0,0 +1,14 @@ +[ + "AIRBUS300", + "AIRBUS320", + "B737", + "B747", + "B767", + "B777", + "CONCORDE", + "DIAMOND_ECLIPSE", + "PIPER_ARCHER(WASHIN-AIR_MARKING)", + "T-400", + "U-125", + "U-125A" +] |
