Skip to content

Commit

Permalink
feat: swap to counts and lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Aug 20, 2024
1 parent 3221276 commit 1870718
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
implementation("net.kyori:adventure-text-minimessage:4.14.0")

implementation("dev.emortal.api:common-proto-sdk:44913ed")
implementation("dev.emortal.api:agones-sdk:1.0.7")
implementation("dev.emortal.api:agones-sdk:1.1.0")
implementation("dev.emortal.api:live-config-parser:8f566b9")
implementation("dev.emortal.api:module-system:1.0.0")
implementation("dev.emortal.api:command-system:1.0.0") {
Expand Down
53 changes: 37 additions & 16 deletions src/main/java/dev/emortal/velocity/agones/AgonesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.agones.sdk.AgonesSDKProto;
import dev.agones.sdk.SDKGrpc;
import dev.agones.sdk.alpha.AlphaAgonesSDKProto;
import dev.agones.sdk.beta.BetaAgonesSDKProto;
import dev.emortal.api.agonessdk.AgonesUtils;
import io.grpc.StatusRuntimeException;
import org.jetbrains.annotations.NotNull;
Expand All @@ -21,12 +22,12 @@ final class AgonesListener {

private final SDKGrpc.SDKBlockingStub agonesService;
private final SDKGrpc.SDKStub standardAgonesService;
private final dev.agones.sdk.alpha.SDKGrpc.SDKBlockingStub alphaAgonesService;
private final dev.agones.sdk.beta.SDKGrpc.SDKBlockingStub betaSdk;

AgonesListener(@NotNull AgonesGrpcStubCollection stubManager) {
this.agonesService = stubManager.getAgonesService();
this.standardAgonesService = stubManager.getStandardAgonesService();
this.alphaAgonesService = stubManager.getAlphaAgonesService();
this.betaSdk = stubManager.getBetaAgonesService();
}

@Subscribe(async = true)
Expand All @@ -45,30 +46,50 @@ void onLogin(@NotNull LoginEvent event) {
UUID id = event.getPlayer().getUniqueId();
AlphaAgonesSDKProto.PlayerID playerId = AlphaAgonesSDKProto.PlayerID.newBuilder().setPlayerID(id.toString()).build();

boolean success;
try {
success = this.alphaAgonesService.playerConnect(playerId).getBool();
} catch (StatusRuntimeException exception) {
LOGGER.error("Failed to set player to connected: ", exception);
return;
}

if (!success) LOGGER.warn("Failed to register player {} with Agones (already marked as logged in)", id);
this.updateAgonesCounter("players", 1);
this.addToAgonesList("players", id.toString());
}

@Subscribe(async = true)
void onDisconnect(@NotNull DisconnectEvent event) {
UUID id = event.getPlayer().getUniqueId();
AlphaAgonesSDKProto.PlayerID playerId = AlphaAgonesSDKProto.PlayerID.newBuilder().setPlayerID(id.toString()).build();

boolean success;
this.updateAgonesCounter("players", -1);
this.removeFromAgonesList("players", id.toString());
}

public void updateAgonesCounter(String name, long diff) {
try {
success = this.alphaAgonesService.playerDisconnect(playerId).getBool();
this.betaSdk.updateCounter(BetaAgonesSDKProto.UpdateCounterRequest.newBuilder()
.setCounterUpdateRequest(BetaAgonesSDKProto.CounterUpdateRequest.newBuilder()
.setName(name)
.setCountDiff(diff))
.build());
} catch (StatusRuntimeException exception) {
LOGGER.error("Failed to set player to disconnected: ", exception);
return;
LOGGER.error("Failed to update counter: ", exception);
}
}

if (!success) LOGGER.warn("Failed to unregister player {} with Agones (not marked as logged in)", id);
public void addToAgonesList(String listName, String value) {
try {
this.betaSdk.addListValue(BetaAgonesSDKProto.AddListValueRequest.newBuilder()
.setName(listName)
.setValue(value)
.build());
} catch (StatusRuntimeException exception) {
LOGGER.error("Failed to add to list: ", exception);
}
}

public void removeFromAgonesList(String listName, String value) {
try {
this.betaSdk.removeListValue(BetaAgonesSDKProto.RemoveListValueRequest.newBuilder()
.setName(listName)
.setValue(value)
.build());
} catch (StatusRuntimeException exception) {
LOGGER.error("Failed to remove from list: ", exception);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/emortal/velocity/lang/ChatMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface ChatMessages {

Args1<String> SENDING_TO_SERVER = serverName -> Component.text()
.append(green("Sending you to "))
.append(Component.text(serverName, NamedTextColor.GOLD))
.append(Component.text(serverName, NamedTextColor.GOLD).clickEvent(ClickEvent.copyToClipboard(serverName)))
.append(green("..."))
.build();

Expand Down

0 comments on commit 1870718

Please sign in to comment.