Begin fixing command system

This commit is contained in:
spacerocket62
2022-01-26 21:28:30 -08:00
parent edef4d8558
commit 587ea8f352
27 changed files with 130 additions and 298 deletions

View File

@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.ConsoleOnlyException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.event.AdminAddEvent;
import dev.plex.event.AdminRemoveEvent;
@ -15,44 +14,40 @@ import dev.plex.event.AdminSetRankEvent;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
@CommandParameters(name = "admin", usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
public class AdminCMD extends PlexCommand
{
//TODO: Better return messages
public AdminCMD()
{
super("admin");
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
sender.send(usage(getUsage()));
return;
return usage(getUsage());
}
if (args[0].equalsIgnoreCase("add"))
{
if (args.length != 2)
{
sender.send(usage("/admin add <player>"));
return;
return usage("/admin add <player>");
}
if (!sender.isConsoleSender())
if (!isConsole(sender))
{
sender.send(tl("consoleOnly"));
send(sender, tl("consoleOnly"));
throw new ConsoleOnlyException();
}
@ -66,24 +61,22 @@ public class AdminCMD extends PlexCommand
if (isAdmin(plexPlayer))
{
sender.send(tl("playerIsAdmin"));
return;
return tl("playerIsAdmin");
}
plexPlayer.setRank(Rank.ADMIN.name());
DataUtils.update(plexPlayer);
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
return;
return null;
}
if (args[0].equalsIgnoreCase("remove"))
{
if (args.length != 2)
{
sender.send(usage("/admin remove <player>"));
return;
return usage("/admin remove <player>");
}
if (!sender.isConsoleSender())
if (!isConsole(sender))
{
throw new ConsoleOnlyException();
}
@ -98,25 +91,23 @@ public class AdminCMD extends PlexCommand
if (!isAdmin(plexPlayer))
{
sender.send(tl("playerNotAdmin"));
return;
return tl("playerNotAdmin");
}
plexPlayer.setRank("");
DataUtils.update(plexPlayer);
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
return;
return null;
}
if (args[0].equalsIgnoreCase("setrank"))
{
if (args.length != 3)
{
sender.send(usage("/admin setrank <player> <rank>"));
return;
return usage("/admin setrank <player> <rank>");
}
if (!sender.isConsoleSender())
if (!isConsole(sender))
{
throw new ConsoleOnlyException();
}
@ -130,24 +121,21 @@ public class AdminCMD extends PlexCommand
if (!rankExists(args[2]))
{
sender.send(tl("rankNotFound"));
return;
return tl("rankNotFound");
}
Rank rank = Rank.valueOf(args[2].toUpperCase());
if (!rank.isAtLeast(Rank.ADMIN))
{
sender.send(tl("rankMustBeHigherThanAdmin"));
return;
return tl("rankMustBeHigherThanAdmin");
}
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
if (!isAdmin(plexPlayer))
{
sender.send(tl("playerNotAdmin"));
return;
return tl("playerNotAdmin");
}
plexPlayer.setRank(rank.name().toLowerCase());
@ -155,23 +143,23 @@ public class AdminCMD extends PlexCommand
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
return;
return null;
}
if (args[0].equalsIgnoreCase("list"))
{
if (args.length != 1)
{
sender.send(usage("/admin list"));
return;
return usage("/admin list");
}
sender.send("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
return fromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
}
return null;
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
@ -184,6 +172,7 @@ public class AdminCMD extends PlexCommand
return ImmutableList.of();
}
private boolean rankExists(String rank)
{
for (Rank ranks : Rank.values())

View File

@ -3,39 +3,32 @@ package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
@CommandParameters(aliases = "aw", description = "Teleport to the adminworld")
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand
{
public AdminworldCMD()
{
super("adminworld");
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)
{
Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
sender.getPlayer().teleportAsync(loc);
send(tl("teleportedToWorld", "adminworld"));
((Player)sender).teleportAsync(loc);
return tl("teleportedToWorld", "adminworld");
}
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
{
return Collections.emptyList();
return null;
}
}

View File

@ -5,27 +5,24 @@ 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.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@CommandParameters(aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
@CommandParameters(name = "adventure", aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
public class AdventureCMD extends PlexCommand
{
public AdventureCMD()
{
super("adventure");
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -61,7 +58,7 @@ public class AdventureCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
if (isAdmin(sender.getPlexPlayer()))
{

View File

@ -7,7 +7,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
@ -32,7 +31,7 @@ public class BanCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -80,7 +79,7 @@ public class BanCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args) {
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -5,7 +5,6 @@ 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.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
@ -25,7 +24,7 @@ public class CreativeCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -60,7 +59,7 @@ public class CreativeCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
if (isAdmin(sender.getPlexPlayer()))
{

View File

@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.util.PlexUtils;
import dev.plex.world.BlockMapChunkGenerator;
@ -34,7 +33,7 @@ public class FionnCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
{
@ -125,7 +124,7 @@ public class FionnCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return ImmutableList.of();
}

View File

@ -3,7 +3,6 @@ package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import org.bukkit.Bukkit;
@ -22,7 +21,7 @@ public class FlatlandsCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -33,7 +32,7 @@ public class FlatlandsCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return Collections.emptyList();
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.CommandSource;
import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
@ -29,7 +28,7 @@ public class FreezeCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length != 1)
{
@ -49,7 +48,7 @@ public class FreezeCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}

View File

@ -3,7 +3,6 @@ package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import org.bukkit.Bukkit;
@ -22,7 +21,7 @@ public class MasterbuilderworldCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)
@ -34,7 +33,7 @@ public class MasterbuilderworldCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return Collections.emptyList();
}

View File

@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.CommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import org.json.simple.JSONArray;
@ -29,7 +28,7 @@ public class NameHistoryCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length != 1)
{
@ -73,7 +72,7 @@ public class NameHistoryCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import org.bukkit.Bukkit;
@ -22,7 +21,7 @@ public class OpAllCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{
@ -32,7 +31,7 @@ public class OpAllCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return ImmutableList.of();
}

View File

@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.CommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import org.bukkit.entity.Player;
@ -22,7 +21,7 @@ public class OpCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length != 1)
{
@ -34,7 +33,7 @@ public class OpCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}

View File

@ -5,12 +5,10 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import org.bukkit.ChatColor;
import java.util.Arrays;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@ -21,7 +19,7 @@ public class PlexCMD extends PlexCommand {
}
@Override
public void execute(CommandSource sender, String[] args) {
public Component execute(CommandSender sender, String[] args) {
if (args.length == 0) {
send(ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
send(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
@ -47,7 +45,7 @@ public class PlexCMD extends PlexCommand {
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args) {
public List<String> tabComplete(CommandSender sender, String[] args) {
return List.of("reload");
}
}

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.PunishmentMenu;
import dev.plex.rank.enums.Rank;
@ -23,14 +22,14 @@ public class PunishmentsCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
Player player = sender.getPlayer();
new PunishmentMenu().openInv(player, 0);
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args) {
public List<String> tabComplete(CommandSender sender, String[] args) {
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -3,7 +3,6 @@ package dev.plex.command.impl;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
@ -19,12 +18,12 @@ public class RankCMD extends PlexCommand {
}
@Override
public void execute(CommandSource sender, String[] args) {
public Component execute(CommandSender sender, String[] args) {
send(tl("yourRank", sender.getPlexPlayer().getRank()));
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args) {
public List<String> tabComplete(CommandSender sender, String[] args) {
return null;
}
}

View File

@ -5,7 +5,6 @@ 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.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
@ -25,7 +24,7 @@ public class SpectatorCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -57,7 +56,7 @@ public class SpectatorCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
if (isAdmin(sender.getPlexPlayer()))
{

View File

@ -5,7 +5,6 @@ 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.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
@ -25,7 +24,7 @@ public class SurvivalCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length == 0)
{
@ -60,7 +59,7 @@ public class SurvivalCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
if (isAdmin(sender.getPlexPlayer()))
{

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
@ -21,13 +20,13 @@ public class TestCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
send(tl("variableTest", sender.getName()));
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
if (args.length == 1)
{

View File

@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.CommandSource;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import org.bukkit.Bukkit;
@ -25,7 +24,7 @@ public class WorldCMD extends PlexCommand
}
@Override
public void execute(CommandSource sender, String[] args)
public Component execute(CommandSender sender, String[] args)
{
if (args.length != 1)
{
@ -37,7 +36,7 @@ public class WorldCMD extends PlexCommand
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
public List<String> tabComplete(CommandSender sender, String[] args)
{
List<String> worlds = new ArrayList<>();
for (World world : Bukkit.getWorlds())