šŸ“‹ [ALPHA] Macros - Simplify your command usage with Macros! V1.0A4

A plugin to simplify the use of running multiple commands with a Macro.

The goal of this plugin is to simplify the use of multiple/long commands.

README.md copy-pasta:

Macros

A SpongeAPI plugin

This plugin is currently in Development. It has many bugs and features to be added.

You are free to test this plugin and make suggestions, report bugs, or even contribute changes through Pull Requests!

The code is very messy, a lot of it was in a ā€œGet it workingā€ stage.

How to use Macros

Creating and editing:

Macros can be created with /macro create <macroName> and edited with /macro edit <macroName> <lineNumber> <Command to run>

/macro create jail
/macro edit jail 0 tp {0} 100 64 100
/macro edit jail 1 gamemode 2 {0}
/macro edit jail 2 tellraw {0} ["",{"text":"You have been sent to Jail!","color":"red","bold":true}]

Alternatively you can use /quickMacro <macroName> <actions>. Lines can be seperated by ;.

The above example also can be condensed to this:

/quickmacro jail tp {0} 100 64 100; gamemode 2 {0}; tellraw {0} ["",{"text":"You have been sent to Jail!","color":"red","bold":true}]

Using:

There are 3 ways you can use a macro.

Command: /macro use <macro> [arguments]

Chat Shortcut: .m:<macro> [arguments]

As itā€™s own command* : /<macro> [arguments]

In order for you to use a macro as a command, you will need to use /macro setAsCommand <macro>.

Arguments:

Arguments can be used to make macros more dynamic.

