Untested change to add pyeval possibility to args
so you do like, for example:
/pex user EVAL:server.getOfflinePlayer("Dico200").getUniqueId()
this could also be used in chat. I know its pretty useless but useful in
some cases.
This commit is contained in:
39
misc.py
39
misc.py
@@ -157,6 +157,27 @@ def eval_thread(sender, code):
|
|||||||
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
||||||
thread.exit()
|
thread.exit()
|
||||||
|
|
||||||
|
def eval_argument_thread(event):
|
||||||
|
words = event.getMessage()[5:].split(" ")
|
||||||
|
for i in range(len(words)):
|
||||||
|
word = words[i]
|
||||||
|
if is_pyeval_call(word):
|
||||||
|
code = word[5:]
|
||||||
|
try:
|
||||||
|
result = unicode(eval(code))
|
||||||
|
except:
|
||||||
|
e = exc_info()[1]
|
||||||
|
try:
|
||||||
|
eclass = e.__class__
|
||||||
|
except AttributeError:
|
||||||
|
eclass = type(e)
|
||||||
|
msg(event.getPlayer(), ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c")
|
||||||
|
result = code
|
||||||
|
words[i] = result
|
||||||
|
event.setMessage(" ".join(words))
|
||||||
|
thread.exit()
|
||||||
|
|
||||||
|
|
||||||
@simplecommand("pyeval",
|
@simplecommand("pyeval",
|
||||||
usage = "[code..]",
|
usage = "[code..]",
|
||||||
description = "Runs python [code..] and returns the result",
|
description = "Runs python [code..] and returns the result",
|
||||||
@@ -185,4 +206,20 @@ def on_player_teleport(event):
|
|||||||
player = event.getPlayer()
|
player = event.getPlayer()
|
||||||
if not event.isCancelled() and str(event.getCause()) == "SPECTATE" and not player.hasPermission("utils.tp.spectate"):
|
if not event.isCancelled() and str(event.getCause()) == "SPECTATE" and not player.hasPermission("utils.tp.spectate"):
|
||||||
event.setCancelled(True)
|
event.setCancelled(True)
|
||||||
msg(event.getPlayer(), "&cSpectator teleportation is disabled")
|
msg(event.getPlayer(), "&cSpectator teleportation is disabled")
|
||||||
|
|
||||||
|
|
||||||
|
@hook.event("player.AsyncPlayerChatEvent", "lowest")
|
||||||
|
def on_chat(event):
|
||||||
|
user = event.getPlayer()
|
||||||
|
if user.hasPermission("utils.pyeval"):
|
||||||
|
thread.start_new_thread(event)
|
||||||
|
|
||||||
|
@hook.event("player.PlayerCommandPreprocessEvent", "lowest")
|
||||||
|
def on_cmd(event):
|
||||||
|
user = event.getPlayer()
|
||||||
|
if user.hasPermission("utils.pyeval"):
|
||||||
|
thread.start_new_thread(event)
|
||||||
|
|
||||||
|
def is_pyeval_call(string):
|
||||||
|
return len(string) > 5 and string[:5] == "EVAL:"
|
||||||
|
|||||||
Reference in New Issue
Block a user