diff --git a/aiocraft/mc/auth/interface.py b/aiocraft/mc/auth/interface.py index 3f40e02..8518129 100644 --- a/aiocraft/mc/auth/interface.py +++ b/aiocraft/mc/auth/interface.py @@ -52,7 +52,7 @@ class AuthInterface: json={ "serverId": server_id, "accessToken": self.accessToken, - "selectedProfile": self.selectedProfile.as_dict() + "selectedProfile": self.selectedProfile.serialize() } ) diff --git a/aiocraft/mc/auth/microsoft.py b/aiocraft/mc/auth/microsoft.py index d44d6ec..be9711a 100644 --- a/aiocraft/mc/auth/microsoft.py +++ b/aiocraft/mc/auth/microsoft.py @@ -48,7 +48,7 @@ class MicrosoftAuthenticator(AuthInterface): return { 'accessToken': self.accessToken, 'refreshToken': self.refreshToken, - 'selectedProfile': self.selectedProfile.as_dict(), + 'selectedProfile': self.selectedProfile.serialize(), } def deserialize(self, data:Dict[str, Any]): diff --git a/aiocraft/mc/auth/mojang.py b/aiocraft/mc/auth/mojang.py index 7905556..4a235da 100644 --- a/aiocraft/mc/auth/mojang.py +++ b/aiocraft/mc/auth/mojang.py @@ -53,7 +53,7 @@ class MojangAuthenticator(AuthInterface): "username":self.username, "accessToken":self.accessToken, "clientToken":self.clientToken, - "selectedProfile": self.selectedProfile.as_dict(), + "selectedProfile": self.selectedProfile.serialize(), } def deserialize(self, data:Dict[str, Any]) -> AuthInterface: diff --git a/aiocraft/mc/definitions.py b/aiocraft/mc/definitions.py index 5997a52..62692b4 100644 --- a/aiocraft/mc/definitions.py +++ b/aiocraft/mc/definitions.py @@ -36,12 +36,12 @@ class GameProfile: name : str def __str__(self): - return json.dumps(self.as_dict(), indent=2) + return json.dumps(self.serialize(), indent=2) def __repr__(self): return f"GameProfile(id='{self.id}', name='{self.name}')" - def as_dict(self): + def serialize(self): return { "id": self.id, "name": self.name diff --git a/aiocraft/mc/packet.py b/aiocraft/mc/packet.py index c0e60a2..86acb84 100644 --- a/aiocraft/mc/packet.py +++ b/aiocraft/mc/packet.py @@ -38,7 +38,7 @@ class Packet: ctx = Context(_proto=proto) for k, t in cls._definitions[proto]: setattr(ctx, k, t.read(buffer, ctx=ctx)) - return cls(proto, **ctx.as_dict()) + return cls(proto, **ctx.serialize()) # return cls(proto, **{ name : t.read(buffer) for (name, t) in cls._definitions[proto] }) def serialize(self) -> io.BytesIO: diff --git a/aiocraft/mc/types.py b/aiocraft/mc/types.py index 8ffd6bb..84e211d 100644 --- a/aiocraft/mc/types.py +++ b/aiocraft/mc/types.py @@ -16,14 +16,14 @@ class Context(object): for k, v in kwargs.items(): setattr(self, k, v) - def as_dict(self) -> dict: + def serialize(self) -> dict: return vars(self) # is this reliable? def __getattr__(self, name) -> Any: return None # return None rather than raising an exc def __str__(self) -> str: - return json.dumps(self.as_dict(), indent=2, default=str, sort_keys=True) + return json.dumps(self.serialize(), indent=2, default=str, sort_keys=True) def __repr__(self) -> str: values = ( f"{k}={repr(v)}" for k,v in vars(self).items() )