feat: LoHub Action system + Join system implementation
This commit is contained in:
parent
69cae99476
commit
6a4c8a7886
55 changed files with 3180 additions and 1022 deletions
25
lovelocity/build.gradle.kts
Normal file
25
lovelocity/build.gradle.kts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.velocitypowered.com/snapshots/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.10.0")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveFileName.set("LoVelocity-1.5.5.jar")
|
||||
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
65
lovelocity/src/main/java/com/loki/lovelocity/LoVelocity.java
Normal file
65
lovelocity/src/main/java/com/loki/lovelocity/LoVelocity.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package com.loki.lovelocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.loki.lovelocity.commands.HubCommand;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@Plugin(
|
||||
id = "lovelocity",
|
||||
name = "LoVelocity",
|
||||
version = "1.5.5",
|
||||
description = "Velocity integration for LoNetwork",
|
||||
authors = {"loki"}
|
||||
)
|
||||
public class LoVelocity {
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
|
||||
@Inject
|
||||
public LoVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
logger.info("LoVelocity loaded!");
|
||||
logger.info("Version: 1.5.5");
|
||||
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
CommandMeta hubMeta = server.getCommandManager().metaBuilder("hub")
|
||||
.aliases("lobby")
|
||||
.plugin(this)
|
||||
.build();
|
||||
|
||||
server.getCommandManager().register(hubMeta, new HubCommand(this));
|
||||
|
||||
logger.info("Commands registered: /hub, /lobby");
|
||||
}
|
||||
|
||||
public ProxyServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public Path getDataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.loki.lovelocity.commands;
|
||||
|
||||
import com.loki.lovelocity.LoVelocity;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class HubCommand implements SimpleCommand {
|
||||
|
||||
private final LoVelocity plugin;
|
||||
private final List<String> hubServers = List.of("hub", "lobby");
|
||||
|
||||
public HubCommand(LoVelocity plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
if (!(invocation.source() instanceof Player player)) {
|
||||
invocation.source().sendMessage(Component.text("This command is only for players!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<RegisteredServer> currentServer = player.getCurrentServer().map(s -> s.getServer());
|
||||
|
||||
if (currentServer.isEmpty()) {
|
||||
player.sendMessage(Component.text("Failed to determine current server!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
String currentServerName = currentServer.get().getServerInfo().getName().toLowerCase();
|
||||
|
||||
if (isHubServer(currentServerName)) {
|
||||
player.sendMessage(Component.text("You are already on the hub!", NamedTextColor.YELLOW));
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<RegisteredServer> hubServer = findHubServer();
|
||||
|
||||
if (hubServer.isEmpty()) {
|
||||
player.sendMessage(Component.text("Hub server not found!", NamedTextColor.RED));
|
||||
plugin.getLogger().warn("Hub server not found! Available servers: " +
|
||||
plugin.getServer().getAllServers().stream()
|
||||
.map(s -> s.getServerInfo().getName())
|
||||
.toList());
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(Component.text("Teleporting to hub...", NamedTextColor.GREEN));
|
||||
|
||||
player.createConnectionRequest(hubServer.get()).fireAndForget();
|
||||
}
|
||||
|
||||
private boolean isHubServer(String serverName) {
|
||||
return hubServers.stream().anyMatch(hub -> serverName.contains(hub));
|
||||
}
|
||||
|
||||
private Optional<RegisteredServer> findHubServer() {
|
||||
return plugin.getServer().getAllServers().stream()
|
||||
.filter(server -> isHubServer(server.getServerInfo().getName().toLowerCase()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
||||
return CompletableFuture.completedFuture(List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return invocation.source().hasPermission("lovelocity.hub");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue