2 Commits

Author SHA1 Message Date
jomo
7cf1be67e9 Fixed hypercommand exceptions
Apparently jython, nested functions, decorators, and wildcard import don't work well together.
I changed the import to non-wildcard and prefixed all function calls with the module name
2015-08-16 02:28:13 +02:00
NEMESIS13cz
e184a6d4e1 Created hopefully the ultimate cmd manager 2015-08-15 18:48:15 +02:00
30 changed files with 172 additions and 2188 deletions

View File

@@ -1,67 +1,13 @@
from helpers import *
"""
@simplecommand is a decorator which is meant to replace @hook.command in redstoner-utils, where useful.
It takes care of checks such as whether the sender is a player, whether they have permission,
whether there are enough argumens, and also takes care of a help message.
On top of that, it makes the code shorter and easier to write with features like Validate, and returning a message instead of a boolean value.
@simplecommand has an inbuilt tracing feature, so you won't have to put all your code in a try/except statement anymore.
Make sure to `from basecommands import simplecommand` before using this decorator.
The arguments are as follows:
* cmd: the command, self explanatory (required);
* aliases: A list containing any aliases for the command, like shortcuts;
* usage: a String defining the expected arguments for the command. Example:
Let's say I have a command /tp <player_to_teleport> <destination_player>. The usage is: "<player_to_teleport> <destination_player>".
I suggest we use the same format throughout redstoner-utils:
- Separate arguments by spaces;
- Use <> if the argument is required, and [] if the argument is optional;
- Add .. to the argument's identifier (name) if it is for example a message (containing spaces).
for example in /msg, the usage would be "<player> <msg..>"
* description: a description of what the command does. Defaults to "Handles cmd".
This is used for the help message, where the description is (meant to be) indented. To keep this indentation
with longer descriptions, call the help message (with the command, ingame) and add '\n'
when it jumps to a new line in the chat. The decorator will take care of the indentation after that.
* senderLimit: an integer resembling the accepted sender type. Defaults to -1. Use:
-1 for console as well as players;
0 for players only;
1 for console only.
* amin: an integer resembling the minimum amount of arguments. Defaults to 0
* amax: an integer resembling the maximum amount of arguments. Defaults to -1, which means that there is no maximum.
* helpNoargs: a boolean value resembling whether the help message should be displayed when no arguments are given.
Defaults to False.
* helpSubcmd: a boolean value resembling whether the help message should be displayed when the first argument.lower() equals "help".
Defaults to False.
Comments on the function added to the decorator:
It should return a message to send to the player. Color codes are translated automatically. It can return None or an empty string to send nothing.
Returning "HELP" makes it show the help message.
Inside the function, calls to static methods in the class Validate can be used to make the code shorter and easier to write (maybe not easier to read).
For example, to make sure that a condition is met, use Validate.isTrue(condition, message to send to the player if the condition is not met)
Don't forget to `from basecommands import Validate` if you wish to make use of this.
For all other Validate checks, see the code below. Feel free to add your own.
Instead of returning a message mid-code to describe an error, you can also use raise CommandException(msg), but it is almost always possible
to replace this return statement with a call to one of the functions in the Validate class. Once again, if you use raise CommandException(msg),
don't forget to `from basecommands import CommandException`.
"""
to_see_permission = "utils.showpermission" # See cmd permission in help
def isSenderValid(senderLimit, isPlayer):
return True if senderLimit == -1 else senderLimit != isPlayer
def invalidSenderMsg(isPlayer):
return "&cThat command can only be used by " + ("the console" if isPlayer else "players")
return "&cThat command can only be run from the console" if isPlayer else "&cThat command can only be run by players"
def helpMsg(sender, cmd, description, usage, aliases, permission):
help_msg = "&aInformation about command /%s:\n &9%s" % (cmd, description.replace("\n", "\n "))
@@ -119,7 +65,7 @@ def simplecommand(cmd,
except CommandException, e:
return e.message
except Exception, e:
error(trace())
error(e.message, trace())
return "&cAn internal error occurred while attempting to perform this command"
return call

View File

@@ -11,17 +11,6 @@ import org.bukkit.event.block.Action as Action
import org.bukkit.block.BlockFace as BlockFace
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
cauldron = [0,
"easy cauldron water level control",
@@ -35,7 +24,7 @@ settingInformation = dict( #[setting type, identifying description, detailed des
],
furnace = [1,
"automatically filling furnaces upon placement",
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle furnace clear to clear all slots.",
"Sets your preferred default furnace contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.",
["cooker", "fillf"], 2
],
#torch = [0,
@@ -55,7 +44,7 @@ settingInformation = dict( #[setting type, identifying description, detailed des
],
hopper = [1,
"automatically filling hoppers upon placement",
"Sets your preferred default hopper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle hopper clear to clear all slots.",
"Sets your preferred default hopper contents to your currently held itemstack. Use an empty hand to empty a slot, or /toggle dropper clear to clear all slots.",
["itemtransporter", "fillh"], 4
]
)
@@ -150,8 +139,7 @@ def toggle_command(sender, command, label, args):
if arg2 == "clear":
if enabled:
del values[uuid]
return " &aDisabled " + details[1]
return " &cAlready disabled: " + details[1]
return " &aDisabled " + details[1]
if arg2 == "details":
return " &aSetting %s:\n &9%s \n&6Accepted arguments: [<slot>|clear|details]" % (setting, details[2])

View File

@@ -10,12 +10,6 @@ calc_perm = "utils.calc"
calc_perm_power = "utils.calc.power"
def calc(sender, text):
try:
return do_calc(sender, text.lower())
except:
return None
def do_calc(sender, text):
"""
extracts a mathematical expression from `text`
returns (expression, result) or None

View File

@@ -1,352 +0,0 @@
############################################
# Alias v2.0 by Pepich #
# Changes to previous version from curs3d: #
# Dynamic alias limit from permissions #
# AC/CG/MSG support #
# Color support #
# Bugfixes #
# #
# TODO: #
# Add command support... #
############################################
import os
import mysqlhack
import org.bukkit as bukkit
from org.bukkit import *
from helpers import *
from traceback import format_exc as trace
from secrets import *
# Version number and requirements
alias_version = "2.0.0"
helpers_versions = ["1.1.0", "2.0.0"]
enabled = False
error = colorify("&cUnspecified error")
commands_per_page = 5
global_aliases = {"./":"/"}
data = {}
# DON'T SET THIS TO TRUE! MySQL requestst are NOT ASYNC yet! (And for some reason it doesn't want to store any data ._.)
use_mysql = False
# Permissions:
# Grants full access immediately
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 #
########
# OnEnable
enabled = helpers_version in helpers_versions
if not enabled:
error = colorify("&6Incompatible versions detected (&chelpers.py&6)")
def safe_open_json(uuid):
if not os.path.exists("plugins/redstoner-utils.py.dir/files/aliases"):
os.makedirs("plugins/redstoner-utils.py.dir/files/aliases")
value = open_json_file("aliases/" + uuid)
if value is None:
value = global_aliases
save_json_file("aliases/" + uuid, value)
return value
@hook.command("alias",
usage="/<command> <add, remove, list, help> [...]",
desc="Allows aliasing of words")
def on_alias_command(sender, cmd, label, args):
try:
args = array_to_list(args)
if not enabled:
disabled_fallback(sender)
return True
if not hasPerm(sender, permission_BASE):
plugin_header(recipient=sender, name="Alias")
noperm(sender)
return True
return subcommands[args[0].lower()](sender, args[1:])
except:
return subcommands["help"](sender, "1")
def help(sender, args):
commands = [colorify("&e/alias help [page]")]
if hasPerm(sender, permission_LIST):
commands += [colorify("&e/alias list &7- Lists all your aliases")]
if hasPerm(sender, permission_MODIFY):
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/alias help " + str(page+2)))
return True
@hook.event("player.PlayerJoinEvent", "high")
def on_join(event):
if enabled:
t = threading.Thread(target=load_data, args=(uid(event.getPlayer()), ))
t.daemon = True
t.start()
else:
if event.getPlayer().hasPermission(permission_FINFO):
disabled_fallback(event.getPlayer())
@hook.event("player.AsyncPlayerChatEvent", "high")
def on_player_chat(event):
try:
if enabled:
if event.isCancelled():
return
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:
print(trace())
def hasPerm(player, permission):
return (player.hasPermission(permission)) or (player.hasPermission(permission_ALL))
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:])]
if not add_alias_data(uid(sender), str(args[0]), args[1]):
msg(sender, colorify("&c") + "Could not add an alias for this sequence because a priorly added alias contains it")
return True
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):
plugin_header(sender, "Alias")
args = args[0:2] + [" ".join(args[2:len(args)-1])] + [args[len(args)-1]]
if is_player(sender):
sender_name = colorify(sender.getDisplayName())
else:
sender_name = colorify("&6Console")
target = get_player(args[0])
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
if len(args) == 3:
args += ["true"]
if not add_alias_data(uid(target), str(args[1]), str(args[2])):
message = colorify("&c") + "Could not add an alias for this sequence because a priorly added alias contains it"
msg(sender, message)
if args[3].lower() == "false":
msg(target, message)
return True
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 add_alias_data(puuid, aliased, new_alias):
prior = data[puuid]
if aliased not in prior:
for alias in prior.values():
if aliased in alias:
return False
prior[aliased] = new_alias
save_data(puuid)
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":
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):
try:
load_data_thread(uuid)
# t = threading.Thread(target=load_data_thread, args=(uuid))
# t.daemon = True
# t.start()
except:
print(trace())
def load_data_thread(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):
try:
save_data_thread(uuid)
# t = threading.Thread(target=save_data_thread, args=(uuid))
# t.daemon = True
# t.start()
except:
print(trace())
def save_data_thread(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,
}

View File

@@ -21,8 +21,6 @@ def on_chatgroup_command(sender, command, label, args):
if len(args) == 1 and args[0] == "leave":
if sender_id in groups.keys():
groupchat(sender, "left the group", True)
if sender in cg_toggle_list:
cg_toggle_list.remove(p)
group = groups[sender_id]
del(groups[sender_id])
save_groups()
@@ -45,18 +43,11 @@ def on_chatgroup_command(sender, command, label, args):
msg(sender, "&aUse chat like '&e%s<message>' to send messages to this group." % get_key(sender_id))
elif len(args) == 1 and args[0] == "key":
msg(sender, "&aYour chatgroup key is currently: '&c%s&a'" % get_key(sender_id))
elif len(args) == 1 and args[0] == "tpahere":
if sender_id in groups.keys():
do_for_chatgroup(groups[sender_id], send_tpa_request, sender)
msg(sender, "&aSent a tpahere request to all users in your chatgroup")
else:
msg(sender, "&cYou have to be in a chatgroup to do that")
else:
msg(sender, "&e/chatgroup join <name>")
msg(sender, "&e/chatgroup leave")
msg(sender, "&e/chatgroup info")
msg(sender, "&e/chatgroup key")
msg(sender, "&e/chatgroup tpahere")
@hook.command("cgt")
@@ -81,19 +72,11 @@ def groupchat(sender, message, ann = False):
mesg = "&8[&bCG&8] &e&o%s&e&o %s" % (name, message)
else:
mesg = "&8[&bCG&8] &f%s&f: &6%s" % (name, message)
mesg = colorify(mesg)
info("[ChatGroups] %s (%s): %s" % (sender.getDisplayName(), group, message))
do_for_chatgroup(group, msg, mesg, usecolor = False)
def do_for_chatgroup(group, func, *args, **kwargs):
for receiver in server.getOnlinePlayers():
if groups.get(uid(receiver)) == group:
func(receiver, *args, **kwargs)
groups.get(uid(receiver)) == group and msg(receiver, mesg)
def send_tpa_request(receiver, sender):
if not receiver == sender:
runas(sender, "/tpahere " + receiver.getName())
def save_groups():
save_json_file("chatgroups", groups)
@@ -132,6 +115,5 @@ def chatgroupkey_command(sender, command, label, args):
save_keys()
return "&aYour chatgroup key was set to: '&c%s&a'" % key
def save_keys():
save_json_file("chatgroup_keys", cg_keys)

View File

@@ -86,10 +86,7 @@ def on_hook_command(sender, command, label, args):
plugin_header(sender, "Check")
msg(sender, "&7Please notice that the data may not be fully accurate!")
player = server.getOfflinePlayer(args[0]) if len(args) > 0 else None
t = threading.Thread(target=get_all_data, args=(sender, player))
t.daemon = True
t.start()
get_all_data(sender, player)
else:
msg(sender, "&4You don't have the required permissions to execute this command!")
return True

View File

@@ -36,9 +36,9 @@ def on_dammnspam_command(sender, command, label, args):
msg(sender, "&c/damnspam <seconds after off> <seconds after on> &e(Levers only)")
return True
#Gittestlol
if not is_creative(sender):
msg(sender, "&cYou can only do this in Creative mode.")
return True
if not is_creative(sender):
msg(sender, "&cYou can only do this in Creative mode.")
return True
# /damnspam <secs>
if len(args) == 1:
@@ -47,6 +47,8 @@ def on_dammnspam_command(sender, command, label, args):
timeout_on = round(float(timeout_on), 2)
timeout_off = timeout_on
if 60 >= timeout_on <= -2 or timeout_on == 0:
timeout_on = False
if timeout_on == False:
msg(sender, "&cThe timeout must be within 0-60 or -1.")
return True
except ValueError:

View File

@@ -5,10 +5,6 @@ friends = open_json_file("friends", {}) # {Player_UUID:[List_of_friend
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
def fjm(event): # friend join message

104
helpers.py Executable file → Normal file
View File

@@ -6,23 +6,14 @@ 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
from secrets import *
import mysqlhack
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
server = bukkit.Bukkit.getServer()
@@ -144,15 +135,6 @@ def is_player(obj):
return (isinstance(obj, Player))
def can_build(player, block):
"""
return True if the player can change/build at the location of given block
"""
event = BlockBreakEvent(block, player)
server.getPluginManager().callEvent(event)
return not event.isCancelled()
def checkargs(sender, args, amin, amax):
"""
check if a command has a valid amount of args, otherwise notify the sender
@@ -204,30 +186,6 @@ def known_player(player):
"""
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):
"""
@@ -265,62 +223,4 @@ def toggle(player, ls, name = "Toggle", add = None):
msg(player, "&a%s turned off!" % name)
elif add != False:
ls.append(pid)
msg(player, "&a%s turned on!" % name)
def send_JSON_message(playername, message):
bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message)
# 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 = ["","","",""]
i = 0
for j in range(0,len(tocheck)):
if not (tocheck[j] in "0123456789."):
return False
elif tocheck[j] == ".":
i += 1
if (i >= 4):
return False
else:
subsets[i] += tocheck[j]
if not (i == 3):
return False
for j in range(0,3):
if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)):
return False
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
#debug wrapper
def debug(func):
def wrap(*args, **kwargs):
try:
func(*args, **kwargs)
except:
print(trace())
return wrap
msg(player, "&a%s turned on!" % name)

87
hypercommand.py Normal file
View File

@@ -0,0 +1,87 @@
# can't import * because that's not working with nested functions & decorators
import helpers
# cmd = the actual command
# tree = e.g. [{ "name": "subcommand", "perm": "utils.cmd.command.subcommand", "func": <function>, "type": "cmd", "cont": [<tree>] }]
# helpnoargs = print help if no args given, else run the command function below decorator
# console = can be ran by console
def hypercommand(cmd, tree = [], helpnoargs = False, console = False):
def help_msg_get(tree):
holder = ""
for data in tree:
if len(data["cont"]) > 0:
holder += ("(" + help_msg_get(data["cont"]) + ")")
else:
holder += (data["name"] if data["type"] == "cmd" else ("<" + data["name"] + ">"))
return holder
def help_msg(sender, tree):
for data in tree:
if len(data["cont"]) > 0:
helpers.msg(sender, "&e-&a " + (data["name"] if data["type"] == "cmd" else ("<" + data["name"] + ">")) + " " + help_msg_get(data["cont"]))
else:
helpers.msg(sender, "&e-&a " + (data["name"] if data["type"] == "cmd" else ("<" + data["name"] + ">")))
return None
has_help = False
for data in tree:
if data["name"] == "help" and data["type"] == "cmd":
has_help = True
break
cmd = cmd.lower()
if not has_help:
tree.append({"name": "help", "perm": "utils." + cmd + ".help", "func": help_msg, "type": "cmd", "cont": []}) # type = "cmd" for subcommands or "arg" for arguments
def decorator(function):
def get_next(sender, tree, args, all_args):
if len(args) == 0: # ran out of arguments but command is supposed to continue, print usage
data = []
for comm in tree:
if comm["type"] == "cmd":
data.append(comm["name"])
else:
data.append("<" + comm["name"] + ">")
return "&c" + " ".join(all_args) + " " + "/".join(data) + "..."
for comm in tree:
if comm["type"] == "cmd":
if comm["name"] == args[0]: # argument exists as a subcommand
if sender.hasPermission(comm["perm"]):
if len(comm["cont"]) > 0: # command continues
return get_next(sender, comm["cont"], args[1:], all_args) # continue in the recursive stack
else:
return comm["func"](sender, args[1:]) # run function with sender and all trailing arguments incase they are relevant
else:
return "&cNo permission"
for comm in tree:
if comm["type"] == "arg":
if len(comm["cont"]) > 0: # command continues, but this is an argument
# run the function its pointing at and substitute itself with the returned subcommand to chose
# continue in stack as if the arg was a subcommand returned by its pointer function
return get_next(sender, comm["cont"], args[0:(len(args) - 1)].insert(0, comm["func"](sender, args[0])), all_args)
else:
return comm["func"](sender, args) # run the function arg is pointing at with current arguments including this one as args[0]
return get_next(sender, tree, [], all_args[0:(len(all_args) - 1)])
@hook.command(cmd)
def call(sender, command, label, args):
message = run(sender, command, label, args)
if message:
helpers.msg(sender, message)
return True
def run(sender, command, label, args):
if not helpers.is_player(sender) and not console:
return "&cThis command can only be executed by players"
try:
if len(args) == 0:
if helpnoargs:
help_msg(sender, tree)
return None
else:
return function(sender, command, label, args)
return get_next(sender, tree, args, args)
except:
helpers.error(helpers.trace())
return "&cInternal Error. Please report to staff!"
return call
return decorator

308
imbusy.py
View File

