2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-08 16:10:26 +00:00

more changes

This commit is contained in:
2026-04-03 18:54:01 +04:00
parent 42e8a861a3
commit f58a212782
19 changed files with 226 additions and 73 deletions

3
.gitignore vendored
View File

@@ -46,4 +46,5 @@ manifest.mf
javadoc
# run-server folders
proxies/*/run
**/run/
!src/**/run/

View File

@@ -1,11 +1,9 @@
description = "Api functions for valiobungee"
java {
withJavadocJar()
withSourcesJar()
plugins {
`maven-publish`
}
description = "Api functions for valiobungee"
dependencies {
testImplementation(libs.testing.juipter)
}
@@ -14,3 +12,12 @@ tasks.test {
useJUnitPlatform()
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package net.limework.valiobungee.api.entity;
import java.util.UUID;
/**
* Network player.
*
@@ -24,13 +22,18 @@ import java.util.UUID;
* @since 1.0.0
*/
public interface NetworkPlayer {
/**
* @return player unique id
*/
UUID getUUID();
/**
* @return proxy player on
*/
NetworkProxy getProxy();
/**
* @return true when player is on the same proxy
*/
boolean isLocal();
/**
* @return true when a player is online on the network
*/
boolean isOnline();
}

View File

@@ -40,7 +40,7 @@ public interface NetworkProxy {
Set<NetworkPlayer> getProxyPlayers();
/**
* @return returns true if this object is proxy on it
* @return returns true if this NetworkProxy is the same proxy
*/
boolean isMe();
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2026 ValioBungee contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.limework.valiobungee.api.entity;
import java.util.UUID;
/**
* Network player. that uses UUID as an ID
*
* @author Ham1255
* @since 1.0.0
*/
public interface UUIDPlayer {
/**
* @return player unique id
*/
UUID getUniqueId();
}

View File

@@ -1,5 +1,4 @@
plugins {
`java-library`
`maven-publish`
}
@@ -10,10 +9,6 @@ dependencies {
description = "ValioBungee Velocity API"
java {
withJavadocJar()
withSourcesJar()
}
tasks {
withType<Javadoc> {
@@ -27,17 +22,6 @@ tasks {
val apiDocs = File(rootProject.projectDir, "api/build/docs/javadoc")
//options.linksOffline("https://ci.limework.net/ValioBungee/api/build/docs/javadoc", apiDocs.path)
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(21) // required by velocity
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
publishing {

View File

@@ -15,12 +15,21 @@
*/
package net.limework.valiobungee.velocity.api.entities;
import com.velocitypowered.api.proxy.Player;
import java.util.Optional;
import net.limework.valiobungee.api.entity.NetworkPlayer;
import net.limework.valiobungee.api.entity.UUIDPlayer;
/**
* Velocity Network player.
* Velocity Network player. hold specific stuff for velocity platform
*
* @author Ham1255
* @since 1.0.0
*/
public interface VelocityNetworkPlayer extends NetworkPlayer {}
public interface VelocityNetworkPlayer extends NetworkPlayer, UUIDPlayer {
/**
* @return an optional that contains a player if he is on the same proxy
*/
Optional<Player> getHandle();
}

View File

@@ -17,17 +17,13 @@ sourceSets {
}
}
java {
withJavadocJar()
withSourcesJar()
}
dependencies {
api(project(":valiobungee-api"))
api(libs.protobuf)
api(libs.caffeine)
api(libs.slf4j)
api(libs.redisson)
testImplementation(libs.testing.juipter)
testImplementation(libs.testing.slf4j.simple)
}

View File

@@ -0,0 +1,10 @@
dependencies {
compileOnly(project(":valiobungee-core"))
}
description = "ValioBungee Redisson implementation"

View File

@@ -23,7 +23,12 @@ import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import java.time.Duration;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.limework.valiobungee.api.entity.NetworkProxy;
import net.limework.valiobungee.core.proto.messages.*;
import net.limework.valiobungee.core.util.logging.LogProviderFactory;
import org.slf4j.Logger;
@@ -104,6 +109,22 @@ public abstract class ProxyNetworkManager {
.build();
}
// return self only if no other proxies
public Set<NetworkProxy> getNetworkProxies() {
return Stream.concat(
this.heartbeats.asMap().values().stream()
.map(h -> platform.proxyPlatformCreator(h.getSender().getProxyId())),
Stream.of(platform.getLocalProxy()))
.collect(Collectors.toSet());
}
public Optional<NetworkProxy> getNetworkProxy(String id) {
if (platform.networkId().equals(id)) return Optional.of(platform.proxyPlatformCreator(id));
if (!this.heartbeats.asMap().containsKey(id)) return Optional.empty();
return Optional.of(
platform.proxyPlatformCreator(this.heartbeats.asMap().get(id).getSender().getProxyId()));
}
protected abstract void publishDeathPayload();
protected abstract void publishHeartbeatPayload();

View File

@@ -19,6 +19,7 @@
package net.limework.valiobungee.core;
import net.limework.valiobungee.api.ValioBungeeAPI;
import net.limework.valiobungee.api.entity.NetworkProxy;
public interface ValioBungeePlatform extends ValioBungeeAPI {
@@ -32,6 +33,8 @@ public interface ValioBungeePlatform extends ValioBungeeAPI {
ProxyNetworkManager proxyNetworkManager();
NetworkProxy proxyPlatformCreator(String id);
@Override
default String getGitCommit() {
return ConstantVariables.GIT_COMMIT;

View File

@@ -22,22 +22,23 @@ import java.util.Objects;
import java.util.UUID;
import net.limework.valiobungee.api.entity.NetworkPlayer;
import net.limework.valiobungee.api.entity.NetworkProxy;
import net.limework.valiobungee.api.entity.UUIDPlayer;
import net.limework.valiobungee.core.ValioBungeePlatform;
public abstract class AbstractNetworkPlayer implements NetworkPlayer {
public abstract class AbstractUUIDNetworkPlayer implements NetworkPlayer, UUIDPlayer {
private final ValioBungeePlatform platform;
private final UUID uuid;
private final NetworkProxy proxy;
public AbstractNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
public AbstractUUIDNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
this.platform = platform;
this.uuid = uuid;
this.proxy = proxy;
}
@Override
public UUID getUUID() {
public UUID getUniqueId() {
return this.uuid;
}
@@ -48,7 +49,7 @@ public abstract class AbstractNetworkPlayer implements NetworkPlayer {
@Override
public boolean equals(Object o) {
if (!(o instanceof AbstractNetworkPlayer that)) return false;
if (!(o instanceof AbstractUUIDNetworkPlayer that)) return false;
return Objects.equals(uuid, that.uuid) && Objects.equals(proxy, that.proxy);
}

View File

@@ -19,7 +19,7 @@ indragit = "net.kyori.indra.git:4.0.0"
shadow = "com.gradleup.shadow:9.3.1"
spotless = "com.diffplug.spotless:8.2.0"
protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" }
run-velocity = { id = "xyz.jpenilla.run-velocity", version = "2.3.1" }
run-velocity = { id = "xyz.jpenilla.run-velocity", version = "3.0.2" }
[libraries]
# protobuf

View File

@@ -8,16 +8,21 @@ pluginManagement {
rootProject.name = "ValioBungee"
fun configureProject(name: String) {
fun configureRootProjects(name: String) {
val projectName = ":valiobungee-$name"
configureProject(projectName, name)
}
fun configureAPIProject(name: String) {
fun configureAPISubProject(name: String) {
val projectName = ":valiobungee-$name-api"
configureProject(projectName, "api/$name")
}
fun configureCoreSubProject(name: String) {
val projectName = ":valiobungee-core-$name"
configureProject(projectName, "core/$name")
}
fun configureProject(name: String, path: String) {
include(name)
project(name).projectDir = file(path)
@@ -34,9 +39,11 @@ dependencyResolutionManagement {
}
// main project stuff
sequenceOf("api", "core", "velocity").forEach { configureProject(it) }
sequenceOf("api", "core", "velocity").forEach { configureRootProjects(it) }
// core data implementations
sequenceOf("redisson").forEach { configureCoreSubProject(it) }
// api
sequenceOf("velocity").forEach { configureAPIProject(it) }
sequenceOf("velocity").forEach { configureAPISubProject(it) }
// RedisBunggee Project
// configureProject(":RedisBungee-API", "redisbungee/api")

View File

@@ -14,22 +14,9 @@ dependencies {
description = "ValioBungee Velocity implementation"
java {
withSourcesJar()
}
tasks {
runVelocity {
velocityVersion(libs.versions.velocity.get())
}
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(21) // required by velocity
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}

View File

@@ -18,6 +18,10 @@
*/
package net.limework.valiobungee.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
@@ -25,12 +29,16 @@ import java.nio.file.Path;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import net.limework.valiobungee.api.entity.NetworkPlayer;
import net.limework.valiobungee.api.entity.NetworkProxy;
import net.limework.valiobungee.core.ConstantVariables;
import net.limework.valiobungee.core.ProxyNetworkManager;
import net.limework.valiobungee.core.ValioBungeePlatform;
import net.limework.valiobungee.core.util.logging.LogProviderFactory;
import net.limework.valiobungee.velocity.api.TestProxyNetworkManager;
import net.limework.valiobungee.velocity.api.entities.ImplVelocityNetworkPlayer;
import net.limework.valiobungee.velocity.api.entities.ImplVelocityNetworkProxy;
import org.slf4j.Logger;
@@ -47,6 +55,7 @@ public class VelocityValioBungeePlugin implements ValioBungeePlatform {
private final Path dataFolder;
private final ProxyNetworkManager proxyNetworkManager;
@Inject
public VelocityValioBungeePlugin(
ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
this.server = server;
@@ -54,9 +63,20 @@ public class VelocityValioBungeePlugin implements ValioBungeePlatform {
this.dataFolder = dataDirectory;
// init logging
LogProviderFactory.register(logger);
this.proxyNetworkManager = null;
this.proxyNetworkManager = new TestProxyNetworkManager(this);
}
@Subscribe(priority = Short.MAX_VALUE) // this really important so MAKE IT MAX
public void onProxyInitializeEvent(ProxyInitializeEvent event) {
logger.info(
"initializing ValioBungee for {} platform, version {}",
platformProxyVendor(),
ConstantVariables.VERSION);
}
@Subscribe(priority = Short.MIN_VALUE) // this really import so Make it AT LOWEST
public void onProxyShutdownEvent(ProxyShutdownEvent event) {}
@Override
public int localOnlinePlayers() {
return this.server.getPlayerCount();
@@ -72,9 +92,16 @@ public class VelocityValioBungeePlugin implements ValioBungeePlatform {
return this.proxyNetworkManager;
}
@Override
public NetworkProxy proxyPlatformCreator(String id) {
return new ImplVelocityNetworkProxy(this, id);
}
private final String id = "test-ido-" + ThreadLocalRandom.current().nextInt(10);
@Override
public String proxyId() {
return "test-ido";
return id;
}
@Override
@@ -90,9 +117,7 @@ public class VelocityValioBungeePlugin implements ValioBungeePlatform {
@Override
public Optional<NetworkProxy> getNetworkProxy(String id) {
if (this.proxyId().equals(id)) return Optional.of(getLocalProxy());
logger.warn("not implemented api call returned as Optional empty");
return Optional.empty();
return this.proxyNetworkManager.getNetworkProxy(id);
}
@Override
@@ -102,14 +127,15 @@ public class VelocityValioBungeePlugin implements ValioBungeePlatform {
@Override
public Set<NetworkProxy> getNetworkProxies() {
logger.warn("not implemented api call returned as Optional empty");
return Set.of();
return proxyNetworkManager.getNetworkProxies();
}
@Override
public Set<NetworkPlayer> getLocalProxyPlayers() {
logger.warn("not implemented api call returned as Optional empty");
return Set.of();
NetworkProxy proxy = getLocalProxy();
return this.server.getAllPlayers().stream()
.map(p -> new ImplVelocityNetworkPlayer(this, p.getUniqueId(), getLocalProxy(), p))
.collect(Collectors.toSet());
}
@Override

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2026 ValioBungee contributors
*
* This file is part of ValioBungee.
*
* ValioBungee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ValioBungee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ValioBungee. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
*/
package net.limework.valiobungee.velocity.api;
import net.limework.valiobungee.core.ProxyNetworkManager;
import net.limework.valiobungee.core.ValioBungeePlatform;
public class TestProxyNetworkManager extends ProxyNetworkManager {
public TestProxyNetworkManager(ValioBungeePlatform platform) {
super(platform);
}
@Override
protected void publishDeathPayload() {}
@Override
protected void publishHeartbeatPayload() {}
@Override
public void init() {}
@Override
public void close() {}
}

View File

@@ -18,13 +18,40 @@
*/
package net.limework.valiobungee.velocity.api.entities;
import com.velocitypowered.api.proxy.Player;
import java.util.Optional;
import java.util.UUID;
import net.limework.valiobungee.api.entity.NetworkProxy;
import net.limework.valiobungee.core.ValioBungeePlatform;
import net.limework.valiobungee.core.api.entities.AbstractNetworkPlayer;
import net.limework.valiobungee.core.api.entities.AbstractUUIDNetworkPlayer;
import net.limework.valiobungee.core.util.logging.LogProviderFactory;
public class ImplVelocityNetworkPlayer extends AbstractNetworkPlayer {
public ImplVelocityNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
public class ImplVelocityNetworkPlayer extends AbstractUUIDNetworkPlayer
implements VelocityNetworkPlayer {
private final Player handle;
public ImplVelocityNetworkPlayer(
ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy, Player handle) {
super(platform, uuid, proxy);
this.handle = handle;
}
@Override
public Optional<Player> getHandle() {
return Optional.ofNullable(handle);
}
@Override
public boolean isLocal() {
return handle != null;
}
@Override
public boolean isOnline() {
if (isLocal()) {
return handle.isActive();
}
LogProviderFactory.get().warn("NOT IMPLEMENTED IS ONLINE for Velocity network player");
return false;
}
}

View File

@@ -23,7 +23,7 @@ import net.limework.valiobungee.api.entity.NetworkPlayer;
import net.limework.valiobungee.core.api.entities.AbstractNetworkProxy;
import net.limework.valiobungee.velocity.VelocityValioBungeePlugin;
public class ImplVelocityNetworkProxy extends AbstractNetworkProxy {
public class ImplVelocityNetworkProxy extends AbstractNetworkProxy implements VelocityNetworkProxy {
public ImplVelocityNetworkProxy(VelocityValioBungeePlugin platform, String proxyId) {
super(platform, proxyId);