# Minecraft RCON Core Library For Python # Version: @1.0.0 # Author: @TermiNexus import MilRcon import MilCon import Milib import typing import json import math import time class MinecraftCore(): def __init__(self, con: MilRcon._MinecraftRcon): self.con=con def _RunCommand(self, command, astext: bool = False): try: return self.con._RunCommand(command, astext = astext) except: return False # Minecraft Command def Tellraw(self, user: MilCon._user, j, astext: bool = False): self._RunCommand(f"tellraw {user} {json.dumps(j, ensure_ascii=False)}", astext) def Title(self, user: MilCon._user, mode: typing.Literal["actionbar", "clear", "reset", "subtitle", "title", "times", "title"], j, astext: bool = False): return self._RunCommand(f"title {user} {mode} {json.dumps(j, ensure_ascii=False)}", astext) def Gamemode(self, mode: MilCon._gamemode, user: MilCon._all_user, astext: bool = False): return self._RunCommand(f"gamemode {mode} {user}", astext) def Particle(self, name: MilCon._minecraft_particles, pos: Milib.RelativePos, delta: Milib.Delta, speed: int = 0, count: int = 0, show: typing.Literal["force", "normal"] = "normal", user: MilCon._user = "@a", astext: bool = False): return self._RunCommand(f"particle {name} {pos} {delta} {speed} {count} {show} {user}", astext) def Execute(self, *args: typing.Unpack[Milib.ExecuteSubCommandRule], astext: bool = False): return self._RunCommand(f"execute {" ".join(map(str, args))}", astext) def Mute(self, user: MilCon._user, mode: MilCon._mute_mode, astext: bool = False): return self._RunCommand(f"mute {user} {mode}", astext) def UnMute(self, user: MilCon._user, astext: bool = False): return self._RunCommand(f"unmute {user}", astext) def List(self, astext: bool = False): if astext: return self._RunCommand(f"list", astext) return self._RunCommand(f"list").split(": ")[1].split(", ") def Weather(self, mode: MilCon._weather_mode, astext: bool = False): return self._RunCommand(f"weather {mode}", astext) def Gamerule(self, rule: MilCon._gamerules, value: typing.Union[bool, int, str], astext: bool = False): return self._RunCommand(f"gamerule {rule} {Milib._Bool2Str(value)}", astext) def Data(self, mode: typing.Literal["get", "merge", "modify", "remove"], usermode: typing.Literal["block", "entity", "storage"], user: MilCon._all_user | Milib.RelativePos, path: str = "", astext: bool = False): _: str=self._RunCommand(f"data {mode} {usermode} {user}" + Milib._WithValue(path), astext) if mode == "get" and (31+len(user)) < len(_) and not path: _2=_[(32+len(user)):] return _2 return _ def Bossbar(self, mode: typing.Literal["add", "get", "list", "remove", "set"], id: str = "", key: str = "", value: typing.Union[str, int, bool, MilCon._minecraft_colors, MilCon._user] = "", astext: bool = False): return self._RunCommand(f"bossbar {mode}" + Milib._WithValue(id) + Milib._WithValue(key) + Milib._WithValue(value), astext) def Tp(self, pos1: MilCon._all_user | Milib.RelativePos, pos2: MilCon._all_user | Milib.RelativePos = "", astext: bool = False): return self._RunCommand(f"tp {pos1}" + Milib._WithValue(pos2), astext) def Kick(self, user: MilCon._user, astext: bool = False): return self._RunCommand(f"kick {user}", astext) def Kill(self, user: MilCon._all_user, astext: bool = False): return self._RunCommand(f"kill {user}", astext) def PlaySound(self, name, mode: typing.Literal["ambient", "block", "hostile", "master", "music", "neutral", "player", "record", "voice", "weather"], value: Milib.RelativePos | int | MilCon._user = None, value2: Milib.RelativePos | int | MilCon._user = None, value3: Milib.RelativePos | int | MilCon._user = None, astext: bool = False): return self._RunCommand(f"playsound {name} {mode}" + Milib._WithValue(value) + Milib._WithValue(value2) + Milib._WithValue(value3), astext) # Python For Minecraft def TellRawAll(self, j: dict | list, astext: bool = False): return self.Tellraw("@a", j, astext) def Speak(self, text: str, color: MilCon._minecraft_colors = "white", user: MilCon._user = "@a", astext: bool = False): return self.Tellraw(user, {"text": text, "color": color}, astext) def SbSpeak(self, asuser: str, text: str, color: MilCon._minecraft_colors = "white", user: MilCon._user = "@a", astext: bool = False): return self.Tellraw(user, [{"text": f"[{asuser}] ", "color": "yellow"}, {"text": text, "color": color}], astext) def SbSpeakRaw(self, asuser: str, j: dict | list, color: MilCon._minecraft_colors = "white", user: MilCon._user = "@a", astext: bool = False): if type(j) == str: j={"text":j, "color":color} if type(j) != list: j=[j] return self.Tellraw(user, [{"text": f"[{asuser}] ", "color": "yellow"}] + j, astext) def SetTitle(self, user: MilCon._user, text: str, color: MilCon._minecraft_colors = "white", astext: bool = False): return self.Title(user, "title", {"text": text, "color": color}, astext) def SetSubTitle(self, user: MilCon._user, text: str, color: MilCon._minecraft_colors = "white", astext: bool = False): return self.Title(user, "subtitle", {"text": text, "color": color}, astext) def PlaySoundWith(self, name, user: list[MilCon._user]): for i in user: self.Execute("as", i, "at", "@s", "run", self.PlaySound(name, "voice", "@s", Milib.RelativePos(), 100, astext=True)) class MCROCN(MilRcon._MinecraftRcon, MinecraftCore): def __init__(self, host, password, port, debug=False): MilRcon._MinecraftRcon.__init__(self, host, password, port) MinecraftCore.__init__(self, self) self.debug=debug def Connect(self): try: self.connect() except: return False return True def _RunCommand(self, command, astext: bool = False): if self.debug: print("> ", command) if astext: return Milib.Command(command) try: r=self.command(command) if self.debug: print(r) return r except: return False '''@typing.overload def Bossbar(self, mode: typing.Literal["add"], id: str, name: str, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["get"], id: str, key: typing.Literal["max", "players", "value", "visible"], astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["list"], astext: bool = False) -> str | bool | list: ... @typing.overload def Bossbar(self, mode: typing.Literal["remove"], id: str, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["color", "max", "name", "players", "style", "value", "visible"], value: str, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["color"], value: _minecraft_colors, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["max"], value: int, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["name"], value: str, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["players"], value: _user, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["style"], value: typing.Literal["notched_10", "notched_12", "notched_20", "notched_6", "progress"], astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["value"], value: int, astext: bool = False) -> str | bool: ... @typing.overload def Bossbar(self, mode: typing.Literal["set"], id: str, key: typing.Literal["visible"], value: bool, astext: bool = False) -> str | bool: ...'''