Skip to content

Commit d1cf2fe

Browse files
committed
add even more commands
1 parent f04f173 commit d1cf2fe

6 files changed

Lines changed: 119 additions & 9 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ These are the currently supported commands. Feel free to create a PR, the goal i
1818
- [ ] /attribute
1919
- [x] /ban
2020
- [x] /ban-ip
21-
- [ ] /banlist
22-
- [ ] /bossbar
21+
- [x] /banlist
22+
- [x] /bossbar
2323
- [x] /clear
2424
- [ ] /clone
2525
- [ ] /data
2626
- [ ] /datapack
2727
- [ ] /debug
2828
- [x] /defaultgamemode
2929
- [x] /deop
30-
- [ ] /difficultiy
30+
- [x] /difficulty
3131
- [ ] /effect
3232
- [ ] /enchant
3333
- [x] /execute
@@ -61,12 +61,12 @@ These are the currently supported commands. Feel free to create a PR, the goal i
6161
- [ ] /setblock
6262
- [x] /setidletimeout
6363
- [x] /setworldspawn
64-
- [ ] /spawnpoint
65-
- [ ] /spectate
64+
- [x] /spawnpoint
65+
- [x] /spectate
6666
- [ ] /spreadplayers
6767
- [x] /stop
68-
- [ ] /stopsound
69-
- [ ] /summon
68+
- [x] /stopsound
69+
- [x] /summon
7070
- [x] /tag
7171
- [x] /team
7272
- [x] /teammsg (/tm)

pymcfunction/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .commands.tag import tag
66
from .commands.team import team
77
from .commands.item import item
8+
from .commands.bossbar import bossbar
89
from .commands.execute import execute
910
from .commands.teleport import teleport
1011
from .commands.scoreboard import Scoreboard

pymcfunction/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def compile():
149149
statements.remove(r)
150150

151151
for s in statements:
152-
code = imports + "\n_output = " + s + "\nprint(_output)"
152+
code = (
153+
imports
154+
+ "\n_output = "
155+
+ s
156+
+ "\nif type(_output) == str: print(_output)"
157+
)
153158
try:
154159
stdout = StringIO()
155160
with redirect_stdout(stdout):

pymcfunction/commands/bossbar.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import re
2+
from pymcfunction.types import BossbarColor, BossbarGetType, BossbarStyle
3+
4+
5+
class bossbar:
6+
def __init__(self, id: str):
7+
self.id = id
8+
9+
def create(self, name: str):
10+
return f"bossbar add {self.id} {name}"
11+
12+
def get(self, propertie: BossbarGetType):
13+
return f"bossbar get {self.id} {propertie.value}"
14+
15+
def listAll(self):
16+
return f"bossbar list"
17+
18+
def setColor(self, color: BossbarColor):
19+
return f"bossbar set {self.id} color {color.value}"
20+
21+
def setMax(self, max: int):
22+
return f"bossbar set {self.id} max {max}"
23+
24+
def setName(self, name: str):
25+
return f"bossbar set {self.id} name {name}"
26+
27+
def setPlayers(self, target: str):
28+
return f"bossbar set {self.id} players {target}"
29+
30+
def setStyle(self, style: BossbarStyle):
31+
return f"bossbar set {self.id} style {style.value}"
32+
33+
def setValue(self, value):
34+
return f"bossbar set {self.id} value {value}"
35+
36+
def setVisibility(self, visible: bool):
37+
return f"bossbar set {self.id} visible " + ("true" if visible else "false")

pymcfunction/commands/simple.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from pymcfunction.types import Gamemode, Weather
1+
from types import NoneType
2+
from pymcfunction.types import BanListType, Difficultiy, Gamemode, Weather
3+
from pymcfunction.util import _dictToMcKeyVal
24

35

46
def say(msg: str):
@@ -103,3 +105,32 @@ def pardon_ip(ip: str):
103105

104106
def teammsg(msg: str):
105107
return "teammsg " + msg
108+
109+
110+
def banlist(_type: BanListType):
111+
return "banlist " + _type.value
112+
113+
114+
def summon(entity: str, pos: str = "~ ~ ~", nbt: dict | str = None):
115+
return f"summon {entity} {pos}" + (
116+
((" " + (_dictToMcKeyVal(nbt)) if type(nbt) == dict else nbt)) if nbt else ""
117+
)
118+
119+
120+
def stopsound(target: str, source: str = None, sound: str = None):
121+
return f"stopsound {target}" + (
122+
(" " + (source + ((" " + sound) if sound else ""))) if source else ""
123+
)
124+
125+
126+
def spectate(target: str | NoneType, spectator: str = "@s"):
127+
if target:
128+
return f"spectate {target} {spectator}"
129+
return "spectate"
130+
131+
132+
def spawnpoint(target: str, coord: str = "~ ~ ~", yaw: float = None):
133+
return f"spawnpoint {target} {coord}" + ((" " + yaw) if yaw else "")
134+
135+
def difficulty(_difficulty:Difficultiy):
136+
return "difficulty " + _difficulty.value

pymcfunction/types.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,39 @@ class Weather(Enum):
189189
class ContainerType(Enum):
190190
ENTITY = "entity"
191191
BLOCK = "block"
192+
193+
194+
class BanListType(Enum):
195+
PLAYERS = "players"
196+
IPS = "ips"
197+
198+
199+
class BossbarGetType(Enum):
200+
MAX = "max"
201+
PLAYERS = "players"
202+
VALUE = "value"
203+
VISIBLE = "visible"
204+
205+
206+
class BossbarColor(Enum):
207+
BLUE = "blue"
208+
GREEN = "green"
209+
PINK = "pink"
210+
PURPLE = "purple"
211+
RED = "red"
212+
WHITE = "white"
213+
YELLOW = "yellow"
214+
215+
216+
class BossbarStyle(Enum):
217+
NOTCHED6 = "notched_6"
218+
NOTCHED10 = "notched_10"
219+
NOTCHED12 = "notched_12"
220+
NOTCHED20 = "notched_20"
221+
PROGRESS = "progress"
222+
223+
class Difficultiy(Enum):
224+
PEACEFUL = "peaceful"
225+
EASY = "easy"
226+
NORMAL = "normal"
227+
HARD = "hard"

0 commit comments

Comments
 (0)