From 17ad19c30478bb9361cb872d4e9bd4cd424edf49 Mon Sep 17 00:00:00 2001 From: Skipper Date: Fri, 14 Feb 2025 21:47:55 +0000 Subject: Added custom aircraft list plugin --- plugins/custom_aircraft_list/Plugin.py | 44 +++++++++++++++++++++++++++ plugins/custom_aircraft_list/__init__.py | 2 ++ plugins/custom_aircraft_list/custom_list.json | 14 +++++++++ 3 files changed, 60 insertions(+) create mode 100644 plugins/custom_aircraft_list/Plugin.py create mode 100644 plugins/custom_aircraft_list/__init__.py create mode 100644 plugins/custom_aircraft_list/custom_list.json (limited to 'plugins') diff --git a/plugins/custom_aircraft_list/Plugin.py b/plugins/custom_aircraft_list/Plugin.py new file mode 100644 index 0000000..b96920f --- /dev/null +++ b/plugins/custom_aircraft_list/Plugin.py @@ -0,0 +1,44 @@ +"""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 = True +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 + return True + + 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 + return True 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" +] -- cgit v1.2.3