Skip to content

Commit e70bf32

Browse files
committed
Added more commands, linted and bumped version to 0.1.2
1 parent 8fedefd commit e70bf32

13 files changed

Lines changed: 246 additions & 33 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release on Pypi
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
ReleasePypi:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Build and publish to pypi
12+
uses: JRubics/poetry-publish@v1.13
13+
with:
14+
pypi_token: ${{ secrets.PYPI_TOKEN }}
15+
python_version: "3.10.8"
16+
allow_poetry_pre_release: "yes"
17+
ignore_dev_requirements: "yes"

README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ These are the currently supported commands. Feel free to create a PR, the goal i
1616

1717
- [ ] /advancement
1818
- [ ] /attribute
19-
- [ ] /ban
20-
- [ ] /ban-ip
19+
- [x] /ban
20+
- [x] /ban-ip
2121
- [ ] /banlist
2222
- [ ] /bossbar
2323
- [x] /clear
@@ -35,48 +35,47 @@ These are the currently supported commands. Feel free to create a PR, the goal i
3535
- [ ] /fill
3636
- [ ] /forceload
3737
- [x] /function
38-
- [ ] /gamemode
39-
- [ ] /gamerule
40-
- [ ] /give
41-
- [ ] /item
42-
- [ ] /kick
43-
- [ ] /kill
38+
- [x] /gamemode
39+
- [x] /gamerule
40+
- [x] /give
41+
- [x] /item
42+
- [x] /kick
43+
- [x] /kill
4444
- [ ] /locate
4545
- [ ] /loot
46-
- [ ] /msg (/tell and /w)
47-
- [ ] /op
48-
- [ ] /pardon
49-
- [ ] /pardon-ip
46+
- [x] /op
47+
- [x] /pardon
48+
- [x] /pardon-ip
5049
- [ ] /particle
5150
- [ ] /place
5251
- [ ] /playsound
5352
- [ ] /publish
5453
- [ ] /recipe
55-
- [ ] /save-all
56-
- [ ] /save-off
57-
- [ ] /save-on
54+
- [x] /save-all
55+
- [x] /save-off
56+
- [x] /save-on
5857
- [x] /say
5958
- [ ] /schedule
6059
- [x] /scoreboard
61-
- [ ] /seed
60+
- [x] /seed
6261
- [ ] /setblock
63-
- [ ] /setidletimeout
64-
- [ ] /setworldspawn
62+
- [x] /setidletimeout
63+
- [x] /setworldspawn
6564
- [ ] /spawnpoint
6665
- [ ] /spectate
6766
- [ ] /spreadplayers
68-
- [ ] /stop
67+
- [x] /stop
6968
- [ ] /stopsound
7069
- [ ] /summon
71-
- [ ] /tag
72-
- [ ] /team
73-
- [ ] /teammsg (/tm)
74-
- [ ] /teleport (/tp)
70+
- [x] /tag
71+
- [x] /team
72+
- [x] /teammsg (/tm)
73+
- [x] /teleport (/tp)
7574
- [ ] /tellraw
7675
- [ ] /time
7776
- [ ] /title
7877
- [ ] /trigger
79-
- [ ] /weather
78+
- [x] /weather
8079
- [ ] /whitelist
8180
- [ ] /worldborder
8281

pymcfunction/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
from .util import *
44

5+
from .commands.tag import tag
6+
from .commands.team import team
7+
from .commands.item import item
58
from .commands.execute import execute
9+
from .commands.teleport import teleport
610
from .commands.scoreboard import Scoreboard
711

812
from .commands.simple import *

pymcfunction/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def publish():
187187
filetypes=files,
188188
defaultextension=files,
189189
title="Save packaged datapack...",
190-
confirmoverwrite = True,
190+
confirmoverwrite=True,
191191
initialfile=f'{config["compiled_folder_name"]}-{int(time.time())}.zip',
192192
)
193193
print(file)
@@ -199,4 +199,5 @@ def publish():
199199
shutil.make_archive(file, "zip", outFolder)
200200
print("Created archive!")
201201

202+
202203
app()

pymcfunction/commands/item.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pymcfunction.types import ContainerType
2+
3+
4+
class item:
5+
def __init__(self) -> None:
6+
pass
7+
8+
def modifyEntity(self, target: str, slot: str, modifier: str):
9+
return f"item modify entity {target} {slot} {modifier}"
10+
11+
def modifyBlock(self, coord: str, slot: str, modifier: str):
12+
return f"item modify block {coord} {slot} {modifier}"
13+
14+
def replaceEntity(self, target: str, slot: str, item: str, count: int = 1):
15+
return f"item replace entity {target} {slot} with {item} {count}"
16+
17+
def replaceBlock(self, coord: str, slot: str, item: str, count: int = 1):
18+
return f"item replace block {coord} {slot} with {item} {count}"
19+
20+
def copy(
21+
self,
22+
sourceType: ContainerType,
23+
source: str,
24+
sourceSlot: str,
25+
destType: ContainerType,
26+
dest: str,
27+
destSlot: str,
28+
modifier: str = None,
29+
):
30+
"""Copy item
31+
32+
Args:
33+
sourceType (ContainerType): ContainerType.ENTITY or ContainerType.Block
34+
source (str): Coordinate or selector of source
35+
sourceSlot (str): Slot of item in the source
36+
destType (ContainerType): ContainerType.ENTITY or ContainerType.BLOCK
37+
dest (str): Coordinate or selector of destination
38+
destSlot (str): Slot of item in destination
39+
"""
40+
return f"item replace {destType.value} {dest} {destSlot} from {sourceType.value} {source} {sourceSlot}{(' ' + modifier) if modifier else ''}"

