use of com.github.games647.changeskin.core.model.UserPreference 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.UserPreference in project ChangeSkin by games647.
the class ServerSwitchListener method onLazyLoad.
private void onLazyLoad(ProxiedPlayer player) {
UserPreference preferences = plugin.getStorage().getPreferences(player.getUniqueId());
plugin.startSession(player.getPendingConnection(), preferences);
if (!preferences.getTargetSkin().isPresent() && core.getConfig().getBoolean("restoreSkins")) {
refetchSkin(player.getName(), preferences);
if (!preferences.getTargetSkin().isPresent()) {
// still no skin
getRandomSkin().ifPresent(preferences::setTargetSkin);
}
}
if (preferences.getTargetSkin().isPresent()) {
plugin.getApi().applySkin(player, preferences.getTargetSkin().get());
}
}
use of com.github.games647.changeskin.core.model.UserPreference 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));
}
}
use of com.github.games647.changeskin.core.model.UserPreference in project ChangeSkin by games647.
the class SharedInvalidator method run.
@Override
public void run() {
UserPreference preferences = core.getStorage().getPreferences(receiverUUID);
Optional<SkinModel> ownedSkin = preferences.getTargetSkin();
if (ownedSkin.isPresent()) {
sendMessageInvoker("invalidate-request");
core.getSkinApi().downloadSkin(ownedSkin.get().getProfileId()).ifPresent(this::scheduleApplyTask);
} else {
sendMessageInvoker("dont-have-skin");
}
}
use of com.github.games647.changeskin.core.model.UserPreference in project ChangeSkin by games647.
the class InfoCommand method sendSkinDetails.
private void sendSkinDetails(UUID uuid, UserPreference preference) {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
Optional<SkinModel> optSkin = preference.getTargetSkin();
if (optSkin.isPresent()) {
String template = plugin.getCore().getMessage("skin-info");
player.sendMessage(formatter.apply(template, optSkin.get()));
} else {
plugin.sendMessage(player, "skin-not-found");
}
}
}
Aggregations