HyperScript
Docs

← All scripts

WorldsManager.hs

/world what /world can do /world list every world, and who is in it /world create <name> [kind] make a world: normal, flat, void, amplified, nether or end /world tp <name> [player] go to a world, or send somebody /world delete <name> remove a world for good /world load <name> bring a world into memory /world unload <name> let go of a world, files stay /world setspawn the world's spawn is where you stand /world info [name] what kind of place a world is /world rule <rule> <value> change a game rule of your world /world time <time> day, noon, night, midnight /world weather <weather> clear, rain or thunder /world difficulty <level> peaceful, easy, normal or hard

by HyperScript TeamHyperScript 1.7.50+1 command298 linesworldsworldteleportadminserver template
In the script list

Put the file in plugins/HyperScript/scripts and it is live. Or type /hyperscript install worldsmanager on your server.

# ==============================================================
#  WorldsManager.hs - make, visit and remove worlds with /world
# ==============================================================
#
# Requires: 1.7.50
# Author: HyperScript Team
# Tags: worlds, world, teleport, admin, server template
#
# /world                      what /world can do
# /world list                 every world, and who is in it
# /world create <name> [kind] make a world: normal, flat, void,
#                             amplified, nether or end
# /world tp <name> [player]   go to a world, or send somebody
# /world delete <name>        remove a world for good
# /world load <name>          bring a world into memory
# /world unload <name>        let go of a world, files stay
# /world setspawn             the world's spawn is where you stand
# /world info [name]          what kind of place a world is
# /world rule <rule> <value>  change a game rule of your world
# /world time <time>          day, noon, night, midnight
# /world weather <weather>    clear, rain or thunder
# /world difficulty <level>   peaceful, easy, normal or hard
#
# Notes
#  - Everything is for whoever has the permission in "admin";
#    with "everyone_may_visit" every player may use
#    /world tp and /world list.
#  - A world is made the moment you ask, which makes the server
#    stand still for a few seconds. Do it when it is quiet.
#  - Only worlds made with /world create (or by another script)
#    can be deleted. The worlds the server came with are safe.
#  - /world delete asks you to say it twice. What is deleted is
#    gone: there is no way back but a backup of your own.
#  - Players in a world that is unloaded or deleted are sent to
#    the main world first.
#  - /world tp waits "wait" seconds and is called off if you
#    move, unless you have the admin permission. Put 0 to go at
#    once. Nobody is sent while they are in a fight.
#  - A world keeps its name, kind and spawn across restarts.

options:
    name: "MY SERVER"
    # What stands in front of every message.
    sign: "&8[&bWorlds&8] "
    # The permission for everything but visiting.
    admin: "worlds.admin"
    # true lets every player use /world tp and /world list.
    everyone_may_visit: false
    # Seconds a player stands still before /world tp takes them. 0 for none.
    wait: 3
    # The world nobody may unload or delete, whatever it is called on your server.
    main_world: "world"

function kinds():
    return ["normal", "flat", "void", "amplified", "nether", "end"]

function may_visit({_who}):
    if {@everyone_may_visit} is true:
        return true
    return {_who} has permission "{@admin}"

function help({_who}):
    send "{@sign}&7What /world can do:" to {_who}
    send "&b/world list &8- &7every world" to {_who}
    send "&b/world tp <name> [player] &8- &7go to a world" to {_who}
    if {_who} has permission "{@admin}":
        send "&b/world create <name> [kind] &8- &7normal, flat, void, amplified, nether, end" to {_who}
        send "&b/world delete <name> &8- &7remove a world for good" to {_who}
        send "&b/world load <name> &8/ &bunload <name>" to {_who}
        send "&b/world setspawn &8- &7the spawn is where you stand" to {_who}
        send "&b/world info [name] &8- &7about a world" to {_who}
        send "&b/world rule <rule> <value> &8- &7a game rule of your world" to {_who}
        send "&b/world time <day|noon|night|midnight>" to {_who}
        send "&b/world weather <clear|rain|thunder>" to {_who}
        send "&b/world difficulty <peaceful|easy|normal|hard>" to {_who}

