2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.command.impl;
|
2020-10-31 08:55:27 +00:00
|
|
|
|
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;
|
2022-02-04 08:18:07 +00:00
|
|
|
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;
|
2022-04-19 20:49:21 +00:00
|
|
|
import dev.plex.util.BuildInfo;
|
2022-04-07 03:55:54 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-04-22 02:26:51 +00:00
|
|
|
import dev.plex.util.TimeUtils;
|
2022-01-27 09:00:50 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-06-08 20:09:42 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-05-13 22:43:42 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2022-02-04 04:01:30 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-02-04 04:49:05 +00:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-10-31 08:55:27 +00:00
|
|
|
|
2023-03-08 20:26:10 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2023-08-25 11:07:56 +00:00
|
|
|
@CommandPermissions(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
|
2020-10-31 08:55:27 +00:00
|
|
|
@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."));
|
2022-04-19 20:49:21 +00:00
|
|
|
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getHead()));
|
2022-03-17 22:16:17 +00:00
|
|
|
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
2022-04-19 20:49:21 +00:00
|
|
|
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
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."));
|
2022-04-08 05:01:02 +00:00
|
|
|
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2);
|
2022-03-17 22:16:17 +00:00
|
|
|
return null;
|
2022-01-04 03:04:39 +00:00
|
|
|
}
|
2022-03-06 06:43:37 +00:00
|
|
|
if (args[0].equalsIgnoreCase("reload"))
|
|
|
|
{
|
2023-08-25 11:07:56 +00:00
|
|
|
checkPermission(sender, "plex.reload");
|
2022-03-01 01:44:10 +00:00
|
|
|
plugin.config.load();
|
2022-01-27 09:00:50 +00:00
|
|
|
send(sender, "Reloaded config file");
|
2022-03-01 01:44:10 +00:00
|
|
|
plugin.messages.load();
|
2022-01-27 09:00:50 +00:00
|
|
|
send(sender, "Reloaded messages file");
|
2022-03-05 23:44:38 +00:00
|
|
|
plugin.indefBans.load(false);
|
2022-03-01 01:44:10 +00:00
|
|
|
plugin.getPunishmentManager().mergeIndefiniteBans();
|
2022-02-28 06:28:00 +00:00
|
|
|
send(sender, "Reloaded indefinite bans");
|
2022-04-10 07:25:14 +00:00
|
|
|
plugin.commands.load();
|
2022-04-08 05:16:05 +00:00
|
|
|
send(sender, "Reloaded blocked commands file");
|
2023-08-25 11:07:56 +00:00
|
|
|
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
2022-04-11 00:22:22 +00:00
|
|
|
{
|
2022-04-13 02:20:56 +00:00
|
|
|
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
2022-04-11 00:22:22 +00:00
|
|
|
}
|
2022-04-07 02:05:29 +00:00
|
|
|
plugin.getServiceManager().endServices();
|
|
|
|
plugin.getServiceManager().startServices();
|
2022-04-22 02:26:51 +00:00
|
|
|
send(sender, "Restarted services.");
|
2022-04-19 21:49:45 +00:00
|
|
|
TimeUtils.TIMEZONE = plugin.config.getString("server.timezone");
|
|
|
|
send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
2022-04-08 05:16:05 +00:00
|
|
|
send(sender, "Plex successfully reloaded.");
|
2022-03-17 22:16:17 +00:00
|
|
|
return null;
|
2022-04-13 02:22:17 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("redis"))
|
2022-03-06 06:43:37 +00:00
|
|
|
{
|
2023-08-25 11:07:56 +00:00
|
|
|
checkPermission(sender, "plex.redis");
|
2022-03-06 06:43:37 +00:00
|
|
|
if (!plugin.getRedisConnection().isEnabled())
|
|
|
|
{
|
2022-02-04 08:18:07 +00:00
|
|
|
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-04-13 02:22: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"))
|
|
|
|
{
|
2023-08-25 11:07:56 +00:00
|
|
|
checkPermission(sender, "plex.modules.reload");
|
2022-04-22 02:26:51 +00:00
|
|
|
plugin.getModuleManager().reloadModules();
|
2022-04-07 04:49:45 +00:00
|
|
|
return mmString("<green>All modules reloaded!");
|
2022-03-06 01:04:34 +00:00
|
|
|
}
|
2022-04-22 02:26:51 +00:00
|
|
|
else if (args[1].equalsIgnoreCase("update"))
|
|
|
|
{
|
2022-05-13 03:45:17 +00:00
|
|
|
if (!hasUpdateAccess(playerSender, sender))
|
2022-04-22 02:26:51 +00:00
|
|
|
{
|
2023-08-29 20:46:21 +00:00
|
|
|
return messageComponent("noPermissionRank", "a Developer");
|
2022-04-22 02:26:51 +00:00
|
|
|
}
|
|
|
|
for (PlexModule module : plugin.getModuleManager().getModules())
|
|
|
|
{
|
|
|
|
plugin.getUpdateChecker().updateJar(sender, module.getPlexModuleFile().getName(), true);
|
|
|
|
}
|
|
|
|
plugin.getModuleManager().reloadModules();
|
|
|
|
return mmString("<green>All modules updated and reloaded!");
|
|
|
|
}
|
2022-04-13 02:22:17 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("update"))
|
2022-04-07 03:55:54 +00:00
|
|
|
{
|
2022-05-13 03:45:17 +00:00
|
|
|
if (!hasUpdateAccess(playerSender, sender))
|
2022-04-07 03:55:54 +00:00
|
|
|
{
|
2023-08-29 20:46:21 +00:00
|
|
|
return messageComponent("noPermissionRank", "a Developer");
|
2022-04-07 03:55:54 +00:00
|
|
|
}
|
2022-04-08 05:01:02 +00:00
|
|
|
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
|
2022-04-07 04:08:03 +00:00
|
|
|
{
|
2022-04-07 04:49:45 +00:00
|
|
|
return mmString("<red>Plex is already up to date!");
|
2022-04-07 04:08:03 +00:00
|
|
|
}
|
2022-04-22 02:26:51 +00:00
|
|
|
plugin.getUpdateChecker().updateJar(sender, "Plex", false);
|
|
|
|
return mmString("<red>Alert: Restart the server for the new JAR file to be applied.");
|
2022-04-13 02:22:17 +00:00
|
|
|
}
|
|
|
|
else
|
2022-03-06 06:43:37 +00:00
|
|
|
{
|
2022-02-14 05:55:50 +00:00
|
|
|
return usage();
|
2022-01-04 03:04:39 +00:00
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
return null;
|
2020-10-31 08:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
{
|
2022-03-18 01:18:35 +00:00
|
|
|
if (args.length == 1)
|
2022-03-17 22:16:17 +00:00
|
|
|
{
|
2022-03-18 01:18:35 +00:00
|
|
|
return Arrays.asList("reload", "redis", "modules");
|
2022-04-13 02:22:17 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("modules"))
|
2022-03-17 22:16:17 +00:00
|
|
|
{
|
2022-03-18 01:18:35 +00:00
|
|
|
return List.of("reload");
|
2022-03-17 22:16:17 +00:00
|
|
|
}
|
|
|
|
return Collections.emptyList();
|
2020-10-31 08:55:27 +00:00
|
|
|
}
|
2022-05-13 03:45:17 +00:00
|
|
|
|
2022-05-13 22:43:42 +00:00
|
|
|
// Owners and developers only have access
|
2022-05-13 03:45:17 +00:00
|
|
|
private boolean hasUpdateAccess(Player player, CommandSender sender)
|
|
|
|
{
|
2022-05-13 22:43:42 +00:00
|
|
|
// Allow CONSOLE, get OfflinePlayer for Telnet
|
2022-05-13 03:45:17 +00:00
|
|
|
if (isConsole(sender))
|
|
|
|
{
|
2022-05-13 22:43:42 +00:00
|
|
|
if (sender.getName().equalsIgnoreCase("CONSOLE"))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.getName());
|
|
|
|
if (offlinePlayer.hasPlayedBefore())
|
|
|
|
{
|
2023-08-29 20:46:21 +00:00
|
|
|
return PlexUtils.DEVELOPERS.contains(offlinePlayer.getUniqueId().toString());
|
2022-05-13 22:43:42 +00:00
|
|
|
}
|
2022-05-13 03:45:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
assert player != null;
|
2023-08-29 20:46:21 +00:00
|
|
|
return PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString());
|
2022-05-13 03:45:17 +00:00
|
|
|
}
|
2020-11-06 03:50:16 +00:00
|
|
|
}
|