Solidify imbusy blocking pms, tpas, etc. #42

Merged
Dico200 merged 8 commits from imbusy-reply-patch into dev 2016-05-28 20:22:01 +00:00
3 changed files with 58 additions and 22 deletions
Showing only changes of commit 7a905643eb - Show all commits

View File

@ -5,6 +5,10 @@ friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend
friend_join_sound = "random.orb" friend_join_sound = "random.orb"
def is_friend_of(player, other):
lst = friends.get(uid(player))
return lst is not None and uid(other) in lst
@hook.event("player.PlayerJoinEvent", "high") # creates sound and sends a bold message on friend join @hook.event("player.PlayerJoinEvent", "high") # creates sound and sends a bold message on friend join
def fjm(event): # friend join message def fjm(event): # friend join message

View File

@ -12,6 +12,7 @@
################################## ##################################
from helpers import * from helpers import *
from friends import is_friend_of
import org.bukkit.command.Command as Command import org.bukkit.command.Command as Command
imbusy_version = "v1.1.0" imbusy_version = "v1.1.0"
@ -21,7 +22,7 @@ use_permission = "utils.busy.use" # for being busy
override_permission = "utils.busy.override" # for being able to bother busy people override_permission = "utils.busy.override" # for being able to bother busy people
busy_players = [] busy_players = {} # name : false/true where false is normal busy and true is super busy
@hook.command("imbusy", @hook.command("imbusy",
@ -51,6 +52,8 @@ def on_busy_command(sender, cmd, label, args):
return off(sender) return off(sender)
if arg0 in ("status", "check"): if arg0 in ("status", "check"):
return status(sender, args[1:]) return status(sender, args[1:])
if arg0 == "super":
return super_cmd(sender)
return help(sender) return help(sender)
@ -60,11 +63,11 @@ def toggle(sender):
return True return True
sender_name = sender.getName() sender_name = sender.getName()
if sender_name in busy_players: if sender_name in busy_players:
busy_players.remove(sender_name) del busy_players[sender_name]
broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) broadcast(None, sender.getDisplayName() + " &7is no longer busy...")
else: else:
busy_players.append(sender_name) busy_players.append(sender_name)
broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) broadcast(None, sender.getDisplayName() + " &7is now busy...")
return True return True
@ -75,6 +78,7 @@ def help(sender):
msg(sender, "&e/busy on &7- Turns on busy status") msg(sender, "&e/busy on &7- Turns on busy status")
msg(sender, "&e/busy off &7- Turns off busy status") msg(sender, "&e/busy off &7- Turns off busy status")
msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status") msg(sender, "&e/busy status [player] &7- shows your or [player]'s current busy status")
msg(sender, "&e/busy super &7- sets your status to SUPER busy such that even friends can not bother you")
return True return True
@ -83,11 +87,11 @@ def on(sender):
noperm(sender) noperm(sender)
return True return True
sender_name = sender.getName() sender_name = sender.getName()
if sender_name in busy_players: if busy_players.get(sender_name) is False: # can be None, False or True
msg(sender, "&7You are already busy!") msg(sender, "&7You are already busy!")
return True else:
busy_players.append(sender_name) busy_players[sender_name] = False # busy but not super busy
broadcast(None, colorify(sender.getDisplayName() + " &7is now busy...")) broadcast(None, sender.getDisplayName() + " &7is now busy...")
return True return True
@ -99,8 +103,8 @@ def off(sender):
if sender_name not in busy_players: if sender_name not in busy_players:
msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?") msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?")
return True return True
busy_players.remove(sender_name) del busy_players[sender_name]
broadcast(None, colorify(sender.getDisplayName() + " &7is no longer busy...")) broadcast(None, sender.getDisplayName() + " &7is no longer busy...")
return True return True
@ -110,7 +114,10 @@ def status(sender, args):
return True return True
if len(args) == 0: if len(args) == 0:
if sender.getName() in busy_players: if sender.getName() in busy_players:
if busy_players[sender_name] is False:
msg(sender, "&7You are currently busy.") msg(sender, "&7You are currently busy.")
else:
msg(sender, "&7You are currently SUPER busy.")
else: else:
msg(sender, "&7You are currently not busy.") msg(sender, "&7You are currently not busy.")
else: else:
@ -118,18 +125,33 @@ def status(sender, args):
if target is None: if target is None:
msg(sender, "&7That player is not online") msg(sender, "&7That player is not online")
elif target.getName() in busy_players: elif target.getName() in busy_players:
msg(sender, "&7Player &e" + args[0] + " &7is currently busy.") if busy_players[target.getName()] is False:
msg(sender, "&7Player %s &7is currently busy." % target.getDisplayName())
else: else:
msg(sender, "&7Player &e" + args[0] + " &7is currently not busy.") msg(sender, "&7Player %s &7is currently SUPER busy." % target.getDisplayName())
else:
msg(sender, "&7Player %s &7is currently not busy." % target.getDisplayName())
return True
def super_cmd(sender):
if not sender.hasPermission(use_permission):
noperm(sender)
return True
sender_name = sender.getName()
if busy_players.get(sender_name) is True:
msg(sender, "&7You are already SUPER busy!")
else:
busy_players[sender_name] = True # SUPER busy
broadcast(None, sender.getDisplayName() + " &7is now SUPER busy...")
return True return True
@hook.event("player.PlayerQuitEvent", "lowest") @hook.event("player.PlayerQuitEvent", "lowest")
def on_player_leave(event): def on_player_leave(event):
try: player_name = event.getPlayer().getName()
busy_players.remove(event.getPlayer().getName()) if player_name in busy_players:
except: del busy_players[player_name]
pass
#---- Dicode for catching any bothering of busy people ---- #---- Dicode for catching any bothering of busy people ----
@ -138,11 +160,19 @@ def on_player_leave(event):
reply_targets = {} reply_targets = {}
def can_send(sender, target):
if not target.getName() in busy_players:
return True
if target is sender or sender.hasPermission(override_permission):
return True
return busy_players[target.getName()] is False and is_friend_of(target, sender)
def whisper(sender, target_name): def whisper(sender, target_name):
target = server.getPlayer(target_name) target = server.getPlayer(target_name)
if target is not None: if target is not None:
if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: if not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False return False
@ -158,7 +188,7 @@ def reply(sender):
if sender.getName() in reply_targets: if sender.getName() in reply_targets:
target = server.getPlayer(reply_targets[sender.getName()]) target = server.getPlayer(reply_targets[sender.getName()])
if target is not None: if target is not None:
if target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: if not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False return False
@ -181,7 +211,7 @@ class CommandWrapper(Command):
def execute(self, sender, label, args): def execute(self, sender, label, args):
try: try:
if self.checker(sender, args): if not is_player(sender) or self.checker(sender, args):
return self.wrapped.execute(sender, label, args) return self.wrapped.execute(sender, label, args)
except: except:
error(trace()) error(trace())
@ -201,7 +231,7 @@ def tpa_command_checker(sender, args):
if len(args) == 0: if len(args) == 0:
return True return True
target = server.getPlayer(args[0]) target = server.getPlayer(args[0])
if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: if target is not None and not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False return False
return True return True
@ -214,7 +244,7 @@ def mail_command_checker(sender, args):
if len(args) < 3 or args[0].lower() != "send": if len(args) < 3 or args[0].lower() != "send":
return True return True
target = server.getPlayer(args[1]) target = server.getPlayer(args[1])
if target is not None and target is not sender and not sender.hasPermission(override_permission) and target.getName() in busy_players: if target is not None and not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName()) msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False return False
return True return True

View File

@ -44,6 +44,8 @@ shared["load_modules"] = [
"calc", "calc",
# Adds aliasing of chat words # Adds aliasing of chat words
"chatalias", "chatalias",
# For players to point friends
"friends",
# Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities # Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities
"lagchunks", "lagchunks",
# Adds /report and /rp, Stores reports with time and location # Adds /report and /rp, Stores reports with time and location