Prevent /up griefing, add /ackey, minor tweaks

Dunno why its posting 'changes' in main.py tho
This commit is contained in:
Dico200
2015-06-03 01:09:07 +02:00
parent 794f0470bf
commit 3cbb8dc9bd
6 changed files with 178 additions and 162 deletions

View File

@@ -1,8 +1,12 @@
#pylint: disable = F0401
from helpers import *
from basecommands import simplecommand
ac_permission = "utils.ac"
ac_key = ","
ac_defaultkey = ","
ac_keys = open_json_file("adminchat_keys", {})
ac_toggle_list = []
ac_prefix = "&8[&cAC&8]"
@@ -13,6 +17,7 @@ def adminchat(sender, msg):
except AttributeError:
name = sender.getName()
broadcast(ac_permission, "%s &9%s&8: &b%s" % (ac_prefix, name, msg))
# Needs something here like fine(message) to show up in the logs when you use ackey, but fine doesnt work for some reason. It did on the server with /pyeval (not show up on console, but show up in logs nevertheless)
# ac toggle
@@ -41,16 +46,41 @@ def on_ac_command(sender, args):
noperm(sender)
return True
def get_key(uuid):
key = ac_keys.get(uuid)
return key if key != None else ac_defaultkey
@simplecommand("adminchatkey",
aliases = ["ackey"],
senderLimit = 0,
helpNoargs = True,
helpSubcmd = True,
description = "Sets a key character for adminchat",
usage = "<key>")
def adminchatkey_command(sender, command, label, args):
key = " ".join(args)
uuid = uid(sender)
if key.lower() == "default" or key == ac_defaultkey:
del ac_keys[uuid]
save_keys()
return "&aYour adminchat key was set to the default character: '&c%s&a'" % ac_defaultkey
ac_keys[uid(sender)] = key
save_keys()
return "&aYour adminchat key was set to: '&c%s&a'" % key
def save_keys():
save_json_file("adminchat_keys", ac_keys)
@hook.event("player.AsyncPlayerChatEvent", "low")
def on_chat(event):
sender = event.getPlayer()
msg = event.getMessage()
if sender.hasPermission(ac_permission) and not event.isCancelled():
if msg[:len(ac_key)] == ac_key:
#This solution to log any AC isn't very optimised as it will check for permission twice. Any fix for this?
runas(sender, "ac " + msg[1:])
key = get_key(uid(sender))
if sender.getName() in ac_toggle_list:
adminchat(sender, msg)
event.setCancelled(True)
elif sender.getName() in ac_toggle_list:
runas(sender, "ac " + msg)
if msg[:len(key)] == key:
adminchat(sender, msg[len(key):])
event.setCancelled(True)

View File