command /world [action] [first] [second]:
    description: Make, visit and remove worlds
    aliases: /worlds, /wm
    tab complete: ["list", "tp", "create", "delete", "load", "unload", "setspawn", "info", "rule", "time", "weather", "difficulty"]
    tab complete 2: server.worlds
    trigger:
        if arg.1 is not set:
            help(player)
            stop
        set {_action} to lowercase arg.1

        # ---- list
        if {_action} is "list":
            if may_visit(player) is false:
                send "{@sign}&cYou may not do that."
                stop
            send "{@sign}&7Worlds:"
            for each {_world} in server.worlds:
                set {_inside} to 0
                for each {_name} in server.players:
                    if world of location of {_name} is {_world}:
                        add 1 to {_inside}
                send "&a%{_world}% &8- &7%{_inside}% player(s)"
            for each {_world} in created worlds:
                if {_world} is not in server.worlds:
                    send "&8%{_world}% &8- &7not loaded &8(/world load %{_world}%)"
            stop

        # ---- tp
        if {_action} is "tp" or {_action} is "teleport" or {_action} is "go":
            if may_visit(player) is false:
                send "{@sign}&cYou may not do that."
                stop
            if arg.2 is not set:
                send "{@sign}&7Use &b/world tp <name> [player]"
                stop
            if arg.2 is not in server.worlds:
                if world arg.2 exists:
                    send "{@sign}&7%arg.2% is not loaded. &b/world load %arg.2%"
                else:
                    send "{@sign}&cThere is no world called %arg.2%."
                stop
            if arg.3 is set:
                if player does not have permission "{@admin}":
                    send "{@sign}&cYou may only send yourself."
                    stop
                if arg.3 is not online:
                    send "{@sign}&c%arg.3% is not here."
                    stop
                teleport arg.3 to spawn of world arg.2
                send "{@sign}&7You were sent to &b%arg.2%&7." to arg.3
                send "{@sign}&7%arg.3% was sent to &b%arg.2%&7."
                stop
            if player has permission "{@admin}" or {@wait} is 0:
                teleport player to spawn of world arg.2
                send "{@sign}&7Welcome to &b%arg.2%&7."
                stop
            if player is in combat:
                send "{@sign}&cNot while you are fighting."
                stop
            teleport player to spawn of world arg.2 after {@wait} seconds unless they move
            stop

        # ---- everything below is for admins
        if player does not have permission "{@admin}":
            send "{@sign}&cYou may not do that."
            stop

        if {_action} is "create" or {_action} is "new":
            if arg.2 is not set:
                send "{@sign}&7Use &b/world create <name> [kind]"
                send "&7Kinds: &f%kinds()%"
                stop
            if world arg.2 exists:
                send "{@sign}&cThere is a world called %arg.2% already."
                stop
            set {_kind} to "normal"
            if arg.3 is set:
                set {_kind} to lowercase arg.3
            if {_kind} is not in kinds():
                send "{@sign}&c%{_kind}% is not a kind of world. &7Kinds: &f%kinds()%"
                stop
            send "{@sign}&7Making &b%arg.2% &7(%{_kind}%). The server stands still for a moment..."
            wait 1 second
            if {_kind} is "flat":
                create world arg.2 flat
            else if {_kind} is "void":
                create world arg.2 void
            else if {_kind} is "amplified":
                create world arg.2 amplified
            else if {_kind} is "nether":
                create world arg.2 nether
            else if {_kind} is "end":
                create world arg.2 end
            else:
                create world arg.2
            set {worlds.kind.%arg.2%} to {_kind}
            send "{@sign}&aDone. &b/world tp %arg.2% &7takes you there."
            stop

        if {_action} is "delete" or {_action} is "remove":
            if arg.2 is not set:
                send "{@sign}&7Use &b/world delete <name>"
                stop
            if arg.2 is "{@main_world}":
                send "{@sign}&cThe main world cannot be deleted."
                stop
            if arg.2 is not in created worlds:
                send "{@sign}&c%arg.2% was not made with /world create, so it is left alone."
                stop
            set {_ask} to "delete %arg.2%"
            if {%player%.worlds_sure} is not {_ask}:
                set {%player%.worlds_sure} to {_ask}
                send "{@sign}&cThis deletes &f%arg.2% &cand everything built in it, for good."
                send "&7Say &b/world delete %arg.2% &7once more to do it."
                stop
            delete {%player%.worlds_sure}
            delete world arg.2
            delete {worlds.kind.%arg.2%}
            send "{@sign}&7%arg.2% is gone."
            stop

        if {_action} is "load":
            if arg.2 is not set:
                send "{@sign}&7Use &b/world load <name>"
                stop
            if world arg.2 exists is false:
                send "{@sign}&cThere is no world called %arg.2%."
                stop
            send "{@sign}&7Loading &b%arg.2%&7..."
            load world arg.2
            send "{@sign}&aLoaded."
            stop

        if {_action} is "unload":
            if arg.2 is not set:
                send "{@sign}&7Use &b/world unload <name>"
                stop
            if arg.2 is "{@main_world}":
                send "{@sign}&cThe main world cannot be unloaded."
                stop
            if arg.2 is not in server.worlds:
                send "{@sign}&c%arg.2% is not loaded."
                stop
            unload world arg.2
            send "{@sign}&7%arg.2% is unloaded. Its files are still there."
            stop

        if {_action} is "setspawn":
            set {_here} to world of player's location
            set spawn of world {_here} to player's location
            send "{@sign}&aThe spawn of %{_here}% is where you stand."
            stop

        if {_action} is "info":
            set {_which} to world of player's location
            if arg.2 is set:
                set {_which} to arg.2
            if {_which} is not in server.worlds:
                send "{@sign}&c%{_which}% is not loaded."
                stop
            set {_inside} to []
            for each {_name} in server.players:
                if world of location of {_name} is {_which}:
                    append {_name} to {_inside}
            send "{@sign}&b%{_which}%"
            if {worlds.kind.%{_which}%} is set:
                send "&7Kind: &f%{worlds.kind.%{_which}%}%"
            send "&7Spawn: &f%spawn of world {_which}%"
            send "&7Difficulty: &f%difficulty of world {_which}%"
            send "&7Players: &f%size of {_inside}%"
            if size of {_inside} > 0:
                send "&7%{_inside}%"
            stop

        if {_action} is "rule" or {_action} is "gamerule":
            if arg.3 is not set:
                send "{@sign}&7Use &b/world rule <rule> <value>&7, such as &b/world rule keepInventory true"
                stop
            set {_here} to world of player's location
            set gamerule arg.2 of world {_here} to arg.3
            send "{@sign}&7%arg.2% is now &f%gamerule arg.2 of world {_here}% &7in %{_here}%."
            stop

        if {_action} is "time":
            set {_here} to world of player's location
            set {_ticks} to parse arg.2 as number
            if arg.2 is "day":
                set {_ticks} to 1000
            else if arg.2 is "noon":
                set {_ticks} to 6000
            else if arg.2 is "night":
                set {_ticks} to 13000
            else if arg.2 is "midnight":
                set {_ticks} to 18000
            if {_ticks} is not set:
                send "{@sign}&7Use &b/world time <day|noon|night|midnight>"
                stop
            set time in world {_here} to {_ticks}
            send "{@sign}&7It is %arg.2% in %{_here}%."
            stop

        if {_action} is "weather":
            if arg.2 is not in ["clear", "rain", "thunder"]:
                send "{@sign}&7Use &b/world weather <clear|rain|thunder>"
                stop
            set {_here} to world of player's location
            set weather in world {_here} to arg.2
            send "{@sign}&7The weather in %{_here}% is %arg.2%."
            stop

        if {_action} is "difficulty":
            if arg.2 is not in ["peaceful", "easy", "normal", "hard"]:
                send "{@sign}&7Use &b/world difficulty <peaceful|easy|normal|hard>"
                stop
            set {_here} to world of player's location
            set difficulty of world {_here} to arg.2
            send "{@sign}&7%{_here}% is now %arg.2%."
            stop

        help(player)