Code cleanup, adding aliases, adding verion number #36
184
imbusy.py
184
imbusy.py
@ -1,99 +1,108 @@
|
|||||||
# I'M BUSY! Plugin by Curs3d #
|
##################################
|
||||||
##############################
|
# I'M BUSY! Plugin by Curs3d #
|
||||||
# Concept by CookieManors :D #
|
# Concept by CookieManors :D #
|
||||||
# http://bit.ly/1GnNPW8 #
|
##################################
|
||||||
##############################
|
# This plugin permits users to #
|
||||||
# This plugin permits users to
|
# send a command that renders #
|
||||||
# send a command that renders
|
# them "busy", not letting them #
|
||||||
# them "busy", not letting them
|
# to get tpa requests or direct #
|
||||||
# to get tpa requests or direct
|
# messages, except from console. #
|
||||||
# messages, except from console.
|
# On restart, all busy data will #
|
||||||
# On restart, all busy data will
|
# be cleared. #
|
||||||
# be cleared.
|
##################################
|
||||||
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from basecommands import simplecommand
|
|
||||||
from traceback import format_exc as trace
|
|
||||||
busy_players = []
|
busy_players = []
|
||||||
|
|
||||||
|
# Version number and variables:
|
||||||
|
|
||||||
def unclear():
|
imbusy_version = "v1.0.0"
|
||||||
msg(sender, "Umm, what? Sorry, directions unlclear, got head stuck in washing machine")
|
blocked_commands = ["m", "tell", "msg", "t", "tpa"]
|
||||||
|
|
||||||
|
|
||||||
@hook.command("busy",
|
# Permissions:
|
||||||
aliases = ["focus"],
|
|
||||||
usage = "/<command> <on|off|status>",
|
permission_ALL = "utils.busy.*"
|
||||||
description = "Sets busy mode on, you cannot recieve tpas and MSGs"
|
permission_BASE = "utils.busy"
|
||||||
|
permission_USE = "utils.busy.use"
|
||||||
|
|
||||||
|
########
|
||||||
|
# CODE #
|
||||||
|
########
|
||||||
|
|
||||||
|
@hook.command("imbusy",
|
||||||
|
aliases = ["busy"],
|
||||||
|
usage = "/<command> <on, off, status/check>",
|
||||||
|
description = "Offers control over your busy status"
|
||||||
)
|
)
|
||||||
def on_busy_command(sender, cmd, label, args):
|
def on_busy_command(sender, cmd, label, args):
|
||||||
|
try:
|
||||||
if not is_player(sender):
|
if not is_player(sender):
|
||||||
msg(sender, "Sorry, Console cannot be busy")
|
msg(sender, "&7Sorry, Console cannot be busy...")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not sender.hasPermission("utils.busy.allowed"):
|
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
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:
|
if len(args) == 0:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
if sender.getName() in busy_players:
|
||||||
msg(sender, "This plugin allows being busy, and when turned on you will not recieve any direct messages or tpa requests.")
|
msg(sender, "&7You are currently busy.")
|
||||||
msg(sender, "\nCommands:")
|
else:
|
||||||
msg(sender, "/busy on: turns on busy mode")
|
msg(sender, "&7You are currently not busy.")
|
||||||
msg(sender, "/busy off: turns off busy mode")
|
|
||||||
msg(sender, "/busy status [player]: shows your or [player]'s current busy status.")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif len(args) == 1:
|
elif len(args) == 1:
|
||||||
if args[0] == "on":
|
if args[0] in busy_players:
|
||||||
if sender.getName() in busy_players:
|
msg(sender, "&7Player &e" + args[0] + " &7is currently busy.")
|
||||||
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
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
msg(sender, "&7Player &e" + args[0] + " &7is currently not busy.")
|
||||||
unclear()
|
return True
|
||||||
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
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
plugin_header(recipient = sender, name = "I'M BUSY!")
|
return help(sender, args)
|
||||||
unclear()
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerCommandPreprocessEvent", "monitor")
|
@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])
|
msg(event.getPlayer(), "We are sorry, but %s is currently busy. Please try again later." % message[1])
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent", "lowest")
|
@hook.event("player.PlayerQuitEvent", "lowest")
|
||||||
def on_player_leave(event):
|
def on_player_leave(event):
|
||||||
try:
|
try:
|
||||||
busy_players.remove(event.getPlayer().getName())
|
busy_players.remove(event.getPlayer().getName())
|
||||||
except:
|
except:
|
||||||
pass
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user