py2hackCraft2 1.0.4__tar.gz → 1.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2hackCraft2
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: These are APIs that connect to the hackCraft2 server from Python to manipulate pets.
5
5
  Home-page: https://pypi.org/project/py2hackCraft2/
6
6
  Author: Masafumi Terazono
@@ -143,6 +143,21 @@ class Location:
143
143
  z: int
144
144
  world: str = "world"
145
145
 
146
+ @dataclass
147
+ class EventMessage:
148
+ """
149
+ イベントメッセージを表すデータクラス。
150
+
151
+ Attributes:
152
+ sender (str): 送信者の名前。
153
+ uuid (str): 送信者の一意の識別子(UUID)。
154
+ message (str): イベントメッセージ。
155
+ """
156
+ entityUuid: str
157
+ sender: str
158
+ uuid: str
159
+ message: str
160
+
146
161
 
147
162
  @dataclass
148
163
  class ChatMessage:
@@ -150,7 +165,7 @@ class ChatMessage:
150
165
  チャットメッセージを表すデータクラス。
151
166
 
152
167
  Attributes:
153
- player (str): プレイヤー名または識別子。
168
+ player (str): プレイヤー名。
154
169
  uuid (str): プレイヤーの一意の識別子(UUID)。
155
170
  message (str): プレイヤーがチャットで送信したメッセージの内容。
156
171
  """
@@ -396,6 +411,28 @@ class Entity:
396
411
  callbackFunc(self, power)
397
412
  self.client.setCallback('onEntityRedstone', callbackWrapper)
398
413
 
414
+ def setOnMessage(self, callbackFunc: Callable[['Entity', str], Any]):
415
+ """
416
+ メッセージを受信したときに呼び出されるコールバック関数を設定する。
417
+ """
418
+ def callbackWrapper(data):
419
+ logging.debug("setOnMessage callbackWrapper '%s'" % data)
420
+ if(data['entityUuid'] == self.uuid):
421
+ logging.debug("callbackWrapper '%s'" % data)
422
+ event = EventMessage(**data)
423
+ callbackFunc(self, event)
424
+ self.client.setCallback('onCustomEvent', callbackWrapper)
425
+
426
+ def sendMessage(self, target: str, message: str):
427
+ """
428
+ メッセージを送信する。
429
+
430
+ Args:
431
+ target (str): 送信先のEntityの名前。
432
+ message (str): 送信するメッセージの内容。
433
+ """
434
+ self.client.sendCall(self.uuid, "sendEvent", [target, message])
435
+
399
436
  def getWorld(self) -> 'World':
400
437
  """
401
438
  指定された名前のワールドを取得する。
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2hackCraft2
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: These are APIs that connect to the hackCraft2 server from Python to manipulate pets.
5
5
  Home-page: https://pypi.org/project/py2hackCraft2/
6
6
  Author: Masafumi Terazono
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="py2hackCraft2",
5
- version="1.0.4",
5
+ version="1.0.5",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "websocket-client" # websocketライブラリの追加
File without changes
File without changes