aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-10-20 08:03:47 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-10-20 08:03:47 +0200
commit418dab390e877e917e6719b3265af38d2cb049b5 (patch)
treee178972f9e63e8f7fd6d71816e26db23b9716bf7
parent2f511877720ed44589d9de40a0919e0c3b27ae1d (diff)
downloadBerryClient-418dab390e877e917e6719b3265af38d2cb049b5.tar.gz
BerryClient-418dab390e877e917e6719b3265af38d2cb049b5.zip
add method to load modules externally
-rw-r--r--BerryClient/core.py17
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