Plex/src/main/java/dev/plex/command/impl/PlexCMD.java

106 lines
4.4 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.command.impl;
2022-03-26 21:36:29 +00:00
import dev.plex.Plex;
2022-01-04 03:04:39 +00:00
import dev.plex.command.PlexCommand;
2021-01-03 07:21:15 +00:00
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
2021-01-03 07:21:15 +00:00
import dev.plex.command.source.RequiredCommandSource;
2022-03-06 01:04:34 +00:00
import dev.plex.module.PlexModule;
import dev.plex.module.PlexModuleFile;
2021-01-03 07:21:15 +00:00
import dev.plex.rank.enums.Rank;
import java.util.Arrays;
2022-03-17 22:16:17 +00:00
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
2022-03-06 01:04:34 +00:00
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
2022-03-06 06:43:37 +00:00
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
{
2022-03-01 01:44:10 +00:00
// Don't modify this command
2022-03-26 21:36:29 +00:00
Plex.BuildProperties build = new Plex.BuildProperties();
@Override
2022-03-06 06:43:37 +00:00
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
2022-03-17 22:16:17 +00:00
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion()));
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
2022-03-26 21:36:29 +00:00
send(sender, mmString("<light_purple>Build: <gold>" + build.number));
2022-03-17 22:16:17 +00:00
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
return null;
2022-01-04 03:04:39 +00:00
}
2022-03-06 06:43:37 +00:00
if (args[0].equalsIgnoreCase("reload"))
{
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
2022-03-01 01:44:10 +00:00
plugin.config.load();
send(sender, "Reloaded config file");
2022-03-01 01:44:10 +00:00
plugin.messages.load();
send(sender, "Reloaded messages file");
plugin.indefBans.load(false);
2022-03-01 01:44:10 +00:00
plugin.getPunishmentManager().mergeIndefiniteBans();
send(sender, "Reloaded indefinite bans");
2022-03-01 01:44:10 +00:00
plugin.getRankManager().importDefaultRanks();
send(sender, "Imported ranks");
send(sender, "Plex successfully reloaded.");
2022-03-17 22:16:17 +00:00
return null;
2022-03-06 06:43:37 +00:00
}
else if (args[0].equalsIgnoreCase("redis"))
{
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
2022-03-06 06:43:37 +00:00
if (!plugin.getRedisConnection().isEnabled())
{
throw new CommandFailException("&cRedis is not enabled.");
}
plugin.getRedisConnection().getJedis().set("test", "123");
send(sender, "Set test to 123. Now outputting key test...");
send(sender, plugin.getRedisConnection().getJedis().get("test"));
2022-02-04 19:30:05 +00:00
plugin.getRedisConnection().getJedis().close();
2022-03-17 22:16:17 +00:00
return null;
}
2022-03-17 22:16:17 +00:00
else if (args[0].equalsIgnoreCase("modules"))
2022-03-06 06:43:37 +00:00
{
if (args.length == 1)
{
2022-03-17 22:16:17 +00:00
return mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
2022-03-06 01:04:34 +00:00
}
2022-03-06 06:43:37 +00:00
if (args[1].equalsIgnoreCase("reload"))
{
checkRank(sender, Rank.SENIOR_ADMIN, "plex.modules.reload");
2022-03-06 01:04:34 +00:00
plugin.getModuleManager().unloadModules();
plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules();
return componentFromString("All modules reloaded!");
2022-03-06 01:04:34 +00:00
}
2022-03-06 06:43:37 +00:00
}
else
{
return usage();
2022-01-04 03:04:39 +00:00
}
return null;
}
@Override
2022-03-06 06:43:37 +00:00
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
2022-03-17 22:16:17 +00:00
{
return Arrays.asList("reload", "redis", "modules");
2022-03-17 22:16:17 +00:00
}
else if (args[0].equalsIgnoreCase("modules"))
2022-03-17 22:16:17 +00:00
{
return List.of("reload");
2022-03-17 22:16:17 +00:00
}
return Collections.emptyList();
}
}