About
SinkScripts is a plugin which adds support for executing, loading & saving groovy scripts.
It also supports interactive ingame scripting.
Groovy is a programming language which is similar to java.
You can find more information about groovy here.
Dependencies
You will need SinkLibrary v1.9.7 or higher if you want to use this plugin. You can get it here.
Interactive Console
You can code while ingame (using the chat)!
Use /script (without any args) to enable and disable the interactive console!
Example:
/script //Enable interactive console int i = Bukkit.getOnlinePlayers().size() return "There are currently " + i + " players online!" .execute /script //Disable interactive console
Script Commands
Commands are prefixed with a . and can be used with the /script command (e.g. /script .execute) and the interactive console
List of commands:
- .help: List all commands
- .load <file>: Load file.groovy and add to code history
- .save <file>: Save code history to file.groovy
- .execute: Execute code history
- .execute <file>: Load and execute file (code history not included)
- .histroy: Show code history
- .clear: Clear code history
Command Scripting
If you don't want to use the interactive console, you can also script using this command: /script
e.g.
/script int i = 5 /script return i /script .execute /script .save test
Pre-defined Variables
Variables are splitted into two: Constant and non Constant variables.
Constant variables won't change and will always stay the same. Non-Constant variables are variables which updates with each execution...
Constants:
- me: User (de.static_interface.sinklibrary.User) instance of the sender
- plugin: JavaPlugin instance of this plugin
- player: Player instance of the sender
- server: Bukkit instance (you can actually use Bukkit.getServer() instead...)
Non-Constants:
- x: X coordinate of the sender (double)
- y: Y coordinate of the sender (double)
- z: Z coordinate of the sender (double)
- players: A Player[] Array with the online players
- users: A Collection<User> with the User instances of the online players
- at: The block the sender is currently looking at
Please note, that you can't use these variable names for other variables.
Example Usage:
for(Player p : players) { p.sendMessage(String.format("Hello World! I'm at X:%s, Y:%s and Z: %s! ", x, y, z)); }
Default Imports
These are the default imports:
import de.static_interface.sinklibrary.*; import org.bukkit.block.*; import org.bukkit.entity.*; import org.bukkit.inventory.*; import org.bukkit.material.*; import org.bukkit.potion.*; import org.bukkit.util.*; import org.bukkit.*;
You can of course import other packages too (just type import tdl.package.example)
Scripts Folder
The scripts are located here:
- <Bukkit Folder>
- plugins
- SinkPlugins
- scripts
- SinkPlugins
- plugins
You can edit or save your script in this folder. The extension needs to be name.groovy
After saving it, you can load it with .load <name>
Example Script
/** * Example script * Description: sends the current TPS to all online players, and heals every player */ double currentTPS = SinkLibrary.getSinkTimer().getAverageTPS(); String sendPlayers = ""; for (Player player : players) { player.sendMessage(ChatColor.AQUA + "Current TPS: " + currentTPS) player.setHealth(20) if (sendPlayers == "") { sendPlayers = player.getName() } else { sendPlayers += ", " + player.getName() } } return "Message has been send to: " + sendPlayers + "!"
Advanced Example
/** This scripts registers an event listener which is listening for IrcReceiveMessageEvent which is fired by SinkIRC and makes the IRC Bot send that message back (something like an echo). It shows how to use listeners with this plugin, you can also listen for other events... **/ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import de.static_interface.sinklibrary.events.IrcReceiveMessageEvent; class TestListener implements Listener { @EventHandler public void onIrcReceiveMessage(IrcReceiveMessageEvent event) { SinkLibrary.sendIrcMessage(event.getMessage()); } } Bukkit.getPluginManager().registerEvents(new TestListener(), plugin);
Permissions
There is only one permission, because if you can execute scripts, you don't need any other permission, because you can give with this even yourself op! So be careful when giving this permission:
sinkscript.execute: Allows to use this plugin
Continuous Integration
Development builds of this project can be acquired at the provided continuous integration server. These builds have not been approved by the
BukkitDev staff. Use them at your own risk. They may be also unstable.
Link: http://ci.static-interface.de/job/SinkScripts/lastBuild/
Source Code
This plugin is Open Source!
http://github.com/adventuria/sinkscripts
Pull Requests are welcome :)