@@ -95,7 +95,6 @@ def getSettingDetails(arg):
helpSubcmd = True,
amax = 2)
def toggle_command(sender, command, label, args):
try:
setting, details = getSettingDetails(args[0])
Validate.isAuthorized(sender, "utils.toggle." + setting, "that setting")
@@ -108,7 +107,6 @@ def toggle_command(sender, command, label, args):
default = details[0] == 0 # If True: toggle on if list doesn't contain the uuid
enabled = (uuid not in values) == default #Invert if details[0] == 2 (toggle disabled by default)
info("Enabled: " + str(enabled))
new = None
if arglen == 1:
new = not enabled
@@ -119,11 +117,9 @@ def toggle_command(sender, command, label, args):
elif arg2 in ("toggle", "switch"):
new = not enabled
elif arg2 in ("on", "enable"):
new = True == default
info("New: " + str(new))
new = not default
elif arg2 in ("off", "disable"):
new = False == default
info("New: " + str(new))
new = default
else:
return " &cArgument '%s' was not recognized. \n Use &o/toggle %s info &cfor more information" % (arg2, setting)
if enabled == new:
@@ -160,7 +156,7 @@ def toggle_command(sender, command, label, args):
del items[slot]
saveSettings()
if len(items) == 0:
del values[uuid]
del items
return " &aDisabled " + details[1]
return " &aCleared slot %s of setting %s" % (slot, setting)
return " &cSlot %s of setting %s was already cleared!" % (slot, setting)
@@ -176,42 +172,6 @@ def toggle_command(sender, command, label, args):
return ((" &aEnabled setting %s, S" % setting) if len(values[uuid]) == 1 else " &aS") + "et itemstack in slot %s to item in hand" % (slot)
return None #This shouldn't happen
except CommandException, e:
raise e
except:
error(trace())
"""
if info[0] in (0,2): # Toggle
default = info[0] == 0
enabled = (uuid not in values) == default #Invert if info[0] == 2 (toggle disabled by default)
info("Enabled": True)
new = None
if arglen == 1:
new = not enabled
else:
arg2 = args[1].lower()
if arg2 == "info":
return " &aSetting %s:\n &9%s\n &6Accepted arguments: [on|enable|off|disable|toggle|switch]\n &6Aliases: %s" % (setting, info[2], ", ".join(info[3]))
elif arg2 in ("toggle", "switch"):
new = not enabled
elif arg2 in ("on", "enable"):
new = True == default
elif arg2 in ("off", "disable"):
new = False == default
else:
return " &cArgument '%s' was not recognized. \nUse &o/toggle %s info &cfor more information" % (arg2, setting)
if enabled == new:
return " &cAlready %s: &a%s" % ("enabled" if enabled else "disabled", info[1])
if new:
values.remove(uuid)
else:
values.append(uuid)
saveSettings()
return (" &aEnabled " if new else " &aDisabled ") + info[1]
"""
def fromStack(itemStack):
@@ -226,7 +186,6 @@ def isEnabled(toggleSetting, uuid):
@hook.event("block.BlockPlaceEvent", "monitor")
def on_block_place(event):
try:
if event.isCancelled():
return
player = event.getPlayer()
@@ -275,13 +234,11 @@ def on_block_place(event):
"""
if (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE) #Not elif because for droppers it can do 2 things
if (material in (Material.PISTON_BASE, Material.PISTON_STICKY_BASE)
and isEnabled("piston", uuid)
and player.hasPermission("utils.toggle.piston")
):
block.setData(faces[block.getFace(event.getBlockAgainst())])
except:
error(trace())
@hook.event("player.PlayerInteractEvent", "monitor")

View File

@@ -39,6 +39,13 @@ def error(text):
"""
server.getLogger().severe("[RedstonerUtils] %s" % text)
def fine(text):
"""
Log anything to the logs alone, not the console
"""
server.getLogger().fine(text)
def msg(player, text, usecolor = True, basecolor = None):
"""
send a message to player
@@ -217,5 +224,3 @@ def toggle(player, ls, name = "Toggle", add = None):
elif add != False:
ls.append(pid)
msg(player, "&a%s turned on!" % name)

View File

@@ -1,4 +1,3 @@
import thread
from helpers import *
from adminchat import *

25
misc.py
View File

@@ -37,11 +37,20 @@ def on_join(event):
player.teleport(player.getWorld().getSpawnLocation())
# Prevent /up griefing. //up is blocked by PlotMe.
@hook.event("player.PlayerCommandPreprocessEvent", "low")
def on_command(event):
if event.getMessage()[:4].lower() == "/up ":
event.setMessage("/" + event.getMessage())
""" Disabled while builder can't access Trusted
@hook.event("player.PlayerGameModeChangeEvent", "low")
def on_gamemode(event):
user = event.getPlayer()
if str(event.getNewGameMode()) != "SPECTATOR" and user.getWorld().getName() == "Trusted" and not user.hasPermission("mv.bypass.gamemode.Trusted"):
event.setCancelled(True)
"""
@hook.event("player.PlayerBedEnterEvent")
@@ -208,3 +217,19 @@ def on_modules_command(sender, command, label, args):
plugin_header(sender, "Modules")
msg(sender, ", ".join([(("&a" if mod in shared["modules"] else "&c") + mod) for mod in shared["load_modules"]]))
""" Something I'm planning for schematics
@hook.event("player.PlayerCommandPreprocessEvent", "low")
def on_command(event):
msg = " ".split(event.getMessage())
if len(msg) < 3:
return
if msg[0].lower() not in ("/schematic", "/schem"):
return
if msg[1].lower() not in ("save", "load"):
return
msg[2] = event.getPlayer().getName() + "/" + msg[2]
"""