Search in sources :

Example 1 with GlowPlayerProfile

use of net.glowstone.entity.meta.profile.GlowPlayerProfile in project Glowstone by GlowstoneMC.

the class LoginStartHandler method handle.

@Override
public void handle(GlowSession session, LoginStartMessage message) {
    String name = message.getUsername();
    int length = name.length();
    if (length > 16 || !usernamePattern.matcher(name).find()) {
        session.disconnect("Invalid username provided.", true);
    }
    GlowServer server = session.getServer();
    if (server.getOnlineMode()) {
        // Get necessary information to create our request message
        String sessionId = session.getSessionId();
        byte[] publicKey = SecurityUtils.generateX509Key(server.getKeyPair().getPublic()).getEncoded();
        byte[] verifyToken = SecurityUtils.generateVerifyToken();
        // Set verify data on session for use in the response handler
        session.setVerifyToken(verifyToken);
        session.setVerifyUsername(name);
        // Send created request message and wait for the response
        session.send(new EncryptionKeyRequestMessage(sessionId, publicKey, verifyToken));
    } else {
        GlowPlayerProfile profile;
        ProxyData proxy = session.getProxyData();
        if (proxy == null) {
            UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
            profile = new GlowPlayerProfile(name, uuid, true);
        } else {
            profile = proxy.getProfile(name);
        }
        AsyncPlayerPreLoginEvent event = EventFactory.getInstance().onPlayerPreLogin(profile.getName(), session.getAddress(), profile.getId());
        if (event.getLoginResult() != Result.ALLOWED) {
            session.disconnect(event.getKickMessage(), true);
            return;
        }
        GlowPlayerProfile finalProfile = profile;
        server.getScheduler().runTask(null, () -> session.setPlayer(finalProfile));
    }
}
Also used : ProxyData(net.glowstone.net.ProxyData) EncryptionKeyRequestMessage(net.glowstone.net.message.login.EncryptionKeyRequestMessage) AsyncPlayerPreLoginEvent(org.bukkit.event.player.AsyncPlayerPreLoginEvent) GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile) GlowServer(net.glowstone.GlowServer) UUID(java.util.UUID)

Example 2 with GlowPlayerProfile

use of net.glowstone.entity.meta.profile.GlowPlayerProfile in project Glowstone by GlowstoneMC.

the class GlowSkull method setOwner.

@Override
public boolean setOwner(String name) {
    GlowPlayerProfile owner = GlowPlayerProfile.getProfile(name).join();
    if (owner == null) {
        return false;
    }
    this.owner = owner;
    setSkullType(SkullType.PLAYER);
    return true;
}
Also used : GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile)

Example 3 with GlowPlayerProfile

use of net.glowstone.entity.meta.profile.GlowPlayerProfile in project Glowstone by GlowstoneMC.

the class GlowMetaSkull method setOwner.

@Override
public boolean setOwner(String name) {
    GlowPlayerProfile owner = GlowPlayerProfile.getProfile(name).join();
    if (owner == null) {
        return false;
    }
    this.owner.set(owner);
    return true;
}
Also used : GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile)

Example 4 with GlowPlayerProfile

use of net.glowstone.entity.meta.profile.GlowPlayerProfile in project Glowstone by GlowstoneMC.

the class GlowMetaSkull method setOwningPlayerInternal.

private boolean setOwningPlayerInternal(OfflinePlayer owningPlayer) {
    if (owningPlayer instanceof GlowOfflinePlayer) {
        GlowOfflinePlayer impl = (GlowOfflinePlayer) owningPlayer;
        this.owner.set(impl.getProfile());
        return true;
    } else if (owningPlayer instanceof GlowPlayer) {
        this.owner.set(((GlowPlayer) owningPlayer).getProfile());
        return true;
    } else {
        CompletableFuture<GlowPlayerProfile> profileFuture = GlowPlayerProfile.getProfile(owningPlayer.getName());
        GlowPlayerProfile profile = profileFuture.getNow(null);
        if (profile != null) {
            this.owner.set(profile);
            return true;
        } else {
            profileFuture.thenAcceptAsync(this.owner::set);
            return false;
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GlowPlayer(net.glowstone.entity.GlowPlayer) GlowOfflinePlayer(net.glowstone.GlowOfflinePlayer) GlowPlayerProfile(net.glowstone.entity.meta.profile.GlowPlayerProfile)

Aggregations

GlowPlayerProfile (net.glowstone.entity.meta.profile.GlowPlayerProfile)4 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 GlowOfflinePlayer (net.glowstone.GlowOfflinePlayer)1 GlowServer (net.glowstone.GlowServer)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 ProxyData (net.glowstone.net.ProxyData)1 EncryptionKeyRequestMessage (net.glowstone.net.message.login.EncryptionKeyRequestMessage)1 AsyncPlayerPreLoginEvent (org.bukkit.event.player.AsyncPlayerPreLoginEvent)1