@@ -1,308 +0,0 @@
##################################
# I'M BUSY! Plugin by Curs3d #
# Concept by CookieManors :D #
##################################
# This plugin permits users to #
# send a command that renders #
# them "busy", not letting them #
# to get tpa requests or direct #
# messages, except from console. #
# On restart, all busy data will #
# be cleared. #
##################################
from helpers import *
from friends import is_friend_of
import org.bukkit.command.Command as Command
imbusy_version = "v1.1.0"
base_permission = "utils.busy" # for /busy status
use_permission = "utils.busy.use" # for being busy
override_permission = "utils.busy.override" # for being able to bother busy people
busy_players = {} # name : false/true where false is normal busy and true is super busy
@hook.command("imbusy",
aliases = ["busy"],
usage = "/<command> [on, off, status/check]",
description = "Offers control over your busy status"
)
def on_busy_command(sender, cmd, label, args):
if not is_player(sender):
msg(sender, "&7Sorry, Console cannot be busy")
return True
plugin_header(recipient = sender, name = "I'M BUSY!")
#args = array_to_list(args)
if not sender.hasPermission(base_permission):
noperm(sender)
return True
if len(args) == 0:
return toggle(sender)
arg0 = args[0].lower()
if arg0 == "on":
return on(sender)
if arg0 == "off":
return off(sender)
if arg0 in ("status", "check"):
return status(sender, args[1:])
if arg0 == "super":
return super_cmd(sender)
return help(sender)
def toggle(sender):
if not sender.hasPermission(use_permission):
noperm(sender)
return True
sender_name = sender.getName()
if sender_name in busy_players:
del busy_players[sender_name]
broadcast(None, sender.getDisplayName() + " &7is no longer busy...")
else:
busy_players.append(sender_name)
broadcast(None, sender.getDisplayName() + " &7is now busy...")
return True
def help(sender):
msg(sender, "Let's you put yourself in busy status, preventing pms and tpa requests from other players")
msg(sender, "\n&eCommands:")
msg(sender, "&e/busy &7- Toggles 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 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
def on(sender):
if not sender.hasPermission(use_permission):
noperm(sender)
return True
sender_name = sender.getName()
if busy_players.get(sender_name) is False: # can be None, False or True
msg(sender, "&7You are already busy!")
else:
busy_players[sender_name] = False # busy but not super busy
broadcast(None, sender.getDisplayName() + " &7is now busy...")
return True
def off(sender):
if not sender.hasPermission(use_permission):
noperm(sender)
return True
sender_name = sender.getName()
if sender_name not in busy_players:
msg(sender, "&7You are not busy! You cannot be even less busy! Are you perhaps bored?")
return True
del busy_players[sender_name]
broadcast(None, sender.getDisplayName() + " &7is no longer busy...")
return True
def status(sender, args):
if not sender.hasPermission(base_permission):
noperm(sender)
return True
if len(args) == 0:
if sender.getName() in busy_players:
if busy_players[sender_name] is False:
msg(sender, "&7You are currently busy.")
else:
msg(sender, "&7You are currently SUPER busy.")
else:
msg(sender, "&7You are currently not busy.")
else:
target = server.getPlayer(args[0])
if target is None:
msg(sender, "&7That player is not online")
elif target.getName() in busy_players:
if busy_players[target.getName()] is False:
msg(sender, "&7Player %s &7is currently busy." % target.getDisplayName())
else:
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
@hook.event("player.PlayerQuitEvent", "lowest")
def on_player_leave(event):
player_name = event.getPlayer().getName()
if player_name in busy_players:
del busy_players[player_name]
#---- Dicode for catching any bothering of busy people ----
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):
target = server.getPlayer(target_name)
if target is not None:
if not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False
reply_targets[sender.getName()] = target.getName()
# allow the target to reply regardless of sender being busy
if target.getName() in reply_targets:
del reply_targets[target.getName()]
return True
def reply(sender):
if sender.getName() in reply_targets:
target = server.getPlayer(reply_targets[sender.getName()])
if target is not None:
if not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False
# allow the target to reply regardless of sender being busy
if target.getName() in reply_targets:
del reply_targets[target.getName()]
return True
class CommandWrapper(Command):
def __init__(self, wrapped, checker):
Command.__init__(self, wrapped.getName())
self.setDescription(wrapped.getDescription())
self.setPermission(wrapped.getPermission())
self.setUsage(wrapped.getUsage())
self.setAliases(wrapped.getAliases())
self.wrapped = wrapped
self.checker = checker
def execute(self, sender, label, args):
try:
if not is_player(sender) or self.checker(sender, args):
return self.wrapped.execute(sender, label, args)
except:
error(trace())
return True
def tabComplete(self, sender, alias, args):
return self.wrapped.tabComplete(sender, alias, args)
def msg_command_checker(sender, args):
return len(args) <= 1 or whisper(sender, args[0])
def reply_command_checker(sender, args):
return len(args) == 0 or reply(sender)
def tpa_command_checker(sender, args):
if len(args) == 0:
return True
target = server.getPlayer(args[0])
if target is not None and not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False
return True
def tpahere_command_checker(sender, args):
return tpa_command_checker(sender, args)
def mail_command_checker(sender, args):
info("Mail command executed")
if len(args) < 3 or args[0].lower() != "send":
return True
target = server.getPlayer(args[1])
if target is not None and not can_send(sender, target):
msg(sender, "&c[&fBUSY&c] %s&r is busy!" % target.getDisplayName())
return False
return True
@hook.event("player.PlayerCommandPreprocessEvent", "monitor")
def on_player_command_preprocess(event):
message = event.getMessage().split(" ")
if len(message) > 1 and message[0].lower() in ("/tell", "/minecraft:tell") and not whisper(event.getPlayer(), message[1]):
event.setCancelled(True)
@hook.enable
def replace_ess_commands():
try:
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap")
map_field.setAccessible(True)
command_map = map_field.get(server.getPluginManager())
commands_field = command_map.getClass().getDeclaredField("knownCommands")
commands_field.setAccessible(True)
map = commands_field.get(command_map)
ess_msg_cmd = map.get("essentials:msg")
ess_reply_cmd = map.get("essentials:reply")
ess_tpa_cmd = map.get("essentials:tpa")
ess_tpahere_cmd = map.get("essentials:tpahere")
ess_mail_cmd = map.get("essentials:mail")
msg_cmd_wrapper = CommandWrapper(ess_msg_cmd, msg_command_checker)
reply_cmd_wrapper = CommandWrapper(ess_reply_cmd, reply_command_checker)
tpa_cmd_wrapper = CommandWrapper(ess_tpa_cmd, tpa_command_checker)
tpahere_cmd_wrapper = CommandWrapper(ess_tpahere_cmd, tpahere_command_checker)
mail_cmd_wrapper = CommandWrapper(ess_mail_cmd, mail_command_checker)
iterator = map.entrySet().iterator()
wrapped_commands = []
while iterator.hasNext():
entry = iterator.next()
value = entry.getValue()
changed = True
if value is ess_msg_cmd:
entry.setValue(msg_cmd_wrapper)
elif value is ess_reply_cmd:
entry.setValue(reply_cmd_wrapper)
elif value is ess_tpa_cmd:
entry.setValue(tpa_cmd_wrapper)
elif value is ess_tpahere_cmd:
entry.setValue(tpahere_cmd_wrapper)
elif value is ess_mail_cmd:
entry.setValue(mail_cmd_wrapper)
else:
changed = False
if changed:
wrapped_commands.append(entry.getKey())
info("[imbusy] wrapped commands: /" + ", /".join(wrapped_commands))
except:
error("[Imbusy] Failed to wrap essentials commands")
error(trace())

View File

@@ -1,108 +0,0 @@
import mysqlhack
import org.bukkit as bukkit
import json
from java.util import UUID as UUID
from helpers import *
from org.bukkit import *
from traceback import format_exc as trace
from iptracker_secrets import *
iptrack_permission = "utils.iptrack"
iptrack_version = "1.1.0"
@hook.event("player.PlayerJoinEvent", "low")
def on_player_join(event):
t = threading.Thread(target=on_player_join_thread, args=(event, ))
t.daemon = True
t.start()
def on_player_join_thread(event):
player = event.getPlayer()
ip = player.getAddress().getHostString()
uuid = uid(player)
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT ips FROM uuid2ips WHERE uuid = ?", (uuid, ))
results = curs.fetchall()
if len(results) == 0:
ips = []
else:
ips = json.loads(results[0][0])
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (ip, ))
results = curs.fetchall()
if len(results) == 0:
uuids = []
else:
uuids = json.loads(results[0][0])
new_ip_entry = (len(ips) == 0)
new_uuid_entry = (len(uuids) == 0)
if ip not in ips:
ips.append(ip)
if new_ip_entry:
curs.execute("INSERT INTO uuid2ips VALUES (?,?)", (uuid, json.dumps(ips), ))
else:
curs.execute("UPDATE uuid2ips SET ips = ? WHERE uuid = ?", (json.dumps(ips), uuid, ))
if uuid not in uuids:
uuids.append(uuid)
if new_uuid_entry:
curs.execute("INSERT INTO ip2uuids VALUES (?,?)", (ip, json.dumps(uuids), ))
else:
curs.execute("UPDATE ip2uuids SET uuids = ? WHERE ip = ?", (json.dumps(uuids), ip, ))
conn.commit()
curs.close()
conn.close()
@hook.command("getinfo")
def on_getinfo_command(sender, args):
t = threading.Thread(target=on_getinfo_command_thread, args=(sender, args))
t.daemon = True
t.start()
def on_getinfo_command_thread(sender, args):
if(sender.hasPermission(iptrack_permission)):
if not checkargs(sender, args, 1, 1):
return False
else:
if is_ip(args[0]):
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT uuids FROM ip2uuids WHERE ip = ?", (args[0], ))
results = curs.fetchall()
curs.close()
conn.close()
if len(results) == 0:
msg(sender, "IP " + args[0] + " is not registered in the database, maybe you got a number wrong?")
else:
uuids = json.loads(results[0][0])
msg(sender, "IP " + args[0] + " was seen with " + str(len(uuids)) + " different Accounts:")
for i in range(0, len(uuids)):
p=Bukkit.getOfflinePlayer(UUID.fromString(uuids[i]))
if is_player(sender):
send_JSON_message(sender.getName(), '["",{"text":"' + p.getName() + ' - (uuid: ' + uuids[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + p.getName() + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for ' + p.getName() + ' in the database, simply click the name!","color":"gold"}]}}}]')
else:
msg(sender,p.getName() + " - (uuid: " + uuids[i] + ")")
else:
target = Bukkit.getOfflinePlayer(args[0])
uuid = target.getUniqueId()
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute("SELECT ips FROM uuid2ips WHERE uuid = ?", (uuid.toString(), ))
results = curs.fetchall()
curs.close()
conn.close()
if len(results) == 0:
msg(sender, "Player " + args[0] + " is not registered in the database, maybe you misspelled the name?")
else:
ips = json.loads(results[0][0])
msg(sender, "Player " + args[0] + " was seen with " + str(len(ips)) + " different IPs:")
for i in range(0, len(ips)):
if is_player(sender):
send_JSON_message(sender.getName(), '["",{"text":"' + ips[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + ips[i] + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for the IP ' + ips[i] + ' in the database, simply click the IP!","color":"gold"}]}}}]')
else:
msg(sender,ips[i])
else:
noperm(sender)
return True

View File

@@ -14,6 +14,7 @@ min_pass_length = 8
blocked_events = ["block.BlockBreakEvent", "block.BlockPlaceEvent", "player.PlayerMoveEvent","player.AsyncPlayerChatEvent"]
logging_in = {}
def matches(password,user):
@@ -23,17 +24,13 @@ def matches(password,user):
def matches_thread(password, user):
hashed = get_pass(uid(user))
py_player = get_py_player(user)
if crypt.verify(password, hashed):
if py_player.logging_in:
py_player.logging_in = False
if user.getName() in logging_in:
del logging_in[user.getName()]
msg(user, "&aLogged in successfully!")
else:
if py_player.logging_in:
msg(user, "&cInvalid password!")
if user.getName() in logging_in:
msg(user, "&cInvalid password")
@simplecommand("cgpass",
@@ -42,112 +39,71 @@ def matches_thread(password, user):
senderLimit = 0,
helpNoargs = True)
def change_pass_command(sender, command, label, args):
py_player = get_py_player(sender)
if py_player.logging_in:
if sender.getName() in logging_in:
return "&cYou are not logged in"
if not len(args) == 2:
return "&cInvalid arguments"
password = args[0]
new_password = args[1]
uuid = uid(sender)
if is_registered(uuid):
change_pass(uuid, crypt.encrypt(new_password, rounds=200000, salt_size=16))
return "&aPassword changed"
return "&cYou are not registered"
@simplecommand("login",
usage = "<password>",
description = "Logs you in if <password> matches your password.",
senderLimit = 0,
helpNoargs = True)
def login_command(sender, command, label, args):
py_player = get_py_player(sender)
if not py_player.logging_in:
msg(sender,"&cAlready logged in!")
password = args[0]
matches(password, sender)
@simplecommand("register",
usage = "<password>",
description = "Registers you with <password>. Next time you join, log in with /login",
senderLimit = 0,
helpNoargs = True)
def register_command(sender, command, label, args):
py_player = get_py_player(sender)
if len(args) > 1:
return "&cPassword can only be one word!"
uuid = uid(sender)
if is_registered(uuid):
return "&cYou are already registered!"
password = args[0]
if len(password) < min_pass_length:
return "&cThe password has to be made up of at least %s characters!" % min_pass_length
create_pass(uuid, password)
return "&cPassword set. Use /login <password> upon join."
@simplecommand("rmpass",
description = "Removes your password if the password matches",
senderLimit = 0,
amax = 0,
helpNoargs = False)
def rmpass_command(sender, command, label, args):
py_player = get_py_player(sender)
if py_player.logging_in:
if sender.getName() in logging_in:
return "&cYou are not logged in"
if not is_registered(uid(sender)):
return "&cYou are not registered!"
if py_player.logging_in == False:
if not sender.getName() in logging_in:
delete_pass(uid(sender))
return "&aPassword removed successfully. You will not be prompted anymore."
return "&cFailed to remove password, please contact a staff member"
@simplecommand("rmotherpass",
aliases = ["lacrmpass"],
usage = "<user>",
senderLimit = -1,
description = "Removes password of <user> and sends them a notification",
helpNoargs = True)
def rmotherpass_command(sender, command, label, args):
py_player = get_py_player(sender)
if py_player.logging_in:
if sender.getName() in logging_in:
return "&cYou are not logged in"
if not sender.hasPermission(admin_perm):
noperm(sender)
return
user = server.getOfflinePlayer(args[0])
if is_registered(uid(user)):
delete_pass(uid(user))
runas(server.getConsoleSender(), colorify("mail send %s &cYour password was reset by a staff member. Use &6/register&c to set a new one." % user.getName()))
@@ -203,27 +159,19 @@ def delete_pass(uuid):
curs.close()
conn.close()
@hook.event("player.PlayerJoinEvent", "highest")
@hook.event("player.PlayerJoinEvent", "high")
def on_join(event):
user = event.getPlayer()
py_player = get_py_player(event.getPlayer())
if is_registered(uid(user)):
msg(event.getPlayer(), "&4You will be disconnected after 60 seconds if you don't &alogin")
msg(event.getPlayer(), "&6You will be disconnected after 60 seconds if you don't &alogin")
msg(user, "&cUse /login <password>")
py_player.logging_in = True
py_player.login_time = time.time()
return
elif user.hasPermission(admin_perm):
pass #Do what? force them to make a password, lots of code, maybe just message us on slack?
logging_in[user.getName()] = time.time()
#This shouldn't be needed anymore as py_player gets removed anyway.
"""
@hook.event("player.PlayerQuitEvent", "high")
def on_quit(event):
if event.getPlayer().getName() in logging_in:
del logging_in[event.getPlayer().getName()]
"""
##Threading start
class kick_class(Runnable):
@@ -239,18 +187,15 @@ def kick_thread():
while True:
time.sleep(1)
now = time.time()
for py_player in py_players:
if py_player.logging_in:
if now - py_player.login_time > wait_time:
player = py_player.player
kick = kick_class(player)
server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"), kick)
for name, jointime in logging_in.iteritems():
if now - jointime > wait_time:
player = server.getPlayer(name)
kick = kick_class(player)
server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"), kick)
if name in logging_in:
del logging_in[name]
break
"""if name in logging_in:
del logging_in[name]
break
"""
thread = threading.Thread(target = kick_thread)
@@ -261,15 +206,6 @@ thread.start()
for blocked_event in blocked_events:
@hook.event(blocked_event, "high")
def on_blocked_event(event):
user = get_py_player(event.getPlayer())
if user.logging_in:
user = event.getPlayer()
if user.getName() in logging_in:
event.setCancelled(True)
@hook.event("player.PlayerCommandPreprocessEvent","normal")
def pre_command_proccess(event):
player = get_py_player(event.getPlayer())
if player.logging_in:
args = event.getMessage().split(" ")
if not args[0].lower() == "/login":
msg(player.player, "&4You need to login before you do that!")
event.setCancelled(True)

32
main.py
View File

@@ -38,14 +38,10 @@ shared["load_modules"] = [
"adminchat",
# Adds /badge, allows to give players achievements
"badges",
# Adds a few block placement corrections/mods
"blockplacemods",
# 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",
# For players to point friends
"friends",
# 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
@@ -56,8 +52,6 @@ shared["load_modules"] = [
"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
@@ -76,8 +70,6 @@ shared["load_modules"] = [
"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
@@ -87,25 +79,7 @@ shared["load_modules"] = [
# 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"
"playermanager"
]
shared["modules"] = {}
for module in shared["load_modules"]:

View File

@@ -4,7 +4,7 @@ from traceback import format_exc as print_traceback
mentions = open_json_file("mentio", {}) # contains a list of keywords for each player (uuid)
max_amount = 1000
max_amount = 3
arrow = colorify(u"&r&7\u2192&r")
colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes
@@ -13,7 +13,7 @@ def saveMentions():
save_json_file("mentio", mentions)
@hook.event("player.AsyncPlayerChatEvent", "monitor")
@hook.event("player.AsyncPlayerChatEvent", "high")
def onChat(event):
if not event.isCancelled():
sender = event.getPlayer()
@@ -70,7 +70,7 @@ def add_keyword(sender, args):
keywords = get_keywords(sender)
new_word = stripcolors(args[1].lower())
if (len(keywords) >= max_amount) and (max_amount >= 0):
if len(keywords) >= max_amount:
msg(sender, "&cYou are already listening for %s words! Try &6/mentio del <word>" % max_amount)
return True
@@ -146,4 +146,4 @@ def onListenCommand(sender, command, label, args):
show_help(sender)
else:
show_help(sender)
return True
return True

53
misc.py
View File

@@ -6,8 +6,7 @@ from sys import exc_info
import thread
import org.bukkit.inventory.ItemStack as ItemStack
import org.bukkit.Bukkit as Bukkit
from basecommands import simplecommand, Validate
import java.util.Arrays as Arrays
from basecommands import simplecommand
@@ -71,6 +70,7 @@ def cmd_event2(event):
""" Disabled while builder can't access Trusted
@hook.event("player.PlayerGameModeChangeEvent", "low")
def on_gamemode(event):
@@ -115,19 +115,6 @@ def rs_material_broken_by_flow(material):
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",
"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", "sudo"]
@simplecommand("sudo",
usage = "<player> [cmd..]",
@@ -140,14 +127,11 @@ def on_sudo_command(sender, command, label, args):
msg(sender, "&2[SUDO] &rRunning '&e%s&r' as &3%s" % (cmd, target))
is_cmd = cmd[0] == "/"
is_console = target.lower() in ["server", "console"]
first_cmd = (args[1])[1:] if is_cmd else None
if first_cmd in sudo_blacklist and (is_player(sender) and uid(sender) not in pythoners):
return "&cYou can't sudo this command"
if is_console:
server.dispatchCommand(server.getConsoleSender(), cmd[1:] if is_cmd else cmd)
return None
target_player = server.getPlayer(target)
if target_player:
if target_player and uid(target_player) not in pythoners:
target_player.chat(cmd)
return None
return "&cPlayer %s not found!" % target
@@ -173,8 +157,7 @@ def on_pluginversions_command(sender, command, label, args):
"""
try:
plugin_header(sender, "Plugin versions")
raw_plugins = server.getPluginManager().getPlugins() # Plugin[]
plugins = [raw_plugins[i].getDescription() for i in range(len(raw_plugins))]
plugins = [pl.getDescription() for pl in list(ArrayList(java_array_to_list(server.getPluginManager().getPlugins())))]
info(type(plugins[0]).__name__)
plugins.sort(key = lambda pl: pl.getDescription().getName())
msg(sender, "&3Listing all " + str(len(plugins)) + " plugins and their version:")
@@ -215,8 +198,7 @@ def eval_thread(sender, code):
pythoners = [
"e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes
"ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo
"305ccbd7-0589-403e-a45b-d791dcfdee7d", # PanFritz
"51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico
"305ccbd7-0589-403e-a45b-d791dcfdee7d" # PanFritz
]
@simplecommand("pyeval",
@@ -270,31 +252,6 @@ def on_modules_command(sender, command, label, args):
msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]]))
@simplecommand("warn",
usage = "",
description = "Warns everybody on the server that you will cause lag shortly",
amax = 0,
helpSubcmd = True)
def warn_command(sender, command, label, args):
if sender.hasPermission("utils.warn"):
broadcast(None, " &b= &2&lLag incoming! &r-%s" % sender.getDisplayName())
else:
noperm(sender)
@simplecommand("warnp",
usage = "",
description = "Warns everybody on the server that you might cause lag shortly",
amax = 0,
helpSubcmd = True)
def warnp_command(sender, command, label, args):
if sender.hasPermission("utils.warnp"):
broadcast(None, " &b= &2&lPossible lag incoming! &r-%s" % sender.getDisplayName())
else:
noperm(sender)
""" Something I'm planning for schematics
@hook.event("player.PlayerCommandPreprocessEvent", "low")
def on_command(event):

View File

@@ -1,37 +0,0 @@
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])

View File

@@ -1,29 +1,27 @@
from helpers import *
py_players = []
players = []
class py_player:
def __init__(self,player):
def __init__(player):
self.player = player
self.logging_in = False
self.login_time = 0
#Properties TODO
#Example:
self.logging_in = False
def get_py_player(player):
#py_player = py_players[py_players.index(player)]
for py_player in py_players:
if py_player.player.getName() == player.getName():
return py_player
py_player = players[players.index(player)]
return py_player
@hook.event("player.PlayerJoinEvent","lowest")
@hook.event("player.PlayerJoinEvent","highest")
def on_join(event):
player = py_player(event.getPlayer())
py_players.append(player)
print str(len(py_players))+event.getPlayer().getName()
players.append(player)
@hook.event("player.PlayerQuitEvent","highest")
def on_leave(event):
py_players.remove(get_py_player(event.getPlayer()))
players.remove(get_py_player(event.getPlayer()))

View File

@@ -2,3 +2,4 @@ name: RedstonerUtils
main: main.py
version: 3.1.0
author: redstone_sheep

View File

@@ -5,11 +5,7 @@ from java.util.UUID import fromString as juuid
toggle_dict = {}
permission = "utils.pmtoggle"
@hook.command("pmtoggle",
aliases = ["tm", "mt", "tmsg", "msgt", "pmt", "tpm"],
usage = "/<command> [player]",
description = "Toggle automatic sending of messages"
)
@hook.command("tm")
def on_toggle_message_command(sender, command, label, args):
if not sender.hasPermission(permission) or not is_player(sender):
noperm(sender)

View File

@@ -1,129 +0,0 @@
from helpers import *
from java.util.UUID import fromString as juuid
import org.bukkit.Material as Material
spawn_world = "Spawn"
punish_world = "Punishments"
slave_perm = "utils.minerslaves"
slaves = []
def save_slaves():
buf = []
for slave in slaves:
buf.append(slave.get_data())
save_json_file("miner_slaves", buf)
def load_slaves():
buf = open_json_file("miner_slaves", [])
for data in buf:
slave = Slave(True, None, None)
slave.load_data(data)
slaves.append(slave)
def get_slave(player):
for slave in slaves:
if slave.get_uuid() == player:
return slave
return None
class Slave(object):
def __init__(self, from_file, player, amount):
if from_file:
self.players = None
self.blocks = None
return
slave = get_slave(uid(player))
if slave != None:
slave.set_blocks(slave.get_blocks() + amount)
else:
self.player = uid(player)
self.blocks = amount
slaves.append(self)
def get_uuid(self):
return self.player
def get_blocks(self):
return self.blocks
def set_blocks(self, amount):
self.blocks = amount
def update(self):
self.blocks -= 1
if self.blocks <= 0:
server.getPlayer(juuid(self.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation())
slaves.remove(self)
save_slaves()
def get_data(self):
return {
"player": self.player,
"amount": self.blocks
}
def load_data(self, data):
self.player = str(data["player"])
self.blocks = int(data["amount"])
load_slaves()
@hook.event("block.BlockBreakEvent", "low")
def event(event):
if event.getPlayer().getWorld().getName() != punish_world:
return
slave = get_slave(uid(event.getPlayer()))
if slave != None and event.getBlock().getType() == Material.OBSIDIAN:
slave.update()
@hook.command("miner")
def command(sender, cmd, label, args):
if not sender.hasPermission(slave_perm):
noperm(sender)
return True
if len(args) == 0 or (len(args) != 1 and args[0] == "list") or (len(args) != 2 and args[0] == "rem") or (len(args) != 3 and args[0] == "add"):
msg(sender, "&e-&a /miner add/rem/list <name> <amount>")
return True
if args[0] == "add":
try:
int(args[2])
except:
msg(sender, "&cArgument <amount> is not a number")
return True
if args[0] == "list":
if len(slaves) == 0:
msg(sender, "&e-&a There are no people mining obsidian")
return True
for slave in slaves:
msg(sender, "&e-&a %s: %s blocks" % (server.getOfflinePlayer(juuid(slave.get_uuid())).getName(), slave.get_blocks()))
return True
elif args[0] == "add":
player = server.getOfflinePlayer(str(args[1]))
if player.isOnline():
player.teleport(server.getWorld(punish_world).getSpawnLocation())
Slave(False, player, int(args[2]))
save_slaves()
msg(player, "&e-&a You have been punished, mine %s blocks of obsidian to get out!" % args[2])
msg(sender, "&e-&a Player %s has been added into punishments for %s blocks of obsidian" % (player.getName(), args[2]))
else:
msg(sender, "&cYou can only punish online players")
return True
elif args[0] == "rem":
player = server.getOfflinePlayer(str(args[1]))
if player.isOnline():
slave = get_slave(uid(player))
if slave != None:
server.getPlayer(juuid(slave.get_uuid())).teleport(server.getWorld(spawn_world).getSpawnLocation())
slaves.remove(slave)
save_slaves()
else:
msg(sender, "&e-&a Player not in punishments")
else:
msg(sender, "&cYou can only remove online players")
return True
else:
msg(sender, "&e-&a /miner add/rem/list <name> <amount>")
return True

View File

@@ -149,7 +149,7 @@ arg 0 size of backup
@hook.command("script_backup_database_end")
def print_backup_db_end(sender, command, label, args):
if not is_player(sender):
broadcast(None, "&6 =&2 Database backup completed.")
broadcast(None, "&6 =&2 Databse backup completed.")
server.dispatchCommand(server.getConsoleSender(), "ac &abackup size: &2%sMB&a." % args[0])
else:
noperm(sender)

View File

@@ -1,115 +0,0 @@
from helpers import *
import socket
import threading
import time
from java.lang import Runnable
from adminchat import adminchat
"""
Module to allow our servercontrol telnet server forward chat and speak in AC
"""
host = ""
port = 1122
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
try:
sock.bind((host,port))
sock.setblocking(True)
sock.listen(5)
except socket.error as e:
print(str(e))
def command_process(text):
text = list(text)
args = []
arg = ""
for char in text:
if char != " " and char != "\n" and char != "\r" and char != "\t":
arg += char
elif arg != "":
args.append(arg)
arg = ""
if arg != "":
args.append(arg)
return args
clients = []
clients_l = threading.Lock()
class client():
def __init__(self,conn,address,name):
self.conn = conn
self.address = address
self.name = name
with clients_l:
clients.append(self)
self.conn.setblocking(False)
self.client_thread = threading.Thread(target=self.client_t)
self.client_thread.daemon = True
self.client_thread.start()
def getName(self):
return self.name
def close_connection(self):
try:
self.conn.close()
with clients_l:
clients.remove(self)
except:
pass
def client_t(self):
while True:
time.sleep(0.1)
try:
data = self.conn.recv(1024)
except:
if self not in clients:
self.close_connection()
continue
if self not in clients: #If the connection was closed, kill the thread
break
adminchat(self,data)
def handle_conn():
while True:
try:
conn, address = sock.accept()
except:
time.sleep(0.1)
continue
#Send name
data = conn.recv(1024)
data = command_process(data)
print "servercontrol connected! %s " %data[0]
client_c = client(conn, address,data[0])
handle_conn_t = threading.Thread(target=handle_conn)
handle_conn_t.daemon = True
handle_conn_t.start()
@hook.event("player.AsyncPlayerChatEvent","low")
def on_chat(event):
sender = event.getPlayer().getName()
msg = event.getMessage()
for entry in clients:
entry.conn.sendall(sender + " " + msg)

View File

@@ -1,297 +0,0 @@
from helpers import *
from basecommands import simplecommand, Validate
import org.bukkit.Material as Material
import java.util.UUID as UUID
import org.bukkit.Material as Material
import org.bukkit.block.BlockFace as BlockFace
blocked_cmds = tuple(shared["modules"]["misc"].sudo_blacklist) + ("pex", "kick", "ban", "tempban", "reload", "op", "deop", "whitelist")
def load_signs():
signs_obj = open_json_file("serversigns", [])
loaded = {}
for entry in signs_obj:
loaded[tuple(entry[:4])] = list(entry[4:])
return loaded
def save_signs():
signs_obj = []
for key, value in signs.iteritems():
signs_obj.append(key + tuple(value))
save_json_file("serversigns", signs_obj)
signs = load_signs() # {("world", x, y, z): ["owner_id", "msg1", "msg2"]}
lines = {} # Accumulated messages so players can have longer messages: {"Dico200": "Message...........", ""}
def fromLoc(bLoc):
"""
# Returns a tuple containing the (bukkit)location's world's name and its x, y and z coordinates
# The format for the tuple is ("world_name", x, y, z)
"""
return (bLoc.getWorld().getName(), bLoc.getBlockX(), bLoc.getBlockY(), bLoc.getBlockZ())
def equals(loc1, loc2):
"""
# Returns whether loc1 and loc2 represent the same block
"""
for i in range(4):
if loc1[i] != loc2[i]:
return False
return True
def getOwner(sign):
"""
# Returns the name of the sign its owner
"""
return retrieve_player(sign[0]).getName()
def isOwner(sign, player):
"""
# Returns whether the given player owns the sign
"""
return sign and sign[0] == uid(player)
def canEdit(sign, player):
"""
# Returns whether the given player can edit the sign.
# Returns False if the sign wasn't claimed.
"""
return (sign and player.hasPermission("utils.serversigns.admin")) or isOwner(sign, player)
def getSign(locAt):
"""
# If data was found for a sign at the given location, returns the data.
# This data follows the format of ["owner_id", "msg1", "msg2"...].
"""
for loc, sign in signs.iteritems():
if equals(locAt, loc):
return sign
return None
def identifySign(loc):
"""
# Returns a string from which the user can tell what sign you're talking about.
# The string follows the format of "sign at (x,y,z) in world_name".
"""
return "sign at (%s) in %s" % (",".join((str(i) for i in loc[1:])), loc[0])
def signsMsg(msg, colour = '4'):
"""
# Returns the given msg, prefixed with '[Signs] '.
# The given colour is after applied to the msg.
# The colour defaults to 4 (dark red).
"""
return "&c[Signs] &" + colour + msg
@simplecommand(cmd = "serversigns", aliases = ["svs", "signmsg"],
description = "Makes something happen when you right click signs. \nUse /svs help for more details.",
usage = "<claim|reset|add <msg>[++]|remove <ID>|clear|info|help>",
helpNoargs = True,
senderLimit = 0)
def svs_command(sender, command, label, args):
arg1 = args[0].lower()
Validate.isTrue(arg1 in ("claim", "reset", "add", "remove", "info", "clear", "help", "switch", "reverse", "unclaim"),
signsMsg("That argument could not be recognized, use &o/svs help &4for expected arguments"))
Validate.isAuthorized(sender, "utils.serversigns." + arg1)
#-------------------- Sub commands that don't require any conditions -----------------------
if arg1 == "help":
admin = sender.hasPermission("utils.serversigns.admin")
msg = signsMsg("Server signs lets you add messages to a sign.", 'a')
msg += "\nRight clicking the sign will display all the messages. Commands"
msg += "\ncan also be added, by prefixing the message with a '/'."
msg += "\nHow to use &b/serversigns&a:"
msg += "\n&b/svs claim" + ("" if not sender.hasPermission("utils.serversigns.admin") else " [owner]")
msg += "\n&a- Claims the sign so that you can add messages to it"
msg += "\n&b/svs info"
msg += "\n&a- Displays information about the (claimed) sign"
msg += "\n&b/svs add <message>[++]"
msg += "\n&a- Adds the message to the sign. Use ++ at the end"
msg += "\n&a- to add the message to your buffer. You can then use"
msg += "\n&a- the same command again to create a longer message."
msg += "\n&b/svs remove <message ID>"
msg += "\n&a- Removes the message with the given ID from the sign."
msg += "\n&a- The ID is given before each message by &b/svs info&a."
msg += "\n&b/svs switch|reverse <message ID 1> <message ID 2>"
msg += "\n&a- Reverses the order in which the given messages are shown."
msg += "\n&b/svs clear"
msg += "\n&a- Removes all messages from the sign."
msg += "\n&b/svs reset|unclaim"
msg += "\n&a- Resets the sign, removing all messages and its owner."
return msg
#-------------------------------------------------------------------------------------------
block = sender.getTargetBlock(None, 5)
Validate.isTrue(block.getType() in (Material.SIGN_POST, Material.WALL_SIGN), signsMsg("You have to be looking at a sign to use that!"))
loc = fromLoc(block.getLocation())
sign = getSign(loc)
signName = identifySign(loc)
arg2 = args[1].lower() if len(args) > 1 else None
#------------------------ Sub commands that require the block to be a sign -------------------------------
if arg1 == "claim":
Validate.isTrue(not sign, signsMsg("The %s was already claimed" % signName))
Validate.isTrue(can_build2(sender, block), signsMsg("You are not permitted to claim signs here"))
target = sender
if arg2:
Validate.isTrue(player.hasPermission("utils.serversigns.admin"), signsMsg("You are not authorized to claim signs for other players"))
target = server.getOfflinePlayer(arg2)
Validate.notNone(target, signsMsg("That player could not be found"))
Validate.isTrue(target.isOnline(), signsMsg("The target has to be online"))
uuid = uid(target)
if sign != None:
if sign[0] == uuid:
return signsMsg("The" + signName + " was already owned by that player")
else:
sign[0] = uuid
else:
signs[loc] = [uuid]
save_signs()
return signsMsg("Claimed the " + signName + ((" for %s" % target.getName()) if (target != sender) else ""), 'a')
#----------------------------------------------------------------------------------------------------------
Validate.notNone(sign, signsMsg("The %s has not been claimed" % signName))
#----------------------Sub commands that require the sign to be claimed as well------------------------------------
if arg1 == "info":
sign_lines = ""
for id, line in enumerate(sign[1:]):
sign_lines += ("\n &a%s: \"&f%s&a\"" % (id + 1, line))
return signsMsg("Properties of the %s:\n Owner: %s\n Lines: %s" % (signName, getOwner(sign), sign_lines), 'a')
#---------------------------------------------------------------------------------------------------------------
Validate.isTrue(canEdit(sign, sender), signsMsg("You do not own the %s!" % signName))
#---------------------- Sub commands that require you to own targeted sign as well -------------------------
if arg1 == "add":
line = " ".join(args[1:])
Validate.isTrue(line != "" and line != None, signsMsg("You have to enter a message to add or accumulate"))
key = sender.getName()
global lines
Validate.isTrue(key in lines or line[:1] != "/" or sender.hasPermission("utils.serversigns.command"), signsMsg("You cannot add commands to a sign!"))
if line[-2:] == "++":
if key not in lines:
lines[key] = ""
lines[key] += " " + line[:-2]
return signsMsg("Added given message to the message you're accumulating. \nYour accumulated message is now as follows: \n&f%s" % lines[key], 'a')
if key in lines:
line = (lines[key] + " " + line)[1:]
Validate.isTrue(line[0] != "/" or line.split(" ")[0][1:] not in blocked_cmds, signsMsg("Usage of that command with server signs is prohibited"))
sign.append(colorify(line) if line[0] != "/" else line)
save_signs()
return signsMsg("Added line \"&f%s&a\" to the %s" % (line, signName), 'a')
if arg1 == "remove":
Validate.notNone(arg2, signsMsg("You have to enter the ID of the message to remove!"))
try:
id = int(arg2)
except:
return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info")
Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id)))
del sign[id]
return signsMsg("Removed message with id %s from the %s" % (id, signName), 'a')
if arg1 in ("switch", "reverse"):
Validate.isTrue(len(args) == 3, signsMsg("You have to enter the 2 IDs of the messages to reverse"))
try:
id1 = int(args[1])
id2 = int(args[2])
except:
return signsMsg("The ID of the message has to be a number and can be found by using &o/svs info")
for id in (id1, id2):
Validate.isTrue(id != 0 and id < len(sign), signsMsg("The %s has no message with an ID of %s, use &o/svs info &4for all messages." % (signName, id)))
sign[id1], sign[id2] = sign[id2], sign[id1]
save_signs()
return signsMsg("Reversed the messages with IDs %s and %s of the %s" % (id1, id2, signName), 'a')
if arg1 == "clear":
signs[loc] = [sign[0]]
save_signs()
return signsMsg("Removed all messages from the %s" % signName, 'a')
if arg1 in ("reset", "unclaim"):
del signs[loc]
save_signs()
return signsMsg("Removed all messages and the owner from the %s, it can now be claimed" % signName, 'a')
#-------------------------------------------------------------------------------------------------------
@hook.event("player.PlayerInteractEvent")
def on_click(event):
if str(event.getAction()) != "RIGHT_CLICK_BLOCK":
return
block = event.getClickedBlock()
if block.getType() not in (Material.WALL_SIGN, Material.SIGN_POST):
return
sign = getSign(fromLoc(block.getLocation()))
if sign != None:
player = event.getPlayer()
for message in sign[1:]:
if message[:1] == "/":
server.dispatchCommand(player, message[1:])
else:
msg(player, message, usecolor = False)
# ---------------------------Sign breaking--------------------------------
checking_block = False
faces = {
BlockFace.NORTH : (0,1,2,),
BlockFace.SOUTH : (3,),
BlockFace.WEST : (4,),
BlockFace.EAST : (5,),
}
@hook.event("block.BlockBreakEvent", "monitor")
def on_break(event):
try:
global checking_block
if checking_block or event.isCancelled():
return
block = event.getBlock()
if block.getType() in (Material.SIGN_POST, Material.WALL_SIGN):
check_sign(event, block, attached = False)
for block_face, data_values in faces.iteritems():
block2 = block.getRelative(block_face)
if block2.getType() == Material.WALL_SIGN and block2.getData() in data_values:
check_sign(event, block2)
block3 = block.getRelative(BlockFace.UP)
if block3.getType() == Material.SIGN_POST:
check_sign(event, block3)
except:
error(trace())
def check_sign(event, block, attached = True):
player = event.getPlayer()
sign = getSign(fromLoc(block.getLocation()))
if not can_build2(player, block):
event.setCancelled(True)
msg(event.getPlayer(), signsMsg("You cannot break %s" % ("the sign attached to that block" if attached else "that sign")))
else:
loc = fromLoc(block.getLocation())
del signs[loc]
save_signs()
msg(player, signsMsg("Reset the %s which you just broke" % identifySign(loc)))
def can_build2(player, block):
global checking_block
event = BlockBreakEvent(block, player)
checking_block = True
server.getPluginManager().callEvent(event)
checking_block = False
return not event.isCancelled()

View File

@@ -4,7 +4,7 @@
set -e
for cmd in curl java unzip git pip; do
if ! which "$cmd" >/dev/null; then
if ! which -s "$cmd"; then
tput setf 4 >&2
echo "Error: please install '$cmd' to proceed" >&2
tput sgr0 >&2
@@ -25,7 +25,7 @@ mkdir -v "build"
cd "build"
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 ..."
java -jar BuildTools.jar > /dev/null
@@ -91,7 +91,7 @@ echo -e "\n> All plugins downloaded"
cd "redstoner-utils.py.dir"
echo -e "\n> Duplicating sample files"
for file in ./*.example; do
for file in ls ./*.example; do
cp -v "$file" "$(echo "$file" | rev | cut -d "." -f 2- | rev)"
done
@@ -172,4 +172,4 @@ echo "eula=true" > eula.txt
echo -e "\n> $(tput setf 2)All Done! $(tput sgr0)Don't forget to configure plugins for your needs."
echo "> Run redstoner/server/start.sh to start the server"
echo "> Our plugins are in redstoner/server/plugins/redstoner-utils.py.dir"
echo "> Our plugins are in redstoner/server/plugins/redstoner-utils.py.dir"

View File

@@ -1,159 +0,0 @@
from helpers import *
import org.bukkit.inventory.ItemStack as ItemStack
import org.bukkit.Material as Material
from math import ceil
from basecommands import simplecommand, Validate, CommandException
""" Suggestion by Armadillo28, see thread: http://redstoner.com/forums/threads/2213?page=1#reply-14507 """
disallowed_item_types = (
Material.getMaterial(0),
Material.getMaterial(175),
Material.getMaterial(383),
)
default_args = open_json_file("signalstrengthdefaults", {})
def save_defaults():
save_json_file("signalstrengthdefaults", default_args)
def item_name(item_type, remove_underscores = True):
typ = str(item_type).lower()
return typ.replace("_", "") if remove_underscores else typ
def item_type_allowed(item_type):
return not item_type in disallowed_item_types
def required_item_count(strength, stack_size, slot_count):
if strength == 0:
item_count = 0
elif strength == 1:
item_count = 1
else:
item_count = int(ceil(slot_count * stack_size / 14.0 * (strength - 1)))
resulting_strength = 0 if item_count == 0 else int(1 + 14.0 * item_count / stack_size / slot_count)
#Clarification on these formulas at http://minecraft.gamepedia.com/Redstone_Comparator#Containers
return item_count if resulting_strength == strength else None
def get_data(player, args):
uuid = uid(player)
if uuid in default_args:
strength, item_type, item_data = default_args[uuid]
item_type = Material.getMaterial(item_type)
else:
strength = 1
item_type = Material.REDSTONE
item_data = 0
if len(args) > 0:
Validate.isTrue(args[0].isdigit() and 0 <= int(args[0]) <= 15, "&cThe signal strength has to be a value from 0 to 15")
strength = int(args[0])
if len(args) > 1:
if args[1].isdigit():
item_type = Material.getMaterial(int(args[1]))
else:
item_type = Material.matchMaterial(args[1])
Validate.notNone(item_type, "&cThat item type could not be found")
Validate.isTrue(item_type not in disallowed_item_types, "&cThat item type may not be used")
if len(args) > 2:
Validate.isTrue(args[2].isdigit() and 0 <= int(args[2]) <= 15, "&cThe data has to be a value from 0 to 15")
item_data = int(args[2])
return (strength, item_type, item_data)
def get_inventory(block):
try:
return block.getState().getInventory()
except AttributeError:
return None
def get_entire_container(container):
container_blocks = [container]
container_type = container.getType()
if container_type in (Material.CHEST, Material.TRAPPED_CHEST):
loc = container.getLocation()
x = loc.getBlockX()
y = loc.getBlockY()
z = loc.getBlockZ()
world = loc.getWorld()
container_blocks += [
block for block in (
world.getBlockAt(x + 1, y, z),
world.getBlockAt(x - 1, y, z),
world.getBlockAt(x, y, z + 1),
world.getBlockAt(x, y, z - 1),
) if block.getType() == container_type
]
return container_blocks
@simplecommand("signalstrength",
usage = "(default) [signalstrength] [item] [data]",
aliases = ["ss", "level"],
description = "Fills the targeted container with the correct amount of items to achieve the desired signal strength.",
amin = 0,
amax = 4,
helpSubcmd = True,
senderLimit = 0)
def on_signalstrength_command(sender, command, label, args):
if len(args) > 0 and args[0].lower() in ("default", "defaults", "setdefaults"):
strength, item_type, item_data = get_data(sender, args[1:])
uuid = uid(sender)
if strength == 1 and item_type == Material.REDSTONE and item_data == 0:
if uuid in default_args:
del default_args[uuid]
save_defaults()
else:
default_args[uuid] = (strength, str(item_type), item_data)
save_defaults()
return "&aSet your signal strength defaults to (%s, %s, %s)" % (strength, item_name(item_type, False), item_data)
Validate.isTrue(len(args) <= 3, "&cExpected at most 3 arguments")
target_block = sender.getTargetBlock(None, 5)
Validate.notNone(target_block, "&cThat command can only be used when a container is targeted")
inventory = get_inventory(target_block)
Validate.notNone(inventory, "&cThat command can only be used if a container is targeted")
strength, item_type, item_data = get_data(sender, args)
#--------Get the stack size and required amount of items to achieve the desired signal strength---------
stack_size = item_type.getMaxStackSize()
slot_count = inventory.getSize()
item_count = required_item_count(strength, stack_size, slot_count)
Validate.notNone(item_count, "&cThe desired signal strength could not be achieved with the requested item type")
#--------Add the other side of the chest if target is a double chest and check if player can build---------
container_blocks = get_entire_container(target_block)
for block in container_blocks:
Validate.isTrue(can_build(sender, block), "&cYou do not have permission to do that here")
#----------------Insert items-------------
full_stack_count, remaining = divmod(item_count, stack_size)
for block in container_blocks:
inv = block.getState().getInventory()
inv.clear()
for i in range(full_stack_count):
inv.setItem(i, ItemStack(item_type, stack_size, item_data))
if remaining > 0:
inv.setItem(full_stack_count, ItemStack(item_type, remaining, item_data))
return "&aComparators attached to that %s will now put out a signal strength of %s" % (item_name(target_block.getType()), strength)

View File

@@ -3,14 +3,6 @@ from secrets import *
import mysqlhack
from com.ziclix.python.sql import zxJDBC
"""
WORK IN PROGRESS
"""
#-----------------------Config--------------------------
config_file = "website-roles"
ranks = {
"member" : 3,
"builder" : 7,
@@ -21,42 +13,33 @@ ranks = {
"admin" : 5
}
ranks = open_json_file(config_file, ranks)
def save_ranks():
save_json_file(config_file, ranks)
#-----------------------Event---------------------------
@hook.event("player.PlayerJoinEvent", "normal")
def on_player_join(event):
user = event.getPlayer()
uuid = uid(player).replace("-", "")
role = get_role(uuid)
if role in [1, 2, 6]: #Disabled/Banned/Superadmin
return
if role:
for rank in ranks:
if user.hasPermission("group." + rank):
if role != ranks[rank]:
set_role(uuid, ranks[rank])
return
if not user.hasPlayedBefore():
return
if role == None:
msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com")
sql_instruction
def callback_thing(role, args):
if role in [1, 2, 6]: #Disabled/Banned/Superadmin
return
if role != None:
for rank in ranks:
if user.hasPermission("group." + rank):
if role != ranks[rank]:
set_role(uuid, ranks[rank])
elif user.hasPlayedBefore():
msg(user, "&cYou haven't registed yet! Make sure to do so on redstoner.com")
def get_role(uuid):
results = execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1;", uuid)
return results[0][0]
# Returns a table with 1 row (LIMIT 1) and 1 column (SELECT `role_id`), so we're looking for the first row of the first column.
return execute_query("SELECT `role_id` FROM users WHERE `uuid` = ? LIMIT 1", uuid)[0][17]
def set_role(uuid, role_id):
execute_update("UPDATE users SET `role_id` = ? WHERE `uuid` = ?;", (role_id, uuid,))
# %d is like %s for integers (unlogically, you'd expect something like %i), though %s also works here.
execute_update("UPDATE users SET `role_id` = %d WHERE `uuid` = ?" % role_id, uuid)
def execute_query(query, uuid):
@@ -73,40 +56,5 @@ def execute_update(update, uuid):
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.cursor()
curs.execute(update, (uuid,))
conn.commit()
curs.close()
conn.close()
def get_role(uuid):
sql_instruction()
#--------------------------------Queries / Updates----------------------------
def sql_instruction(instruction, args, fetch = True, callback_func = ignored_func, callback_args = tuple()):
thread = threading.Thread(target = curs_instruction, args = (instruction_executor, instruction, fetch, callback_func, callback_args))
thread.start()
def curs_instruction(func, instruction, fetch, callback_func, callback_args):
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
curs = conn.getCursor()
if fetch:
returned = func(curs, instruction, fetch)
curs.close()
conn.close()
callback_func(returned, callback_args)
else:
func(curs, instruction, fetch)
conn.commit()
curs.close()
conn.close()
def instruction_executor(curs, instruction, fetch):
curs.execute(instruction)
return curs.fetchall() if fetch else None
def ignored_func(*args):
pass
conn.close()

78
tag.py
View File

@@ -1,78 +0,0 @@
from helpers import *
add_perm = "utils.tag.add"
del_perm = "utils.tag.del"
check_perm = "utils.tag.check"
data = open_json_file("tag", {})
@hook.command("tag")
def command(sender, command, label, args):
if len(args) > 0:
if str(args[0]) == "add":
if sender.hasPermission(add_perm):
if len(args) > 2:
add(sender, args[1:])
else:
msg(sender, "&a-&c Usage: /tag add <name> <reason>")
else:
noperm(sender)
elif str(args[0]) == "check":
if sender.hasPermission(check_perm):
if len(args) == 2:
check(sender, args[1:])
else:
msg(sender, "&a-&c Usage: /tag check <name>")
else:
noperm(sender)
elif str(args[0]) == "del":
if sender.hasPermission(del_perm):
if len(args) == 3:
delete(sender, args[1:])
else:
msg(sender, "&a-&c Usage: /tag del <id>")
else:
msg(sender, "&a-&c Unknown subcommand! (add, check, del)")
else:
msg(sender, "&a&c Usage: /tag add/check/del")
return True
def delete(sender, args):
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
if data[uuid] == None:
pass
except:
msg(sender, "&a-&e There are no notes about this player")
return
if int(args[1]) - 1 >= len(data[uuid]):
msg(sender, "&a-&c Id of note is out of range")
return
del (data[uuid])[int(args[1]) - 1]
save_json_file("tag", data)
msg(sender, "&a-&e Deleted note at %s" % args[1])
def add(sender, args):
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
if data[uuid] == None:
pass
except:
data[uuid] = []
data[uuid].append(" ".join(args[1:]))
msg(sender, "&a-&e Note added")
save_json_file("tag", data)
def check(sender, args):
player = server.getOfflinePlayer(args[0])
uuid = uid(player)
try:
num = 0
for tag in data[uuid]:
num += 1
msg(sender, "&a-&e %s: %s" % (str(num), str(tag)))
except:
msg(sender, "&a-&e There are no notes about this player")

121
vanish.py
View File

@@ -1,121 +0,0 @@
from helpers import *
from basecommands import simplecommand
from basecommands import Validate
vanished = []
def is_authorized(player):
return player.hasPermission("utils.vanish")
def is_vanished(player):
return uid(player) in vanished
#this can be used to silently set the vanished state of a player
def set_state(player, state):
if state == is_vanished(player):
return
if state:
enable_vanish(player)
else:
disable_vanish(player)
def enable_vanish(target):
vanished.append(uid(target))
for player in list(server.getOnlinePlayers()):
if not is_authorized(player):
player.hidePlayer(target)
def disable_vanish(target):
vanished.remove(uid(target))
for player in list(server.getOnlinePlayers()):
player.showPlayer(target)
@simplecommand("vanish",
aliases = ["v"],
usage = "[on/off]",
description = "Toggles vanish mode, hiding you and your online status \nfrom other players.",
senderLimit = 0,
amin = 0,
amax = 1,
helpNoargs = False,
helpSubcmd = True
)
def vanish_command(sender, command, label, args):
try:
current_state = is_vanished(sender)
new_state = not current_state
if len(args) == 1:
arg = args[0].lower()
if arg == "on":
new_state = True
elif arg == "off":
new_state = False
if current_state == new_state:
return "&cYou were %s vanished!" % ("already" if current_state else "not yet")
set_state(sender, new_state)
return "&a%s vanish mode!" % ("Enabled" if new_state else "Disabled")
except:
error(trace())
@hook.event("player.PlayerJoinEvent")
def on_player_join(event):
player = event.getPlayer()
if not is_authorized(player):
for uuid in vanished:
player.hidePlayer(retrieve_player(uuid))
elif is_vanished(player):
msg(player, "&cKeep in mind that you are still vanished! Use /vanish to disable.")
@hook.event("player.PlayerQuitEvent")
def on_player_quit(event):
player = event.getPlayer()
if not is_authorized(player):
for uuid in vanished:
player.showPlayer(retrieve_player(uuid))
@simplecommand("vanishother",
usage = "{player} [on/off]",
description = "Toggles vanish mode for someone, hiding them and their online status from other players.",
amin = 1,
amax = 2,
helpNoargs = True,
helpSubcmd = True)
def vanishother_command(sender, command, label, args):
target = server.getPlayer(args[0])
Validate.notNone(target, "&cThe specified player is not online")
current_state = is_vanished(target)
new_state = not current_state
if len(args) == 2:
arg = args[1].lower()
if arg == "on":
new_state = True
elif arg == "off":
new_state = False
if current_state == new_state:
return "&cThat player was already vanished!" if current_state else "&cThat player was not yet vanished!"
set_state(target, new_state)
enabled_str = "enabled" if new_state else "disabled"
if target != sender:
msg(target, "&aVanish mode %s by %s" % (enabled_str, sender.getDisplayName() if is_player(sender) else "&9CONSOLE"))
return "&aVanish mode %s%s" % (enabled_str, " for " + target.getDisplayName() if target != sender else "")

View File

@@ -1,14 +0,0 @@
from helpers import *
from java.lang import Runnable
class run(Runnable):
def run(self):
players = server.getOnlinePlayers()
for player in players:
if player.hasPermission("essentials.vanish"):
player.performCommand("vanish")
player.performCommand("vanish")
def enabled():
server.getScheduler().runTaskTimer(server.getPluginManager().getPlugin("RedstonerUtils"), run(), 20, 1200)