Skip to content
Snippets Groups Projects
Commit 41dc4833 authored by Martin Hustoles's avatar Martin Hustoles
Browse files

implemented hub command

parent 3db35b81
No related branches found
No related tags found
No related merge requests found
package HubCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.fsi.pixelcampusproxy.PixelcampusProxy;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class HubCommand implements SimpleCommand {
@Override
public void execute(Invocation invocation) {
CommandSource source = invocation.source();
if(source instanceof Player p){
try {
p.createConnectionRequest(
PixelcampusProxy.getProxy().getServer("lobby").orElse(null)
).connect();
}catch (Exception e){
p.sendMessage(Component.text("Could not connect to Lobby").color(NamedTextColor.RED));
}
}
}
@Override
public List<String> suggest(Invocation invocation) {
return SimpleCommand.super.suggest(invocation);
}
@Override
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
return SimpleCommand.super.suggestAsync(invocation);
}
@Override
public boolean hasPermission(Invocation invocation) {
return SimpleCommand.super.hasPermission(invocation);
}
}
package org.fsi.pixelcampusproxy;
import HubCommand.HubCommand;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import org.slf4j.Logger;
@Plugin(
id = "pixelcampusproxy",
name = "PixelcampusProxy",
version = BuildConstants.VERSION
)
public class PixelcampusProxy {
private static ProxyServer proxy;
@Inject
public PixelcampusProxy(ProxyServer proxy) {
this.proxy = proxy;
}
public static ProxyServer getProxy(){
return proxy;
}
@Inject
private Logger logger;
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
CommandManager commandManager = proxy.getCommandManager();
CommandMeta commandMeta = commandManager.metaBuilder("hub")
.aliases("lobby", "l")
.plugin(this)
.build();
SimpleCommand hubCommand = new HubCommand();
commandManager.register(commandMeta, hubCommand);
}
}
package org.fsi.pixelcampusproxy;
// The constants are replaced before compilation
public class BuildConstants {
public static final String VERSION = "${version}";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment