Search in sources :

Example 1 with GameProfile

use of com.velocitypowered.api.util.GameProfile in project Floodgate by GeyserMC.

the class VelocityListener method onGameProfileRequest.

@Subscribe(order = PostOrder.EARLY)
public void onGameProfileRequest(GameProfileRequestEvent event) {
    FloodgatePlayer player = playerCache.getIfPresent(event.getConnection());
    if (player != null) {
        playerCache.invalidate(event.getConnection());
        // The texture properties addition is to fix the February 2 2022 Mojang authentication changes
        event.setGameProfile(new GameProfile(player.getCorrectUniqueId(), player.getCorrectUsername(), Collections.singletonList(new Property("textures", "", ""))));
    }
}
Also used : FloodgatePlayer(org.geysermc.floodgate.api.player.FloodgatePlayer) GameProfile(com.velocitypowered.api.util.GameProfile) Property(com.velocitypowered.api.util.GameProfile.Property) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 2 with GameProfile

use of com.velocitypowered.api.util.GameProfile in project LimboAPI by Elytrium.

the class EventManagerHook method proxyHook.

private <E> CompletableFuture<E> proxyHook(E event) {
    if (event instanceof GameProfileRequestEvent) {
        GameProfile originalProfile = ((GameProfileRequestEvent) event).getGameProfile();
        if (this.proceededProfiles.contains(originalProfile)) {
            this.proceededProfiles.remove(originalProfile);
            return null;
        }
        CompletableFuture<E> fireFuture = new CompletableFuture<>();
        CompletableFuture<E> hookFuture = new CompletableFuture<>();
        fireFuture.thenAccept((modifiedEvent) -> {
            try {
                GameProfileRequestEvent requestEvent = (GameProfileRequestEvent) modifiedEvent;
                GameProfile profile = requestEvent.getGameProfile();
                this.plugin.getLoginListener().hookLoginSession(requestEvent);
                this.proceededProfiles.add(profile);
                hookFuture.complete(modifiedEvent);
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            }
        });
        try {
            if (this.hasHandlerRegistration) {
                fire.invoke(this, fireFuture, event, 0, false, this.handlerRegistrations);
            } else {
                fireFuture.complete(event);
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            fireFuture.complete(event);
        }
        return hookFuture;
    }
    return null;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GameProfile(com.velocitypowered.api.util.GameProfile) GameProfileRequestEvent(com.velocitypowered.api.event.player.GameProfileRequestEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

GameProfile (com.velocitypowered.api.util.GameProfile)2 Subscribe (com.velocitypowered.api.event.Subscribe)1 GameProfileRequestEvent (com.velocitypowered.api.event.player.GameProfileRequestEvent)1 Property (com.velocitypowered.api.util.GameProfile.Property)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 FloodgatePlayer (org.geysermc.floodgate.api.player.FloodgatePlayer)1