use of net.md_5.bungee.connection.LoginResult in project ChangeSkin by games647.
the class BungeeSkinAPI method applySkin.
@Override
public void applySkin(ProxiedPlayer player, SkinModel targetSkin) {
plugin.getLog().debug("Applying skin for {}", player.getName());
InitialHandler initialHandler = (InitialHandler) player.getPendingConnection();
LoginResult loginProfile = initialHandler.getLoginProfile();
// this is null in offline mode
if (loginProfile == null) {
String mojangUUID = UUIDTypeAdapter.toMojangId(player.getUniqueId());
if (profileSetter != null) {
try {
LoginResult loginResult = new LoginResult(mojangUUID, player.getName(), toProperties(targetSkin));
profileSetter.invokeExact(initialHandler, loginResult);
} catch (Error error) {
// rethrow errors we shouldn't silence them like OutOfMemoryError
throw error;
} catch (Throwable throwable) {
plugin.getLog().error("Error applying skin: {} for {}", targetSkin, player, throwable);
}
}
} else {
applyProperties(loginProfile, targetSkin);
}
// send plugin channel update request
plugin.sendPluginMessage(player.getServer(), new SkinUpdateMessage(player.getName()));
}
use of net.md_5.bungee.connection.LoginResult in project SkinsRestorerX by DoNotSpamPls.
the class SkinApplier method applySkin.
public static void applySkin(final ProxiedPlayer p) {
ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
try {
Property textures = (Property) SkinStorage.getOrCreateSkinForPlayer(p.getName());
InitialHandler handler = (InitialHandler) p.getPendingConnection();
if (handler.isOnlineMode()) {
sendUpdateRequest(p, textures);
return;
}
LoginResult profile;
try {
// NEW BUNGEECORD
profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, String.class, Property[].class }, p.getUniqueId().toString(), p.getName(), new Property[] { textures });
} catch (Exception e) {
// FALL BACK TO OLD
profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, Property[].class }, p.getUniqueId().toString(), new Property[] { textures });
}
Property[] present = profile.getProperties();
Property[] newprops = new Property[present.length + 1];
System.arraycopy(present, 0, newprops, 0, present.length);
newprops[present.length] = textures;
profile.getProperties()[0].setName(newprops[0].getName());
profile.getProperties()[0].setValue(newprops[0].getValue());
profile.getProperties()[0].setSignature(newprops[0].getSignature());
ReflectionUtil.setObject(InitialHandler.class, handler, "loginProfile", profile);
if (SkinsRestorer.getInstance().isMultiBungee())
sendUpdateRequest(p, textures);
else
sendUpdateRequest(p, null);
} catch (Exception e) {
e.printStackTrace();
}
});
}
Aggregations