Add Player field to all commands, add readable string to ranks

This commit is contained in:
Telesphoreo 2022-02-03 22:49:05 -06:00
parent 081a702c70
commit 753dba8986
27 changed files with 91 additions and 38 deletions

View File

@ -23,6 +23,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
@CommandParameters(name = "admin", usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
@ -31,7 +32,7 @@ public class AdminCMD extends PlexCommand
//TODO: Better return messages
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -10,13 +10,15 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)

View File

@ -15,6 +15,7 @@ import org.bukkit.GameMode;
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.gamemode.adventure", source = RequiredCommandSource.ANY)
@CommandParameters(name = "adventure", aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
@ -22,7 +23,7 @@ public class AdventureCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -23,6 +23,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
@ -30,7 +31,7 @@ import org.jetbrains.annotations.NotNull;
public class BanCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -15,13 +15,14 @@ import org.bukkit.GameMode;
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.gamemode.creative", source = RequiredCommandSource.ANY)
@CommandParameters(name = "creative", aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
public class CreativeCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -9,13 +9,15 @@ import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "deopall", description = "Deop everyone on the server", aliases = "deopa")
@CommandPermissions(level = Rank.ADMIN)
public class DeopAllCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{

View File

@ -12,13 +12,14 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
public class DeopCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -10,6 +10,8 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
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.flatlands", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
@ -17,7 +19,7 @@ public class FlatlandsCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -19,13 +19,14 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
public class FreezeCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -11,13 +11,15 @@ import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "list", description = "Show a list of all online players")
@CommandPermissions(level = Rank.OP, permission = "plex.list")
public class ListCMD extends PlexCommand
{
@Override
protected Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
Component component = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)

View File

@ -3,17 +3,20 @@ 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.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
@CommandPermissions(level = Rank.OP, permission = "plex.spawnpoint")
@CommandPermissions(level = Rank.OP, permission = "plex.spawnpoint", source = RequiredCommandSource.IN_GAME)
public class LocalSpawnCMD extends PlexCommand
{
@Override
protected Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
return tl("teleportedToWorldSpawn");

View File

@ -10,6 +10,8 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
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.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
@ -17,7 +19,7 @@ public class MasterbuilderworldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
// TODO: Add adminworld settings
if (args.length == 0)

View File

@ -23,6 +23,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
@ -31,7 +32,7 @@ public class NameHistoryCMD extends PlexCommand
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' HH:mm:ss");
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -9,13 +9,15 @@ import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "opall", description = "Op everyone on the server", aliases = "opa")
@CommandPermissions(level = Rank.ADMIN)
public class OpAllCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
for (Player player : Bukkit.getOnlinePlayers())
{

View File

@ -12,13 +12,14 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "op", description = "Op a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.OP)
public class OpCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -14,14 +14,14 @@ import org.bukkit.ChatColor;
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)
@CommandParameters(name = "plex", usage = "/<command> [reload]", aliases = "plexhelp", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -13,13 +13,14 @@ import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
public class PunishmentsCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
new PunishmentMenu().openInv(((Player)sender), 0);
return null;

View File

@ -4,10 +4,13 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
// TODO: See ranks of other players
@ -16,8 +19,10 @@ import org.bukkit.entity.Player;
public class RankCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
return tl("yourRank", getPlexPlayer(playerSender).getLoginMSG());
PlexPlayer plexPlayer = getPlexPlayer(playerSender);
Rank rank = plugin.getRankManager().getRankFromString(plexPlayer.getRank());
return tl("yourRank", rank.getReadableString());
}
}

View File

