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));
}
}
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;
}
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;
}
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;
}
}
}
Aggregations