Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

254 add metadata #265

Closed
wants to merge 17 commits into from
10 changes: 8 additions & 2 deletions plugins/example-plugin/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
git_url: https://github.com/py-mine/example-plugin.git
module_folder: example_plugin
git_url: "https://github.com/py-mine/example-plugin.git"
module_folder: "example_plugin"
name: "example_plugin"
description: "This is an example plugin bada bing bada boom."
version: 1
author: "PyMine Devs"
license: "GPLv3.0"
website: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
2 changes: 2 additions & 0 deletions pymine/logic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"spawn_animals": True,
"spawn_monsters": True,
"generate_structures": True,
"enable_query": True,
"query_port": 25565,
}


Expand Down
69 changes: 69 additions & 0 deletions pymine/logic/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from __future__ import annotations
import struct

# from pymine.server import server # not yet ferb


class QueryBuffer:
"""Buffer for the query protocol, will contain most relevant methods."""

def __init__(self, buf: bytes = None) -> None:
self.buf = b"" if buf is None else buf
self.pos = 0

def write(self, data: bytes) -> None:
"""Writes data to the buffer."""

self.buf += data

def read(self, length: int = None) -> bytes:
"""
Reads n bytes from the buffer, if the length is None
then all remaining data from the buffer is sent.
"""

try:
if length is None:
length = len(self.buf)
return self.buf[self.pos :]

return self.buf[self.pos : self.pos + length]
finally:
self.pos += length

def reset(self) -> None:
"""Resets the position in the buffer."""

self.pos = 0

@staticmethod
def pack_short(short: int) -> bytes:
return struct.pack("<h", short)

@staticmethod
def unpack_short(short: int) -> int:
return struct.unpack("<h", short)

@staticmethod
def pack_magic() -> bytes:
return b"\xFE\xFD"

@staticmethod
def unpack_magic() -> int:
return 65277 # I hate myself.

@staticmethod
def pack_string(string: str) -> bytes:
return bytes(string, "latin-1") + b"\x00"

@staticmethod
def pack_int32(num: int) -> bytes:
return struct.pack(">i", num)

@staticmethod
def unpack_int32(num: int) -> int: # I think.
return struct.unpack(">i", num)

@staticmethod
def pack_byte(byte: int) -> bytes:
return struct.pack(">b", byte)
Empty file added pymine/types/query.py
Empty file.