fix colors, highlight word, create sound

This commit is contained in:
jomo
2014-06-21 00:52:16 +02:00
parent 3e27b2691b
commit c150fae053
3 changed files with 31 additions and 14 deletions

View File

@@ -31,6 +31,9 @@ def broadcast(perm, text):
def colorify(text):
return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)
def stripcolors(text):
return sub(u"\u00A7[\\da-fk-or]", "", "%s" % text)
def safetp(player, world, x, y, z, yaw = 0, pitch = 0):
tpblock = Location(world, x, y, z).getBlock()
if (tpblock.isEmpty() and tpblock.getRelative(bblock.BlockFace.UP).isEmpty()) or y > 255:

View File

@@ -30,7 +30,7 @@ def onDisable():
log("Loading RedstonerUtils...")
# Import all modules
modules = ["misc", "adminchat", "lagchunks", "reports", "chatgroups", "webtoken", "saylol", "skullclick"]
modules = ["misc", "adminchat", "lagchunks", "reports", "chatgroups", "webtoken", "saylol", "skullclick", "mentio"]
mod = {}
for module in modules:
try:

View File

@@ -1,18 +1,32 @@
#pylint: disable=F0401
from helpers import *
from re import compile as reg_compile
arrow = colorify(u"&r&7\u2192&r")
regex = reg_compile(u"\u00A7[\\da-fk-or]")
mio_permission = "utils.mio"
@hook.event("player.PlayerChatEvent", "normal")
@hook.event("player.AsyncPlayerChatEvent", "normal")
def onChat(event):
symbol = u"\u272a"
if not event.isCancelled():
sender = event.getPlayer()
messages = event.getMessage()
messagesList = messages.split(" ")
for message in messagesList:
for recipient in server.getOnlinePlayers().tolist():
if message[:3].lower() in recipient.getName().lower() and len(message) > 2:
msg(recipient, "&6" + symbol + " &f%s &6mentioned you" % sender.getDisplayName())
# Couldn't figure out how to do this
# recipient.playSound(recipient.getLocation(), Sound.CHICKEN_EGG_POP, 1, 1)
words = event.getMessage().split(" ")
recipients = event.getRecipients()
for recipient in recipients:
rec_words = words[:] # copy
for i in range(len(rec_words)):
word = rec_words[i]
if recipient.getName().lower() in word.lower():
colors = "".join(regex.findall("".join(words[:i+1]))) # join all color codes used upto this word
rec_words[i] = colorify("&r&a<&6") + stripcolors(word) + colorify("&r&a>&r") + colors # extra fancy highlight
# player was mentioned
if rec_words != words:
try: # list might not be mutable
recipients.remove(recipient) # don't send original message
except:
pass
message = " ".join([sender.getDisplayName(), arrow] + rec_words)
msg(recipient, message, usecolor = False)
recipient.playSound(recipient.getLocation(), "mob.chicken.plop", 1, 0)