mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Implement support for adding Geyser subcommands
This commit is contained in:
parent
57345fa102
commit
30303d5f16
90 changed files with 1207 additions and 402 deletions
|
@ -29,7 +29,7 @@ import com.google.inject.Inject;
|
|||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.GeyserBootstrap;
|
||||
import org.geysermc.geyser.command.CommandManager;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
||||
|
@ -120,6 +120,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
|
|||
}
|
||||
|
||||
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
|
||||
this.geyserCommandManager.init();
|
||||
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser");
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandManager getGeyserCommandManager() {
|
||||
public GeyserCommandManager getGeyserCommandManager() {
|
||||
return this.geyserCommandManager;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
package org.geysermc.geyser.platform.sponge.command;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.command.CommandExecutor;
|
||||
import org.geysermc.geyser.command.CommandSender;
|
||||
import org.geysermc.geyser.command.GeyserCommandExecutor;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
import org.geysermc.geyser.command.GeyserCommand;
|
||||
import org.geysermc.geyser.text.ChatColor;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
@ -45,7 +45,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GeyserSpongeCommandExecutor extends CommandExecutor implements CommandCallable {
|
||||
public class GeyserSpongeCommandExecutor extends GeyserCommandExecutor implements CommandCallable {
|
||||
|
||||
public GeyserSpongeCommandExecutor(GeyserImpl geyser) {
|
||||
super(geyser);
|
||||
|
@ -53,14 +53,14 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
|
|||
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String arguments) {
|
||||
CommandSender commandSender = new SpongeCommandSender(source);
|
||||
GeyserCommandSource commandSender = new SpongeCommandSource(source);
|
||||
GeyserSession session = getGeyserSession(commandSender);
|
||||
|
||||
String[] args = arguments.split(" ");
|
||||
if (args.length > 0) {
|
||||
GeyserCommand command = getCommand(args[0]);
|
||||
if (command != null) {
|
||||
if (!source.hasPermission(command.getPermission())) {
|
||||
if (!source.hasPermission(command.permission())) {
|
||||
// Not ideal to use log here but we dont get a session
|
||||
source.sendMessage(Text.of(ChatColor.RED + GeyserLocale.getLocaleStringLog("geyser.bootstrap.command.permission_fail")));
|
||||
return CommandResult.success();
|
||||
|
@ -80,7 +80,7 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm
|
|||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) {
|
||||
if (arguments.split(" ").length == 1) {
|
||||
return tabComplete(new SpongeCommandSender(source));
|
||||
return tabComplete(new SpongeCommandSource(source));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
package org.geysermc.geyser.platform.sponge.command;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.command.CommandManager;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandMapping;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
public class GeyserSpongeCommandManager extends CommandManager {
|
||||
public class GeyserSpongeCommandManager extends GeyserCommandManager {
|
||||
private final org.spongepowered.api.command.CommandManager handle;
|
||||
|
||||
public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserImpl geyser) {
|
||||
|
@ -41,7 +41,7 @@ public class GeyserSpongeCommandManager extends CommandManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(String command) {
|
||||
public String description(String command) {
|
||||
return handle.get(command).map(CommandMapping::getCallable)
|
||||
.map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY))
|
||||
.orElse(Text.EMPTY).toPlain();
|
||||
|
|
|
@ -27,13 +27,13 @@ package org.geysermc.geyser.platform.sponge.command;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import org.geysermc.geyser.command.CommandSender;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.command.source.ConsoleSource;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SpongeCommandSender implements CommandSender {
|
||||
public class SpongeCommandSource implements GeyserCommandSource {
|
||||
|
||||
private CommandSource handle;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue