Global Functions and Variables
This document details all of the global functions and variables built into the buscript engine.
Global Functions
broadcast
void broadcast(String message)
- This function broadcasts the given message to all players on the server.
- usage: broadcast("Hello, server")
- usage: broadcast("Thanks for voting, %target%!")
broadcastPerm
void broadcastPerm(String message, String permission)
- This function broadcasts the given message to players on the server with the given permission.
- usage: broadcastPerm("Hello, some of you", "some.permission")
command
void command(String command)
- This function runs a command on the server as if run through console. Please leave out the preceding slash.
- usage: command("op someplayer")
- usage: command("kick %target%")
commandSpoof
void commandSpoof(String player, String command)
- This function runs a command on the server as if run by the given player. The player must be online or nothing will happen.
- usage: commandSpoof("someplayer", "help")
- usage: commandSpoof("%target%", "/suicide")
message
void message(String player, String message)
- This function messages the given player with the given message. The player must be online or nothing will happen.
- usage: message("%target%", "Best be respectin'")
isOnline
boolean isOnline(String player)
- This function returns true if the given player is online and false otherwise.
- usage: isOnline("someplayer")
- usage: isOnline("%target%")
run
void run(String script)
- This function executes the given script which should be the file name of an existing script in the plugin's script folder.
- usage: run("somescript.txt")
runTarget
void runTarget(String script, String target)
- This function executes the given script with the given player target.
- The given script should be the file name of an existing script in the plugin's script folder.
- The given target will be the name that fills in the target variable as well as replaces the "%target%" string when the new script is run.
- usage: runTarget("somescript.txt", "%target%")
runLater
void runLater(String script, String delay)
- This function executes the given script after the given delay.
- The given delay should be formatted as such: 1d5h29m45s which indicates a delay of 1 day, 5 hours, 29 minutes and 45 seconds. Any amount shorter will suffice as well such as 5m for simply 5 minutes.
- The given script should be the file name of an existing script in the plugin's script folder.
- usage: runLater("somescript.txt", "30s")
runLaterTarget
void runLaterTarget(String script, String delay, String target)
- This function executes the given script with the given player target after the given delay.
- The given script should be the file name of an existing script in the plugin's script folder.
- The given delay should be formatted as such: 1d5h29m45s which indicates a delay of 1 day, 5 hours, 29 minutes and 45 seconds. Any amount shorter will suffice as well such as 5m for simply 5 minutes.
- The given target will be the name that fills in the target variable as well as replaces the "%target%" string when the new script is run.
- usage: runLaterTarget("somescript.txt", "1m45s", "%target%")
clearScripts
void clearScripts(String target)
- This function removes any scripts that are waiting to be executed for the target.
- usage: clearScripts("%target%")
stringReplace
String stringReplace(String string)
- This function returns a string where all instances of strings that should be replaced (such as "%target%") are replaced with their proper value within :the given string.
- usage: if (stringReplace("%target%") == "dumptruckman") { do stuff }
registerEvent
void registerEvent(String event, String priority, String script)
- This function will register the given script to a listener for the given event at the given priority.
- event should be the fully realized class name for a Bukkit event.
- priority is the string form of Bukkit's EventPriority.
- When the given script is run, a variable event will be available that contains the details of the event.
- usage: registerEvent("org.bukkit.event.entity.PlayerDeathEvent", "NORMAL", "player-died.txt")
hasPerm
boolean hasPerm(String player, String permission)
- This function returns true if the given player has the given permission and false otherwise. The player must be online or this will always return false.
- usage: hasPerm("%target%", "some.permission")
Vault Functions
hasPermOffline
boolean hasPermOffline(String world, String player, String permission)
- This function returns true if the given player has the given permission for the given world and false otherwise. This works for offline players.
- requires: Vault
- usage: hasPermOffline("world_nether", "%target%", "some.permission")
addPerm
boolean addPerm(String world, String player, String permission)
- This function grants the given permission to the given player for the given world.
- requires: Vault
- usage: addPerm("world_nether", "%target%", "some.permission")
removePerm
boolean removePerm(String world, String player, String permission)
- This function removes the given permission from the given player for the given world.
- requires: Vault
- usage: removePerm("world_nether", "%target%", "some.permission")
hasMoney
boolean hasMoney(String player, Double money)
- This function returns true if the given player has the given amount of money and false otherwise.
- requires: Vault
- usage: hasMoney("%target%", 20.0)
addMoney
boolean addMoney(String player, Double money)
- This function gives the given amount of money to the given player and returns true if successful and false otherwise.
- requires: Vault
- usage: addMoney("%target%", 20.0)
removeMoney
boolean removeMoney(String player, Double money)
- This function takes the given amount of money from the given player and returns true if successful and false otherwise.
- requires: Vault
- usage: removeMoney("%target%", 20.0)
Global Variables
Generally, these variables allow for much more advanced scripts to be created.
target
target
- This variable contains the name of the current script's target.
- This will have to be used in place of "%target%" for everything outside of the functions listed above.
server
server
- This variable contains the actual Bukkit server which has all the same methods available to it as if you were writing an actual plugin.
- The javadocs for this are available here http://jd.bukkit.org/apidocs/org/bukkit/Server.html
- usage: server.getOnlinePlayers()
plugin
plugin
- This variable contains the Bukkit Plugin that is implementing buscript.
- The javadocs for this are available here http://jd.bukkit.org/apidocs/org/bukkit/plugin/Plugin.html
- usage: plugin.getDataFolder()
NULL
NULL
- A string that represents what is used to replace replacement strings (such as "%target%") when the value they represent is null.
- usage: if (stringReplace("%target%") == NULL) { there's no target }
metaData
metaData
- This variable functions exactly like a Java map (java.util.Map). This data will be available in the global script environment and will be saved for use in scheduled (runLater) scripts. When a scheduled script runs, this data will be replaced by the contents when the script was scheduled.
- Important! Since this data is persisted via Bukkit's Yaml Configuration, any data stored within MUST be serializable as such or problems will likely occur.
Vault Variables
economy
economy
- This contains the Economy module for Vault. This will not be available if Vault is not on the server.
permissions
permissions
- This contains the Permission module for Vault. This will not be available if Vault is not on the server.
chat
chat
- This contains the Chat module for Vault. This will not be available if Vault is not on the server.
So, in testing this out:
commandSpoof("%target%", "/island")
I get an "Unknown command. Type /help for help." message.
I know the command /island does work, because if I enter it myself, it runs fine.
The script above also works, because if I replace /island with /help, then it works.
Any idea why it wont read the /island command? (The plugin is aSkyBlock)
Thanks
I haven't touch these scripts in ages but try "island" rather than "/island".
I have a question regarding the clearScripts() function. It doesn't seem to work when using the %target% variable as shown in the example above; the scheduled scripts do not get cleared for the player. However it does work when inputting the player's name directly.
Do you have any idea how I could make this work with the %target% variable?
Thanks in advance.