use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class SetCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
if (!(src instanceof Player)) {
plugin.sendMessage(src, "no-console");
return CommandResult.empty();
}
UUID uniqueId = ((Player) src).getUniqueId();
if (core.getCooldownService().isTracked(uniqueId)) {
plugin.sendMessage(src, "cooldown");
return CommandResult.empty();
}
Player receiver = (Player) src;
String targetSkin = args.<String>getOne("skin").get();
boolean keepSkin = args.hasAny("keep");
if ("reset".equals(targetSkin)) {
targetSkin = receiver.getUniqueId().toString();
}
if (targetSkin.length() > 16) {
UUID targetUUID = UUID.fromString(targetSkin);
if (core.getConfig().getBoolean("skinPermission") && !plugin.hasSkinPermission(src, targetUUID, true)) {
return CommandResult.empty();
}
plugin.sendMessage(src, "skin-change-queue");
Runnable skinDownloader = new SkinDownloader(plugin, src, receiver, targetUUID, keepSkin);
Task.builder().async().execute(skinDownloader).submit(plugin);
return CommandResult.success();
}
Runnable nameResolver = new NameResolver(plugin, src, targetSkin, receiver, keepSkin);
Task.builder().async().execute(nameResolver).submit(plugin);
return CommandResult.success();
}
use of com.github.games647.craftapi.model.skin.Skin 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.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class AbstractSkinListener method initializeProfile.
protected UserPreference initializeProfile(UUID uniqueId, String playerName) {
UserPreference preferences = plugin.getStorage().getPreferences(uniqueId);
Optional<SkinModel> optSkin = preferences.getTargetSkin();
if (optSkin.isPresent()) {
SkinModel targetSkin = optSkin.get();
if (!preferences.isKeepSkin()) {
targetSkin = core.checkAutoUpdate(targetSkin);
}
preferences.setTargetSkin(targetSkin);
} else if (core.getConfig().getBoolean("restoreSkins")) {
refetchSkin(playerName, preferences);
if (!preferences.getTargetSkin().isPresent()) {
// still no skin
getRandomSkin().ifPresent(preferences::setTargetSkin);
}
}
return preferences;
}
use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class ConnectListener method onPlayerLogin.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerLogin(PostLoginEvent postLoginEvent) {
ProxiedPlayer player = postLoginEvent.getPlayer();
UserPreference preferences = plugin.getLoginSession(player.getPendingConnection());
if (preferences == null || isBlacklistEnabled()) {
return;
}
preferences.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
use of com.github.games647.craftapi.model.skin.Skin 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 (connectEvent.isCancelled() || !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, () -> {
UserPreference preference = initializeProfile(player.getUniqueId(), plugin.getName());
plugin.startSession(player.getPendingConnection(), preference);
preference.getTargetSkin().ifPresent(skin -> plugin.getApi().applySkin(player, skin));
});
} else {
// player switched to an enabled server
Optional<SkinModel> optSkin = session.getTargetSkin();
optSkin.ifPresent(skin -> plugin.getApi().applySkin(player, skin));
}
}
Aggregations