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

show_title #5

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mcproto/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

icezyclon marked this conversation as resolved.
Show resolved Hide resolved
import grpc

from ._types import COLOR
from ._base import HasStub
from .entity import _EntityCache
from .events import _EventHandler
Expand All @@ -13,6 +14,7 @@
from .mcpb import minecraft_pb2 as pb
from .player import _PlayerCache
from .world import _DefaultWorld, _WorldHub
from typing import Literal

__all__ = ["Minecraft"]

Expand Down Expand Up @@ -54,3 +56,10 @@ def port(self) -> int:
def postToChat(self, *args, sep: str = " ") -> None:
response = self._stub.postToChat(pb.ChatPostRequest(message=sep.join(map(str, args))))
raise_on_error(response)

def showTitle(self, text: str, typ: Literal["actionbar", "subtitle", "title"] = "title", color: COLOR = "gray", bold: bool = "false", italic: bool = "false", strikethrough: bool = "false", underlined: bool = "false", obfuscated: bool = "false", duration: int = 3, fade_in: int = 1, fade_out: int = 1) -> None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Und zuletzt bitte noch die Datentypen anpassen: Datentyp boolsollte als default Argument True oder False haben, nicht "true" oder "false". 👍

HasStub.runCommand(self, f'title @a times {fade_in}s {duration}s {fade_out}s')
HasStub.runCommand(self, f'title @a {typ} ' + '{' + f'"text":"{text}","color":"{color}","bold":{bold},"italic":{italic},"strikethrough":{strikethrough},"underlined":{underlined},"obfuscated":{obfuscated}' + '}')

def clearTitle(self):
HasStub.runCommand(self, 'title @a clear')
8 changes: 8 additions & 0 deletions mcproto/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import partial
from typing import Literal

from ._types import COLOR
from ._base import HasStub, _PlayerProvider
from ._util import ThreadSafeCachedKeyBasedFactory
from .entity import Entity
Expand Down Expand Up @@ -118,6 +119,13 @@ def op(self) -> None:
def deop(self) -> None:
HasStub.runCommand(self, f"deop {self.name}")

def showTitle(self, text: str, typ: Literal["actionbar", "subtitle", "title"] = "title", color: COLOR = "gray", bold: bool = "false", italic: bool = "false", strikethrough: bool = "false", underlined: bool = "false", obfuscated: bool = "false", duration: int = 3, fade_in: int = 1, fade_out: int = 1) -> None:
HasStub.runCommand(self, f'title {self.name} times {fade_in}s {duration}s {fade_out}s')
HasStub.runCommand(self, f'title {self.name} {typ} ' + '{' + f'"text":"{text}","color":"{color}","bold":{bold},"italic":{italic},"strikethrough":{strikethrough},"underlined":{underlined},"obfuscated":{obfuscated}' + '}')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da wir in der Klasse Player > Entity hier sind, können wir ruhig die überschriebene "runCommand" Funktion dieser Klasse verwenden. Hier direkt HasStub.runCommand zu verwenden umgeht die Klassenhierachie.
Wenn man das macht, könnte man auch bei allen Befehlen einfach 'title @s ...' schreiben, da der Player identifier schon in Entity.runCommand gesetzt wird 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitte diesen Punkt noch ausbessern, alle Instanzen von HasStub.runCommand durch self.runCommand ersetzten, und im Falle von der Player-Klasse, mit title @s ... anstelle von title {self.name} ...


def clearTitle(self):
self.runCommand("title @s clear")

# properties that have different stub entpoints than entity
@property
def pos(self) -> Vec3:
Expand Down