From 546aeaaea7c28ac5d1bc9bb00ace337f85f4ccf9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 3 Jun 2024 05:29:43 +0100 Subject: [PATCH] fix: use importlib_metadata for backwards compatibility, fix #14 --- include/bedrock/forward.h | 1 + include/bedrock/world/level/level_interface.h | 1 - pyproject.toml | 1 + python/src/endstone/_internal/plugin_loader.py | 2 +- python/src/endstone/plugin.py | 14 ++++++-------- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/bedrock/forward.h b/include/bedrock/forward.h index 30e5300af..65028f705 100644 --- a/include/bedrock/forward.h +++ b/include/bedrock/forward.h @@ -106,6 +106,7 @@ class LevelSoundManager; class LevelStorage; class Localization; class LootTables; +class MapDataManager; class MapItemSavedData; class MaterialTypeHelper; class MobEffectInstance; diff --git a/include/bedrock/world/level/level_interface.h b/include/bedrock/world/level/level_interface.h index a7c3e82f1..1fc368fd2 100644 --- a/include/bedrock/world/level/level_interface.h +++ b/include/bedrock/world/level/level_interface.h @@ -40,7 +40,6 @@ #include "bedrock/world/events/event_coordinator.h" #include "bedrock/world/level/level_listener.h" #include "bedrock/world/level/level_settings.h" -#include "bedrock/world/level/saveddata/maps/map_data_manager.h" class ILevel : public Bedrock::EnableNonOwnerReferences { public: diff --git a/pyproject.toml b/pyproject.toml index e896b4407..74276c6ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ classifiers = [ ] dependencies = [ "click", + "importlib_metadata", "importlib_resources", "packaging", "requests", diff --git a/python/src/endstone/_internal/plugin_loader.py b/python/src/endstone/_internal/plugin_loader.py index 7f208b773..bbc3d99f8 100644 --- a/python/src/endstone/_internal/plugin_loader.py +++ b/python/src/endstone/_internal/plugin_loader.py @@ -3,7 +3,7 @@ import site import subprocess import sys -from importlib.metadata import entry_points, metadata +from importlib_metadata import entry_points, metadata from typing import List from endstone import Server from endstone.command import Command diff --git a/python/src/endstone/plugin.py b/python/src/endstone/plugin.py index 55c8c4a2e..1133ebede 100644 --- a/python/src/endstone/plugin.py +++ b/python/src/endstone/plugin.py @@ -2,12 +2,10 @@ import os import shutil import typing -import importlib_resources +from importlib_resources import files, as_file from pathlib import Path import tomlkit from endstone._internal.endstone_python import ( - Command, - CommandSender, PluginDescription, PluginLoader, PluginLoadOrder, @@ -15,7 +13,7 @@ ) from endstone._internal.endstone_python import Plugin as _Plugin from endstone._internal.endstone_python import PluginCommand as _PluginCommand -from endstone.command import CommandExecutor +from endstone.command import Command, CommandExecutor, CommandSender from endstone.event import Event __all__ = [ @@ -32,7 +30,7 @@ class PluginCommand(Command): def __init__(self, impl: _PluginCommand) -> None: Command.__init__(self, impl.name) self._impl = impl - self._executor: CommandExecutor | None = None + self._executor: typing.Optional[CommandExecutor] = None @property def executor(self) -> CommandExecutor: @@ -139,7 +137,7 @@ class Plugin(_Plugin): def __init__(self): _Plugin.__init__(self) - self._description: PluginDescription | None = None + self._description: typing.Optional[PluginDescription] = None self._plugin_commands: dict[_PluginCommand, PluginCommand] = {} self._config = None @@ -222,8 +220,8 @@ def save_resources(self, path: str, replace: bool = False) -> None: out_path = Path(self.data_folder) / path if not out_path.exists() or replace: out_path.parent.mkdir(exist_ok=True) - resource = importlib_resources.files(self.__class__.__module__).joinpath(path) - with importlib_resources.as_file(resource) as f: + resource = files(self.__class__.__module__).joinpath(path) + with as_file(resource) as f: shutil.copy(f, out_path) else: self.logger.warning(f"Could not save {out_path.name} to {out_path}: file already exists.")