Add MiniMessage
This commit is contained in:
parent
bb5c642f31
commit
083012abfe
74 changed files with 1328 additions and 1078 deletions
|
|
@ -6,10 +6,15 @@ import cloud.commandframework.context.CommandContext;
|
|||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import net.frankheijden.serverutils.common.commands.CommandPlugins;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
import net.frankheijden.serverutils.common.config.MessageKey;
|
||||
import net.frankheijden.serverutils.common.config.MessagesResource;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityAudience;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
public class VelocityCommandPlugins extends CommandPlugins<VelocityPlugin, PluginContainer, VelocityCommandSender> {
|
||||
public class VelocityCommandPlugins extends CommandPlugins<VelocityPlugin, PluginContainer, VelocityAudience> {
|
||||
|
||||
public VelocityCommandPlugins(VelocityPlugin plugin) {
|
||||
super(plugin);
|
||||
|
|
@ -17,8 +22,8 @@ public class VelocityCommandPlugins extends CommandPlugins<VelocityPlugin, Plugi
|
|||
|
||||
@Override
|
||||
protected void register(
|
||||
CommandManager<VelocityCommandSender> manager,
|
||||
Command.Builder<VelocityCommandSender> builder
|
||||
CommandManager<VelocityAudience> manager,
|
||||
Command.Builder<VelocityAudience> builder
|
||||
) {
|
||||
manager.command(builder
|
||||
.flag(parseFlag("version"))
|
||||
|
|
@ -26,26 +31,25 @@ public class VelocityCommandPlugins extends CommandPlugins<VelocityPlugin, Plugi
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlugins(CommandContext<VelocityCommandSender> context) {
|
||||
VelocityCommandSender sender = context.getSender();
|
||||
protected void handlePlugins(CommandContext<VelocityAudience> context) {
|
||||
VelocityAudience sender = context.getSender();
|
||||
boolean hasVersionFlag = context.flags().contains("version");
|
||||
|
||||
MessagesResource messages = plugin.getMessagesResource();
|
||||
handlePlugins(sender, plugin.getPluginManager().getPluginsSorted(), container -> {
|
||||
PluginDescription description = container.getDescription();
|
||||
|
||||
String message = plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.format",
|
||||
"%plugin%", description.getId()
|
||||
);
|
||||
|
||||
TextComponent.Builder builder = Component.text();
|
||||
builder.append(messages.get(MessageKey.PLUGINS_FORMAT).toComponent(
|
||||
Template.of("plugin", description.getId())
|
||||
));
|
||||
if (hasVersionFlag) {
|
||||
message += plugin.getMessagesResource().getMessage(
|
||||
"serverutils.plugins.version",
|
||||
"%version%", description.getVersion().orElse("<UNKNOWN>")
|
||||
);
|
||||
builder.append(messages.get(MessageKey.PLUGINS_FORMAT).toComponent(
|
||||
Template.of("version", description.getVersion().orElse("<UNKNOWN>"))
|
||||
));
|
||||
}
|
||||
|
||||
return message;
|
||||
return builder.build();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,24 +10,24 @@ import java.util.function.Consumer;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import net.frankheijden.serverutils.common.commands.CommandServerUtils;
|
||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.KeyValueComponentBuilder;
|
||||
import net.frankheijden.serverutils.common.utils.ListComponentBuilder;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityAudience;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityCommandManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class VelocityCommandServerUtils
|
||||
extends CommandServerUtils<VelocityPlugin, PluginContainer, VelocityCommandSender> {
|
||||
public class VelocityCommandServerUtils extends CommandServerUtils<VelocityPlugin, PluginContainer, VelocityAudience> {
|
||||
|
||||
public VelocityCommandServerUtils(VelocityPlugin plugin) {
|
||||
super(plugin, PluginContainer[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createPluginInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
protected KeyValueComponentBuilder createPluginInfo(
|
||||
KeyValueComponentBuilder builder,
|
||||
Function<Consumer<ListComponentBuilder<String>>, Component> listBuilderFunction,
|
||||
PluginContainer container
|
||||
) {
|
||||
PluginDescription desc = container.getDescription();
|
||||
|
|
@ -52,9 +52,9 @@ public class VelocityCommandServerUtils
|
|||
}
|
||||
|
||||
@Override
|
||||
protected FormatBuilder createCommandInfo(
|
||||
FormatBuilder builder,
|
||||
Function<Consumer<ListBuilder<String>>, String> listBuilderFunction,
|
||||
protected KeyValueComponentBuilder createCommandInfo(
|
||||
KeyValueComponentBuilder builder,
|
||||
Function<Consumer<ListComponentBuilder<String>>, Component> listBuilderFunction,
|
||||
String commandName
|
||||
) {
|
||||
ServerUtils plugin = ServerUtils.getInstance();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.frankheijden.serverutils.common.entities.ServerUtilsAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
public class VelocityAudience extends ServerUtilsAudience<CommandSource> {
|
||||
|
||||
protected VelocityAudience(Audience audience, CommandSource source) {
|
||||
super(audience, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return source instanceof Player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return source.hasPermission(permission);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.frankheijden.serverutils.common.providers.ServerUtilsAudienceProvider;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class VelocityAudienceProvider implements ServerUtilsAudienceProvider<CommandSource> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
private final VelocityAudience consoleServerAudience;
|
||||
|
||||
/**
|
||||
* Constructs a new VelocityAudienceProvider.
|
||||
*/
|
||||
public VelocityAudienceProvider(ServerUtils plugin) {
|
||||
this.plugin = plugin;
|
||||
this.consoleServerAudience = new VelocityAudience(
|
||||
plugin.getProxy().getConsoleCommandSource(),
|
||||
plugin.getProxy().getConsoleCommandSource()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityAudience getConsoleServerAudience() {
|
||||
return consoleServerAudience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityAudience get(CommandSource source) {
|
||||
return new VelocityAudience(source, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(Component component, String permission) {
|
||||
for (Player player : plugin.getProxy().getAllPlayers()) {
|
||||
if (player.hasPermission(permission)) {
|
||||
player.sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import net.frankheijden.serverutils.common.providers.ChatProvider;
|
||||
import net.frankheijden.serverutils.common.utils.HexUtils;
|
||||
import net.frankheijden.serverutils.velocity.ServerUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class VelocityChatProvider implements ChatProvider<VelocityCommandSender, CommandSource> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
|
||||
public VelocityChatProvider(ServerUtils plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandSender getConsoleSender() {
|
||||
return new VelocityCommandSender(plugin.getProxy().getConsoleCommandSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandSender get(CommandSource source) {
|
||||
return new VelocityCommandSender(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String color(String str) {
|
||||
return HexUtils.convertHexString(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(String permission, String message) {
|
||||
Component msg = LegacyComponentSerializer.legacyAmpersand().deserialize(message);
|
||||
plugin.getProxy().getAllPlayers().stream()
|
||||
.filter(p -> p.hasPermission(permission))
|
||||
.forEach(p -> p.sendMessage(msg));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package net.frankheijden.serverutils.velocity.entities;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class VelocityCommandSender implements ServerCommandSender<CommandSource> {
|
||||
|
||||
private final CommandSource source;
|
||||
|
||||
public VelocityCommandSender(CommandSource source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return source.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the given instance is a player.
|
||||
* @return Boolean true or false.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return source instanceof Player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSource getSource() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,13 +15,13 @@ import net.frankheijden.serverutils.velocity.listeners.VelocityPlayerListener;
|
|||
import net.frankheijden.serverutils.velocity.managers.VelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.managers.VelocityTaskManager;
|
||||
|
||||
public class VelocityPlugin extends ServerUtilsPlugin<PluginContainer, ScheduledTask, VelocityCommandSender, CommandSource, VelocityPluginDescription> {
|
||||
public class VelocityPlugin extends ServerUtilsPlugin<PluginContainer, ScheduledTask, VelocityAudience, CommandSource, VelocityPluginDescription> {
|
||||
|
||||
private final ServerUtils plugin;
|
||||
private final VelocityPluginManager pluginManager;
|
||||
private final VelocityTaskManager taskManager;
|
||||
private final VelocityResourceProvider resourceProvider;
|
||||
private final VelocityChatProvider chatProvider;
|
||||
private final VelocityAudienceProvider chatProvider;
|
||||
|
||||
/**
|
||||
* Creates a new BungeePlugin instance of ServerUtils.
|
||||
|
|
@ -36,17 +36,17 @@ public class VelocityPlugin extends ServerUtilsPlugin<PluginContainer, Scheduled
|
|||
);
|
||||
this.taskManager = new VelocityTaskManager(plugin);
|
||||
this.resourceProvider = new VelocityResourceProvider(plugin);
|
||||
this.chatProvider = new VelocityChatProvider(plugin);
|
||||
this.chatProvider = new VelocityAudienceProvider(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VelocityCommandManager<VelocityCommandSender> newCommandManager() {
|
||||
VelocityCommandManager<VelocityCommandSender> commandManager = new VelocityCommandManager<>(
|
||||
protected VelocityCommandManager<VelocityAudience> newCommandManager() {
|
||||
VelocityCommandManager<VelocityAudience> commandManager = new VelocityCommandManager<>(
|
||||
plugin.getPluginContainer(),
|
||||
plugin.getProxy(),
|
||||
AsynchronousCommandExecutionCoordinator.<VelocityCommandSender>newBuilder().build(),
|
||||
AsynchronousCommandExecutionCoordinator.<VelocityAudience>newBuilder().build(),
|
||||
chatProvider::get,
|
||||
VelocityCommandSender::getSource
|
||||
VelocityAudience::getSource
|
||||
);
|
||||
handleBrigadier(commandManager.brigadierManager());
|
||||
return commandManager;
|
||||
|
|
@ -78,7 +78,7 @@ public class VelocityPlugin extends ServerUtilsPlugin<PluginContainer, Scheduled
|
|||
}
|
||||
|
||||
@Override
|
||||
public VelocityChatProvider getChatProvider() {
|
||||
public VelocityAudienceProvider getChatProvider() {
|
||||
return this.chatProvider;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import com.velocitypowered.api.event.Subscribe;
|
|||
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import net.frankheijden.serverutils.common.listeners.PlayerListener;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityCommandSender;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityAudience;
|
||||
import net.frankheijden.serverutils.velocity.entities.VelocityPlugin;
|
||||
|
||||
public class VelocityPlayerListener
|
||||
extends PlayerListener<VelocityPlugin, PluginContainer, VelocityCommandSender> {
|
||||
public class VelocityPlayerListener extends PlayerListener<VelocityPlugin, PluginContainer, VelocityAudience> {
|
||||
|
||||
public VelocityPlayerListener(VelocityPlugin plugin) {
|
||||
super(plugin);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import net.frankheijden.serverutils.velocity.reflection.RVelocityEventManager;
|
|||
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginContainer;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityPluginManager;
|
||||
import net.frankheijden.serverutils.velocity.reflection.RVelocityScheduler;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class VelocityPluginManager extends AbstractPluginManager<PluginContainer, VelocityPluginDescription> {
|
||||
|
|
@ -91,9 +92,8 @@ public class VelocityPluginManager extends AbstractPluginManager<PluginContainer
|
|||
candidate.getId(),
|
||||
dependency.getId()
|
||||
);
|
||||
return loadResults.addResult(
|
||||
description.getId(),
|
||||
Result.UNKNOWN_DEPENDENCY.arg(dependency.getId())
|
||||
return loadResults.addResult(description.getId(), Result.UNKNOWN_DEPENDENCY,
|
||||
Template.of("dependency", dependency.getId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue