diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-10-20 08:03:47 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-10-20 08:03:47 +0200 |
commit | 418dab390e877e917e6719b3265af38d2cb049b5 (patch) | |
tree | e178972f9e63e8f7fd6d71816e26db23b9716bf7 | |
parent | 2f511877720ed44589d9de40a0919e0c3b27ae1d (diff) | |
download | BerryClient-418dab390e877e917e6719b3265af38d2cb049b5.tar.gz BerryClient-418dab390e877e917e6719b3265af38d2cb049b5.zip |
add method to load modules externally
-rw-r--r-- | BerryClient/core.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/BerryClient/core.py b/BerryClient/core.py index 1b4e5b5..28e2a3b 100644 --- a/BerryClient/core.py +++ b/BerryClient/core.py @@ -5,6 +5,7 @@ from importlib import import_module, reload from mcpi import minecraft from BerryClient.events import process_events from BerryClient.logging import MinecraftChatHandler +from BerryClient.commands import COMMANDS log = logging.getLogger() @@ -22,7 +23,7 @@ class BerryCore: self.running = False self.__setupLogging() - self.__loadAddons() + self.__loadDefaultAddons() def __setupLogging(self): root_logger = logging.getLogger() @@ -42,12 +43,21 @@ class BerryCore: root_logger.addHandler(stdout_handler) - def __loadAddons(self): + def __loadDefaultAddons(self): for addon in self.ADDONS: + self.__loadAddon(addon) + + + def __loadAddon(self, addon): + try: self.ADDON_MODULES[addon] = import_module(addon) log.info(f"Loaded {addon}") + except ImportError as e: + log.error(f"Failed to load {addon}") + log.exception(e) def __reloadAddons(self): + COMMANDS.clear() for addon in self.ADDONS: try: self.ADDON_MODULES[addon] = reload(self.ADDON_MODULES[addon]) @@ -66,6 +76,9 @@ class BerryCore: def reload(self): self.__reloadAddons() + def load(self, addon): + self.__loadAddon(addon) + def stop(self): self.running = False |