Arguments are formatted as {#} or {#orVALUE}. With Brackets containing them, a number to define which argument to use and an option orVALUE to use if no argument is present.

If an argument contains an optional value, you can use ~ when using the macro to use the argumentā€™s value.

Advanced Macro Usage

Advanced Arguments:

Using {=#=} will use all arguments after #.

Using {==} will return all arguments passed by the player. This is good for say ANNOUNCEMENT: {==}

Special Arguments:

Special Arguments are arguments that are filled in by the plugin rather than the player. These can provide usefull information without bothering the player to provide them.

Argument Description
{user} Get the name of the user using this Macro.
{userID} Get the UUID of the user using this Macro.
{macroName} Get the name of this Macro.
{macroID} Get the ID of this Macro.
{authorID} Get this Macroā€™s Authorā€™s UUID.
{authorName} Get this Macroā€™s Authorā€™s username.

Action Commands

Action Commands are special Macro-only commands allowing expanding what Macros can do.

Action commands are formatted differently than normal commands. Current formatting is .<command>: [Args] Notice the . and : before and after the command.

Action Commands are NOT case-sensitive.

Command Usage Description
# .#: [Message] Create a comment that is ignored when parsing the Macro.
Done .done: [Message] End the Macro with an optional message
Echo .echo: [Message] Send a message to the user of the macro
Goto .goto: <LineNumber> Set the next line of the Macro to run
LogD .logd: <Message> Log a [DEBUG] message to console
LogE .loge: <Message> Log a [Error] message to console
LogI .logi: <Message> Log a [Info] message to console
LogW .logw: <Message> Log a [WARN] message to console
Perm .perm: <PermissionNode> Run a permission check on the User. Will end macro if check failed.
Sudo .sudo: <Command> DANGEROUS! Run command as Console. Requires user to have permmision macro.use.other.sudo.<UUID>.<MacroName> to use sudo on that macro.
Wait .

Installing

  • Download the macros.jar
  • Place it in your serverā€™s mods folder
  • Start the server

This plugin can run out-of-the box with no aditional config editing needed.

Config//todo

Currently the config is a work in progress, it may change by the full release.

Config folder Format:

\configs\macros\macros.conf
\configs\macros\storage.conf
\configs\macros\custom\

macros.conf

This file contains all the settings for the plugin.

Current Settings:

chatShortcut=[
    ".m:",
    ".macro:"
]
maxCommandsPerTick=10
maxJavaErrors=10
maxTimePerTick=5
startMacrosOnTheSameTick=true
Name Discription Type
chatShortcut Allows you to define custom chat shortcuts String Array
maxCommandsPerTick Max commands to run per Tick Integer
maxJavaErrors Max amount of Exceptions thrown before aborting Integer
maxTimePerTick Max ammount of time(ms) for a macro to run on a single tick Integer
startMacrosOnTheSameTick Start macros on the same tick they are called boolean

storage.conf

This file is where all the macros are stored

/custom/

This folder is for external macros.

External macros are macros you can export and easily transfer them between servers or for easier manual editing.

Exported macros are named in the format AuthorUUID.MacroName.mcmacro; these files can be renamed.

Permissions

Commands

Commands are simple: macro.command.<subcommand>

Macros

By default, a Macro can only be used by Console and itā€™s Author.

To allow a user to use anotherā€™s macro: macro.use.other.<UUID>.<Macro>

You can restict the access they have on anotherā€™s macro by changing what permission you give them.

macro.<Usage>.other.<UUID>.<Macro>

Usages:

use
view
edit
delete

Server Security

Anyone can create and fill a macro, this means anyone can add /op 1337h@ck3rz to their macro but it wont op them. Not unless they themselves has permission to use /op, then they wouldnā€™t need to use a macro to do itā€¦

Macros are ran through the player that ran them, meaning if they dont have permission to a command, they wont be able to run that command.


Admins, be aware of the contents of the macro before running it. If you have permissions to higher commands, those commands can run!

/macros view <macro> <line#> lets you view the contents of a macro so you know what the macro is doing.


Sudo is a new Macro Action that can run commands as Console. This is usefull for admins and automation but this can be usefull to malicious players in gaining access to the server Console.

To counter act players being able to create Sudo Macros, the Macro User requires macro.use.other.sudo.<MacroID> to use sudo for that macro. This helps if a user has access to using Sudo on one macro and not another. This also means an Administrator will need to check the macro before allowing permission to use sudo on it.

Other

Saving

The plugin automatically saves macros during the save cycle of Worlds. By default, worlds save every 900 ticks(45 seconds). This can be changed by auto-save-interval in global.conf.

You can manually load and save by using /macro save and /macro load.

Planned features

Security checking - InDev:

  • Checks for attempt at using blacklisted commands(op, ban, whitelist, ext)
  • Checks for infinite loops - Calling the macro within the macro
  • Warn an admin of malicious macros
  • Require adminā€™s approval above a certain warning level

Useful links:

Github: GitHub - Gamecube762/Macros: SpongeAPI plugin allowing you to create macros for commands.
Releases: Releases Ā· Gamecube762/Macros Ā· GitHub
IssueTracker: Issues Ā· Gamecube762/Macros Ā· GitHub

Latest Release: 1.0-Alpha-4

5 Likes

This is one of the reasons why I like the sponge system. Itā€™s really easy to generate commands.

Is there any kind of permissions handling in this? Or do all players get access to all macros by default? Iā€™m interested in using this to achieve some complicated permissions somersaultsā€¦

user creates macro to op themselves

user doesnā€™t have permission to /op

Commands in Macros are ran by the player using it, so unless that player has permission to OP themselves, than you should be safe.

/macro view <macro> <line#> can be used to view the contents of a macro, it displays up to 7(iirc) lines at a time.

1 Like

Well, Iā€™m certainly glad that you chose to implement macros this way.

1 Like

Yes, I forgot to document permissions.

Command perms: macro.command.<subCommand>
Turns out I forgot about updating the permissions for some commandsā€¦

Macros by default can be used by only the Author and Console.
Public macros can be used by anyone (/macro setPublic <macro>)

For macros from other users, you will need permission: macros.use.other.<UUID>.<MacroName>

Code for checking who can access a macro can be found here.

Permissions was something I neglected for a while and now that I look at it, most of it isnā€™t correctly implemented. I will work on that for the next version!

2 Likes

@Gamecube762
Looks very interesting! Thank you!

Alpha2 is out with permissions fixed.

is there anyway to set a macro to execute with the permissions of itā€™s creator or the console? defaulting to off of course

for example once every 24 hours I want to create a command that runs essentially this sequence, in extreme pseudocode

say Soandso has been outfitted by the gods!
give Soandso item
give Soandso item
give Soandso item
create lighning strike at Soandso

but the key thing is I want it to be done with an /outfit command which is why Iā€™m using your plugin, which I love for the record.

the way I understand it, none of those commands will execute because of the lack of permissions to the individual commands, and I donā€™t want to give access to those commands on a full time basis.

1 Like

The way you understand it is correct.

I am planning on adding additional ways to manipulate how a macro works. Planning on adding comments, waiting, and a few others. I could look into adding ā€˜sudoā€™, but Iā€™d feel that is a huge security risk as it would be running as console and bypassing all permissions.

I donā€™t know any kit plugins that would strike and announce when used, but I havenā€™t looked at any.

it is a security risk, but so is /op if used inappropriately, the functionality would still be welcomed and encourage admins to setup their permissions correctly.

1 Like

Permitting players to use (admin created) Macros is an important part of what Iā€™m trying do with this. So itā€™s sort of critical that they can execute the macro, and yet not normally have permission to use those commands (because itā€™s five commands in sequence that gets the job done).

It would also be a very convenient way of allowing specific things to be done by players without necessarily giving them full access to a command. So Iā€™ll argue in favour of allowing the macros to be executed as if the permissions level was that of the creator of the macro (or assigned to some other group). Itā€™d be even more convenient if it was just all bundled up in a single, user-defined permission that could be granted to players / groups.

2 Likes

Iā€™ll look into creating it.

The plugin uses CommandManager#process(source, string) to run commands, so I donā€™t have control over permissions of the commands ran. However I can run the commands as Console ignoring all permissions.

My idea was to add a prefix to the line you want executed by console rather than setting the whole script.

.echo: Giving a Diamond to {0} //prints a message to the macro user
.sudo: give {0} Diamond //runs as Console
tellraw {0} ["",{"text":"You have received a Diamond"}] //normal command

As for permissions, I could do macros.use.other.<UUID>.<MacroName>.sudo only allowing sudo to run if they have permission to it.

could you consider the other way around, macro.use.other.sudo.<UUID>.<MacroName> in addition to macro.use.other.<UUID>.<MacroName> for non-sudo?, that way we could more easily allow all macroā€™s created by one person to be run, feel free to veto me on this

Iā€™m happy either way as it should provide the same functionality. When compared side by side, your suggestion does look cleaner.

Another question: would it be possible to implement the vanilla @p feature in a Macro?
That would save some hassles with certain open-ended commands if it could only target the player who used it.

I havenā€™t done too much testing on it, but it seemed @e passes through and is accepted by Vanilla commands.

Simple test of tp {0} Gamecube762 with /macro use toMe @e[type=creeper] teleported all creepers to me with MCā€™s tp command looping and not the macro.

is there a way to pass all parameters from a range? for example Iā€™m making a restart counter, and I want to

/restart 30 This is why we're restarting

problem is I donā€™t know how many paramters I need when I create the macro

Iā€™m looking for something like {1-5} but without requiring params 2-5, is it currently possible to do that?

Currently no, but I am working on adding this.

My original idea was {==} for remaining arguments | {=2=} for arguments 2 and after All arguments after are optional