Start getting rid of legacy strings

This commit is contained in:
2022-03-17 17:16:17 -05:00
parent 8f7fed5835
commit 3c0b79ba06
14 changed files with 198 additions and 129 deletions

View File

@ -19,6 +19,7 @@ import java.util.Arrays;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
@ -90,9 +91,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
* Executes the command
*
* @param sender The sender of the command
* @param playerSender The player who executed the command (null if command source is console or if command source is any but console executed)
* @param playerSender The player who executed the command (null if CommandSource is console or if CommandSource is any but console executed)
* @param args A Kyori Component to send to the sender (can be null)
* @return
*/
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
@ -165,9 +165,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Checks if the string given is a command string
* Checks if the String given is a matching command
*
* @param label The string to check
* @param label The String to check
* @return true if the string is a command name or alias
*/
private boolean matches(String label)
@ -202,9 +202,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Sends a message to an audience
* Sends a message to an Audience
*
* @param audience The audience to send the message to
* @param audience The Audience to send the message to
* @param s The message to send
*/
protected void send(Audience audience, String s)
@ -213,10 +213,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Sends a message to an audience
* Sends a message to an Audience
*
* @param audience The audience to send the message to
* @param component The component to send
* @param audience The Audience to send the message to
* @param component The Component to send
*/
protected void send(Audience audience, Component component)
{
@ -226,7 +226,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
/**
* Checks whether a sender has enough permissions or is high enough a rank
*
* @param sender A command sender
* @param sender A CommandSender
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
@ -415,7 +415,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
*
* @param s The message entry
* @param objects Any objects to replace in order
* @return A Kyori component
* @return A Kyori Component
*/
protected Component messageComponent(String s, Object... objects)
{
@ -435,25 +435,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Converts usage to a component
* Converts usage to a Component
*
* @return A Kyori component stating the usage
* @return A Kyori Component stating the usage
*/
protected Component usage()
{
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + this.getUsage());
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(this.getUsage()).color(NamedTextColor.GRAY));
}
/**
* Converts usage to a component
* Converts usage to a Component
* <p>
* s The usage to convert
*
* @return A Kyori component stating the usage
* @return A Kyori Component stating the usage
*/
protected Component usage(String s)
{
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s);
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(s).color(NamedTextColor.GRAY));
}
protected Player getNonNullPlayer(String name)
@ -498,21 +498,21 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Converts a string to a legacy Kyori component
* Converts a String to a legacy Kyori Component
*
* @param s The string to convert
* @param s The String to convert
* @return A Kyori component
*/
protected Component componentFromString(String s)
{
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
}
/**
* Converts a string to a mini message kyori component
* Converts a String to a MiniMessage Component
*
* @param s The string to convert
* @return A Kyori component
* @param s The String to convert
* @return A Kyori Component
*/
protected Component mmString(String s)
{

View File

@ -7,20 +7,15 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;
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;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
public class LockupCMD extends PlexCommand

View File

@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -9,18 +9,16 @@ 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.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.stream.Collectors;
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
@ -31,10 +29,11 @@ public class PlexCMD extends PlexCommand
{
if (args.length == 0)
{
send(sender, ChatColor.LIGHT_PURPLE + "Plex - A new freedom plugin.");
send(sender, ChatColor.LIGHT_PURPLE + "Plugin version: " + plugin.getDescription().getVersion());
send(sender, ChatColor.LIGHT_PURPLE + "Authors: " + ChatColor.GOLD + "Telesphoreo, Taahh");
return componentFromString(ChatColor.LIGHT_PURPLE + "Run " + ChatColor.GOLD + "/plex modules" + ChatColor.LIGHT_PURPLE + " to see a list of modules.");
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"));
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
return null;
}
if (args[0].equalsIgnoreCase("reload"))
{
@ -49,6 +48,7 @@ public class PlexCMD extends PlexCommand
plugin.getRankManager().importDefaultRanks();
send(sender, "Imported ranks");
send(sender, "Plex successfully reloaded.");
return null;
}
else if (args[0].equalsIgnoreCase("redis"))
{
@ -61,12 +61,13 @@ public class PlexCMD extends PlexCommand
send(sender, "Set test to 123. Now outputting key test...");
send(sender, plugin.getRedisConnection().getJedis().get("test"));
plugin.getRedisConnection().getJedis().close();
return null;
}
if (args[0].equalsIgnoreCase("modules"))
else if (args[0].equalsIgnoreCase("modules"))
{
if (args.length == 1)
{
return MiniMessage.miniMessage().deserialize("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
return mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
}
if (args[1].equalsIgnoreCase("reload"))
{
@ -74,6 +75,7 @@ public class PlexCMD extends PlexCommand
plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules();
return null;
}
}
else
@ -86,6 +88,14 @@ public class PlexCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return ImmutableList.of("reload", "redis");
if (args.length == 0)
{
return ImmutableList.of("reload", "redis", "modules");
}
if (args[0].equalsIgnoreCase("modules"))
{
return ImmutableList.of("reload");
}
return Collections.emptyList();
}
}