public CommandModule
Command module allows you to register custom commands. Those commands are only available to this game. They won't be accessible from outside. Access to this module is limited to Command-typed scripts.
void setLogVerbosity(boolean verbose)
Set whether or not to print out debugging message inside script log.
void register(@NotNull java.lang.String name, @NotNull io.github.jorelali.commandapi.api.CommandPermission permissions, @Nullable java.lang.String[] aliases, @Nullable java.util.LinkedHashMap<java.lang.String,io.github.jorelali.commandapi.api.arguments.Argument> args, @NotNull CommandHandler handler)
Register a command which is only available in this game.
name
- Name of command without prefix-slash(/).permissions
- Permission applied to whole command.aliases
- Array of possible aliases. (optional, can be null)args
- Command arguments. (optional, can be null)handler
- Definition of command operation.@NotNull org.bukkit.scheduler.BukkitTask repeat(int counter, @NotNull Timer interval, @NotNull java.lang.Runnable task)
Repeat to execute task.
counter
- The number of times to repeat.interval
- The class Timer
of repeating task.task
- The task to be executed.IllegalArgumentException
- is thrown if interval
is less than 1 tick.@NotNull org.bukkit.scheduler.BukkitTask wait(@NotNull Timer delay, @NotNull java.lang.Runnable task)
Wait before executing the task.
delay
- The amount of class Timer
to wait.task
- The task to be executed.IllegalArgumentException
- is thrown if delay
is less than 1 tick.@NotNull java.io.File getFile(@NotNull java.lang.String path)
Returns the File which is silently created if it didn't exist there.
The file is resolved by given path
- a relative path that is joined
to the root folder of the game layout where this module is derived from.
To illustrate this, let's assume that our game 'skywars'
is rooted from 'plugins/CraftGames/skywars/'.
If your path
were 'data/test.txt', then actual outcome would be
'plugins/CraftGames/skywars/data/test.txt'
void readObjectStream(@NotNull java.io.File file, @NotNull java.util.function.Consumer<org.bukkit.util.io.BukkitObjectInputStream> reader)
Read data from your custom getFile
through BukkitObjectInputStream.
You can deserialize file contents into various types of primitive data as well as ConfigurationSerializable objects. i.e. Boolean, String, ItemStack, PotionEffect, etc.
file
- The file to read data from. Use getFile
to get one.reader
- This lends you the InputStream to read stuff.You don't need to flush/close the stream afterwards as plugin does it for you.FileNotFoundException
- is thrown if file
does not exist.getFile
,
BukkitObjectInputStream,
ConfigurationSerializablevoid writeObjectStream(@NotNull java.io.File file, @NotNull java.util.function.Consumer<org.bukkit.util.io.BukkitObjectOutputStream> writer)
Write data to your custom getFile
through BukkitObjectOutputStream.
You can serialize primitive data and ConfigurationSerializable objects to save those into the file.
file
- The file to write data to. Use getFile
to get one.writer
- This lends you the OutputStream to write stuff.You don't need to flush/close the stream afterwards as plugin does it for you.FileNotFoundException
- is thrown if file
does not exist.getFile
,
BukkitObjectOutputStream,
ConfigurationSerializablevoid getYamlConfiguration(@NotNull java.io.File file, @NotNull java.util.function.Consumer<org.bukkit.configuration.file.YamlConfiguration> consumer)
Read or write data of your custom YAML configuration.
file
- The file you want to treat as YAML. Use getFile
to get one.consumer
- This lends you to the YamlConfiguration for you to take control of the file.You don't have to worry about saving the file because the plugin does it for you.