fix colors, highlight word, create sound

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

View File

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

View File

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

View File

@@ -1,18 +1,32 @@
#pylint: disable=F0401 #pylint: disable=F0401
from helpers import * 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.AsyncPlayerChatEvent", "normal")
@hook.event("player.PlayerChatEvent", "normal")
def onChat(event): def onChat(event):
symbol = u"\u272a" if not event.isCancelled():
sender = event.getPlayer() sender = event.getPlayer()
messages = event.getMessage() words = event.getMessage().split(" ")
messagesList = messages.split(" ") recipients = event.getRecipients()
for message in messagesList:
for recipient in server.getOnlinePlayers().tolist(): for recipient in recipients:
if message[:3].lower() in recipient.getName().lower() and len(message) > 2: rec_words = words[:] # copy
msg(recipient, "&6" + symbol + " &f%s &6mentioned you" % sender.getDisplayName()) for i in range(len(rec_words)):
# Couldn't figure out how to do this word = rec_words[i]
# recipient.playSound(recipient.getLocation(), Sound.CHICKEN_EGG_POP, 1, 1) 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)