diff --git a/adminchat.py b/adminchat.py index 3b07f18..b5c9d55 100644 --- a/adminchat.py +++ b/adminchat.py @@ -50,12 +50,12 @@ 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", +@simplecommand("adminchatkey", + aliases = ["ackey"], + senderLimit = 0, + helpNoargs = True, + helpSubcmd = True, + description = "Sets a key character for adminchat", usage = "") def adminchatkey_command(sender, command, label, args): key = " ".join(args) diff --git a/adminnotes.py b/adminnotes.py index 9c6d16f..f486c7e 100644 --- a/adminnotes.py +++ b/adminnotes.py @@ -92,7 +92,7 @@ def adminnotes_command(sender, command, label, args): show_an_help(sender) return if not args[1].isdigit(): - msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)") + msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)") return note_id = int(args[1])-1 if note_id >= len(notes): diff --git a/basecommands.py b/basecommands.py index d2cb3ab..89e08aa 100644 --- a/basecommands.py +++ b/basecommands.py @@ -20,13 +20,13 @@ def helpMsg(sender, cmd, description, usage, aliases, permission): def simplecommand(cmd, - aliases = [], - usage = "[args...]", + aliases = [], + usage = "[args...]", description = None, - senderLimit = -1, - amin = 0, - amax = -1, - helpNoargs = False, + senderLimit = -1, + amin = 0, + amax = -1, + helpNoargs = False, helpSubcmd = False): cmd = cmd.lower() permission = "utils." + cmd @@ -107,4 +107,4 @@ class Validate(): if not checkargs(sender, args, amin, amax): raise CommandException("") - + diff --git a/blockplacemods.py b/blockplacemods.py index 6885f84..246f9eb 100644 --- a/blockplacemods.py +++ b/blockplacemods.py @@ -50,7 +50,7 @@ settingInformation = dict( #[setting type, identifying description, detailed des ) defaults = { - 0: list, + 0: list, 1: dict, 2: list } @@ -87,8 +87,8 @@ def getSettingDetails(arg): raise CommandException(" &cThat setting could not be found.\n For command help, use &o/toggle &cor &o/set") @simplecommand("toggle", - aliases = ["setting", "set", "config"], - usage = " [value|info]", + aliases = ["setting", "set", "config"], + usage = " [value|info]", description = "Toggles or sets your preferences for our redstone \nutilities. The following settings are available:\n" + ", ".join([x for x in settingInformation]), senderLimit = 0, helpNoargs = True, @@ -144,13 +144,13 @@ def toggle_command(sender, command, label, args): if arg2 == "details": return " &aSetting %s:\n &9%s \n&6Accepted arguments: [|clear|details]" % (setting, details[2]) - slot = int(arg2) if arg2.isdigit() else 0 + slot = int(arg2) if arg2.isdigit() else 0 if not (0 <= slot <= details[4]): return " &cSlot number must be more than or equal to 0 and less than or equal to %s!" % details[4] item = fromStack(player.getItemInHand()) if item[0] == 0 or item[1] <= 0: - if enabled: + if enabled: items = values[uuid] if slot in items: del items[slot] @@ -197,16 +197,16 @@ def on_block_place(event): material = block.getType() - if (material in (Material.WOOD_STEP, Material.STEP) - and isEnabled("slab", uuid) - and player.hasPermission("utils.toggle.slab") + if (material in (Material.WOOD_STEP, Material.STEP) + and isEnabled("slab", uuid) + and player.hasPermission("utils.toggle.slab") and block.getData() < 8 ): block.setData(block.getData() + 8) # Flip upside down - elif (material == Material.CAULDRON - and isEnabled("cauldron", uuid) + elif (material == Material.CAULDRON + and isEnabled("cauldron", uuid) and player.hasPermission("utils.toggle.cauldron") ): block.setData(3) #3 layers of water, 3 signal strength @@ -214,7 +214,7 @@ def on_block_place(event): elif ((material == Material.FURNACE and player.hasPermission("utils.toggle.furnace")) or (material == Material.DROPPER and player.hasPermission("utils.toggle.dropper")) - or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper")) + or (material == Material.HOPPER and player.hasPermission("utils.toggle.hopper")) ): stacks = get(str(material).lower()).get(uuid) if stacks != None: # Enabled @@ -227,7 +227,7 @@ def on_block_place(event): """ elif (material == Material.REDSTONE_TORCH_ON and event.getBlockAgainst().getType() == Material.REDSTONE_BLOCK - and isEnabled("torch", uuid) + and isEnabled("torch", uuid) and player.hasPermission("utils.toggle.torch") ): torches_to_break.append(block) @@ -244,8 +244,8 @@ def on_block_place(event): @hook.event("player.PlayerInteractEvent", "monitor") def on_interact(event): player = event.getPlayer() - if (isEnabled("cauldron", uid(player)) - and player.hasPermission("utils.toggle.cauldron") + if (isEnabled("cauldron", uid(player)) + and player.hasPermission("utils.toggle.cauldron") and is_creative(player) and event.getAction() == Action.RIGHT_CLICK_BLOCK and (not event.hasItem() or event.getItem().getType() == Material.REDSTONE) @@ -269,7 +269,7 @@ def stop_breaking_torches(): class torch_breaker(Runnable): def run(): - + try: if break_torches: for i in range(len(torches_to_break)): diff --git a/calc.py b/calc.py index 7c752e7..8ac48f0 100644 --- a/calc.py +++ b/calc.py @@ -1,29 +1,67 @@ from helpers import * +import threading +import time calc_users = open_json_file("calc", []) -math_operators = ["+", "-", "*", "/", "&", "|"] -ignore_operators = ["**", "&&", "||"] # ** may be too intensive, the others cause syntax errors +math_operators = ["+", "-", "*", "/", "%", ">", "<", "^", "&", "|"] +allowed_strings = ["0b", "0x", "(", ")", "hex(", "bin(", "abs(", "int(", "min(", "max(", "round(", "float("] +allowed_alpha = ["a", "b", "c", "d", "e", "f"] calc_perm = "utils.calc" +calc_perm_power = "utils.calc.power" - -def calc(text): +def calc(sender, text): """ extracts a mathematical expression from `text` returns (expression, result) or None """ expression = "" should_calc = False - for char in text: - if char.isdigit() or (expression and char == ".") or (should_calc and char == " "): + i = 0 + while True: + if i >= len(text): + break + char = text[i] + if i < len(text) - 5 and str(char + text[i+1] + text[i+2] + text[i+3] + text[i+4] + text[i+5]) in allowed_strings: expression += char - elif char in math_operators: + expression += text[i + 1] + expression += text[i + 2] + expression += text[i + 3] + expression += text[i + 4] + expression += text[i + 5] + i += 5 + should_calc = True + elif i < len(text) - 3 and str(char + text[i+1] + text[i+2] + text[i+3]) in allowed_strings: + expression += char + expression += text[i + 1] + expression += text[i + 2] + expression += text[i + 3] + i += 3 + should_calc = True + elif i < len(text) - 1 and str(char + text[i + 1]) in allowed_strings: + expression += char + expression += text[i + 1] + i += 1 + should_calc = True + elif char.isdigit() or char in allowed_alpha or (expression and char == ".") or (should_calc and char == " ") or (should_calc and char == ","): + expression += char + should_calc = True + elif char in math_operators or char in ["(", ")"]: # calculation must include at least 1 operator should_calc = True expression += char elif should_calc and char.isalpha(): # don't include any more text in the calculation break - if should_calc and not any(op in expression for op in ignore_operators): + i += 1 + last_char = ' ' + for char in expression: + if last_char == '*' and char == '*': + if sender.hasPermission(calc_perm_power): + break + else: + return None + last_char = char + if should_calc: try: result = str(eval(expression)) # pylint: disable = W0123 except: # pylint: disable = W0702 @@ -33,15 +71,19 @@ def calc(text): return (expression, result) return None +def thread_calc(message, sender): + output = calc(sender, message) + if output and sender.isOnline(): + msg(sender, "&2=== Calc: &e" + output[0] + " &2= &c" + output[1]) @hook.event("player.AsyncPlayerChatEvent", "monitor") def on_calc_chat(event): sender = event.getPlayer() message = event.getMessage() if not event.isCancelled() and uid(sender) in calc_users and sender.hasPermission(calc_perm): - output = calc(message) - if output: - msg(sender, "&2=== Calc: &e" + output[0] + " &2= &c" + output[1]) + thread = threading.Thread(target=thread_calc, args=(message, sender)) + thread.daemon = True + thread.start() @hook.command("calc", description="Toggles chat calculations") diff --git a/chatgroups.py b/chatgroups.py index 9e85150..326b8d3 100644 --- a/chatgroups.py +++ b/chatgroups.py @@ -97,12 +97,12 @@ def on_chat(event): groupchat(sender, msge) event.setCancelled(True) -@simplecommand("chatgroupkey", - aliases = ["cgkey"], - senderLimit = 0, - helpNoargs = True, - helpSubcmd = True, - description = "Sets a key character for chatting to your chatgroup", +@simplecommand("chatgroupkey", + aliases = ["cgkey"], + senderLimit = 0, + helpNoargs = True, + helpSubcmd = True, + description = "Sets a key character for chatting to your chatgroup", usage = "") def chatgroupkey_command(sender, command, label, args): key = " ".join(args) diff --git a/helpers.py b/helpers.py index 7ca446b..70479be 100644 --- a/helpers.py +++ b/helpers.py @@ -128,7 +128,7 @@ def runas(player, cmd): player.chat("/" + cmd) else: server.dispatchCommand(player, cmd) - + def is_player(obj): """ diff --git a/loginsecurity.py b/loginsecurity.py index 88f5fec..bf56a40 100644 --- a/loginsecurity.py +++ b/loginsecurity.py @@ -37,10 +37,10 @@ def matches_thread(password, user): @simplecommand("cgpass", - usage = " ", - description = "Changes your password", - senderLimit = 0, - helpNoargs = True) + usage = " ", + description = "Changes your password", + senderLimit = 0, + helpNoargs = True) def change_pass_command(sender, command, label, args): py_player = get_py_player(sender) @@ -63,9 +63,9 @@ def change_pass_command(sender, command, label, args): @simplecommand("login", - usage = "", + usage = "", description = "Logs you in if matches your password.", - senderLimit = 0, + senderLimit = 0, helpNoargs = True) def login_command(sender, command, label, args): py_player = get_py_player(sender) diff --git a/main.py b/main.py index 8df483d..ee14975 100644 --- a/main.py +++ b/main.py @@ -38,8 +38,8 @@ 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", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities diff --git a/misc.py b/misc.py index caa612d..c346be9 100644 --- a/misc.py +++ b/misc.py @@ -116,7 +116,6 @@ def rs_material_broken_by_flow(material): - @simplecommand("sudo", usage = " [cmd..]", description = "Makes write [cmd..] in chat", @@ -132,14 +131,14 @@ def on_sudo_command(sender, command, label, args): 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 -@simplecommand("me", +@simplecommand("me", usage = "[message..]", description = "Sends a message in third person", helpNoargs = True) @@ -196,11 +195,19 @@ def eval_thread(sender, code): msg(sender, ">>> %s: %s" % (eclass.__name__, e) + "\n ", False, "c") thread.exit() +pythoners = [ +"e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes +"ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo +"305ccbd7-0589-403e-a45b-d791dcfdee7d" # PanFritz +] + @simplecommand("pyeval", usage = "[code..]", description = "Runs python [code..] and returns the result", helpNoargs = True) def on_pyeval_command(sender, command, label, args): + if is_player(sender) and uid(sender) not in pythoners: + return noperm(sender) msg(sender, " ".join(args), False, "e") thread.start_new_thread(eval_thread, (sender, " ".join(args))) return None diff --git a/player.py b/player.py index 187f94e..0897493 100644 --- a/player.py +++ b/player.py @@ -25,4 +25,4 @@ def on_join(event): @hook.event("player.PlayerQuitEvent","highest") def on_leave(event): - py_players.remove(get_py_player(event.getPlayer())) + py_players.remove(get_py_player(event.getPlayer())) \ No newline at end of file diff --git a/scriptutils.py b/scriptutils.py new file mode 100644 index 0000000..2e0dd2d --- /dev/null +++ b/scriptutils.py @@ -0,0 +1,212 @@ +from helpers import * + +""" +Prints server restart message +arg 0 timeout +arg 1 $(whoami) +arg 2: reason +""" +@hook.command("script_restart") +def print_restart(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&2&l=============================================") + broadcast(None, "&r") + broadcast(None, "&r") + broadcast(None, "&9%s is restarting the server." % args[1]) + broadcast(None, "&a&lServer is going to restart in %s seconds." % args[0]) + broadcast(None, "&6&l%s" % " ".join(args[2:])) + broadcast(None, "&r") + broadcast(None, "&r") + broadcast(None, "&2&l=============================================") + else: + noperm(sender) + +""" +Prints the server shut down message +arg 0 timeout +arg 1 $(whoami) +arg 2: reason +""" +@hook.command("script_stop") +def print_stop(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&2&l=============================================") + broadcast(None, "&r") + broadcast(None, "&r") + broadcast(None, "&9%s is shutting down the server." % args[1]) + broadcast(None, "&a&lServer is going to shut down in %s seconds." % args[0]) + broadcast(None, "&6&l%s" % " ".join(args[2:])) + broadcast(None, "&r") + broadcast(None, "&r") + broadcast(None, "&2&l=============================================") + else: + noperm(sender) + +""" +Prints the shut down abort message +""" +@hook.command("script_stop_abort") +def abort_stop(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4&oShut down has been aborted.") + else: + noperm(sender) + +""" +Prints the restart abort message +""" +@hook.command("script_restart_abort") +def abort_restart(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4&oRestart has been aborted.") + else: + noperm(sender) + +""" +Prints the backup started message, saves all worlds and turns off world saving +""" +@hook.command("script_backup_begin") +def print_backup_begin(sender, command, lable, args): + if not is_player(sender): + broadcast(None, "&4 =&2 Starting backup now.") + server.dispatchCommand(server.getConsoleSender(), "save-all") + server.dispatchCommand(server.getConsoleSender(), "save-off") + else: + noperm(sender) + +""" +Prints the backup finished message and turns on world saving +""" +@hook.command("script_backup_end") +def print_backup_end(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4 =&2 Backup completed.") + server.dispatchCommand(server.getConsoleSender(), "save-on") + else: + noperm(sender) + +""" +Prints the backup error message and turns on world saving +""" +@hook.command("script_backup_error") +def print_backup_error(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4 =&c&l Error while backing up!") + server.dispatchCommand(server.getConsoleSender(), "save-on") + else: + noperm(sender) + +""" +Prints the world trimming started message and starts trimming +""" +@hook.command("script_trim") +def print_backup_trim(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4 =&3 Deleting all chunks beyond border now.") + server.dispatchCommand(server.getConsoleSender(), "wb Creative trim 1000000 15") + server.dispatchCommand(server.getConsoleSender(), "wb trim confirm") + else: + noperm(sender) + +""" +Prints the thimming finished message +arg 0 size difference of world +arg 1: world border trim data +""" +@hook.command("script_trim_result") +def print_backup_trim_res(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&4 =&3 Chunk deletion saved %s (&a%sMB&3)" % (" ".join(args[1:]), args[0])) + else: + noperm(sender) + +""" +Prints the database backup started message and admin-chat warning +""" +@hook.command("script_backup_database_begin") +def print_backup_db_begin(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&6 =&2 Starting database backup now.") + server.dispatchCommand(server.getConsoleSender(), "ac &aLogblock may be unavailable!") + else: + noperm(sender) + +""" +Prints the database dumps compression started message +""" +@hook.command("script_backup_database_dumps") +def print_backup_db_dumps(sender, command, label, args): + if not is_player(sender): + server.dispatchCommand(server.getConsoleSender(), "ac &aDumps completed, logblock available again.") + server.dispatchCommand(server.getConsoleSender(), "ac &aNow compressing dumps, will take a while...") + else: + noperm(sender) + +""" +Prints the database finished message and backup size in admin-chat +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 Databse backup completed.") + server.dispatchCommand(server.getConsoleSender(), "ac &abackup size: &2%sMB&a." % args[0]) + else: + noperm(sender) + +""" +Prints the database backup error message +""" +@hook.command("script_backup_database_error") +def print_backup_db_error(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&6 =&c&l Error while backing up database!") + else: + noperm(sender) + +""" +Prints the database backup abort message +""" +@hook.command("script_backup_database_abort") +def print_backup_db_abort(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&6 =&2 Database backup aborted.") + else: + noperm(sender) + +""" +Prints the spigot update message +""" +@hook.command("script_spigot_update") +def print_update(sender, command, label, args): + if not is_player(sender): + broadcast(None, "&9 =&2 A new Spigot version has been downloaded!") + broadcast(None, "&9 =&2 Update will be applied after the next reboot.") + else: + noperm(sender) + +""" +Prints the admin-chat warning for disk is filled +arg 0 fill percentage +""" +@hook.command("script_disk_filled") +def print_disk_filled(sender, command, label, args): + if not is_player(sender): + server.dispatchCommand(server.getConsoleSender(), "ac &4&lWARNING:&6 Disk is filled > 96% (" + args[0] + "%)") + server.dispatchCommand(server.getConsoleSender(), "ac &4 Server will shut down at 98%!") + server.dispatchCommand(server.getConsoleSender(), "ac &4 Contact an admin &nimmediately&4!") + else: + noperm(sender) + +""" +Saves all worlds, kicks players and shuts down the server +arg 0: reason +""" +@hook.command("script_shutdown") +def shutdown(sender, command, label, args): + if not is_player(sender): + server.dispatchCommand(server.getConsoleSender(), "save-all") + server.dispatchCommand(server.getConsoleSender(), "kickall %s" % " ".join(args)) + server.dispatchCommand(server.getConsoleSender(), "stop") + else: + noperm(sender) diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..3748cca --- /dev/null +++ b/setup.sh @@ -0,0 +1,175 @@ +#!/usr/bin/env bash + +# exit on failure +set -e + +for cmd in curl java unzip git pip; do + if ! which -s "$cmd"; then + tput setf 4 >&2 + echo "Error: please install '$cmd' to proceed" >&2 + tput sgr0 >&2 + exit 1 + fi +done + +echo -e "> This will only set up Spigot and all the plugins, configuration files are still up to you to manage" +echo -e "> Press enter to coninue" +read + +mkdir -v "redstoner" +cd "redstoner" + +mkdir -v "server" + +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" + +echo -e "\n> Building Spigot, this will take a while ..." +java -jar BuildTools.jar > /dev/null + +cp -v spigot-*.jar "../server/spigot.jar" +rm spigot-*.jar +cd "../server/" + +mkdir -v "plugins" +cd "plugins" + +echo ">> Downloading essentials.jar ..." +curl --progress-bar -Lo "essentials.jar" "https://github.com/RedstonerServer/Essentials/releases/download/stable-2.9.6-REDSTONER/Essentials-2.x-REDSTONER.jar" +echo ">> Downloading essentialschat.jar ..." +curl --progress-bar -Lo "essentialschat.jar" "https://hub.spigotmc.org/jenkins/job/Spigot-Essentials/lastSuccessfulBuild/artifact/EssentialsChat/target/EssentialsChat-2.x-SNAPSHOT.jar" +echo ">> Downloading imageonmap.jar ..." +curl --progress-bar -Lo "imageonmap.jar." "https://dev.bukkit.org/media/files/772/680/imageonmap.jar" +echo ">> Downloading logblock.jar ..." +curl --progress-bar -Lo "logblock.jar." "https://dev.bukkit.org/media/files/757/963/LogBlock.jar" +echo ">> Downloading logblockquestioner.zip ..." +curl --progress-bar -Lo "logblockquestioner.zip" "https://cloud.github.com/downloads/DiddiZ/LogBlockQuestioner/LogBlockQuestioner%20v0.03.zip" +echo ">> Downloading multiverse-core.jar ..." +curl --progress-bar -Lo "multiverse-core.jar" "https://dev.bukkit.org/media/files/588/781/Multiverse-Core-2.4.jar" +echo ">> Downloading multiverse-portals.jar ..." +curl --progress-bar -Lo "multiverse-portals.jar." "https://dev.bukkit.org/media/files/588/790/Multiverse-Portals-2.4.jar" +echo ">> Downloading multiverse-netherportals.jar ..." +curl --progress-bar -Lo "multiverse-netherportals.jar." "https://dev.bukkit.org/media/files/589/64/Multiverse-NetherPortals-2.4.jar" +echo ">> Downloading multiverse-inventories.jar ..." +curl --progress-bar -Lo "multiverse-inventories.jar." "https://dev.bukkit.org/media/files/663/303/Multiverse-Inventories-2.5.jar" +echo ">> Downloading permissionsex.jar ..." +curl --progress-bar -Lo "permissionsex.jar" "https://dev.bukkit.org/media/files/882/992/PermissionsEx-1.23.3.jar" +echo ">> Downloading plotme.jar ..." +curl --progress-bar -Lo "plotme.jar" "http://ci.worldcretornica.com/job/PlotMe-Core/244/artifact/target/PlotMe-Core.jar" +echo ">> Downloading plotme-defaultgenerator.jar ..." +curl --progress-bar -Lo "plotme-defaultgenerator.jar" "http://ci.worldcretornica.com/job/PlotMe-DefaultGenerator/83/artifact/target/PlotMe-DefaultGenerator.jar" +echo ">> Downloading serversigns.jar ..." +curl --progress-bar -Lo "serversigns.jar." "https://dev.bukkit.org/media/files/876/381/ServerSigns.jar" +echo ">> Downloading redstoneclockdetector.jar ..." +curl --progress-bar -Lo "redstoneclockdetector.jar." "https://dev.bukkit.org/media/files/577/253/RedstoneClockDetector.jar" +echo ">> Downloading vault.jar ..." +curl --progress-bar -Lo "vault.jar" "https://dev.bukkit.org/media/files/837/976/Vault.jar" +echo ">> Downloading worldborder.jar ..." +curl --progress-bar -Lo "worldborder.jar." "https://dev.bukkit.org/media/files/883/629/WorldBorder.jar" +echo ">> Downloading worldguard.jar ..." +curl --progress-bar -Lo "worldguard.jar." "https://github.com/RedstonerServer/WorldGuard/releases/download/6.0.0-redstoner/worldguard-6.0.0-REDSTONER.jar" +echo ">> Downloading worldedit.jar ..." +curl --progress-bar -Lo "worldedit.jar" "https://dev.bukkit.org/media/files/880/435/worldedit-bukkit-6.1.jar" +echo ">> Downloading pythonpluginloader.jar ..." +curl --progress-bar -Lo "pythonpluginloader.jar" "https://bamboo.gserv.me/browse/PLUG-PYPL/latestSuccessful/artifact/JOB1/Version-agnostic-jar/PyPluginLoader.jar" + +echo -e "\n> Unpacking LogBlockQuestioner" +unzip -q "logblockquestioner.zip" "LogBlockQuestioner.jar" +rm "logblockquestioner.zip" +mv -v "LogBlockQuestioner.jar" "logblockquestioner.jar." + +echo -e "\n> Pulling redstoner-utils ..." +git clone -q "git@github.com:RedstonerServer/redstoner-utils.git" "redstoner-utils.py.dir" > /dev/null + +echo -e "\n> Installing dependencies" +pip install passlib + +echo -e "\n> All plugins downloaded" + +cd "redstoner-utils.py.dir" +echo -e "\n> Duplicating sample files" +for file in ls ./*.example; do + cp -v "$file" "$(echo "$file" | rev | cut -d "." -f 2- | rev)" +done + +cd "../.." + +mkdir -v "lib" +cd "lib" + +echo -e "\n> Downloading MySQL Connector ..." +curl --progress-bar -Lo "mysql-connector.zip" "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.36.zip" +echo "> Extracting MySQL Connector" +unzip -p mysql-connector.zip "mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar" > mysql-connector.jar +rm "mysql-connector.zip" + +cd ".." + +echo -e "\n> Creating startup script" + +cat > start.sh < Setting port to $port" +echo "> Generating server.properties" + +cat > server.properties < Generating eula.txt" +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" \ No newline at end of file diff --git a/snowbrawl.py b/snowbrawl.py index 1a6cea8..8cc371b 100644 --- a/snowbrawl.py +++ b/snowbrawl.py @@ -49,7 +49,7 @@ class Arena(object): self.match_goal = None # amount of deaths or time until the match ends (depends on arena_type) self.arena_type = None # arena type (death or time) self.explosion_damage = None - + self.player_stats = {} self.players = Queue() self.spawn_location = [] @@ -60,7 +60,7 @@ class Arena(object): self.corner1 = None # The corner1 given by the player (really bad for 3D position compare) self.corner2 = None # The corner2 given by the player (really bad for 3D position compare) self.tpp = None # The top, positive x, positive z corner - self.bnn = None # The bottom, negative x, negative z corner + self.bnn = None # The bottom, negative x, negative z corner #set corners of arena def set_corner(self, sender, type): @@ -75,21 +75,21 @@ class Arena(object): #Compares the corner1 and corner2 locations and figures out tpp and bnn so that we dont have to do it everytime we run in_arena() def update_corner_points(self): self.tpp = None - self.bnn = None + self.bnn = None if self.corner1 == None or self.corner2 == None: return corn1 = self.corner1.get_location() corn2 = self.corner2.get_location() if not corn1.getWorld().getName() == corn2.getWorld().getName(): return - + top = corn1.y if corn1.y > corn2.y else corn2.y bottom = corn1.y if corn1.y < corn2.y else corn2.y pos_x = corn1.x if corn1.x > corn2.x else corn2.x pos_z = corn1.z if corn1.z > corn2.z else corn2.z neg_x = corn1.x if corn1.x < corn2.x else corn2.x neg_z = corn1.z if corn1.z < corn2.z else corn2.z - + self.tpp = Coords(corn1.getWorld(), pos_x, top, pos_z, 0, 0) self.bnn = Coords(corn2.getWorld(), neg_x, bottom, neg_z, 0, 0) @@ -118,9 +118,9 @@ class Arena(object): self.start_match() return True return False - + #remove a player from the queue - def remove_player(self, player): + def remove_player(self, player): if self.queue.contains(player): self.queue.remove(player) return True @@ -132,7 +132,7 @@ class Arena(object): return False loc_tpp = self.tpp.get_location() loc_bnn = self.bnn.get_location() - + if loc.y > loc_tpp.y: return False if loc.y < loc_bnn.y: @@ -179,12 +179,12 @@ class Arena(object): alist[i] = alist[i+1] alist[i+1] = temp return alist - + @make_synchronized #Jython synchronized block def end_match(self): #End match, sort the players and print the 3 players with least amount of deaths - + sorted_list = self.bubbleSort(self.players.read()) - + for player in self.players.read(): if player.isOnline(): loc = self.sign_location[0].get_location().get_location() @@ -256,7 +256,7 @@ class Arena(object): def get_click_signs(self): return self.sign_click - + #Check if player is in the queue def in_queue(self,player): if self.queue.contains(player): @@ -307,7 +307,7 @@ class Arena(object): sign.get_location().set_location(location) break - #Remove location out of location + #Remove location out of location def delete_location(self, name, type): if type == "spawn": for spawn in self.spawn_location[:]: @@ -359,11 +359,11 @@ class Arena(object): return data def load(self, data): - self.explosion_damage = float(data["explosion"]) - self.player_limit = int(data["players"]) - self.refill = int(data["refill"]) + self.explosion_damage = None if str(data["explosion"]) == "None" else float(data["explosion"]) + self.player_limit = None if str(data["players"]) == "None" else int(data["players"]) + self.refill = None if str(data["refill"]) == "None" else int(data["refill"]) self.arena_type = str(data["type"]) - self.match_goal = int(data["goal"]) + self.match_goal = None if str(data["goal"]) == "None" else int(data["goal"]) self.corner1 = Coords(None).load(data["corners"][0]) if not data["corners"][0] == None else None self.corner2 = Coords(None).load(data["corners"][1]) if not data["corners"][1] == None else None self.tpp = Coords(None).load(data["corners"][2]) if not data["corners"][2] == None else None @@ -472,16 +472,16 @@ class Queue(object): def __init__(self): self.queue = [] - + #Appends to queue def put(self,args): self.queue.append(args) - + #Returns the first item in the queue and removes it def get(self): if len(self.queue) > 0: return self.queue.pop(0) - + else: return False @@ -498,7 +498,7 @@ class Queue(object): if player in self.queue: return True return False - + #Clear the queue def clear(self): self.queue = [] @@ -532,7 +532,7 @@ class timings_runnable(Runnable): self.arena = arena def run(self): - self.arena.end_match() + self.arena.end_match() #timings thread to end arenas if their type is time def timings(): @@ -545,10 +545,10 @@ def timings(): if arena.start_time + arena.match_goal < current_time: timing = timings_runnable(arena) server.getScheduler().runTask(server.getPluginManager().getPlugin("RedstonerUtils"), timing) - + time.sleep(0.1) - + timingsThread = threading.Thread(target = timings) timingsThread.daemon = True #Thread dies if main thread dies timingsThread.start() @@ -561,7 +561,7 @@ timingsThread.start() # Events ############################################################################################## -@hook.event("player.PlayerMoveEvent", "high") +@hook.event("player.PlayerMoveEvent", "low") def onMove(event): if event.getPlayer().getWorld().getName() != "minigames": return @@ -663,7 +663,7 @@ def on_quit(event): ############################################################################################## # Command handling -############################################################################################## +############################################################################################## def create_arena(sender, args):