use of com.github.games647.changeskin.core.model.skin.SkinModel 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 com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class BungeeSkinAPI method toProperties.
private Property[] toProperties(SkinModel targetSkin) {
if (targetSkin == null) {
return emptyProperties;
}
String encodedValue = targetSkin.getEncodedValue();
String signature = targetSkin.getSignature();
Property prop = new Property(SkinProperty.SKIN_KEY, encodedValue, signature);
return new Property[] { prop };
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class SharedUploader method run.
@Override
public void run() {
GameProfile profile = owner.getProfile();
String oldSkinUrl = core.getSkinApi().downloadSkin(profile.getId()).map(skinModel -> skinModel.getTextures().get(TextureType.SKIN).getUrl()).orElse("");
UUID uuid = profile.getId();
UUID accessToken = UUIDTypeAdapter.parseId(owner.getAccessToken());
core.getAuthApi().changeSkin(uuid, accessToken, url, false);
// this could properly cause issues for uuid resolving to this database entry
core.getSkinApi().downloadSkin(uuid).ifPresent(skinData -> {
core.getStorage().save(skinData);
core.getAuthApi().changeSkin(uuid, accessToken, oldSkinUrl, false);
String localeMessage = core.getMessage("skin-uploaded").replace("{0}", owner.getProfile().getName()).replace("{1}", "Skin-" + skinData.getRowId());
sendMessageInvoker(localeMessage);
});
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class LoginListener method onPlayerPreLogin.
@Listener
public void onPlayerPreLogin(ClientConnectionEvent.Auth preLoginEvent) {
SkinStorage storage = core.getStorage();
GameProfile profile = preLoginEvent.getProfile();
UUID playerUUID = profile.getUniqueId();
UserPreference preferences = storage.getPreferences(playerUUID);
Optional<SkinModel> optSkin = preferences.getTargetSkin();
if (optSkin.isPresent()) {
SkinModel targetSkin = optSkin.get();
if (!preferences.isKeepSkin()) {
targetSkin = core.checkAutoUpdate(targetSkin);
}
plugin.getApi().applyProperties(profile, targetSkin);
save(preferences);
} else {
String playerName = profile.getName().get();
if (!core.getConfig().getBoolean("restoreSkins") || !refetchSkin(playerName, preferences)) {
setDefaultSkin(preferences, profile);
}
}
}
use of com.github.games647.changeskin.core.model.skin.SkinModel in project ChangeSkin by games647.
the class ServerSwitchListener method onServerConnect.
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerConnect(ServerConnectEvent connectEvent) {
ServerInfo targetServer = connectEvent.getTarget();
Server fromServer = connectEvent.getPlayer().getServer();
if (fromServer != null && Objects.equals(targetServer, fromServer.getInfo())) {
// check if we are switching to the same server
return;
}
if (!isBlacklistEnabled()) {
return;
}
ProxiedPlayer player = connectEvent.getPlayer();
UserPreference session = plugin.getLoginSession(player.getPendingConnection());
List<String> blacklist = core.getConfig().getStringList("server-blacklist");
if (blacklist.contains(targetServer.getName())) {
// clear the skin
plugin.getApi().applySkin(player, null);
} else if (session == null) {
// lazy load
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> onLazyLoad(player));
} else {
// player switched to an enabled server
Optional<SkinModel> optSkin = session.getTargetSkin();
optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
}
Aggregations