import discord from discord.ext import commands import enum from transitions import Machine from cogs.spawner import get_server import utils color = discord.Color.from_rgb(181, 24, 60) class Whitelist: "A workflow machine for managing Whitelist states" On = None Off = None toggle = None class States(enum.Enum): NOTHING = 0 INIT = 1 SAFE = 2 FIGHT = 3 SUDDENDEATH = 4 END = 5 class Minecraft(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot transitions = [ ['init_game', States.NOTHING, States.INIT], ['start_game', States.INIT, States.SAFE], ['start_fight', States.SAFE, States.FIGHT], ['start_last_round', States.FIGHT, States.SUDDENDEATH], ['end_game', States.FIGHT, States.END], ['end_game', States.SUDDENDEATH, States.END], ['reset', States.END, States.INIT], ['abort', '*', States.NOTHING] ] self.machine = Machine(states=States, transitions=transitions, initial=States.NOTHING) @commands.hybrid_command(name='init') async def init(self, ctx: commands.Context, server_name: str): """ Initialize a Border Wars session Parameters ---------- ctx: commands.Context The context of the command invocation server_name: str Server on which the Session should be initialized """ c = get_server(server_name) if not c: await ctx.send("---The server doesn't run---") return cmds = [ "/effect give @a minecraft:resistance infinite 255 true", "/effect give @a minecraft:saturation infinite 4 true", "/tp @a 0 200 0", "/gamemode adventure @a", "/worldborder center 0 0", "/worldborder set 5", "/whitelist off" ] c.rcon.rconnect() c.rcon.sendcmd(cmds) embed = discord.Embed( title=f"Border Wars @ {server_name.title()}", description=''' Session initialized Get ready to get a good armorset. **Explanation** This phase last as long as the moderator wants. Every player is immune to damage and can't die by hunger. Look out for a good direction to scout. Happy Border Wars! ''', color=color, timestamp=utils.now() ) file = discord.File("../assets/init.png", filename="init.png") embed.set_thumbnail(url="attachment://init.png") await ctx.send(file=file, embed=embed) @commands.hybrid_command(name='safe') async def safe(self, ctx: commands.Context, server_name: str): """ Switches to Safe Phase on a Border Wars session Parameters ---------- ctx: commands.Context The context of the command invocation server_name: str Server on which the Session should be initialized """ c = get_server(server_name) if not c: await ctx.send("---The server doesn't run---") return cmds = [ '''/title @a subtitle ["",{"text":"bei ","color":"blue"},{"text":"BORDER WARS!","bold":true,"color":"red"}]''', '''/title @a title {"text":"Viel Glück!","bold":true,"color":"blue"}''', "playsound minecraft:entity.wither.spawn ambient @a 0 64 080", "/worldborder set 1000", "/gamerule keepInventory true", "/gamemode survival @a", "/effect clear @a" ] c.rcon.sendcmd(cmds) embed = discord.Embed( title=f"Border Wars @ {server_name.title()}", description=''' Switched to Safe Phase Hide from other players and scout for resources. **Explanation** This phase lasts 30 minutes, after that the fighting phase begins. Every player who dies will keep there inventory. Get a good armorset and be ready to fight. Happy Border Wars! ''', color=color, timestamp=utils.now() ) file = discord.File("../assets/safe.png", filename="safe.png") embed.set_thumbnail(url="attachment://safe.png") await ctx.send(file=file, embed=embed) @commands.hybrid_command(name='fight') async def fight(self, ctx: commands.Context, server_name: str): """ Switches to Fight Phase on a Border Wars session Parameters ---------- ctx: commands.Context The context of the command invocation server_name: str Server on which the Session should be initialized """ c = get_server(server_name) if not c: await ctx.send("---The server doesn't run---") return cmds = [ '''/title @a subtitle {"text":"ÜBERLEBEN!","bold":true,"color":"red"}''', '''/title @a title {"text":"Möge der beste","color":"blue"}''', "/playsound minecraft:item.totem.use ambient @a 0 64 0 80", "/worldborder set 75 3600", "/gamerule keepInventory false" ] c.rcon.sendcmd(cmds) embed = discord.Embed( title=f"Border Wars @ {server_name.title()}", description=''' Switched to Fight Phase Now the real fun begins. **Explanation** This phase lasts 60 minutes, after that the game ends. Every player can die now and therefor will lose. Look out for other players. Happy Border Wars! ''', color=color, timestamp=utils.now() ) file = discord.File("../assets/fight.png", filename="fight.png") embed.set_thumbnail(url="attachment://fight.png") await ctx.send(file=file, embed=embed) @commands.hybrid_command(name='death') async def death(self, ctx: commands.Context, server_name: str): """ Switches to Sudden Death Phase on a Border Wars session Parameters ---------- ctx: commands.Context The context of the command invocation server_name: str Server on which the Session should be initialized """ c = get_server(server_name) if not c: await ctx.send("---The server doesn't run---") return cmds = [ '''/title @a title ["",{"text":"Sudden ","color":"dark_blue"},{"text":"DEATH!","bold":true,"color":"red"}]''', "/playsound minecraft:entity.ender_dragon.growl ambient @a 0 64 0 80", "/worldborder set 5 600" ] c.rcon.sendcmd(cmds) embed = discord.Embed( title=f"Border Wars @ {server_name.title()}", description=''' Switched to Sudden Death Only one can be the Winner. **Explanation** This phase lasts as long as only one player survives. The worldborder will now shrink 'till zero zero. Good Luck. Happy Border Wars! ''', color=color, timestamp=utils.now() ) file = discord.File("../assets/death.png", filename="death.png") embed.set_thumbnail(url="attachment://death.png") await ctx.send(file=file, embed=embed) @commands.hybrid_command(name='end') async def end(self, ctx: commands.Context, server_name: str, playername: str): """ Ends a Border Wars session Parameters ---------- ctx: commands.Context The context of the command invocation server_name: str Server on which the Session should be initialized playername: str Player which is announced as the Winner """ c = get_server(server_name) if not c: await ctx.send("---The server doesn't run---") return cmds = [ "/worldborder center 0 0", "/worldborder set 75", "/gamerule keepInventory true", '''/title @a subtitle ["",{"text":"''' + playername + '''","bold":true,"color":"red"},{"text":" gewinnt","color":"dark_blue"}]''', '''/title @a title {"text":"ENDE!","color":"dark_blue"}''', "/playsound minecraft:entity.ender_dragon_death ambient @a 0 64 0 80", ] c.rcon.sendcmd(cmds) embed = discord.Embed( title=f"Border Wars @ {server_name.title()}", description=f''' *Game Over* Congratulations **{playername}**. Hope you had fun @ **Border Wars!** ''', color=color, timestamp=utils.now() ) file = discord.File("../assets/end.png", filename="end.png") embed.set_thumbnail(url="attachment://end.png") await ctx.send(file=file, embed=embed)