-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SkJsonTeam/master
Bunch fixes (Typos, Expressions, Examples)
- Loading branch information
Showing
9 changed files
with
113 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
src/main/java/lol/aabss/skuishy/elements/expressions/ExprMainHand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/lol/aabss/skuishy/other/skins/SkinWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package lol.aabss.skuishy.other.skins; | ||
|
||
import com.destroystokyo.paper.profile.PlayerProfile; | ||
import com.destroystokyo.paper.profile.ProfileProperty; | ||
import org.bukkit.entity.Player; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.StringReader; | ||
import java.net.URL; | ||
import java.util.Base64; | ||
|
||
public abstract class SkinWrapper { | ||
public static BufferedImage get(Player player, @Nullable Number size, boolean lay) throws Exception { | ||
BufferedImage textureImage = imgTexture(player); | ||
BufferedImage subImage = textureImage.getSubimage(8,8,8,8); | ||
assert size != null; | ||
BufferedImage face = new BufferedImage(size.intValue(), size.intValue(), subImage.getType()); | ||
Graphics2D faceTmp = face.createGraphics(); | ||
faceTmp.drawImage(textureImage, 0, 0, size.intValue(), size.intValue(), null); | ||
faceTmp.dispose(); | ||
if (lay) { | ||
try { | ||
BufferedImage outerLayer = textureImage.getSubimage(40, 8, 8, 8); | ||
faceTmp.drawImage(outerLayer, 0, 0, size.intValue(), size.intValue(), null); | ||
faceTmp.dispose(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
return face; | ||
} | ||
|
||
public static ProfileProperty getProfileProperties(Player p) { | ||
PlayerProfile playerProfile = p.getPlayerProfile(); | ||
ProfileProperty prop = null; | ||
for (ProfileProperty property : playerProfile.getProperties()) { | ||
if (property.getName().equals("textures")) { | ||
prop = property; | ||
break; | ||
// add break statement for that for loop, cause when for loop matches the condition it's should stop looping | ||
} | ||
} | ||
return prop; | ||
} | ||
|
||
static final JSONParser JSON_PARSER = new JSONParser(); | ||
|
||
public static String urlTexture(Player player) throws Exception { | ||
// Gets the player's value | ||
Player p = player.getPlayer(); | ||
assert p != null; | ||
String value = getProfileProperties(p).getValue(); | ||
byte[] playerBytes = Base64.getDecoder().decode(value); | ||
String playerString = new String(playerBytes); | ||
Object parsedPlayerString = JSON_PARSER.parse(new StringReader(playerString)); | ||
if (parsedPlayerString instanceof JSONObject object) { | ||
JSONObject textures = (JSONObject) object.get("textures"); | ||
JSONObject skin = (JSONObject) textures.get("SKIN"); | ||
return skin.get("url").toString(); | ||
} | ||
return null; | ||
} | ||
public static BufferedImage imgTexture(Player player) { | ||
String url; | ||
try { | ||
url = urlTexture(player); | ||
assert url != null; | ||
URL skinurl = new URL(url); | ||
return ImageIO.read(skinurl); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |