Skip to content

Commit

Permalink
feat: Improve player death handling and server reset logic
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Labeyrie <[email protected]>
  • Loading branch information
Razano26 committed Aug 28, 2024
1 parent 1cf01a3 commit c10bb32
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions hardloop/hardloop/observer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
from mcrcon import MCRcon
from .server import update_motd
import aioping

last_dead_player = "Unknown"

Expand All @@ -12,13 +11,21 @@ async def listen():
with MCRcon("0.0.0.0", "password", port=25575) as client:
while True:
try:
response = client.command("/scoreboard players list")
if "There are no tracked entities" not in response:
last_dead_player = response.split(": ")[1]
client.command(f"/kick @a {last_dead_player} is dead !")
update_motd(last_dead_player)
await reset_server(client)
break
players = client.command("/list")
players = players.split(": ")[1].split(", ")
if len(players) != 0:
for player in players:
response = client.command(
f"/scoreboard players get {player} Deaths"
)
if "has" in response:
last_dead_player = player
client.command(
f"/kick @a {last_dead_player} is dead !"
)
update_motd(last_dead_player)
await reset_server(client)
break
except Exception:
print("error fetching deaths")

Expand Down

0 comments on commit c10bb32

Please sign in to comment.