mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-08 16:10:26 +00:00
player manager
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":valiobungee-core"))
|
||||
|
||||
api(libs.redisson)
|
||||
}
|
||||
|
||||
description = "ValioBungee Redisson implementation"
|
||||
|
||||
@@ -18,4 +18,28 @@
|
||||
*/
|
||||
package net.limework.valiobungee.core;
|
||||
|
||||
public abstract class PlayerManager {}
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||
|
||||
public abstract class PlayerManager {
|
||||
|
||||
protected final ValioBungeePlatform platform;
|
||||
|
||||
public PlayerManager(ValioBungeePlatform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public abstract Optional<NetworkPlayer> getNetworkPlayer(UUID uuid);
|
||||
|
||||
public abstract Set<NetworkPlayer> getNetworkPlayers();
|
||||
|
||||
public abstract boolean isOnline(UUID uuid);
|
||||
|
||||
public abstract void handleJoin(UUID uuid);
|
||||
|
||||
public abstract void handleQuit(UUID uuid);
|
||||
|
||||
public abstract void correctionTask();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public abstract class ProxyNetworkManager {
|
||||
(key, value, cause) -> {
|
||||
if (cause == RemovalCause.EXPIRED) {
|
||||
assert value != null;
|
||||
log.warn("proxy {} has disconnected but did not send death message", value);
|
||||
log.warn("proxy {} has disconnected but did not send death message", key);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -33,6 +33,8 @@ public interface ValioBungeePlatform extends ValioBungeeAPI {
|
||||
|
||||
ProxyNetworkManager proxyNetworkManager();
|
||||
|
||||
PlayerManager playerManager();
|
||||
|
||||
NetworkProxy proxyPlatformCreator(String id);
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,16 +22,15 @@ 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 AbstractUUIDNetworkPlayer implements NetworkPlayer, UUIDPlayer {
|
||||
public abstract class AbstractNetworkPlayer implements NetworkPlayer {
|
||||
|
||||
private final ValioBungeePlatform platform;
|
||||
private final UUID uuid;
|
||||
private final NetworkProxy proxy;
|
||||
protected final ValioBungeePlatform platform;
|
||||
protected final UUID uuid;
|
||||
protected final NetworkProxy proxy;
|
||||
|
||||
public AbstractUUIDNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
|
||||
public AbstractNetworkPlayer(ValioBungeePlatform platform, UUID uuid, NetworkProxy proxy) {
|
||||
this.platform = platform;
|
||||
this.uuid = uuid;
|
||||
this.proxy = proxy;
|
||||
@@ -49,7 +48,7 @@ public abstract class AbstractUUIDNetworkPlayer implements NetworkPlayer, UUIDPl
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof AbstractUUIDNetworkPlayer that)) return false;
|
||||
if (!(o instanceof AbstractNetworkPlayer that)) return false;
|
||||
return Objects.equals(uuid, that.uuid) && Objects.equals(proxy, that.proxy);
|
||||
}
|
||||
|
||||
9
core/standalone/build.gradle.kts
Normal file
9
core/standalone/build.gradle.kts
Normal file
@@ -0,0 +1,9 @@
|
||||
dependencies {
|
||||
compileOnly(project(":valiobungee-core"))
|
||||
|
||||
}
|
||||
|
||||
description = "ValioBungee standalone `offline` implementation"
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.limework.valiobungee.api.entity.NetworkPlayer;
|
||||
|
||||
public class StandalonePlayerManager extends PlayerManager {
|
||||
|
||||
public StandalonePlayerManager(ValioBungeePlatform platform) {
|
||||
super(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NetworkPlayer> getNetworkPlayer(UUID uuid) {
|
||||
return platform.getLocalProxyPlayers().stream()
|
||||
.filter(p -> p.getUniqueId().equals(uuid))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NetworkPlayer> getNetworkPlayers() {
|
||||
return platform.getLocalProxyPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline(UUID uuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleJoin(UUID uuid) {}
|
||||
|
||||
@Override
|
||||
public void handleQuit(UUID uuid) {}
|
||||
|
||||
@Override
|
||||
public void correctionTask() {}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import net.limework.valiobungee.core.proto.messages.Death;
|
||||
import net.limework.valiobungee.core.proto.messages.DeathReason;
|
||||
import net.limework.valiobungee.core.proto.messages.Heartbeat;
|
||||
import net.limework.valiobungee.core.proto.messages.ProxyInfo;
|
||||
|
||||
/** this class is used to debug the abstract class */
|
||||
public class StandaloneProxyNetworkManager extends ProxyNetworkManager {
|
||||
public StandaloneProxyNetworkManager(ValioBungeePlatform platform) {
|
||||
super(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishDeathPayload() {}
|
||||
|
||||
@Override
|
||||
protected void publishHeartbeatPayload() {}
|
||||
|
||||
private final AtomicBoolean shutdown = new AtomicBoolean(false);
|
||||
|
||||
private void makeFakeProxiesRunning() {
|
||||
// fake 12 proxies
|
||||
String fakePrefix = "fake-proxy-";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
String prefix = fakePrefix + i;
|
||||
Heartbeat heartbeat =
|
||||
Heartbeat.newBuilder()
|
||||
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||
.setOnlinePlayersCount(i)
|
||||
.build();
|
||||
Thread.ofVirtual()
|
||||
.start(
|
||||
() -> {
|
||||
while (!shutdown.get()) {
|
||||
handleProxyHeartBeat(heartbeat);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
handleProxyDeath(
|
||||
Death.newBuilder()
|
||||
.setReason(DeathReason.SHUTDOWN)
|
||||
.setSender(heartbeat.getSender())
|
||||
.build());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void makeFakeProxiesDisappearing() {
|
||||
// fake 12 proxies
|
||||
String fakePrefix = "fake-disappear-proxy-";
|
||||
for (int i = 0; i < 2; i++) {
|
||||
String prefix = fakePrefix + i;
|
||||
Heartbeat heartbeat =
|
||||
Heartbeat.newBuilder()
|
||||
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||
.setOnlinePlayersCount(i)
|
||||
.build();
|
||||
handleProxyHeartBeat(heartbeat);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeFakeProxiesShuttingDown() {
|
||||
// fake 12 proxies
|
||||
String fakePrefix = "fake-shutdown-proxy-";
|
||||
for (int i = 0; i < 2; i++) {
|
||||
String prefix = fakePrefix + i;
|
||||
Heartbeat heartbeat =
|
||||
Heartbeat.newBuilder()
|
||||
.setSender(ProxyInfo.newBuilder().setProxyId(prefix).build())
|
||||
.setOnlinePlayersCount(i)
|
||||
.build();
|
||||
Thread.ofVirtual()
|
||||
.start(
|
||||
() -> {
|
||||
int li = 0;
|
||||
int liMax = 60 + ThreadLocalRandom.current().nextInt(20);
|
||||
while (!shutdown.get() && li <= liMax) {
|
||||
handleProxyHeartBeat(heartbeat);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
li++;
|
||||
}
|
||||
handleProxyDeath(
|
||||
Death.newBuilder()
|
||||
.setReason(DeathReason.SHUTDOWN)
|
||||
.setSender(heartbeat.getSender())
|
||||
.build());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
makeFakeProxiesRunning();
|
||||
makeFakeProxiesDisappearing();
|
||||
makeFakeProxiesShuttingDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
shutdown.set(true);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user