Major changes

- Convert prefixes to Component
- Styling improvements to the list command
- Fix tab completing on plex command
- Allow console to check ranks of other players
- Add coloring in tab for admins
- Add color field to ranks and titles
- Fix debug logging not working
This commit is contained in:
2022-03-17 20:18:35 -05:00
parent 3c0b79ba06
commit 06e51926be
18 changed files with 155 additions and 74 deletions

View File

@ -508,6 +508,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
}
protected Component noColorComponentFromString(String s)
{
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
}
/**
* Converts a String to a MiniMessage Component
*

View File

@ -17,7 +17,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "debug", description = "Debug command", usage = "/<command> <redis-reset | gamerules> [player]")
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <redis-reset <player> | gamerules>")
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
public class DebugCMD extends PlexCommand
{

View File

@ -8,7 +8,6 @@ import dev.plex.rank.enums.Rank;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -23,7 +22,8 @@ public class ListCMD extends PlexCommand
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)
Component list = Component.empty();
Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)
.append(Component.space())
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
.append(Component.space())
@ -33,18 +33,17 @@ public class ListCMD extends PlexCommand
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
.append(Component.space())
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY))
.append(Component.newline());
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
send(sender, header);
for (int i = 0; i < players.size(); i++)
{
Player player = players.get(i);
component = component.append(LegacyComponentSerializer.legacyAmpersand().deserialize(getPlexPlayer(player).getRankFromString().getPrefix())).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
if (i != players.size() - 1)
{
component = component.append(Component.text(",")).append(Component.space());
list = list.append(Component.text(",")).append(Component.space());
}
}
return component;
return list;
}
}

View File

@ -26,5 +26,4 @@ public class OpAllCMD extends PlexCommand
PlexUtils.broadcast(messageComponent("oppedAllPlayers", sender.getName()));
return null;
}
}

View File

@ -1,6 +1,5 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
@ -9,6 +8,7 @@ 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.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -75,7 +75,7 @@ public class PlexCMD extends PlexCommand
plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules();
return null;
return componentFromString("All modules reloaded!");
}
}
else
@ -88,13 +88,13 @@ public class PlexCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 0)
if (args.length == 1)
{
return ImmutableList.of("reload", "redis", "modules");
return Arrays.asList("reload", "redis", "modules");
}
if (args[0].equalsIgnoreCase("modules"))
else if (args[0].equalsIgnoreCase("modules"))
{
return ImmutableList.of("reload");
return List.of("reload");
}
return Collections.emptyList();
}

View File

@ -22,7 +22,7 @@ public class PunishmentsCMD extends PlexCommand
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
new PunishmentMenu().openInv(((Player)sender), 0);
new PunishmentMenu().openInv(playerSender, 0);
return null;
}

View File

@ -3,6 +3,7 @@ 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.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
@ -11,7 +12,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.rank", source = RequiredCommandSource.IN_GAME)
@CommandPermissions(level = Rank.OP, permission = "plex.rank", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rank", description = "Displays your rank")
public class RankCMD extends PlexCommand
{
@ -20,6 +21,10 @@ public class RankCMD extends PlexCommand
{
if (args.length == 0)
{
if (isConsole(sender))
{
throw new CommandFailException("<red>When using the console, you must specify a player's rank.");
}
if (!(playerSender == null))
{
Rank rank = getPlexPlayer(playerSender).getRankFromString();

View File

@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.OP, permission = "plex.tag", source = RequiredCommandSource.ANY)
@CommandParameters(name = "tag", aliases = "prefix", description = "Manages your prefix", usage = "/<command> <set | clear> <prefix | player>")
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
public class TagCMD extends PlexCommand
{
@Override
@ -47,8 +47,7 @@ public class TagCMD extends PlexCommand
return usage("/tag set <prefix>");
}
String prefix = StringUtils.join(args, " ", 1, args.length);
Component convertedComponent = removeEvents(componentFromString(prefix));
Component convertedComponent = removeEvents(noColorComponentFromString(prefix));
convertedComponent = removeEvents(MiniMessage.miniMessage().deserialize(LegacyComponentSerializer.legacySection().serialize(convertedComponent)));
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
@ -56,7 +55,7 @@ public class TagCMD extends PlexCommand
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
}
player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
player.setPrefix(Component.text(MiniMessage.miniMessage().serialize(convertedComponent)));
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
}
@ -70,14 +69,14 @@ public class TagCMD extends PlexCommand
}
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
player.setPrefix("");
player.setPrefix(null);
return messageComponent("prefixCleared");
}
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
Player target = getNonNullPlayer(args[1]);
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
plexTarget.setPrefix("");
plexTarget.setPrefix(null);
messageComponent("otherPrefixCleared");
}
return usage();