@ -15,13 +15,14 @@ import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
@CommandParameters(name = "spectator", aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode")
public class SpectatorCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -15,13 +15,14 @@ import org.bukkit.GameMode;
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.gamemode.survival", source = RequiredCommandSource.ANY)
@CommandParameters(name = "survival", aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
public class SurvivalCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
public class UnbanCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
public Component execute(@NotNull CommandSender sender, @NotNull Player playerSender, String[] args)
{
if (args.length == 0)
{

View File

@ -16,13 +16,14 @@ import org.bukkit.World;
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.world", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand
{
@Override
public Component execute(CommandSender sender, Player playerSender, String[] args)
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length != 1)
{

View File

@ -10,12 +10,14 @@ public class DefaultRankObj
{
private final String prefix;
private final String loginMSG;
private final String readableName;
private final List<String> permissions;
public DefaultRankObj(Rank rank)
{
this.prefix = rank.getPrefix();
this.loginMSG = rank.getLoginMSG();
this.readableName = rank.getReadableString();
this.permissions = Lists.newArrayList();
permissions.add("example.permission");
}

View File

@ -89,8 +89,8 @@ public class RankManager
}
rank.setLoginMessage(rankObj.getJSONObject(rank.name().toUpperCase()).getString("loginMSG"));
rank.setPrefix(rankObj.getJSONObject(rank.name().toUpperCase()).getString("prefix")); //should i even be doing this
rank.setHumanReadableString(rankObj.getJSONObject(rank.name().toUpperCase()).getString("readableName")); // i dont know
rank.setPermissions(rankObj.getJSONObject(rank.name().toUpperCase()).getJSONArray("permissions").toList().stream().map(Object::toString).collect(Collectors.toList()));
}
}
catch (IOException e)

View File

@ -6,22 +6,24 @@ import org.bukkit.ChatColor;
public enum Rank
{
IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", ChatColor.YELLOW + "[Imp]"),
NONOP(0, "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""),
OP(1, "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"),
ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"),
SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"),
EXECUTIVE(4, "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]");
IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", "Impostor", ChatColor.YELLOW + "[Imp]"),
NONOP(0, "a " + ChatColor.WHITE + "Non-Op", "Non-Op", ChatColor.WHITE + ""),
OP(1, "an " + ChatColor.GREEN + "Operator", "Operator", ChatColor.GREEN + "[OP]"),
ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", "Admin", ChatColor.DARK_GREEN + "[Admin]"),
SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", "Senior Admin", ChatColor.GOLD + "[SrA]"),
EXECUTIVE(4, "an " + ChatColor.RED + "Executive", "Executive", ChatColor.RED + "[Exec]");
private final int level;
private String loginMessage;
private String readable;
private String prefix;
private int level;
private List<String> permissions;
Rank(int level, String loginMessage, String prefix)
Rank(int level, String loginMessage, String readable, String prefix)
{
this.level = level;
this.loginMessage = loginMessage;
this.readable = readable;
this.prefix = prefix;
this.permissions = Lists.newArrayList();
}
@ -41,6 +43,11 @@ public enum Rank
return level;
}
public String getReadableString()
{
return readable;
}
public void setLoginMessage(String msg)
{
this.loginMessage = msg;
@ -51,6 +58,11 @@ public enum Rank
this.prefix = prefix;
}
public void setHumanReadableString(String readable)
{
this.readable = readable;
}
public boolean isAtLeast(Rank rank)
{
return getLevel() >= rank.getLevel();

View File

@ -4,18 +4,20 @@ import org.bukkit.ChatColor;
public enum Title
{
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[DEV]"),
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]");
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", "Developer", ChatColor.DARK_PURPLE + "[DEV]"),
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", "Owner", ChatColor.BLUE + "[Owner]");
private int level;
private String loginMSG;
private String readable;
private String prefix;
Title(int level, String loginMSG, String prefix)
Title(int level, String loginMSG, String readable, String prefix)
{
this.level = level;
this.loginMSG = loginMSG;
this.readable = readable;
this.prefix = prefix;
}
}

View File

@ -1,5 +1,6 @@
package dev.plex.util;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.config.Config;
@ -38,6 +39,10 @@ public class PlexUtils extends PlexBase
{
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
public static List<ChatColor> CHAT_COLOR_POOL;
public static List<String> DEVELOPERS =
Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
"f5cd54c4-3a24-4213-9a56-c06c49594dff" // Taahh
);
private static final Random RANDOM;
static