forked from SteamWar/SteamWar
Fix build errors of CommandFramework
This commit is contained in:
@@ -31,6 +31,7 @@ import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
@@ -99,7 +100,11 @@ public class SpigotCommand extends AbstractCommand<CommandSender> {
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
// TODO: this.message.send(message, sender, args);
|
||||
sender.sendMessage(MessageFormat.format(message, args));
|
||||
Locale locale = Locale.getDefault();
|
||||
if (sender instanceof Player) {
|
||||
locale = Locale.forLanguageTag(((Player) sender).getLocale());
|
||||
}
|
||||
sender.sendMessage(new MessageFormat(message, locale).format(args));
|
||||
}
|
||||
|
||||
/* TODO
|
||||
|
||||
@@ -30,5 +30,6 @@ dependencies {
|
||||
implementation(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||
|
||||
annotationProcessor(libs.velocityapi)
|
||||
compileOnly(libs.velocityapi)
|
||||
compileOnly(libs.velocity)
|
||||
}
|
||||
+36
-27
@@ -19,57 +19,57 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import de.steamwar.command.mapper.ProxiedPlayerMapper;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.steamwar.command.mapper.PlayerMapper;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class VelocityCommand extends AbstractCommand<CommandSender> {
|
||||
public class VelocityCommand extends AbstractCommand<CommandSource> {
|
||||
|
||||
static {
|
||||
CommandUtils.addMapper(ProxiedPlayer.class, new ProxiedPlayerMapper());
|
||||
addExecutorMapper(VelocityCommand.class, CommandSender.class, Function.identity());
|
||||
CommandUtils.addMapper(Player.class, new PlayerMapper());
|
||||
addExecutorMapper(VelocityCommand.class, CommandSource.class, Function.identity());
|
||||
}
|
||||
|
||||
private Command command;
|
||||
private SimpleCommand command;
|
||||
|
||||
private List<String> defaultHelpMessages = new ArrayList<>();
|
||||
|
||||
public VelocityCommand(String command, Consumer<CommandLoader<CommandSender>> initializer, String... aliases) {
|
||||
public VelocityCommand(String command, Consumer<CommandLoader<CommandSource>> initializer, String... aliases) {
|
||||
super(command, initializer, aliases);
|
||||
}
|
||||
|
||||
public VelocityCommand(String command, String permission, Consumer<CommandLoader<CommandSender>> initializer, String... aliases) {
|
||||
public VelocityCommand(String command, String permission, Consumer<CommandLoader<CommandSource>> initializer, String... aliases) {
|
||||
super(command, permission, initializer, aliases);
|
||||
}
|
||||
|
||||
private abstract static class TabCompletableCommand extends Command implements TabExecutor {
|
||||
public TabCompletableCommand(String name, String permission, String... aliases) {
|
||||
super(name, permission, aliases);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void initCommand() {
|
||||
if (command != null) return;
|
||||
command = new TabCompletableCommand(VelocityCommand.super.command, permission, aliases) {
|
||||
command = new SimpleCommand() {
|
||||
@Override
|
||||
public void execute(CommandSender commandSender, String[] strings) {
|
||||
VelocityCommand.this.execute(commandSender, null, strings);
|
||||
public void execute(Invocation invocation) {
|
||||
VelocityCommand.this.execute(invocation.source(), invocation.alias(), invocation.arguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
|
||||
return VelocityCommand.this.tabComplete(commandSender, null, strings);
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
return VelocityCommand.this.tabComplete(invocation.source(), invocation.alias(), invocation.arguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
if (permission == null) return true;
|
||||
return invocation.source().hasPermission(permission);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public class VelocityCommand extends AbstractCommand<CommandSender> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void commandSystemError(CommandSender sender, CommandFrameworkException e) {
|
||||
ProxyServer.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
protected void commandSystemError(CommandSource sender, CommandFrameworkException e) {
|
||||
VelocityCommandFrameworkPlugin.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||
// TODO: ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR");
|
||||
}
|
||||
|
||||
@@ -94,10 +94,19 @@ public class VelocityCommand extends AbstractCommand<CommandSender> {
|
||||
defaultHelpMessages.add(message);
|
||||
}
|
||||
|
||||
private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder().extractUrls().build();
|
||||
|
||||
@Override
|
||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
||||
protected void sendMessage(CommandSource sender, String message, Object[] args) {
|
||||
// TODO: ChatSender.of(sender).system(message, args);
|
||||
sender.sendMessage(MessageFormat.format(message, args));
|
||||
Locale locale = null;
|
||||
if (sender instanceof Player) {
|
||||
locale = ((Player) sender).getEffectiveLocale();
|
||||
}
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
sender.sendMessage(SERIALIZER.deserialize(new MessageFormat(message, locale).format(args)));
|
||||
}
|
||||
|
||||
/* TODO
|
||||
|
||||
+24
@@ -19,11 +19,35 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Plugin(
|
||||
id = "commandframework",
|
||||
name = "CommandFramework"
|
||||
)
|
||||
public class VelocityCommandFrameworkPlugin {
|
||||
|
||||
private static VelocityCommandFrameworkPlugin instance;
|
||||
|
||||
public static ProxyServer getProxy() {
|
||||
return instance.proxyServer;
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return instance.logger;
|
||||
}
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
public VelocityCommandFrameworkPlugin(ProxyServer proxyServer, Logger logger) {
|
||||
instance = this;
|
||||
this.proxyServer = proxyServer;
|
||||
this.logger = logger;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -19,9 +19,10 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.proxy.Velocity;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
@UtilityClass
|
||||
@@ -29,11 +30,12 @@ class VelocityCommandRegistering {
|
||||
|
||||
private static final Plugin plugin = ProxyServer.getInstance().getPluginManager().getPlugins().iterator().next();
|
||||
|
||||
static void unregister(Command command) {
|
||||
static void unregister(SimpleCommand command) {
|
||||
VelocityCommandFrameworkPlugin.getProxy().
|
||||
ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
|
||||
}
|
||||
|
||||
static void register(Command command) {
|
||||
static void register(SimpleCommand command) {
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(plugin, command);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
public interface VelocityTypeMapper<T> extends AbstractTypeMapper<CommandSender, T> {
|
||||
public interface VelocityTypeMapper<T> extends AbstractTypeMapper<CommandSource, T> {
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
public interface VelocityTypeSupplier<T> extends AbstractTypeSupplier<CommandSender, T> {
|
||||
public interface VelocityTypeSupplier<T> extends AbstractTypeSupplier<CommandSource, T> {
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
public interface VelocityTypeValidator<T> extends AbstractTypeValidator<CommandSender, T> {
|
||||
public interface VelocityTypeValidator<T> extends AbstractTypeValidator<CommandSource, T> {
|
||||
}
|
||||
|
||||
+11
-10
@@ -19,26 +19,27 @@
|
||||
|
||||
package de.steamwar.command.mapper;
|
||||
|
||||
import de.steamwar.command.VelocityTypeMapper;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import de.steamwar.command.VelocityCommandFrameworkPlugin;
|
||||
import de.steamwar.command.VelocityTypeMapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProxiedPlayerMapper implements VelocityTypeMapper<ProxiedPlayer> {
|
||||
public class PlayerMapper implements VelocityTypeMapper<Player> {
|
||||
|
||||
@Override
|
||||
public ProxiedPlayer map(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return ProxyServer.getInstance().getPlayer(s);
|
||||
public Player map(CommandSource sender, PreviousArguments previousArguments, String s) {
|
||||
return VelocityCommandFrameworkPlugin.getProxy().getPlayer(s).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return ProxyServer.getInstance().getPlayers().stream()
|
||||
.map(ProxiedPlayer::getName)
|
||||
public Collection<String> tabComplete(CommandSource sender, PreviousArguments previousArguments, String s) {
|
||||
return VelocityCommandFrameworkPlugin.getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.map(Player::getUsername)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,4 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.hamcrest)
|
||||
}
|
||||
Reference in New Issue
Block a user