use of com.velocitypowered.api.event.player.GameProfileRequestEvent in project LimboAPI by Elytrium.
the class LoginTasksQueue method finish.
private void finish() {
this.plugin.removeLoginQueue(this.player);
MinecraftConnection connection = this.player.getConnection();
this.server.getEventManager().fire(new GameProfileRequestEvent(this.inbound, this.player.getGameProfile(), this.player.isOnlineMode())).thenAcceptAsync(gameProfile -> this.server.getEventManager().fire(new SafeGameProfileRequestEvent(gameProfile.getGameProfile(), gameProfile.isOnlineMode())).thenAcceptAsync(safeGameProfile -> {
try {
profile.set(this.player, safeGameProfile.getGameProfile());
// From Velocity.
this.server.getEventManager().fire(new PermissionsSetupEvent(this.player, (PermissionProvider) defaultPermissions.get(null))).thenAcceptAsync(event -> {
if (!connection.isClosed()) {
// Wait for permissions to load, then set the players' permission function.
final PermissionFunction function = event.createFunction(this.player);
if (function == null) {
this.plugin.getLogger().error("A plugin permission provider {} provided an invalid permission function" + " for player {}. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", event.getProvider().getClass().getName(), this.player.getUsername());
} else {
try {
setPermissionFunction.invoke(this.player, function);
} catch (IllegalAccessException | InvocationTargetException ex) {
this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
}
}
try {
this.initialize(connection);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
} catch (IllegalAccessException ex) {
this.plugin.getLogger().error("Exception while completing injection to {}", this.player, ex);
}
}, connection.eventLoop()), connection.eventLoop());
}
use of com.velocitypowered.api.event.player.GameProfileRequestEvent 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;
}
Aggregations