-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow URL argument in setSkullTexture() #213
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
@@ -118,17 +120,25 @@ public static String getTexture(@NonNull ItemStack itemStack) { | |
* Set the Base64 texture of the given skull ItemStack. | ||
* | ||
* @param itemStack The ItemStack. | ||
* @param texture The new skull texture (Base64). | ||
* @param texture The new skull texture (Base64 or URL). | ||
*/ | ||
public static void setSkullTexture(@NonNull ItemStack itemStack, @NonNull String texture) { | ||
try { | ||
ItemMeta meta = itemStack.getItemMeta(); | ||
if (meta instanceof SkullMeta) { | ||
GameProfile profile = new GameProfile(UUID.randomUUID(), ""); | ||
Property property = new Property("textures", texture); | ||
|
||
PropertyMap properties = profile.getProperties(); | ||
properties.put("textures", property); | ||
String json = Base64.getDecoder().decode(texture); | ||
EvModder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(!json.contains("\"url\":\"")){ | ||
// Decoded json does not contain a skin URL, so check if the 'texture' argument is a URL. | ||
if(texture.startsWith("http://")); // We are all set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is problematic as it ignores the possibility of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point, but Minecraft's skin server only uses http://. They could change in the future, but currently the game won't render skins that aren't hosted under Minecraft's website, so I didn't bother for https:// (since no existing valid skin will have it). The old HD skins (super-high resolution heads, 640x640 etc) from the Education Edition website used https://, but when Minecraft removed that they did so on their server end, so it applies to ALL versions of Minecraft To be flexible in case they start re-allowing that in the future, could do "http" as you suggest. It's a bit more vague, but yeah likely not an issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I also find a bit problematic is, how this setup could allow any URL to work as a skin. While I doubt it will work, do I feel like it's not a good idea to leave it up to the server to do the cleanup here... It just feels... odd. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, I'll update the check to be more thorough (by checking for the full Minecraft skin server URL) (Note that the same criticism could be used against the existing Base64 codepath) |
||
// Check if the texture is a hexidecimal (like the skinfiles on Minecraft's servers) | ||
else if(texture.matches("^[0-9a-fA-F]+$")) texture = "http://textures.minecraft.net/texture/"+texture; | ||
else; // TODO: Texture invalid, print a warning or something? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't log anything. The method is called frequently and we don't want it to spam the console. |
||
json = "{\"textures\":{\"SKIN\":{\"url\":\""+texture+"\"}}}"; // (Stable for all MC versions with custom skins.) | ||
texture = Base64.getEncoder().encodeToString(json.getBytes(StandardCharsets.ISO_8859_1)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After you move the private String normalizeTextureURL(String texture) {
// ...
} |
||
profile.getProperties().put("textures", new Property("textures", texture)); | ||
|
||
if (SET_PROFILE_METHOD == null && !INITIALIZED) { | ||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really "or URL". It can either be a very specific URL:
http://textures.minecraft.net/texture/
or a hexidecimal id? of a texture on the same site. Just mentioning URL can be misleading here.