from commands import name, add, admin, alias   # ladies and gentlemen i apologize
import commands                                # for not adding any comments

@alias('bk')
@admin
@name('blockkill')
def block_kill(self):
    if self.protocol.deadly_blocks == True:
        self.protocol.deadly_blocks = False
        message = 'Blocks are peacefull again.'
        self.protocol.send_chat(message)
        return message
    else:
        self.protocol.deadly_blocks = True
        message = 'Blocks are deadly weapons now!'
        self.protocol.send_chat(message)
        return message
commands.add(block_kill)

@alias('bkr')
@admin
@name('blockkillrefill')
def block_kill_refill(self):
    if self.protocol.refill_on_kill == True:
        self.protocol.refill_on_kill = False
        message = 'Block-kills will not replenish your ammo and life anymore.'
        self.protocol.send_chat(message)
        return message
    else:
        self.protocol.refill_on_kill = True
        message = 'Block-kills will refill your HP and blocks again.'
        self.protocol.send_chat(message)
        return message
commands.add(block_kill_refill)


def apply_script(protocol, connection, config): # i just ran out of ideas Y_Y

    class blockkillprotocol(protocol):

        deadly_blocks = True   # yeah naming variables like an 8years old
        refill_on_kill = True  # i should try to write a poem with my comments

    class blockkillconnection(connection):

        def on_block_build(self, x, y, z): # too lazy to apply the same to block lines

            for pony in self.protocol.players.values():
            	if pony.team != 2: # necessary because it will show errors once somebody is in spectator team
                    x2, y2, z2 = pony.get_location() # uh yeah i bet you expected something with cats now - WRONG

                    if (round(x2), round(y2), round(z2)) == (x+1, y+1, z) and pony.team != self.team and self.protocol.deadly_blocks and pony.hp != None or (round(x2), round(y2), round(z2)) == (x+1, y+1, z-1) and pony.team != self.team and self.protocol.deadly_blocks and pony.hp != None : # that line appears to be slightly long, i realy should not write it like that
                        if self.protocol.refill_on_kill: self.refill() # comment
                        pony.kill(self) #

            return connection.on_block_build(self, x, y ,z)

    return blockkillprotocol, blockkillconnection







# i hate nuclearpotato <3