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

Could use an alternative connection for write only which is ServerTap websocket #14

Open
atyrode opened this issue Sep 23, 2023 · 0 comments

Comments

@atyrode
Copy link
Member

atyrode commented Sep 23, 2023

import shulker as mc
import time
import websocket
import datetime
import time

authentication_key = "my-key"
url = "ws://localhost:4567/v1/ws/console"
ws = websocket.WebSocket()
ws.connect(url, cookie="x-servertap-key=" + authentication_key)

mc.connect()
cube_size = 20
origin = mc.BlockCoordinates(0, 4, 0)
poster = {
    'rcon': lambda cmd: mc.post(cmd),
    'servertap': lambda cmd: ws.send(cmd)
}

ret = mc.post("sudo PortalHub /replacenear 300 stone,netherrack air")
time.sleep(2)

with ws.connect(url, cookie="x-servertap-key=" + authentication_key) as ws:
    for option in ['servertap']:
        if option == 'servertap':
            origin = origin.offset(x=cube_size + 4)

        start = datetime.datetime.now().strftime('%H:%M:%S')
        poster[option](f"say Starting {option} at {start}")

        for x in range(cube_size):
            for y in range(cube_size):
                for z in range(cube_size):
                    cmd = f'setblock {origin.x + x} {origin.y + y} {origin.z + z} {"stone" if option == "rcon" else "netherrack"}'
                    ret = poster[option](cmd)
                    print(ret)
        
        end = datetime.datetime.now().strftime('%H:%M:%S')
        poster[option](f"say Finished {option} at {end} (took {datetime.datetime.strptime(end, '%H:%M:%S') - datetime.datetime.strptime(start, '%H:%M:%S')})")

print("done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant