Skip to content

Commit

Permalink
feat: Refactor server.py and observer.py for better code organization…
Browse files Browse the repository at this point in the history
… and readability
  • Loading branch information
Nayrode committed Aug 29, 2024
1 parent 0ac7987 commit a3826a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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

0 comments on commit a3826a2

Please sign in to comment.