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