Improve documentation

This commit is contained in:
KingRainbow44 2022-06-10 21:52:05 -04:00
parent 5ae1fcbfea
commit 104ea01d25
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 48 additions and 7 deletions

View File

@ -1,13 +1,23 @@
package xyz.grasscutters.pltm;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.EventHandler;
import emu.grasscutter.server.event.HandlerPriority;
import emu.grasscutter.server.event.player.PlayerJoinEvent;
import xyz.grasscutters.pltm.objects.PluginConfig;
/**
* A class containing all event handlers.
*
* Syntax in event handler methods are similar to CraftBukkit.
* To register an event handler, create a new instance of {@link EventHandler}.
* Pass through the event class you want to handle. (ex. `new EventHandler<>(PlayerJoinEvent.class);`)
* From this class, invoke {@link EventHandler#register()} to register the handler.
* You can change the point at which the handler method is invoked with {@link EventHandler#priority(HandlerPriority)}.
* You can set whether the handler method should be invoked when another plugin cancels the event with {@link EventHandler#ignore(boolean)}.
*/
public final class EventListeners {
/* Saves the configuration to a local variable, reducing calls made to the plugin instance. */
private static final PluginConfig config = PluginTemplate.getInstance().getConfiguration();
/**
@ -15,9 +25,9 @@ public final class EventListeners {
* @param event PlayerJoinEvent.
*/
public static void onJoin(PlayerJoinEvent event) {
if(!config.sendJoinMessage) return;
if(!config.sendJoinMessage) return; // Check if the plugin is configured to send a message when a player joins.
Player player = event.getPlayer();
player.dropMessage(config.joinMessage);
Player player = event.getPlayer(); // Get the player who joined from the event.
player.dropMessage(config.joinMessage); // "Drop" the player a message.
}
}

View File

@ -5,7 +5,9 @@ import emu.grasscutter.plugin.Plugin;
import emu.grasscutter.server.event.EventHandler;
import emu.grasscutter.server.event.HandlerPriority;
import emu.grasscutter.server.event.player.PlayerJoinEvent;
import xyz.grasscutters.pltm.objects.PluginConfig;
import xyz.grasscutters.pltm.commands.*;
import xyz.grasscutters.pltm.objects.*;
import java.io.*;
import java.util.stream.Collectors;
@ -63,6 +65,9 @@ public final class PluginTemplate extends Plugin {
} catch (IOException exception) {
this.getLogger().error("Failed to create config file.", exception);
}
// Log a plugin status message.
this.getLogger().info("The example plugin has been loaded.");
}
/**
@ -74,13 +79,20 @@ public final class PluginTemplate extends Plugin {
.priority(HandlerPriority.LOW)
.listener(EventListeners::onJoin)
.register();
// Register commands.
this.getHandle().registerCommand(new ExampleCommand());
// Log a plugin status message.
this.getLogger().info("The example plugin has been enabled.");
}
/**
* This method is called when the plugin is disabled.
*/
@Override public void onDisable() {
// Log a plugin status message.
this.getLogger().info("The example plugin has been disabled.");
}
/**

View File

@ -1,9 +1,28 @@
package xyz.grasscutters.pltm.objects;
import com.google.gson.Gson;
import java.io.Reader;
import java.lang.reflect.Type;
/**
* A data container for the plugin configuration.
*
* This class is used in conjunction with {@link Gson#toJson(Object)} and {@link Gson#fromJson(Reader, Type)}.
* With {@link Gson}, it is possible to save and load configuration values from a JSON file.
*
* You can set property defaults using `public Object property = (default value);`.
* Use {@link Gson#fromJson(Reader, Type)} to load the values set from a reader/string into a new instance of this class.
*/
public final class PluginConfig {
public boolean sendJoinMessage;
public String joinMessage;
public boolean sendJoinMessage = true;
public String joinMessage = "Welcome to the server!";
/**
* When saved with {@link Gson#toJson(Object)}, it produces:
* {
* "sendJoinMessage": true,
* "joinMessage": "Welcome to the server!"
* }
*/
}