Add documentation to dev.plex.admin, dev.plex.banning, dev.plex.cache, and dev.plex.command (annotations and PlexCommand.java only)

Convert Date in punishments to LocalDateTime
This commit is contained in:
spacerocket62
2022-02-05 15:14:23 -08:00
parent 5e64e5e1b5
commit 211308e813
17 changed files with 426 additions and 40 deletions

View File

@ -26,16 +26,39 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.UUID;
/**
* Superclass for all commands
*/
public abstract class PlexCommand extends Command implements PluginIdentifiableCommand
{
/**
* Returns the instance of the plugin
*/
protected static Plex plugin = Plex.get();
/**
* The parameters for the command
*/
private final CommandParameters params;
/**
* The permissions for the command
*/
private final CommandPermissions perms;
/**
* Minimum required rank fetched from the permissions
*/
private final Rank level;
/**
* Required command source fetched from the permissions
*/
private final RequiredCommandSource commandSource;
/**
* Creates an instance of the command
*/
public PlexCommand()
{
super("");
@ -56,9 +79,19 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
getMap().register("plex", this);
}
/**
* Executes the command
* @param sender The sender of the command
* @param playerSender The player who executed the command (null if command source is console or if command source is any but console executed)
* @param args A Kyori Component to send to the sender (can be null)
* @return
*/
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
/**
* @hidden
*/
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
{
@ -158,6 +191,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Checks if the string given is a command string
* @param label The string to check
* @return true if the string is a command name or alias
*/
private boolean matches(String label)
{
if (params.aliases().split(",").length > 0)
@ -176,31 +214,63 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return false;
}
/**
* Gets a PlexPlayer from Player object
* @param player The player object
* @return PlexPlayer Object
* @see PlexPlayer
*/
protected PlexPlayer getPlexPlayer(@NotNull Player player)
{
return DataUtils.getPlayer(player.getUniqueId());
}
/**
* Sends a message to an audience
* @param audience The audience to send the message to
* @param s The message to send
*/
protected void send(Audience audience, String s)
{
audience.sendMessage(componentFromString(s));
}
/**
* Sends a message to an audience
* @param audience The audience to send the message to
* @param component The component to send
*/
protected void send(Audience audience, Component component)
{
audience.sendMessage(component);
}
/**
* Checks whether a sender has enough permissions or is high enough a rank
* @param sender A command sender
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
* @see Rank
*/
protected boolean checkRank(CommandSender sender, Rank rank, String permission)
{
if (!isConsole(sender))
{
checkRank((Player) sender, rank, permission);
return true;
return checkRank((Player) sender, rank, permission);
// return true;
}
return true;
}
/**
* Checks whether a player has enough permissions or is high enough a rank
* @param player The player object
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
* @see Rank
*/
protected boolean checkRank(Player player, Rank rank, String permission)
{
PlexPlayer plexPlayer = getPlexPlayer(player);
@ -220,11 +290,22 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return true;
}
/**
* Checks if a player is an admin
* @param plexPlayer The PlexPlayer object
* @return true if the player is an admin
* @see PlexPlayer
*/
protected boolean isAdmin(PlexPlayer plexPlayer)
{
return Plex.get().getRankManager().isAdmin(plexPlayer);
}
/**
* Checks if a sender is an admin
* @param sender A command sender
* @return true if the sender is an admin or if console
*/
protected boolean isAdmin(CommandSender sender)
{
if (!(sender instanceof Player player))
@ -235,12 +316,22 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return plugin.getRankManager().isAdmin(plexPlayer);
}
/**
* Checks if a username is an admin
* @param name The username
* @return true if the username is an admin
*/
protected boolean isAdmin(String name)
{
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
return plugin.getRankManager().isAdmin(plexPlayer);
}
/**
* Checks if a sender is a senior admin
* @param sender A command sender
* @return true if the sender is a senior admin or if console
*/
protected boolean isSeniorAdmin(CommandSender sender)
{
if (!(sender instanceof Player player))
@ -251,6 +342,12 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return plugin.getRankManager().isSeniorAdmin(plexPlayer);
}
/**
* Gets the UUID of the sender
* @param sender A command sender
* @return A unique ID or null if the sender is console
* @see UUID
*/
protected UUID getUUID(CommandSender sender)
{
if (!(sender instanceof Player player))
@ -260,23 +357,43 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return player.getUniqueId();
}
/**
* The plugin
* @return The instance of the plugin
* @see Plex
*/
@Override
public @NotNull Plugin getPlugin()
public @NotNull Plex getPlugin()
{
return plugin;
}
/**
* Checks whether a sender is console
* @param sender A command sender
* @return true if the sender is console
*/
protected boolean isConsole(CommandSender sender)
{
return !(sender instanceof Player);
}
/**
* Converts a message entry from the "messages.yml" to a component
* @param s The message entry
* @param objects Any objects to replace in order
* @return A kyori component
*/
protected Component tl(String s, Object... objects)
{
return componentFromString(PlexUtils.tl(s, objects));
}
/**
* Converts usage to a component
* @param s The usage to convert
* @return A kyori component stating the usage
*/
protected Component usage(String s)
{
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s);
@ -323,6 +440,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return world;
}
/**
* Converts a string to a legacy kyori component
* @param s The string to convert
* @return A kyori component
*/
protected Component componentFromString(String s)
{
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);