diff --git a/adminchat.py b/adminchat.py index 7cce9d0..2955564 100644 --- a/adminchat.py +++ b/adminchat.py @@ -10,7 +10,7 @@ def adminchat(sender, msg): name = "&7{unknown}" try: name = sender.getDisplayName() - except: + except AttributeError: name = sender.getName() broadcast(ac_permission, "%s &9%s&8: &b%s" % (ac_prefix, name, msg)) diff --git a/chatgroups.py b/chatgroups.py index 3f734b6..9012cc9 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -10,43 +10,40 @@ cg_toggle_list = [] @hook.command("chatgroup") def on_chatgroup_command(sender, args): - try: - plugin_header(sender, "ChatGroups") - sender_id = uid(sender) - if len(args) == 1 and args[0] == "leave": - if sender_id in groups.keys(): - groupchat(sender, "left the group", True) - group = groups[sender_id] - del(groups[sender_id]) - save_groups() - else: - msg(sender, "&aYou can't leave no group, derp!") - elif len(args) == 1 and args[0] == "info": - if sender_id in groups.keys(): - group = groups[sender_id] - msg(sender, "&aCurrent chatgroup: %s" % group) - users = [] - for uuid, ugroup in groups.iteritems(): - if ugroup == group: - usr = server.getPlayer(juuid(uuid)) - if usr: - users.append(usr.getDisplayName()) - msg(sender, "&aUsers in this group:") - msg(sender, "&a%s" % ", ".join(users)) - else: - msg(sender, "&aYou're in no chatgroup.") - elif len(args) == 2 and args[0] == "join": - groups[sender_id] = args[1] - groupchat(sender, "joined the group", True) + plugin_header(sender, "ChatGroups") + sender_id = uid(sender) + if len(args) == 1 and args[0] == "leave": + if sender_id in groups.keys(): + groupchat(sender, "left the group", True) + group = groups[sender_id] + del(groups[sender_id]) save_groups() - msg(sender, "&aYour chatgroup is set to '%s'" % args[1]) - msg(sender, "&aUse chat like '&e%s' to send messages to this group." % cg_key) else: - msg(sender, "&e/chatgroup join ") - msg(sender, "&e/chatgroup leave") - msg(sender, "&e/chatgroup info") - except Exception, e: - error(e) + msg(sender, "&aYou can't leave no group, derp!") + elif len(args) == 1 and args[0] == "info": + if sender_id in groups.keys(): + group = groups[sender_id] + msg(sender, "&aCurrent chatgroup: %s" % group) + users = [] + for uuid, ugroup in groups.iteritems(): + if ugroup == group: + usr = server.getPlayer(juuid(uuid)) + if usr: + users.append(usr.getDisplayName()) + msg(sender, "&aUsers in this group:") + msg(sender, "&a%s" % ", ".join(users)) + else: + msg(sender, "&aYou're in no chatgroup.") + elif len(args) == 2 and args[0] == "join": + groups[sender_id] = args[1] + groupchat(sender, "joined the group", True) + save_groups() + msg(sender, "&aYour chatgroup is set to '%s'" % args[1]) + msg(sender, "&aUse chat like '&e%s' to send messages to this group." % cg_key) + else: + msg(sender, "&e/chatgroup join ") + msg(sender, "&e/chatgroup leave") + msg(sender, "&e/chatgroup info") @hook.command("cgt") @@ -62,7 +59,6 @@ def on_cgt_command(sender, args): def groupchat(sender, message, ann = False): - #try: group = groups.get(uid(sender)) if group == None: msg(sender, "&cYou are not in a group!") @@ -75,8 +71,7 @@ def groupchat(sender, message, ann = False): info("[ChatGroups] %s (%s): %s" % (sender.getDisplayName(), group, message)) for receiver in server.getOnlinePlayers(): groups.get(uid(receiver)) == group and msg(receiver, mesg) - #except Exception, e: - # error(e) + def save_groups(): diff --git a/lagchunks.py b/lagchunks.py index 163d22f..96c3fe2 100644 --- a/lagchunks.py +++ b/lagchunks.py @@ -12,19 +12,16 @@ def print_help(sender): def scan_chunks(amount): - try: - global lagchunks - chunks = [] - for world in bukkit.Bukkit.getServer().getWorlds(): - for chunk in world.getLoadedChunks(): - if len(chunk.getEntities()) >= amount: - ents = chunk.getEntities() - # [0]world [1]X [2]Y [3]Z [4]amount - chunks.append([chunk.getWorld(), int(ents[-1].getLocation().getX()), int(ents[0].getLocation().getY()), int(ents[0].getLocation().getZ()), len(ents)]) - chunks.sort(key = lambda entry: entry[4], reverse = True) - lagchunks = chunks - except Exception, e: - error(e) + global lagchunks + chunks = [] + for world in bukkit.Bukkit.getServer().getWorlds(): + for chunk in world.getLoadedChunks(): + if len(chunk.getEntities()) >= amount: + ents = chunk.getEntities() + # [0]world [1]X [2]Y [3]Z [4]amount + chunks.append([chunk.getWorld(), int(ents[-1].getLocation().getX()), int(ents[0].getLocation().getY()), int(ents[0].getLocation().getZ()), len(ents)]) + chunks.sort(key = lambda entry: entry[4], reverse = True) + lagchunks = chunks def list_chunks(sender): @@ -41,26 +38,23 @@ def tp_chunk(sender, id): @hook.command("lagchunks") def on_lagchunks_command(sender, args): - try: - if sender.hasPermission("utils.lagchunks"): - plugin_header(sender, "Lagchunks") - global lagchunks - if len(args) == 1 and args[0].isdigit() and int(args[0]) > 0: - amount = args[0] - msg(sender, "&aChunks with at least &b%s &aentities:" % amount, ) - scan_chunks(int(amount)) - list_chunks(sender) - elif len(args) == 1 and args[0].lower() == "list": - list_chunks(sender) - elif len(args) == 2 and args[0].lower() == "tp" and args[1].isdigit() and int(args[1]) <= len(lagchunks)-1: - if isinstance(sender, Player): - tp_chunk(sender, int(args[1])) - else: - msg(sender, "&cOnly players can do this!") + if sender.hasPermission("utils.lagchunks"): + plugin_header(sender, "Lagchunks") + global lagchunks + if len(args) == 1 and args[0].isdigit() and int(args[0]) > 0: + amount = args[0] + msg(sender, "&aChunks with at least &b%s &aentities:" % amount, ) + scan_chunks(int(amount)) + list_chunks(sender) + elif len(args) == 1 and args[0].lower() == "list": + list_chunks(sender) + elif len(args) == 2 and args[0].lower() == "tp" and args[1].isdigit() and int(args[1]) <= len(lagchunks)-1: + if isinstance(sender, Player): + tp_chunk(sender, int(args[1])) else: - print_help(sender) + msg(sender, "&cOnly players can do this!") else: - noperm(sender) - return True - except Exception, e: - error(e) \ No newline at end of file + print_help(sender) + else: + noperm(sender) + return True \ No newline at end of file diff --git a/mentio.py b/mentio.py index 16db9ff..2ff0dc9 100644 --- a/mentio.py +++ b/mentio.py @@ -11,101 +11,94 @@ colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") @hook.event("player.AsyncPlayerChatEvent", "high") def onChat(event): - try: - if not event.isCancelled(): - sender = event.getPlayer() - words = event.getMessage().split(" ") - recipients = event.getRecipients() + if not event.isCancelled(): + sender = event.getPlayer() + words = event.getMessage().split(" ") + recipients = event.getRecipients() - for recipient in list(recipients): - listeners = mentions[str(recipient.getUniqueId())] - rec_words = words[:] # copy - for i in range(len(rec_words)): - word = rec_words[i] - isMentioned = False + for recipient in list(recipients): + listeners = mentions[str(recipient.getUniqueId())] + rec_words = words[:] # copy + for i in range(len(rec_words)): + word = rec_words[i] + isMentioned = False - if recipient.getName().lower() in word.lower(): # is the player's full ign in the list - isMentioned = True + if recipient.getName().lower() in word.lower(): # is the player's full ign in the list + isMentioned = True - if word.lower() in [i.lower() for i in listeners]: # is the word in the listeners list - isMentioned = True + if word.lower() in [i.lower() for i in listeners]: # is the word in the listeners list + isMentioned = True - if isMentioned: - # join all color codes used upto this word - colors = "".join(colors_reg.findall("".join(words[:i+1]))) - # highlight word containing mention, then apply all previous color codes - rec_words[i] = colorify("&r&a&n") + stripcolors(word) + colorify("&r") + colors + if isMentioned: + # join all color codes used upto this word + colors = "".join(colors_reg.findall("".join(words[:i+1]))) + # highlight word containing mention, then apply all previous color codes + rec_words[i] = colorify("&r&a&n") + stripcolors(word) + colorify("&r") + colors - # player was mentioned - if rec_words != words: - try: - recipients.remove(recipient) # don't send original message - except: - # list might not be mutable, ignoring. Receiver will get the message twice - pass - message = " ".join([sender.getDisplayName(), arrow] + rec_words) - msg(recipient, message, usecolor = False) - recipient.playSound(recipient.getLocation(), "liquid.lavapop", 1, 2) - except: - error("Failed to handle PlayerChatEvent:") - error(print_traceback()) + # player was mentioned + if rec_words != words: + try: + recipients.remove(recipient) # don't send original message + except: + # list might not be mutable, ignoring. Receiver will get the message twice + pass + message = " ".join([sender.getDisplayName(), arrow] + rec_words) + msg(recipient, message, usecolor = False) + recipient.playSound(recipient.getLocation(), "liquid.lavapop", 1, 2) @hook.command("listen") def onListenCommand(sender, args): - try: - currWords = [] - if str(sender.getUniqueId()) in mentions.keys(): - currWords = mentions[str(sender.getUniqueId())] + currWords = [] + if str(sender.getUniqueId()) in mentions.keys(): + currWords = mentions[str(sender.getUniqueId())] - # /listen add - if len(args) == 2 and args[0].lower() == "add": + # /listen add + if len(args) == 2 and args[0].lower() == "add": - if len(currWords) >= max_amount: - msg(sender, "&cYou are already listening for %s words! Try &6/listen del " % max_amount) - return True - if len(args[1].lower()) > 16: - msg(sender, "&cThis word is longer than 16 characters. Pick a shorter one!") - if args[1].lower() in currWords: - msg(sender, "&cYou are already listening for this word! Try &6/listen list") - return True - if args[1].lower() is sender.getName(): - msg(sender, "&cYou are always listening for your full ingame name by default") - currWords.append(args[1].lower()) - mentions[str(sender.getUniqueId())] = currWords - msg(sender, "&aYou are now listening for '&2"+args[1].lower()+"'!") + if len(currWords) >= max_amount: + msg(sender, "&cYou are already listening for %s words! Try &6/listen del " % max_amount) + return True + if len(args[1].lower()) > 16: + msg(sender, "&cThis word is longer than 16 characters. Pick a shorter one!") + if args[1].lower() in currWords: + msg(sender, "&cYou are already listening for this word! Try &6/listen list") + return True + if args[1].lower() is sender.getName(): + msg(sender, "&cYou are always listening for your full ingame name by default") + currWords.append(args[1].lower()) + mentions[str(sender.getUniqueId())] = currWords + msg(sender, "&aYou are now listening for '&2"+args[1].lower()+"'!") + saveMentions() + return True + # /listen del + elif len(args) == 2 and args[0].lower() == "del": + if len(currWords) <= 0: + msg(sender, "&cYou are currently listening for no words! Try &6/listen add ") + return True + success = False + for word in currWords[:]: + if word.lower() == args[1].lower(): + currWords.remove(word.lower()) + mentions[str(sender.getUniqueId())] = currWords + success = True + if success == True: saveMentions() - return True - # /listen del - elif len(args) == 2 and args[0].lower() == "del": - if len(currWords) <= 0: - msg(sender, "&cYou are currently listening for no words! Try &6/listen add ") - return True - success = False - for word in currWords[:]: - if word.lower() == args[1].lower(): - currWords.remove(word.lower()) - mentions[str(sender.getUniqueId())] = currWords - success = True - if success == True: - saveMentions() - msg(sender, "&eYou are no longer listening for '&2"+args[1].lower()+"&e'!") - else: - msg(sender, "&cWe can't remove something that doesn't exist! Try &6/listen list") - return True - - # /listen list - elif len(args) == 1 and args[0].lower() == "list": - msg(sender, "&6Words you're listening for:") - for word in currWords: - msg(sender, "&c- &3"+word) + msg(sender, "&eYou are no longer listening for '&2"+args[1].lower()+"&e'!") else: - msg(sender, "&eNobody calls you %s &efor some particular reason? Too long? Add some aliases!\n\n" % sender.getDisplayName()) - msg(sender, "&6/listen add ") - msg(sender, "&6/listen del ") - msg(sender, "&6/listen list") - except Exception, e: - error(e) + msg(sender, "&cWe can't remove something that doesn't exist! Try &6/listen list") + return True + + # /listen list + elif len(args) == 1 and args[0].lower() == "list": + msg(sender, "&6Words you're listening for:") + for word in currWords: + msg(sender, "&c- &3"+word) + else: + msg(sender, "&eNobody calls you %s &efor some particular reason? Too long? Add some aliases!\n\n" % sender.getDisplayName()) + msg(sender, "&6/listen add ") + msg(sender, "&6/listen del ") + msg(sender, "&6/listen list") def saveMentions():