pymcfunction/commands/scoreboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def delete(self):
1515
def setdisplay(self, slot: str):
1616
return f"scoreboard objectives setdisplay {slot} {self.name}"
1717

18-
def modifyDisplayName(self, displayNameJsonComponent: str|dict):
18+
def modifyDisplayName(self, displayNameJsonComponent: str | dict):
1919
return f"scoreboard objectives modify {self.name} displayname {displayNameJsonComponent}"
2020

2121
def modifyRendertype(self, rendertype: ScoreboardRenderType):

pymcfunction/commands/simple.py

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,104 @@
1-
from pymcfunction.types import Gamemode
1+
from pymcfunction.types import Gamemode, Weather
2+
23

34
def say(msg):
45
return "say " + str(msg)
56

67

78
def function(path: str, includeWorkspace=True):
8-
return "function " + ("@@PYMCFUNCTION-NAMESPACE:" if includeWorkspace else "") + path
9+
return (
10+
"function " + ("@@PYMCFUNCTION-NAMESPACE:" if includeWorkspace else "") + path
11+
)
12+
913

10-
def clear(target:str="@s"):
14+
def clear(target: str = "@s"):
1115
return "clear " + target
1216

13-
def defaultgamemode(mode:Gamemode):
17+
18+
def defaultgamemode(mode: Gamemode):
1419
val = mode.value
1520
if val[0] == "!":
1621
raise Exception("Default gamemode needs to be one specific gamemode.")
1722
return "defaultgamemode " + val
1823

19-
def deop(player:str):
20-
return "deop " + player
24+
25+
def deop(player: str):
26+
return "deop " + player
27+
28+
29+
def op(player: str):
30+
return "op " + player
31+
32+
33+
def stop():
34+
return "stop"
35+
36+
37+
def weather(_type: Weather, duration: int = 999999):
38+
return f"weather {_type.value} {duration}"
39+
40+
41+
def seed():
42+
return "seed"
43+
44+
45+
def setworldspawn(coord: str, yaw: float = 0.0):
46+
return f"setworldspawn {coord} {yaw}"
47+
48+
49+
def setidletimeout(minutes: int):
50+
return "setidletimeout " + str(minutes)
51+
52+
53+
def give(target: str, item: str, count: int = 1):
54+
return f"give {target} {count}"
55+
56+
57+
def kill(target: str):
58+
return "kill " + target
59+
60+
61+
def kick(target: str):
62+
return "kick " + target
63+
64+
65+
def gamemode(mode: Gamemode):
66+
val = mode.value
67+
if val[0] == "!":
68+
raise Exception("Gamemode needs to be one specific gamemode.")
69+
return "gamemode " + val
70+
71+
72+
def gamerule(rule: str, val: str):
73+
return f"gamerule {rule} {val}"
74+
75+
76+
def save_all(flush=False):
77+
return "save-all" + (" flush" if flush else "")
78+
79+
80+
def save_off():
81+
return "save-off"
82+
83+
84+
def save_on():
85+
return "save-on"
86+
87+
88+
def ban(player: str, reason: str = None):
89+
return f"ban {player}" + ((" " + reason) if reason else "")
90+
91+
92+
def ban_ip(ip: str, reason: str = None):
93+
return f"ban-ip {ip}" + ((" " + reason) if reason else "")
94+
95+
96+
def pardon(player: str):
97+
return "pardon " + player
98+
99+
100+
def pardon_ip(ip: str):
101+
return "pardon " + ip
102+
103+
def teammsg(msg:str):
104+
return "teammsg " + msg

pymcfunction/commands/tag.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class tag:
2+
def __init__(self, target: str) -> None:
3+
self.target = target
4+
5+
def add(self, tag):
6+
return f"tag {self.target} add {tag}"
7+
8+
def remove(self, tag):
9+
return f"tag {self.target} remove {tag}"
10+
11+
def list(self):
12+
return f"tag {self.target} list"

pymcfunction/commands/team.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class team:
2+
def __init__(self, name: str) -> None:
3+
self.name = name
4+
5+
def create(self, displayName: str = None):
6+
return f"team add {self.name}" + ((" " + displayName) if displayName else "")
7+
8+
def listTeams(self):
9+
return "team list"
10+
11+
def listMembers(self):
12+
return "team list " + self.name
13+
14+
def remove(self):
15+
return "team remove " + self.name
16+
17+
def empty(self):
18+
return "team emtpy " + self.name
19+
20+
def join(self, target:str="@s"):
21+
return f"team join {self.name} {target}"
22+
23+
def leave(self, target:str):
24+
return f"team leave {target}"
25+
26+
def modify(self, option:str, value:str):
27+
return f"team modify {self.name} {option} {value}"

pymcfunction/commands/teleport.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pymcfunction.types import AnchorType
2+
3+
class teleport:
4+
def __init__(self, target:str="@s") -> None:
5+
self.target = target
6+
7+
def destination(self, coord:str, rotation:float|int=None):
8+
return f"teleport {self.target} {coord}" + ((" " + str(rotation)) if rotation else "")
9+
10+
def facingCoordinate(self, coord:str, facing:str):
11+
return f"teleport {self.target} {coord} facing {facing}"
12+
13+
def facingEntity(self, coord:str, facingEntity:str, anchor:AnchorType=AnchorType.EYES):
14+
return f"teleport {self.target} {coord} facing entity {facingEntity} {anchor.value}"

0 commit comments

Comments
 (0)