mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-01 23:56:40 +00:00
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:
@ -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);
|
||||
|
@ -3,14 +3,33 @@ package dev.plex.command.annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Storage for a command's parameters
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
/**
|
||||
* The name
|
||||
* @return Name of the command
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* The description
|
||||
* @return Description of the command
|
||||
*/
|
||||
String description() default "";
|
||||
|
||||
/**
|
||||
* The usage (optional)
|
||||
* @return The usage of the command
|
||||
*/
|
||||
String usage() default "/<command>";
|
||||
|
||||
/**
|
||||
* The aliases (optional)
|
||||
* @return The aliases of the command
|
||||
*/
|
||||
String aliases() default "";
|
||||
}
|
@ -5,12 +5,29 @@ import dev.plex.rank.enums.Rank;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Storage for the command's permissions
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
/**
|
||||
* Minimum rank required
|
||||
* @return Minimum rank required for the command
|
||||
* @see Rank
|
||||
*/
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
|
||||
/**
|
||||
* Required command source
|
||||
* @return The required command source of the command
|
||||
* @see RequiredCommandSource
|
||||
*/
|
||||
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||
|
||||
/**
|
||||
* The permission
|
||||
* @return Permission of the command
|
||||
*/
|
||||
String permission() default ""; // No idea what to put here
|
||||
}
|
@ -15,6 +15,8 @@ import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -75,8 +77,8 @@ public class BanCMD extends PlexCommand
|
||||
punishment.setReason("No reason provided.");
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
Date date = new Date();
|
||||
punishment.setEndDate(DateUtils.addDays(date, 1));
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
punishment.setEndDate(date.plusDays(1));
|
||||
punishment.setCustomTime(false);
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(tl("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
|
@ -11,6 +11,8 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -36,8 +38,8 @@ public class FreezeCMD extends PlexCommand
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
Date date = new Date();
|
||||
punishment.setEndDate(DateUtils.addMinutes(date, 5));
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
punishment.setEndDate(date.plusMinutes(5));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setReason("");
|
||||
|
Reference in New Issue
Block a user