From eee0588fe4747d2e9cfc90411ef19267e53aeb2c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Feb 2016 17:45:02 +0100 Subject: [PATCH] Code cleanup, adding aliases, adding verion number --- imbusy.py | 184 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 80 deletions(-) diff --git a/imbusy.py b/imbusy.py index 37a964e..7d39118 100644 --- a/imbusy.py +++ b/imbusy.py @@ -1,99 +1,108 @@ -# I'M BUSY! Plugin by Curs3d # -############################## -# Concept by CookieManors :D # -# http://bit.ly/1GnNPW8 # -############################## -# This plugin permits users to -# send a command that renders -# them "busy", not letting them -# to get tpa requests or direct -# messages, except from console. -# On restart, all busy data will -# be cleared. +################################## +# I'M BUSY! Plugin by Curs3d # +# Concept by CookieManors :D # +################################## +# This plugin permits users to # +# send a command that renders # +# them "busy", not letting them # +# to get tpa requests or direct # +# messages, except from console. # +# On restart, all busy data will # +# be cleared. # +################################## from helpers import * -from basecommands import simplecommand -from traceback import format_exc as trace busy_players = [] +# Version number and variables: -def unclear(): - msg(sender, "Umm, what? Sorry, directions unlclear, got head stuck in washing machine") +imbusy_version = "v1.0.0" +blocked_commands = ["m", "tell", "msg", "t", "tpa"] -@hook.command("busy", - aliases = ["focus"], - usage = "/ ", - description = "Sets busy mode on, you cannot recieve tpas and MSGs" +# Permissions: + +permission_ALL = "utils.busy.*" +permission_BASE = "utils.busy" +permission_USE = "utils.busy.use" + +######## +# CODE # +######## + +@hook.command("imbusy", + aliases = ["busy"], + usage = "/ ", + description = "Offers control over your busy status" ) def on_busy_command(sender, cmd, label, args): - - if not is_player(sender): - msg(sender, "Sorry, Console cannot be busy") - return True - - if not sender.hasPermission("utils.busy.allowed"): + try: + if not is_player(sender): + msg(sender, "&7Sorry, Console cannot be busy...") + return True plugin_header(recipient = sender, name = "I'M BUSY!") - noperm(sender) - return True + args = array_to_list(args) + if not hasPerm(sender, permission_BASE): + noperm(sender) + return True + return subcommands[args[0].lower()](sender, args[1:]) + except: + print(trace()) + return subcommands["help"](sender, []) + +def help(sender, args): + msg(sender, "&7This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.") + msg(sender, "\n&eCommands:") + msg(sender, "&e/busy on &7- Turns on busy mode") + msg(sender, "&e/busy off &7- Turns off busy mode") + msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status") + return True + + +def on(sender, args): + if not hasPerm(sender, permission_USE): + noPerm(sender) + return True + if sender.getName() in busy_players: + msg(sender, "&7You are already busy!") + return True + busy_players.append(sender.getName()) + broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) + return True + + +def off(sender, args): + if not hasPerm(sender, permission_USE): + noPerm(sender) + return True + try: + busy_players.remove(sender.getName()) + broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) + return True + except ValueError: + msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?") + return True + + +def get_status(sender, args): + if not hasPerm(sender, permission_BASE): + noPerm(sender) + return True if len(args) == 0: - plugin_header(recipient = sender, name = "I'M BUSY!") - msg(sender, "This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.") - msg(sender, "\nCommands:") - msg(sender, "/busy on: turns on busy mode") - msg(sender, "/busy off: turns off busy mode") - msg(sender, "/busy status [player]: shows your or [player]'s current busy status.") + if sender.getName() in busy_players: + msg(sender, "&7You are currently busy.") + else: + msg(sender, "&7You are currently not busy.") return True - elif len(args) == 1: - if args[0] == "on": - if sender.getName() in busy_players: - plugin_header(recipient = sender, name = "I'M BUSY!") - msg(sender, "You cannot be even more focused than this without being a jedi!") - return True - busy_players.append(sender.getName()) - plugin_header(recipient = sender, name = "I'M BUSY!") - broadcast(None, "%s is now SUPER busy! Don't even TRY bothering them, it will not work!" % sender.getName()) - return True - - elif args[0] == "off": - plugin_header(recipient = sender, name = "I'M BUSY!") - try: - busy_players.remove(sender.getName()) - msg(sender, "Master has sent /busy command, %s is freeee!" % sender.getName()) - return True - except ValueError: - msg(sender, "You are not busy! You cannot be even less busy! Are you perhaps bored?") - return True - - elif args[0] == "status": - plugin_header(recipient = sender, name = "I'M BUSY!") - if sender.getName() in busy_players: - msg(sender, "You are super-duper busy and concentrated right now. Think, think, think!") - return True - else: - msg(sender, "You are completely unable to focus right now.") - return True - + if args[0] in busy_players: + msg(sender, "&7Player &e" + args[0] + " &7is currently busy.") else: - plugin_header(recipient = sender, name = "I'M BUSY!") - unclear() - return False - - elif len(args) == 2 and args[0] == "status": - plugin_header(recipient = sender, name = "I'M BUSY!") - if args[1] in busy_players: - msg(sender, "Yes, %s is busy. Shhh..." % args[1]) - return True - else: - msg(sender, "No, you're good. Feel free to chat with %s!" % args[1]) - return True - + msg(sender, "&7Player &e" + args[0] + " &7is currently not busy.") + return True else: - plugin_header(recipient = sender, name = "I'M BUSY!") - unclear() - return False + return help(sender, args) @hook.event("player.PlayerCommandPreprocessEvent", "monitor") @@ -106,9 +115,24 @@ def on_cmd_preprocess_event(event): msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1]) event.setCancelled(True) + @hook.event("player.PlayerQuitEvent", "lowest") def on_player_leave(event): try: busy_players.remove(event.getPlayer().getName()) except: pass + +def hasPerm(player, permission): + return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL)) + + +# Subcommands: + +subcommands = { + "help": help, + "on": on, + "off": off, + "check": get_status, + "status": get_status +} -- 2.45.2