use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class MojangSkinApi method downloadSkin.
public Optional<SkinModel> downloadSkin(UUID ownerUUID) {
if (crackedUUID.containsKey(ownerUUID)) {
return Optional.empty();
}
// unsigned is needed in order to receive the signature
String uuidString = UUIDTypeAdapter.toMojangId(ownerUUID);
try {
HttpURLConnection httpConnection = getConnection(String.format(SKIN_URL, uuidString));
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
crackedUUID.put(ownerUUID, new Object());
return Optional.empty();
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
TexturesModel texturesModel = gson.fromJson(reader, TexturesModel.class);
SkinProperty[] properties = texturesModel.getProperties();
if (properties != null && properties.length > 0) {
SkinProperty propertiesModel = properties[0];
// base64 encoded skin data
String encodedSkin = propertiesModel.getValue();
String signature = propertiesModel.getSignature();
return Optional.of(SkinModel.createSkinFromEncoded(encodedSkin, signature));
}
}
} catch (IOException ex) {
logger.error("Tried downloading skin data of: {} from Mojang", ownerUUID, ex);
}
return Optional.empty();
}
use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class ChangeSkinSponge method onInit.
@Listener
public void onInit(GameInitializationEvent initEvent) {
if (!initialized)
return;
CommandManager cmdManager = Sponge.getCommandManager();
// command and event register
cmdManager.register(this, injector.getInstance(SelectCommand.class).buildSpec(), "skin-select", "skinselect");
cmdManager.register(this, injector.getInstance(InfoCommand.class).buildSpec(), "skin-info");
cmdManager.register(this, injector.getInstance(UploadCommand.class).buildSpec(), "skin-upload");
cmdManager.register(this, injector.getInstance(SetCommand.class).buildSpec(), "changeskin", "setskin", "skin");
cmdManager.register(this, injector.getInstance(InvalidateCommand.class).buildSpec(), "skininvalidate", "skin-invalidate");
Sponge.getEventManager().registerListeners(this, injector.getInstance(LoginListener.class));
// incoming channel
ChannelRegistrar channelReg = Sponge.getChannelRegistrar();
String updateChannelName = new NamespaceKey(ARTIFACT_ID, UPDATE_SKIN_CHANNEL).getCombinedName();
String permissionChannelName = new NamespaceKey(ARTIFACT_ID, CHECK_PERM_CHANNEL).getCombinedName();
RawDataChannel updateChannel = channelReg.getOrCreateRaw(this, updateChannelName);
RawDataChannel permChannel = channelReg.getOrCreateRaw(this, permissionChannelName);
updateChannel.addListener(Type.SERVER, injector.getInstance(UpdateSkinListener.class));
permChannel.addListener(Type.SERVER, injector.getInstance(CheckPermissionListener.class));
}
use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class PluginMessageListener method onPermissionSuccess.
private void onPermissionSuccess(PermResultMessage message, ProxiedPlayer invoker) {
SkinModel targetSkin = message.getSkin();
UUID receiverUUID = message.getReceiverUUID();
ProxiedPlayer receiver = ProxyServer.getInstance().getPlayer(receiverUUID);
if (receiver == null || !receiver.isConnected()) {
// receiver is not online cancel
return;
}
// add cooldown
core.getCooldownService().trackPlayer(invoker.getUniqueId());
// Save the target uuid from the requesting player source
final UserPreference preferences = core.getStorage().getPreferences(receiver.getUniqueId());
preferences.setTargetSkin(targetSkin);
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
if (core.getStorage().save(targetSkin)) {
core.getStorage().save(preferences);
}
});
if (core.getConfig().getBoolean("instantSkinChange")) {
plugin.getApi().applySkin(receiver, targetSkin);
plugin.sendMessage(invoker, "skin-changed");
} else {
plugin.sendMessage(invoker, "skin-changed-no-instant");
}
}
use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class InfoCommand method sendSkinDetails.
private void sendSkinDetails(UUID uuid, UserPreference preference) {
Optional<Player> optPlayer = Sponge.getServer().getPlayer(uuid);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
Optional<SkinModel> optSkin = preference.getTargetSkin();
if (optSkin.isPresent()) {
String template = plugin.getCore().getMessage("skin-info");
String formatted = formatter.apply(template, optSkin.get());
Text text = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(formatted);
player.sendMessage(text);
} else {
plugin.sendMessage(player, "skin-not-found");
}
}
}
use of com.github.games647.craftapi.model.skin.Skin in project ChangeSkin by games647.
the class SkinFormatter method apply.
@Override
public String apply(String template, SkinModel skin) {
if (template == null) {
return null;
}
int rowId = skin.getRowId();
UUID ownerId = skin.getProfileId();
String ownerName = skin.getProfileName();
long timeFetched = skin.getTimestamp();
Map<TextureType, TextureModel> textures = skin.getTextures();
Optional<TextureModel> skinTexture = Optional.ofNullable(textures.get(TextureType.SKIN));
Optional<TextureModel> capeTexture = Optional.ofNullable(textures.get(TextureType.CAPE));
String skinUrl = skinTexture.map(TextureModel::getShortUrl).orElse("");
String slimModel = skinTexture.map(TextureModel::isSlim).map(slim -> "Alex").orElse("Steve");
String capeUrl = capeTexture.map(TextureModel::getShortUrl).orElse(" - ");
String timeFormat = timeFormatter.format(Instant.ofEpochMilli(timeFetched));
return template.replace("{0}", Integer.toString(rowId)).replace("{1}", ownerId.toString()).replace("{2}", ownerName).replace("{3}", timeFormat).replace("{4}", skinUrl).replace("{5}", slimModel).replace("{6}", capeUrl);
}
Aggregations