From 7b7c1d6cb5dad2ad3e52b9e9d40be26ae7365126 Mon Sep 17 00:00:00 2001 From: HappyAreaBean Date: Tue, 2 Jul 2024 00:43:39 +0800 Subject: [PATCH 1/2] feat: initial commit for PartyAndFriendsAddon Velocity support --- partyandfriendsaddon-velocity/pom.xml | 70 +++++++++++++++++++ .../PBServerConnector.java | 36 ++++++++++ .../src/main/resources/velocity-plugin.json | 20 ++++++ pom.xml | 1 + 4 files changed, 127 insertions(+) create mode 100644 partyandfriendsaddon-velocity/pom.xml create mode 100644 partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java create mode 100644 partyandfriendsaddon-velocity/src/main/resources/velocity-plugin.json diff --git a/partyandfriendsaddon-velocity/pom.xml b/partyandfriendsaddon-velocity/pom.xml new file mode 100644 index 0000000..3b70b8c --- /dev/null +++ b/partyandfriendsaddon-velocity/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + com.bghddevelopment.partyandfriendsaddon + PBServerConnector-Velocity + 2.3.5 + jar + + PartyAndFriendsAddon-Velocity + + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + src/main/resources + true + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + simonsators Repo + https://simonsator.de/repo + + + + + + de.simonsator + VelocityPoweredPartyAndFriends + 1.0.91 + provided + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + com.jaimemartz + playerbalancer-velocity + 2.3.5 + provided + + + diff --git a/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java b/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java new file mode 100644 index 0000000..adc32ca --- /dev/null +++ b/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java @@ -0,0 +1,36 @@ +package com.bghddevelopment.partyandfriendsaddon; + +import com.google.inject.Inject; +import com.jaimemartz.playerbalancer.velocity.helper.PlayerLocker; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import de.simonsator.partyandfriends.velocity.api.friends.ServerConnector; +import de.simonsator.partyandfriends.velocity.api.pafplayers.PAFPlayerClass; + +import java.util.logging.Logger; + +public class PBServerConnector implements ServerConnector { + + private final Logger logger; + + @Inject + public PBServerConnector(Logger logger) { + this.logger = logger; + } + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + PAFPlayerClass.setServerConnector(this); + logger.info("Enabled PBServerConnector connection for PlayerBalancer!"); + } + + @Override + public void connect(Player player, RegisteredServer registeredServer) { + PlayerLocker.lock(player); + player.createConnectionRequest(registeredServer).fireAndForget(); + PlayerLocker.unlock(player); + } + +} diff --git a/partyandfriendsaddon-velocity/src/main/resources/velocity-plugin.json b/partyandfriendsaddon-velocity/src/main/resources/velocity-plugin.json new file mode 100644 index 0000000..9e78cab --- /dev/null +++ b/partyandfriendsaddon-velocity/src/main/resources/velocity-plugin.json @@ -0,0 +1,20 @@ +{ + "id": "playerbalancerpartyandfriendsaddon", + "name": "PlayerBalancerPartyAndFriendsAddon", + "version": "${version}", + "authors": [ + "BGHDDevelopmentLLC", + "HappyAreaBean" + ], + "dependencies": [ + { + "id": "partyandfriends", + "optional": false + }, + { + "id": "playerbalancer", + "optional": false + } + ], + "main": "com.bghddevelopment.partyandfriendsaddon.PBServerConnector" +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 321bfe8..65cd6d1 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ balancer-velocity addon partyandfriendsaddon + partyandfriendsaddon-velocity PlayerBalancerParent From b676aacbf2d5ef39e816b0553205dc29e250d5bc Mon Sep 17 00:00:00 2001 From: HappyAreaBean Date: Tue, 2 Jul 2024 00:51:20 +0800 Subject: [PATCH 2/2] fix(pafvelocity): only unlock the player after the connection request is processed --- .../partyandfriendsaddon/PBServerConnector.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java b/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java index adc32ca..1d33bf9 100644 --- a/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java +++ b/partyandfriendsaddon-velocity/src/main/java/com/bghddevelopment/partyandfriendsaddon/PBServerConnector.java @@ -29,8 +29,11 @@ public class PBServerConnector implements ServerConnector { @Override public void connect(Player player, RegisteredServer registeredServer) { PlayerLocker.lock(player); - player.createConnectionRequest(registeredServer).fireAndForget(); - PlayerLocker.unlock(player); + player.createConnectionRequest(registeredServer) + .connectWithIndication() + .whenComplete((result, throwable) -> { + PlayerLocker.unlock(player); + }); } }