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

feat: Refactor server.py and observer.py for better code organization… #14

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
14 changes: 12 additions & 2 deletions hardloop/hardloop/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ async def reset_server(client):
def uptime_incr():
global server_uptime
server_uptime = server_uptime + 1
return server_uptime
return int_to_date(server_uptime)

def played_time_incr():
global played_time
played_time = played_time + 1
return played_time
return int_to_date(played_time)

def int_to_date(time: int) -> str:
seconds = time % 60
minutes = time // 60 % 60
hours = time // 3600 % 24
days = time // 86400
if (minutes == 0 and hours == 0 and days == 0): return f"{seconds}s"
if (hours == 0 and days == 0): return f"{minutes}m {seconds}s"
if (days == 0): return f"{hours}h {minutes}m {seconds}s"
return f"{days}d {hours}h {minutes}m {seconds}s"
10 changes: 8 additions & 2 deletions hardloop/hardloop/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ async def start_server(server_port=25565):
client.command("/scoreboard objectives setdisplay list health")
client.command("/scoreboard objectives add Hardloop dummy {\"text\":\"HardLoop\",\"bold\":true,\"color\":\"light_purple\"}")
client.command("/scoreboard objectives setdisplay sidebar Hardloop")
client.command("/scoreboard players set Uptime Hardloop 1")
client.command("/scoreboard players set Played Hardloop 0")
client.command("/scoreboard players set =-=-=-=-=-=-=-=-=-=-=-=-= Hardloop 3")
client.command("/scoreboard players set Uptime Hardloop 2")
client.command("/scoreboard players set Played Hardloop 1")
client.command("/scoreboard players set -=-=-=-=-=-=-=-=-=-=-=-=- Hardloop 0")
client.command("/team add uptime")
client.command("/team add played")
client.command("/team add separators")
client.command("/team join uptime Uptime")
client.command("/team join played Played")
client.command("/team join separators -=-=-=-=-=-=-=-=-=-=-=-=-")
client.command("/team join separators =-=-=-=-=-=-=-=-=-=-=-=-=")
client.command("/team modify separators color light_purple")
client.command("/team modify uptime color red")
client.command("/team modify played color red")
client.command("/team modify uptime suffix {\"text\":\" : 00m00\",\"color\":\"red\"}")
Expand Down