-
Notifications
You must be signed in to change notification settings - Fork 1
Core Introduction
DEVIN has a lot to offer as far as making Spigot development a lot simpler and more maintainable, so there are a few helper classes that are part of DEVIN that will be gone over in this introduction. Most of the helper classes will be referred to in other parts of the wiki, so it is a good idea to understand them.
The MessageSender
is an object that tells DEVIN about any info headers and error headers for your messages. It also shortens code when sending messages to CommandSender
's or broadcasting them because the MessageSender
adds the headers for you. You build a MessageSender
like so:
// [INFO] is the info header and [ERROR] is the error header.
MessageSender ms = new MessageSender("[INFO] ", ChatColor.RED + "[ERROR] ");
Using the message sender from above, it can send messages to CommandSender
's, groups of CommandSender
's and broadcast messages.
...
// Sends message to player without any headers.
ms.send(player, "Hello Player!");
// Sends multiple messages to sender with the info header
// using variable parameters.
ms.info(sender, "This is important information.", "You get a free diamond!");
// Sends multiple message to sender with the error header
// using a String array.
String[] errors = new String[]{ "Critical Error!", "Shutting down the server" };
ms.error(sender, errors);
Below is sending messages to a group.
...
// Send group a message without headers.
ms.send({sender0, sender1}, "Hello Everyone!");
// Send group a message with the info headers.
ms.info({sender0, sender1}, "This is important.");
// Send group a message with the error headers.
ms.error({sender0, sender1}, "Fatal error has occurred.");
Below is broadcasting messages.
...
// Broadcasts a message without headers.
ms.broadcast("Hello Everyone!");
// Broadcasts a message with the info headers.
ms.info("This is important.");
// Broadcasts a message with the error headers.
ms.error("Fatal error has occurred.");
CommandUtils
is a class that does not need to be instantiated, but provides some utilities that are common when building commands such as pagination and combining arguments that are in quotes.
Pagination is taking a long list of strings (or array of strings) and separating them by pages. This is useful when you have a lot of information such as the /help
. This command separates all the commands into pages, so it doesn't fill up the screen.
This array will be paginated with a page length of 3.
Original
Array |
---|
Hello World |
This is cool |
Look at this! |
New Page :) |
Hello Universe! |
Goodbye Page 2 |
Paginated
Page 0 | Page 1 |
---|---|
Hello World | New Page :) |
This is cool | Hello Universe! |
Look at this! | Goodbye Page 2 |
String[] book = {
"Hello World",
"This is cool",
"Look at this!",
"New Page :)",
"Hello Universe!",
"Goodbye Page 2"
}
String[] page0 = CommandUtils.pagination(book, /* Page Length */ 3, /* Page Number */ 0);
String[] page1 = CommandUtils.pagination(book, 3, 1)
If a page number higher than the number of pages or lower than 0 is used, the method just clamps it to the closest page.
When you stringify and arguments array, it combines all the arguments that are inside '
or "
into a single argument and returns the new argument array with the combined values.
Original "notch", "\"Hello", "World\"", "'Hello", "notch", "on", "this", "lovely", "day!'"
Stringified "notch", "Hello World", "Hello notch on this lovely day!"
This is very useful when single arguments are allowed to have spaces in them.
String[] args = { "notch", "\"Hello", "World\"", "'Hello", "notch", "on", "this", "lovely", "day!'" };
String[] stringifiedArgs = CommandUtils.stringify(args);