Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fa6926987 | ||
|
|
46f1564af0 | ||
|
|
0aad531f9e | ||
|
|
412ed59225 | ||
|
|
9160c85d09 | ||
|
|
a98a8a8657 | ||
|
|
34ed3a1023 | ||
|
|
ddc4a9b457 | ||
|
|
6a4d1447ec | ||
|
|
5a0477fdbf | ||
|
|
91afa684cd | ||
|
|
70f2001e7b | ||
|
|
f03f34777b | ||
|
|
799584df46 | ||
|
|
3a2d1193ca | ||
|
|
cbc77de826 | ||
|
|
883b02acd5 | ||
|
|
4cf08dcd6d | ||
|
|
fa81ace66e | ||
|
|
528269afd6 | ||
|
|
2c8bfff01f | ||
|
|
2690da5666 | ||
|
|
1969584312 | ||
|
|
0172cf2feb | ||
|
|
522a7a99a1 | ||
|
|
4d5861fd36 | ||
|
|
9d0e4c99ba | ||
|
|
e57f721db3 | ||
|
|
2808c5838b |
@@ -11,6 +11,17 @@ import org.bukkit.event.block.Action as Action
|
|||||||
import org.bukkit.block.BlockFace as BlockFace
|
import org.bukkit.block.BlockFace as BlockFace
|
||||||
import org.bukkit.scheduler.BukkitRunnable as Runnable
|
import org.bukkit.scheduler.BukkitRunnable as Runnable
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Permissions:
|
||||||
|
# - utils.toggle: for use of the command
|
||||||
|
# - utils.toggle.cauldron
|
||||||
|
# - utils.toggle.slab
|
||||||
|
# - utils.toggle.furnace
|
||||||
|
# - utils.toggle.piston
|
||||||
|
# - utils.toggle.dropper
|
||||||
|
# - utils.toggle.hopper
|
||||||
|
"""
|
||||||
|
|
||||||
settingInformation = dict( #[setting type, identifying description, detailed description, aliases, (optional) max slot id], setting types: 0 = toggle, default on. 1 = Set your setting to held itemstack, 2 = toggle, default off
|
settingInformation = dict( #[setting type, identifying description, detailed description, aliases, (optional) max slot id], setting types: 0 = toggle, default on. 1 = Set your setting to held itemstack, 2 = toggle, default off
|
||||||
cauldron = [0,
|
cauldron = [0,
|
||||||
"easy cauldron water level control",
|
"easy cauldron water level control",
|
||||||
|
|||||||
405
chatalias.py
405
chatalias.py
@@ -1,138 +1,319 @@
|
|||||||
# Chat Aliasing plugin by Curs3d #
|
############################################
|
||||||
##################################
|
# Alias v2.0 by Pepich #
|
||||||
# Allows users to alias words,
|
# Changes to previous version from curs3d: #
|
||||||
# so that when they send a
|
# Dynamic alias limit from permissions #
|
||||||
# message in chat, it gets
|
# AC/CG/MSG support #
|
||||||
# replaced by their specified
|
# Color support #
|
||||||
# word. The JSON file for this
|
# Bugfixes #
|
||||||
# plugin is generated if not
|
# #
|
||||||
# present. Set values to -1
|
# TODO: #
|
||||||
# for "unlimited" setting.
|
# Add command support... #
|
||||||
|
############################################
|
||||||
|
|
||||||
|
import os
|
||||||
|
import org.bukkit as bukkit
|
||||||
|
from org.bukkit import *
|
||||||
from helpers import *
|
from helpers import *
|
||||||
import re
|
|
||||||
from traceback import format_exc as trace
|
from traceback import format_exc as trace
|
||||||
|
from secrets import *
|
||||||
|
|
||||||
data = None
|
# Version number and requirements
|
||||||
|
|
||||||
max_entries = 10
|
alias_version = "2.0.0"
|
||||||
max_alias_length = 35
|
helpers_versions = ["1.1.0", "2.0.0"]
|
||||||
# Minecraft message limit is 100 so I decided to give a little tolerance (and I added a bit more)
|
enabled = False
|
||||||
max_overall_length = 100 + max_alias_length
|
error = colorify("&cUnspecified error")
|
||||||
|
commands_per_page = 5
|
||||||
|
global_aliases = {"./":"/"}
|
||||||
|
data = {}
|
||||||
|
use_mysql = False
|
||||||
|
|
||||||
alias_perm = "utils.alias.allowed"
|
# Permissions:
|
||||||
exceed_length = "utils.alias.exceedlimit"
|
|
||||||
exceed_entries = "utils.alias.exceedlimit"
|
# Grants full access immediately
|
||||||
exceed_overall_length = "utils.alias.exceedlimit"
|
permission_ALL = "utils.alias.*"
|
||||||
|
# Access to the command to display the help screen
|
||||||
|
permission_BASE = "utils.alias"
|
||||||
|
# Make replacements only when the user has this permission
|
||||||
|
permission_USE = "utils.alias.use"
|
||||||
|
# Modify aliases
|
||||||
|
permission_MODIFY = "utils.alias.modify"
|
||||||
|
permission_MODIFY_OTHERS = "utils.alias.modify.others"
|
||||||
|
# List aliases
|
||||||
|
permission_LIST = "utils.alias.list"
|
||||||
|
permission_LIST_OTHERS = "utils.alias.list.others"
|
||||||
|
# Set alias amounts/length limits, e.g. utils.alias.amount.420
|
||||||
|
permission_AMOUNT = "utils.alias.amount."
|
||||||
|
permission_LENGTH = "utils.alias.length."
|
||||||
|
# See when the plugin was disabled due to version errors
|
||||||
|
permission_INFO = "utils.alias.info"
|
||||||
|
permission_FINFO = "utils.alias.finfo"
|
||||||
|
|
||||||
|
########
|
||||||
|
# CODE #
|
||||||
|
########
|
||||||
|
|
||||||
|
enabled = helpers_version in helpers_versions
|
||||||
|
if not enabled:
|
||||||
|
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
|
||||||
|
|
||||||
|
|
||||||
def safe_open_json():
|
def safe_open_json(uuid):
|
||||||
global data
|
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
|
||||||
if data is not None:
|
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
|
||||||
return data
|
value = open_json_file("aliases/" + uuid)
|
||||||
data = open_json_file("aliases")
|
if value is None:
|
||||||
if data is None:
|
value = global_aliases
|
||||||
data = {}
|
save_json_file("aliases/" + uuid, value)
|
||||||
save_json_file("aliases", data)
|
return value
|
||||||
return data
|
|
||||||
|
|
||||||
def multiple_replace(aliases, text):
|
|
||||||
regex = re.compile("|".join(map(re.escape, aliases.keys())))
|
|
||||||
return regex.sub(lambda mo: aliases[mo.group(0)], text)
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command("alias",
|
@hook.command("alias",
|
||||||
usage="/<command> [to_alias] [alias...]",
|
usage="/<command> <add, remove, list, help> [...]",
|
||||||
desc="Aliases words in chat")
|
desc="Allows aliasing of words")
|
||||||
def on_alias_command(sender, cmd, label, args):
|
def on_alias_command(sender, cmd, label, args):
|
||||||
|
try:
|
||||||
if not is_player(sender):
|
args = array_to_list(args)
|
||||||
msg(sender, "Sorry, non-players cannot alias words")
|
if not enabled:
|
||||||
|
disabled_fallback(sender)
|
||||||
return True
|
return True
|
||||||
if not sender.hasPermission(alias_perm):
|
if not hasPerm(sender, permission_BASE):
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
plugin_header(recipient=sender, name="Alias")
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
return True
|
return True
|
||||||
if len(args) == 0:
|
return subcommands[args[0].lower()](sender, args[1:])
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
except:
|
||||||
msg(sender, "&7This is a plugin that allows you to get words" +
|
return subcommands["help"](sender, "1")
|
||||||
"replaced by other ones automatically!")
|
|
||||||
msg(sender, "&7\nCommands:")
|
|
||||||
msg(sender, "&e/alias <word> &7removes <word> from your aliases. " +
|
def help(sender, args):
|
||||||
"Use &e/alias * &7to remove all aliases.")
|
commands = [colorify("&e/alias help [page]")]
|
||||||
msg(sender, "&e/alias <word> <replacement> &7will change &e<word> " +
|
if hasPerm(sender, permission_LIST):
|
||||||
"&7to &e<replacement> &7in chat")
|
commands += [colorify("&e/alias list &7- Lists all your aliases")]
|
||||||
msg(sender, "&7\nYour Aliases:")
|
if hasPerm(sender, permission_MODIFY):
|
||||||
data = safe_open_json()
|
commands += [colorify("&e/alias add <word> <alias> &7- Add an alias")]
|
||||||
|
commands += [colorify("&e/alias remove <word> &7- Remove an alias")]
|
||||||
|
if can_remote(sender):
|
||||||
|
while len(commands) < commands_per_page:
|
||||||
|
commands += [""]
|
||||||
|
commands += [colorify("&7Following commands will be executed on <player> yet all output will be redirected to you, except when you set silent to false, then <player> will see it too.")]
|
||||||
|
if hasPerm(sender, permission_LIST_OTHERS):
|
||||||
|
commands += [colorify("&e/alias player <name> list [silent]")]
|
||||||
|
if hasPerm(sender, permission_MODIFY_OTHERS):
|
||||||
|
commands += [colorify("&e/alias player <name> add <word> <alias> [silent]")]
|
||||||
|
commands += [colorify("&e/alias player <name> remove <word> [silent]")]
|
||||||
|
pages = (len(commands)-1)/commands_per_page + 1
|
||||||
|
page = 1
|
||||||
|
if len(args) != 0:
|
||||||
|
page = int(args[0])
|
||||||
|
if (page > pages):
|
||||||
|
page = pages
|
||||||
|
if page < 1:
|
||||||
|
page = 1
|
||||||
|
msg(sender, colorify("&e---- &6Help &e-- &6Page &c" + str(page) + "&6/&c" + str(pages) + " &e----"))
|
||||||
|
page -= 1
|
||||||
|
to_display = commands[5*page:5*page+5]
|
||||||
|
for message in to_display:
|
||||||
|
msg(sender, message)
|
||||||
|
if page+1 < pages:
|
||||||
|
msg(sender, colorify("&6To display the next page, type &c/help " + str(page+2)))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.PlayerJoinEvent", "high")
|
||||||
|
def on_join(event):
|
||||||
try:
|
try:
|
||||||
for alias, value in data[str(sender.getUniqueId())].items():
|
if enabled:
|
||||||
msg(sender, "&7%s &7==> %s" % (alias, value))
|
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
|
||||||
except KeyError:
|
t.daemon = True
|
||||||
pass
|
t.start()
|
||||||
return True
|
|
||||||
elif len(args) == 1:
|
|
||||||
data = safe_open_json()
|
|
||||||
if args[0] == "*":
|
|
||||||
try:
|
|
||||||
del data[str(sender.getUniqueId())]
|
|
||||||
except KeyError:
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7No alias data to remove!")
|
|
||||||
return True
|
|
||||||
save_json_file("aliases", data)
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&cALL &7alias data successfuly removed!")
|
|
||||||
return True
|
|
||||||
try:
|
|
||||||
if data[str(sender.getUniqueId())].pop(args[0], None) is None:
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7Could not remove: alias not present!")
|
|
||||||
return True
|
|
||||||
except KeyError:
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7Could not remove: you do not have any aliases!")
|
|
||||||
return True
|
|
||||||
save_json_file("aliases", data)
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7Alias for %s &7successfuly removed" % args[0])
|
|
||||||
return True
|
|
||||||
elif len(args) >= 2:
|
|
||||||
data = safe_open_json()
|
|
||||||
alias = " ".join(args[1:])
|
|
||||||
try:
|
|
||||||
if (len(alias) > max_alias_length) and (max_alias_length >= 0) and (not sender.hasPermission(exceed_length)):
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7Please do not alias long words/sentences.")
|
|
||||||
return True
|
|
||||||
if (len(data[str(sender.getUniqueId())]) >= max_entries) and (max_entries >= 0) and (not sender.hasPermission(exceed_entries)):
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7You have reached your alias limit!")
|
|
||||||
return True
|
|
||||||
except KeyError:
|
|
||||||
data[str(sender.getUniqueId())] = {}
|
|
||||||
data[str(sender.getUniqueId())][args[0]] = alias
|
|
||||||
save_json_file("aliases", data)
|
|
||||||
plugin_header(recipient=sender, name="Chat Alias")
|
|
||||||
msg(sender, "&7Chat Alias %s &7==> %s &7successfully created!" % (args[0], alias))
|
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return False
|
if event.getPlayer().hasPermission(permission_FINFO):
|
||||||
|
disabled_fallback(event.getPlayer())
|
||||||
|
except:
|
||||||
|
print(trace())
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "high")
|
@hook.event("player.AsyncPlayerChatEvent", "high")
|
||||||
def on_player_chat(event):
|
def on_player_chat(event):
|
||||||
playerid = str(event.getPlayer().getUniqueId())
|
try:
|
||||||
data = safe_open_json()
|
if enabled:
|
||||||
if event.isCancelled():
|
if event.isCancelled():
|
||||||
return
|
return
|
||||||
if not data[playerid]:
|
if not hasPerm(event.getPlayer(), permission_USE):
|
||||||
|
return
|
||||||
|
for alias, value in data[str(uid(event.getPlayer()))].items():
|
||||||
|
if not event.getPlayer().hasPermission(permission_ALL) and len(event.getMessage()) > int(get_permission_content(event.getPlayer(), permission_LENGTH)):
|
||||||
|
event.setCanceled(True)
|
||||||
|
plugin_header(event.getPlayer, "Alias")
|
||||||
|
msg(event.getPlayer(), "The message you wanted to generate would exceed your limit. Please make it shorter!")
|
||||||
|
return
|
||||||
|
if event.getPlayer().hasPermission("essentials.chat.color"):
|
||||||
|
event.setMessage(event.getMessage().replace(colorify(alias), colorify(value)))
|
||||||
|
else:
|
||||||
|
event.setMessage(event.getMessage().replace(alias, value))
|
||||||
|
except:
|
||||||
return
|
return
|
||||||
event.setMessage(multiple_replace(data[playerid], event.getMessage()))
|
|
||||||
|
|
||||||
if (event.getPlayer().hasPermission("essentials.chat.color")):
|
def hasPerm(player, permission):
|
||||||
event.setMessage(colorify(event.getMessage()))
|
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
|
||||||
if (max_overall_length >= 0) and (len(event.getMessage()) > max_overall_length) and (not event.getPlayer().hasPermission(exceed_overall_length)):
|
|
||||||
event.setCancelled(True)
|
|
||||||
plugin_header(recipient=event.getPlayer(), name="Chat Alias")
|
|
||||||
msg(event.getPlayer(), "&7The message generated was too long and was not sent. :/")
|
|
||||||
|
|
||||||
|
|
||||||
|
def disabled_fallback(receiver):
|
||||||
|
if not hasPerm(receiver, permission_INFO):
|
||||||
|
msg(receiver, colorify("&cUnknown command. Use &e/help&c, &e/plugins &cor ask a mod."))
|
||||||
|
else:
|
||||||
|
msg(receiver, colorify("&cPlugin alias v" + alias_version + " has experienced an &eEMERGENCY SHUTDOWN:"))
|
||||||
|
msg(receiver, error)
|
||||||
|
msg(receiver, colorify("&cPlease contact a dev/admin (especially pep :P) about this to take a look at it."))
|
||||||
|
|
||||||
|
|
||||||
|
def can_remote(player):
|
||||||
|
return hasPerm(player, permission_LIST_OTHERS) or hasPerm(player, permission_MODIFY_OTHERS)
|
||||||
|
|
||||||
|
|
||||||
|
def add(sender, args):
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(sender, permission_AMOUNT)):
|
||||||
|
msg(sender, "&cCould not create alias: Max_limit reached!")
|
||||||
|
return True
|
||||||
|
args = [args[0]] + [" ".join(args[1:])]
|
||||||
|
data[str(uid(sender))][str(args[0])] = args[1]
|
||||||
|
save_data(uid(sender))
|
||||||
|
msg(sender, colorify("&7Alias: ") + args[0] + colorify("&7 -> " + args[1] + colorify("&7 was succesfully created!")), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def radd(sender, args):
|
||||||
|
args = [args[0:1]] + [" ".join([args[2:len(args)-2]])] + [args[len(args)-1]]
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
if args[3].lower() == "false":
|
||||||
|
plugin_header(target, "Alias")
|
||||||
|
msg(target, "&cPlayer " + sender_name + " &cis creating an alias for you!")
|
||||||
|
if not sender.hasPermission(permission_ALL) and len(data[uid(sender)]) >= int(get_permission_content(target, permission_AMOUNT)):
|
||||||
|
msg(sender, "&cCould not create alias: Max_limit reached!")
|
||||||
|
if args[3].lower() == "false":
|
||||||
|
msg(target, "&cCould not create alias: Max_limit reached!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
target = get_player(args[0])
|
||||||
|
if is_player(sender):
|
||||||
|
sender_name = colorify(sender.getDisplayName)
|
||||||
|
else:
|
||||||
|
sender_name = colorify("&6Console")
|
||||||
|
if len(args) == 3:
|
||||||
|
args += ["true"]
|
||||||
|
data[str(uid(target))][str(args[1])] = str(args[2])
|
||||||
|
save_data(uid(target))
|
||||||
|
msg(sender, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
|
if args[3].lower() == "false":
|
||||||
|
msg(target, colorify("&7Alias: ") + args[1] + colorify("&7 -> " + args[2] + colorify("&7 was succesfully created!")), usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def remove(sender, args):
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
try:
|
||||||
|
msg(sender, colorify("&7Successfully removed alias ") + args[0] + colorify(" &7-> ") + data[uid(sender)].pop(args[0]) + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
save_data(uid(sender))
|
||||||
|
except:
|
||||||
|
msg(sender, colorify("&cCould not remove alias ") + args[0] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def rremove(sender, args):
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
target = get_player(args[0])
|
||||||
|
if is_player(sender):
|
||||||
|
sender_name = colorify(sender.getDisplayName)
|
||||||
|
else:
|
||||||
|
sender_name = colorify("&6Console")
|
||||||
|
if args[2].lower() == "false":
|
||||||
|
print("WTF")
|
||||||
|
plugin_header(target, "Alias")
|
||||||
|
msg(target, "&cPlayer " + sender_name + " &cis removing an alias for you!")
|
||||||
|
try:
|
||||||
|
alias = data[uid(target)].pop(args[1])
|
||||||
|
msg(sender, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
if args[2].lower() == "false":
|
||||||
|
msg(target, colorify("&7Successfully removed alias ") + args[1] + colorify(" &7-> ") + alias + colorify("&7!"), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
save_data(uid(target))
|
||||||
|
except:
|
||||||
|
msg(sender, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
if args[2].lower() == "false":
|
||||||
|
msg(target, colorify("&cCould not remove alias ") + args[1] + colorify(", it does not exist."), usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def list_alias(sender, args):
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
msg(sender, "&7You have a total of " + str(len(data[uid(sender)])) + " aliases:")
|
||||||
|
for word, alias in data[str(uid(sender))].items():
|
||||||
|
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=sender.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def rlist_alias(sender, args):
|
||||||
|
plugin_header(sender, "Alias")
|
||||||
|
target = get_player(args[0])
|
||||||
|
if is_player(sender):
|
||||||
|
sender_name = colorify(sender.getDisplayName)
|
||||||
|
else:
|
||||||
|
sender_name = colorify("&6Console")
|
||||||
|
if len(args) == 1:
|
||||||
|
args += ["true"]
|
||||||
|
msg(sender, "Player " + args[0] + " has following aliases (" + str(len(data[uid(target)])) + " in total):")
|
||||||
|
if args[1].lower() == "false":
|
||||||
|
plugin_header(target, "Alias")
|
||||||
|
msg(target, "&cPlayer " + sender_name + " &cis listing your aliases (" + str(len(data[uid(target)])) + " in total):")
|
||||||
|
for word, alias in data[str(uid(target))].items():
|
||||||
|
msg(sender, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
|
if args[1].lower() == "false":
|
||||||
|
msg(target, colorify("&7") + word + colorify("&7 -> ") + alias, usecolor=target.hasPermission("essentials.chat.color"))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def remote(sender, args):
|
||||||
|
try:
|
||||||
|
return remotes[args[1].lower()](sender, [args[0]] + [args[2:]])
|
||||||
|
except:
|
||||||
|
return subcommands["help"](sender, ["2"])
|
||||||
|
|
||||||
|
|
||||||
|
def load_data(uuid):
|
||||||
|
if use_mysql:
|
||||||
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
curs = conn.cursor()
|
||||||
|
curs.execute("SELECT alias FROM alias WHERE uuid = ?", (uuid, ))
|
||||||
|
results = curs.fetchall()
|
||||||
|
if len(results) == 0:
|
||||||
|
results = global_aliases
|
||||||
|
curs.execute("INSERT INTO alias VALUES (?,?)", (uuid, results, ))
|
||||||
|
data[uuid] = results
|
||||||
|
else:
|
||||||
|
data[uuid] = safe_open_json(uuid)
|
||||||
|
|
||||||
|
|
||||||
|
def save_data(uuid):
|
||||||
|
if use_mysql:
|
||||||
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
curs = conn.cursor()
|
||||||
|
curs.execute("UPDATE alias SET alias = ? WHERE uuid = ?", (data[uuid], uuid, ))
|
||||||
|
else:
|
||||||
|
save_json_file("aliases/" + uuid, data[uuid])
|
||||||
|
|
||||||
|
# Subcommands:
|
||||||
|
|
||||||
|
subcommands = {
|
||||||
|
"help": help,
|
||||||
|
"add": add,
|
||||||
|
"remove": remove,
|
||||||
|
"player": remote,
|
||||||
|
"list": list_alias
|
||||||
|
}
|
||||||
|
|
||||||
|
remotes = {
|
||||||
|
"add": radd,
|
||||||
|
"remove": rremove,
|
||||||
|
"list": rlist_alias,
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ def on_chatgroup_command(sender, command, label, args):
|
|||||||
if len(args) == 1 and args[0] == "leave":
|
if len(args) == 1 and args[0] == "leave":
|
||||||
if sender_id in groups.keys():
|
if sender_id in groups.keys():
|
||||||
groupchat(sender, "left the group", True)
|
groupchat(sender, "left the group", True)
|
||||||
|
if sender in cg_toggle_list:
|
||||||
|
cg_toggle_list.remove(p)
|
||||||
group = groups[sender_id]
|
group = groups[sender_id]
|
||||||
del(groups[sender_id])
|
del(groups[sender_id])
|
||||||
save_groups()
|
save_groups()
|
||||||
|
|||||||
98
helpers.py
Normal file → Executable file
98
helpers.py
Normal file → Executable file
@@ -1,32 +1,28 @@
|
|||||||
#pylint: disable = F0401
|
#pylint: disable = F0401
|
||||||
|
|
||||||
import org.bukkit as bukkit
|
|
||||||
import org.bukkit.block as bblock
|
|
||||||
import org.bukkit.Location as Location
|
|
||||||
import org.bukkit.event.entity as entity
|
|
||||||
import org.bukkit.entity.Player as Player
|
|
||||||
import org.bukkit.command.ConsoleCommandSender
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause
|
|
||||||
|
|
||||||
from re import sub
|
from re import sub
|
||||||
from thread_utils import *
|
|
||||||
from player import py_players
|
|
||||||
from org.bukkit.entity import *
|
|
||||||
from player import get_py_player
|
|
||||||
from traceback import format_exc as trace
|
|
||||||
from java.util.UUID import fromString as juuid
|
from java.util.UUID import fromString as juuid
|
||||||
from json import dumps as json_dumps, loads as json_loads
|
from json import dumps as json_dumps, loads as json_loads
|
||||||
|
import org.bukkit as bukkit
|
||||||
|
import org.bukkit.Location as Location
|
||||||
|
import org.bukkit.entity.Player as Player
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause as TeleportCause
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent as BlockBreakEvent
|
||||||
|
import org.bukkit.block as bblock
|
||||||
|
import org.bukkit.event.entity as entity
|
||||||
|
import org.bukkit.command.ConsoleCommandSender
|
||||||
|
from org.bukkit.entity import *
|
||||||
|
from player import get_py_player
|
||||||
|
from player import py_players
|
||||||
|
|
||||||
#Imports for async query
|
#Imports for async query
|
||||||
import threading
|
|
||||||
import mysqlhack
|
|
||||||
|
|
||||||
from secrets import *
|
from secrets import *
|
||||||
|
import mysqlhack
|
||||||
from com.ziclix.python.sql import zxJDBC
|
from com.ziclix.python.sql import zxJDBC
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from traceback import format_exc as trace
|
||||||
|
|
||||||
|
helpers_version = "2.0.0"
|
||||||
shared = {} # this dict can be used to share stuff across modules
|
shared = {} # this dict can be used to share stuff across modules
|
||||||
|
|
||||||
server = bukkit.Bukkit.getServer()
|
server = bukkit.Bukkit.getServer()
|
||||||
@@ -91,7 +87,7 @@ def colorify(text):
|
|||||||
"""
|
"""
|
||||||
replace &-codes with real color codes
|
replace &-codes with real color codes
|
||||||
"""
|
"""
|
||||||
return sub("&" + u"\u00A7", "&", "%s" % sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text))
|
return sub("&(?=[?\\da-fk-or])", u"\u00A7", "%s" % text)
|
||||||
|
|
||||||
|
|
||||||
def stripcolors(text):
|
def stripcolors(text):
|
||||||
@@ -185,16 +181,6 @@ def is_creative(player):
|
|||||||
return str(player.getGameMode()) == "CREATIVE"
|
return str(player.getGameMode()) == "CREATIVE"
|
||||||
|
|
||||||
|
|
||||||
def is_rank(player, rank):
|
|
||||||
"""
|
|
||||||
rank: a string equal to the PEX group name found in /pex groups
|
|
||||||
returns True if one of the following conditions are met:
|
|
||||||
- the player is of the given rank,
|
|
||||||
- their rank inherits the given rank.
|
|
||||||
"""
|
|
||||||
return player.hasPermission("groups." + rank)
|
|
||||||
|
|
||||||
|
|
||||||
def uid(player):
|
def uid(player):
|
||||||
"""
|
"""
|
||||||
returns the player's UUID
|
returns the player's UUID
|
||||||
@@ -218,6 +204,31 @@ def known_player(player):
|
|||||||
"""
|
"""
|
||||||
return player.hasPlayedBefore()
|
return player.hasPlayedBefore()
|
||||||
|
|
||||||
|
"""
|
||||||
|
Runs a async query, calls target function with fetchall as an argument, it will be an empty list if there is nothing to fetch.
|
||||||
|
(So make sure your function takes that argument.)
|
||||||
|
|
||||||
|
If you want your function to run sync in the case you are doing something spigot wouldn't like to be async use the bukkit scheduler.
|
||||||
|
Example can be found in loginsecurity.py
|
||||||
|
|
||||||
|
"""
|
||||||
|
def async_query(mysql_database,query,query_args,target,*target_args,**target_kwargs):
|
||||||
|
|
||||||
|
def async_query_t(mysql_database,query,query_args,target,target_args,target_kwargs):
|
||||||
|
db_conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
db_curs = db_conn.cursor()
|
||||||
|
db_curs.execute(query,query_args)
|
||||||
|
db_conn.commit()
|
||||||
|
fetchall = db_curs.fetchall()
|
||||||
|
db_curs.close()
|
||||||
|
db_conn.close()
|
||||||
|
target(fetchall,target_args,target_kwargs)
|
||||||
|
|
||||||
|
t = threading.Thread(target=async_query_t,args=(mysql_database,query,query_args,target,target_args,target_kwargs))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
def open_json_file(filename, default = None):
|
def open_json_file(filename, default = None):
|
||||||
"""
|
"""
|
||||||
opens the given json file and returns an object or returns None on error
|
opens the given json file and returns an object or returns None on error
|
||||||
@@ -260,7 +271,8 @@ def send_JSON_message(playername, message):
|
|||||||
bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message)
|
bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message)
|
||||||
|
|
||||||
|
|
||||||
def isIP(tocheck):
|
# Allows to check if a String is a valid IPv4 or not. Accepts any string, returns true if the String is a valid IPv4
|
||||||
|
def is_ip(tocheck):
|
||||||
subsets = ["","","",""]
|
subsets = ["","","",""]
|
||||||
i = 0
|
i = 0
|
||||||
for j in range(0,len(tocheck)):
|
for j in range(0,len(tocheck)):
|
||||||
@@ -278,3 +290,27 @@ def isIP(tocheck):
|
|||||||
if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)):
|
if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# Allows the use of e.g. numeric permission nodes like "permission.amount.5" and similar.
|
||||||
|
# To get the data fetch the player and the start of the permission node, looking like "permission.amount."
|
||||||
|
def get_permission_content(player, permnode):
|
||||||
|
perms = player.getEffectivePermissions()
|
||||||
|
for perm in perms:
|
||||||
|
if str(perm.getPermission()).startswith(permnode):
|
||||||
|
return str(perm.getPermission()).replace(permnode, "")
|
||||||
|
|
||||||
|
|
||||||
|
# Gets an online player from their name
|
||||||
|
def get_player(name):
|
||||||
|
for p in bukkit.Bukkit.getServer().getOnlinePlayers():
|
||||||
|
if p.getName().lower() == name.lower():
|
||||||
|
return p
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def array_to_list(array):
|
||||||
|
return_list = []
|
||||||
|
for a in array:
|
||||||
|
return_list += [a]
|
||||||
|
return return_list
|
||||||
|
|||||||
@@ -105,3 +105,10 @@ def on_cmd_preprocess_event(event):
|
|||||||
plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!")
|
plugin_header(recipient = event.getPlayer(), name = "I'M BUSY!")
|
||||||
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")
|
||||||
|
def on_player_leave(event):
|
||||||
|
try:
|
||||||
|
busy_players.remove(event.getPlayer().getName())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|||||||
9
iptracker.py
Normal file → Executable file
9
iptracker.py
Normal file → Executable file
@@ -9,6 +9,7 @@ from iptracker_secrets import *
|
|||||||
|
|
||||||
|
|
||||||
iptrack_permission = "utils.iptrack"
|
iptrack_permission = "utils.iptrack"
|
||||||
|
iptrack_version = "1.1.0"
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "low")
|
@hook.event("player.PlayerJoinEvent", "low")
|
||||||
@@ -42,13 +43,13 @@ def on_player_join_thread(event):
|
|||||||
if new_ip_entry:
|
if new_ip_entry:
|
||||||
curs.execute("INSERT INTO uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), ))
|
curs.execute("INSERT INTO uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), ))
|
||||||
else:
|
else:
|
||||||
curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), ))
|
curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (json.dumps(ips), uuid, ))
|
||||||
if uuid not in uuids:
|
if uuid not in uuids:
|
||||||
uuids.append(uuid)
|
uuids.append(uuid)
|
||||||
if new_uuid_entry:
|
if new_uuid_entry:
|
||||||
curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), ))
|
curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), ))
|
||||||
else:
|
else:
|
||||||
curs.execute("UPDATE ip2uuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), ))
|
curs.execute("UPDATE ip2uuids SET uuids = ? WHERE ip = ?", (json.dumps(uuids), ip, ))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
curs.close()
|
curs.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
@@ -56,7 +57,7 @@ def on_player_join_thread(event):
|
|||||||
|
|
||||||
@hook.command("getinfo")
|
@hook.command("getinfo")
|
||||||
def on_getinfo_command(sender, args):
|
def on_getinfo_command(sender, args):
|
||||||
t = threading.Thread(target=on_player_join_thread, args=(sender, args))
|
t = threading.Thread(target=on_getinfo_command_thread, args=(sender, args))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ def on_getinfo_command_thread(sender, args):
|
|||||||
if not checkargs(sender, args, 1, 1):
|
if not checkargs(sender, args, 1, 1):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if isIP(args[0]):
|
if is_ip(args[0]):
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (args[0], ))
|
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (args[0], ))
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import mysqlhack
|
|||||||
from com.ziclix.python.sql import zxJDBC
|
from com.ziclix.python.sql import zxJDBC
|
||||||
from java.lang import Runnable
|
from java.lang import Runnable
|
||||||
|
|
||||||
wait_time = 60 #seconds
|
wait_time = 30 #seconds
|
||||||
admin_perm = "utils.loginsecurity.admin"
|
admin_perm = "utils.loginsecurity.admin"
|
||||||
min_pass_length = 8
|
min_pass_length = 8
|
||||||
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"]
|
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"]
|
||||||
|
|||||||
83
main.py
83
main.py
@@ -11,9 +11,8 @@ sys.path += ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/l
|
|||||||
try:
|
try:
|
||||||
# Library that adds a bunch of re-usable methods which are used in nearly all other modules
|
# Library that adds a bunch of re-usable methods which are used in nearly all other modules
|
||||||
from helpers import *
|
from helpers import *
|
||||||
from wrapper import *
|
|
||||||
except:
|
except:
|
||||||
print("[RedstonerUtils] ERROR: Failed to import Wrapper:")
|
print("[RedstonerUtils] ERROR: Failed to import helpers:")
|
||||||
print(print_traceback())
|
print(print_traceback())
|
||||||
|
|
||||||
|
|
||||||
@@ -25,17 +24,87 @@ def on_enable():
|
|||||||
|
|
||||||
@hook.disable
|
@hook.disable
|
||||||
def on_disable():
|
def on_disable():
|
||||||
#shared["modules"]["reports"].stop_reporting()
|
shared["modules"]["reports"].stop_reporting()
|
||||||
info("RedstonerUtils disabled!")
|
info("RedstonerUtils disabled!")
|
||||||
|
|
||||||
|
|
||||||
info("Loading RedstonerUtils...")
|
info("Loading RedstonerUtils...")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Import all modules, in this order
|
# Import all modules, in this order
|
||||||
shared["load_modules"] = ["test"]
|
shared["load_modules"] = [
|
||||||
|
# Collection of tiny utilities
|
||||||
|
"misc",
|
||||||
|
# Adds chat for staff using /ac <text or ,<text>
|
||||||
|
"adminchat",
|
||||||
|
# Adds /badge, allows to give players achievements
|
||||||
|
"badges",
|
||||||
|
# Adds a few block placement corrections/mods
|
||||||
|
"blockplacemods",
|
||||||
|
# Adds /calc, toggles automatic solving of Math expressions in chat
|
||||||
|
"calc",
|
||||||
|
# Adds aliasing of chat words
|
||||||
|
#"chatalias",
|
||||||
|
# Plugin to locate laggy chunks. /lc <n> lists chunks with more than n entities
|
||||||
|
"lagchunks",
|
||||||
|
# Adds /report and /rp, Stores reports with time and location
|
||||||
|
"reports",
|
||||||
|
# Adds group-chat with /chatgroup and /cgt to toggle normal chat into group mode
|
||||||
|
"chatgroups",
|
||||||
|
# Adds /token, reads and writes from the database to generate pronouncable (and thus memorable) registration-tokens for the website
|
||||||
|
"webtoken",
|
||||||
|
# Adds /lol, broadcasts random funyy messages. A bit like the splash text in the menu
|
||||||
|
"saylol",
|
||||||
|
# Adds /signalstrength, lets you request a signal strength and an amount of items will be inserted into target container to meet that strength.
|
||||||
|
"signalstrength",
|
||||||
|
# Shows the owner of a skull when right-clicked
|
||||||
|
"skullclick",
|
||||||
|
# Adds /listen, highlights chat and plays a sound when your name was mentioned
|
||||||
|
"mentio",
|
||||||
|
# Adds /cycler, swaps the hotbar with inventory when player changes slot from right->left or left->right
|
||||||
|
"cycle",
|
||||||
|
# Adds /getmotd & /setmotd to update the motd on the fly (no reboot)
|
||||||
|
"motd",
|
||||||
|
# AnswerBot. Hides stupid questions from chat and tells the sender about /faq or the like
|
||||||
|
"abot",
|
||||||
|
# Adds '/forcefield', creates forcefield for players who want it.
|
||||||
|
"forcefield",
|
||||||
|
# Adds /damnspam, creates timeout for buttons/levers to mitigate button spam.
|
||||||
|
"damnspam",
|
||||||
|
# Adds /check, useful to lookup details about a player
|
||||||
|
"check",
|
||||||
|
# Adds /an, a command you can use to share thoughts/plans/news
|
||||||
|
"adminnotes",
|
||||||
|
# Adds busy status to players
|
||||||
|
"imbusy",
|
||||||
|
# Adds /imout, displays fake leave/join messages
|
||||||
|
"imout",
|
||||||
|
#adds snowbrawl minigame
|
||||||
|
"snowbrawl",
|
||||||
|
# Adds /tm [player] for a messages to be sent to this player via /msg
|
||||||
|
"pmtoggle",
|
||||||
|
# Replacement for LoginSecurity
|
||||||
|
"loginsecurity",
|
||||||
|
# Centralized Player class
|
||||||
|
"player",
|
||||||
|
# Servercontrol extension for telnet access to logs/AC
|
||||||
|
#"servercontrol",
|
||||||
|
# Script helper plugin
|
||||||
|
"scriptutils",
|
||||||
|
# Per-player notes
|
||||||
|
"tag",
|
||||||
|
# vanish toggle module - temporary fix
|
||||||
|
#"vanishfix",
|
||||||
|
# obisidian mining punishment plugin
|
||||||
|
"punishments",
|
||||||
|
# a simple replacement for the buggy essentials /vanish
|
||||||
|
"vanish",
|
||||||
|
# ip-tracking utility - disabled as of instability
|
||||||
|
#"iptracker",
|
||||||
|
#server signs for everyone
|
||||||
|
"serversigns",
|
||||||
|
# Makes player's names colored, sorts tab list by rank
|
||||||
|
"nametags"
|
||||||
|
]
|
||||||
shared["modules"] = {}
|
shared["modules"] = {}
|
||||||
for module in shared["load_modules"]:
|
for module in shared["load_modules"]:
|
||||||
try:
|
try:
|
||||||
|
|||||||
13
misc.py
13
misc.py
@@ -114,9 +114,20 @@ def rs_material_broken_by_flow(material):
|
|||||||
length = len(parts)
|
length = len(parts)
|
||||||
return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR"))
|
return length > 1 and (parts[0] == "DIODE" or parts[1] in ("TORCH", "WIRE", "BUTTON", "HOOK") or (length == 3 and parts[1] == "COMPARATOR"))
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.PlayerInteractEvent")
|
||||||
|
def on_interact(event):
|
||||||
|
if (not event.isCancelled()
|
||||||
|
and str(event.getAction()) == "RIGHT_CLICK_BLOCK"
|
||||||
|
and str(event.getMaterial()) in ("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON")
|
||||||
|
and not can_build(player, event.getClickedBlock())
|
||||||
|
):
|
||||||
|
event.setCancelled(True)
|
||||||
|
|
||||||
|
|
||||||
sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end",
|
sudo_blacklist = ["pyeval", "script_backup_begin", "script_backup_end", "script_backup_error", "script_backup_database_begin", "script_backup_database_dumps", "script_backup_database_end",
|
||||||
"script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort",
|
"script_backup_database_error", "script_backup_database_abort", "script_trim", "script_trim_result", "script_spigot_update", "script_disk_filled", "script_restart", "script_restart_abort",
|
||||||
"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo"]
|
"script_stop", "script_stop_abort", "script_shutdown", "stop", "esudo", "essentials:sudo", "sudo"]
|
||||||
|
|
||||||
@simplecommand("sudo",
|
@simplecommand("sudo",
|
||||||
usage = "<player> [cmd..]",
|
usage = "<player> [cmd..]",
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import mysqlhack
|
|
||||||
from secrets import *
|
|
||||||
from thread_utils import *
|
|
||||||
from com.ziclix.python.sql import zxJDBC
|
|
||||||
from traceback import format_exc as trace
|
|
||||||
|
|
||||||
class mysql_connect:
|
|
||||||
def __init__(self):
|
|
||||||
self.conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
self.curs = self.conn.cursor()
|
|
||||||
|
|
||||||
def execute(self, query, args=None):
|
|
||||||
if args is None:
|
|
||||||
return self.curs.execute(query)
|
|
||||||
else:
|
|
||||||
return self.curs.execute(query, args)
|
|
||||||
|
|
||||||
def fetchall(self):
|
|
||||||
return self.curs.fetchall()
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_inst, exc_tb):
|
|
||||||
if exc_type is None:
|
|
||||||
try:
|
|
||||||
self.conn.commit()
|
|
||||||
self.curs.close()
|
|
||||||
self.conn.close()
|
|
||||||
except:
|
|
||||||
print(trace())
|
|
||||||
else:
|
|
||||||
print(exc_tb)
|
|
||||||
10
mysqlhack.py
10
mysqlhack.py
@@ -4,12 +4,12 @@ A library that makes use of the so called ClassPathHack for jython
|
|||||||
to allow proper loading of mysql-connector.jar at runtime.
|
to allow proper loading of mysql-connector.jar at runtime.
|
||||||
Import only, no methods.
|
Import only, no methods.
|
||||||
"""
|
"""
|
||||||
import jarray
|
|
||||||
import java.net.URL
|
|
||||||
import java.io.File
|
|
||||||
from java.lang import Class
|
|
||||||
import java.net.URLClassLoader
|
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URL
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
import jarray
|
||||||
|
from java.lang import Class
|
||||||
|
|
||||||
|
|
||||||
# hacky code to add mysql-connector to java's classpath ('classPathHack')
|
# hacky code to add mysql-connector to java's classpath ('classPathHack')
|
||||||
|
|||||||
37
nametags.py
Executable file
37
nametags.py
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
from helpers import *
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# #
|
||||||
|
# This module automatically puts people in the corresponding #
|
||||||
|
# scoreboard team so that their name is colored properly and #
|
||||||
|
# tab will be nicely sorted. #
|
||||||
|
# #
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
ranks = ["visitor", "member", "builder", "trusted", "trainingmod", "mod", "admin"]
|
||||||
|
# prefixes are used for sorting in the tab list
|
||||||
|
prefixes = {"admin":"a", "mod":"b", "trainingmod":"c", "trusted":"d", "builder":"e", "member":"f","visitor":"g"}
|
||||||
|
|
||||||
|
@hook.event("player.PlayerJoinEvent", "low")
|
||||||
|
def on_player_join(event):
|
||||||
|
player = event.getPlayer()
|
||||||
|
team = get_team(player)
|
||||||
|
if team:
|
||||||
|
cmd = "scoreboard teams join %s %s" % (team, player.getName())
|
||||||
|
server.dispatchCommand(server.getConsoleSender(), cmd)
|
||||||
|
|
||||||
|
def get_rank(player):
|
||||||
|
player_rank = None
|
||||||
|
for rank in ranks:
|
||||||
|
if not player.hasPermission("group.%s" % rank):
|
||||||
|
break
|
||||||
|
player_rank = rank
|
||||||
|
if not player_rank:
|
||||||
|
warn("Couldn't find rank for player %s" % player.getName())
|
||||||
|
return player_rank
|
||||||
|
|
||||||
|
def get_team(player):
|
||||||
|
rank = get_rank(player)
|
||||||
|
if rank:
|
||||||
|
prefix = prefixes.get(rank)
|
||||||
|
return "_".join([prefix, rank])
|
||||||
@@ -5,7 +5,11 @@ from java.util.UUID import fromString as juuid
|
|||||||
toggle_dict = {}
|
toggle_dict = {}
|
||||||
permission = "utils.pmtoggle"
|
permission = "utils.pmtoggle"
|
||||||
|
|
||||||
@hook.command("tm")
|
@hook.command("pmtoggle",
|
||||||
|
aliases = ["tm", "mt", "tmsg", "msgt", "pmt", "tpm"],
|
||||||
|
usage = "/<command> [player]",
|
||||||
|
description = "Toggle automatic sending of messages"
|
||||||
|
)
|
||||||
def on_toggle_message_command(sender, command, label, args):
|
def on_toggle_message_command(sender, command, label, args):
|
||||||
if not sender.hasPermission(permission) or not is_player(sender):
|
if not sender.hasPermission(permission) or not is_player(sender):
|
||||||
noperm(sender)
|
noperm(sender)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.UUID as UUID
|
|||||||
import org.bukkit.Material as Material
|
import org.bukkit.Material as Material
|
||||||
import org.bukkit.block.BlockFace as BlockFace
|
import org.bukkit.block.BlockFace as BlockFace
|
||||||
|
|
||||||
blocked_cmds = ("pex", "kick", "ban", "tempban", "pyeval", "sudo", "stop", "reload", "op", "deop", "whitelist")
|
blocked_cmds = tuple(shared["modules"]["misc"].sudo_blacklist) + ("pex", "kick", "ban", "tempban", "reload", "op", "deop", "whitelist")
|
||||||
|
|
||||||
def load_signs():
|
def load_signs():
|
||||||
signs_obj = open_json_file("serversigns", [])
|
signs_obj = open_json_file("serversigns", [])
|
||||||
|
|||||||
4
setup.sh
4
setup.sh
@@ -25,7 +25,7 @@ mkdir -v "build"
|
|||||||
cd "build"
|
cd "build"
|
||||||
|
|
||||||
echo -e "\n> Downloading Spigot build tools"
|
echo -e "\n> Downloading Spigot build tools"
|
||||||
curl --progress-bar -Lo "buildtools.jar" "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
|
curl --progress-bar -Lo "BuildTools.jar" "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
|
||||||
|
|
||||||
echo -e "\n> Building Spigot, this will take a while ..."
|
echo -e "\n> Building Spigot, this will take a while ..."
|
||||||
java -jar BuildTools.jar > /dev/null
|
java -jar BuildTools.jar > /dev/null
|
||||||
@@ -91,7 +91,7 @@ echo -e "\n> All plugins downloaded"
|
|||||||
|
|
||||||
cd "redstoner-utils.py.dir"
|
cd "redstoner-utils.py.dir"
|
||||||
echo -e "\n> Duplicating sample files"
|
echo -e "\n> Duplicating sample files"
|
||||||
for file in ls ./*.example; do
|
for file in ./*.example; do
|
||||||
cp -v "$file" "$(echo "$file" | rev | cut -d "." -f 2- | rev)"
|
cp -v "$file" "$(echo "$file" | rev | cut -d "." -f 2- | rev)"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import threading
|
|
||||||
"""
|
|
||||||
Quick implementation of a @synchronized and @asynchronized decorators
|
|
||||||
"""
|
|
||||||
|
|
||||||
#To be replaced by bukkit scheduler.
|
|
||||||
"""
|
|
||||||
def sync(lock=None):
|
|
||||||
def decorator(wrapped):
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
with lock:
|
|
||||||
return wrapped(*args, **kwargs)
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
"""
|
|
||||||
|
|
||||||
def async(daemon = True):
|
|
||||||
def decorator(function):
|
|
||||||
def wrapper(*args,**kwargs):
|
|
||||||
thread = threading.Thread(target=function,args=args,kwargs=kwargs)
|
|
||||||
thread.daemon = daemon
|
|
||||||
thread.start()
|
|
||||||
return wrapper
|
|
||||||
return decorator
|
|
||||||
11
wrapper.py
11
wrapper.py
@@ -1,11 +0,0 @@
|
|||||||
"""
|
|
||||||
Adapter classes for spigot api for more idiomatic python code.
|
|
||||||
|
|
||||||
Before you run away from this if the class you need to use isn't here, please create it.
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
from helpers import *
|
|
||||||
from wrapper_event import *
|
|
||||||
from wrapper_player import *
|
|
||||||
from wrapper_command import *
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
from wrapper_player import *
|
|
||||||
|
|
||||||
def command(command = "help"):
|
|
||||||
def decorator(wrapped):
|
|
||||||
@hook.command(command)
|
|
||||||
def wrapper(sender, command, label, args):
|
|
||||||
try:
|
|
||||||
return wrapped(sender = py_players[sender], command = command, label = label, args = args)
|
|
||||||
except:
|
|
||||||
print(print_traceback())
|
|
||||||
return decorator
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
from wrapper import *
|
|
||||||
from wrapper_player import *
|
|
||||||
from traceback import format_exc as print_traceback
|
|
||||||
|
|
||||||
class py_event:
|
|
||||||
def __init__(self,event):
|
|
||||||
self.event = event
|
|
||||||
try:
|
|
||||||
self.player = py_players[event.getPlayer()]
|
|
||||||
except:
|
|
||||||
warn("Player doesn't exist")
|
|
||||||
|
|
||||||
def event_handler(event_name = None, priority = "normal"):
|
|
||||||
def decorator(wrapped):
|
|
||||||
@hook.event(event_name, priority)
|
|
||||||
def wrapper(event):
|
|
||||||
try:
|
|
||||||
wrapped(py_event(event))
|
|
||||||
except:
|
|
||||||
print(print_traceback())
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import time
|
|
||||||
import mysqlhack
|
|
||||||
from mysql_utils import *
|
|
||||||
from thread_utils import *
|
|
||||||
from players_secret import *
|
|
||||||
from datetime import datetime
|
|
||||||
from com.ziclix.python.sql import zxJDBC
|
|
||||||
|
|
||||||
class py_player:
|
|
||||||
def __init__(self,player):
|
|
||||||
self.player = player
|
|
||||||
self.login_time = time.time()
|
|
||||||
self.logging_in = False
|
|
||||||
|
|
||||||
self.nickname = self.name
|
|
||||||
self.registered = False
|
|
||||||
self.password = "None"
|
|
||||||
self.banned = False
|
|
||||||
self.banned_reason = "You have been banned!"
|
|
||||||
self.played_time = time.time() - self.login_time
|
|
||||||
self.last_login = datetime.now()
|
|
||||||
self.first_seen = datetime.now()
|
|
||||||
|
|
||||||
def kick(self, kick_message = "You have been kicked from the server!"):
|
|
||||||
self.player.KickPlayer(kick_message)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
return self.player.getName()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def uuid(self):
|
|
||||||
return str(self.player.getUniqueId())
|
|
||||||
|
|
||||||
|
|
||||||
class Py_players:
|
|
||||||
def __init__(self):
|
|
||||||
self.players = []
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.players)
|
|
||||||
|
|
||||||
def __getitem__(self, player):
|
|
||||||
for py_player in self.players:
|
|
||||||
if py_player.name == player.getName():
|
|
||||||
return py_player
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def remove(self, player):
|
|
||||||
self.players.remove(player)
|
|
||||||
|
|
||||||
def append(self, player):
|
|
||||||
self.players.append(player)
|
|
||||||
|
|
||||||
py_players = Py_players()
|
|
||||||
|
|
||||||
@async(daemon=True)
|
|
||||||
def fetch_player(player):
|
|
||||||
with mysql_connect() as sql:
|
|
||||||
sql.execute("SELECT * FROM utils_players WHERE uuid = ?", (player.uuid,))
|
|
||||||
result = sql.fetchall()
|
|
||||||
|
|
||||||
if len(result) is 0:
|
|
||||||
with mysql_connect() as sql:
|
|
||||||
sql.execute("INSERT INTO utils_players \
|
|
||||||
(uuid, name, nickname, registered, password, banned, \
|
|
||||||
banned_reason, played_time, last_login, first_seen) \
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
||||||
|
|
||||||
args=(player.uuid, player.name, player.nickname, player.registered,
|
|
||||||
player.password, player.banned,
|
|
||||||
player.banned_reason, player.played_time,
|
|
||||||
player.last_login, player.first_seen))
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
#test
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent","lowest")
|
|
||||||
def on_join(event):
|
|
||||||
player = py_player(event.getPlayer())
|
|
||||||
py_players.append(player)
|
|
||||||
fetch_player(player)
|
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.PlayerQuitEvent","highest")
|
|
||||||
def on_leave(event):
|
|
||||||
py_players.remove(py_players[event.getPlayer()])
|
|
||||||
Reference in New Issue
Block a user