- Begin BETA module system

This commit is contained in:
Taah
2022-03-05 17:04:34 -08:00
parent 2804f6bc41
commit 87ddf355b5
6 changed files with 219 additions and 61 deletions

View File

@ -1,37 +1,38 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.module.PlexModule;
import dev.plex.module.PlexModuleFile;
import dev.plex.rank.enums.Rank;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.stream.Collectors;
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
@CommandParameters(name = "plex", usage = "/<command> [reload | redis]", aliases = "plexhelp", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
{
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules] [reload]", aliases = "plexhelp", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand {
// Don't modify this command
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) {
if (args.length == 0) {
send(sender, ChatColor.LIGHT_PURPLE + "Plex - A new freedom plugin.");
send(sender, ChatColor.LIGHT_PURPLE + "Plugin version: " + plugin.getDescription().getVersion());
return componentFromString(ChatColor.LIGHT_PURPLE + "Authors: " + ChatColor.GOLD + "Telesphoreo, Taahh");
}
if (args[0].equalsIgnoreCase("reload"))
{
if (args[0].equalsIgnoreCase("reload")) {
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
plugin.config.load();
send(sender, "Reloaded config file");
@ -43,12 +44,9 @@ public class PlexCMD extends PlexCommand
plugin.getRankManager().importDefaultRanks();
send(sender, "Imported ranks");
send(sender, "Plex successfully reloaded.");
}
else if (args[0].equalsIgnoreCase("redis"))
{
} else if (args[0].equalsIgnoreCase("redis")) {
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
if (!plugin.getRedisConnection().isEnabled())
{
if (!plugin.getRedisConnection().isEnabled()) {
throw new CommandFailException("&cRedis is not enabled.");
}
plugin.getRedisConnection().getJedis().set("test", "123");
@ -56,16 +54,25 @@ public class PlexCMD extends PlexCommand
send(sender, plugin.getRedisConnection().getJedis().get("test"));
plugin.getRedisConnection().getJedis().close();
}
else
{
if (args[0].equalsIgnoreCase("modules")) {
if (args.length == 1) {
return MiniMessage.miniMessage().deserialize("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
}
if (args[1].equalsIgnoreCase("reload")) {
plugin.getModuleManager().unloadModules();
plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules();
plugin.getModuleManager().disableModules();
}
} else {
return usage();
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
return ImmutableList.of("reload", "redis");
}
}