Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("deprecation")
- public byte[][] getSkinIcon(String name) {
- byte[][] kq = new byte[8][8];
- PreparedStatement ps = null;
- ResultSet r = null;
- try {
- // Lấy value từ mysql
- ps = sql.prepare(SKIN_VALUE);
- ps.setString(1, name);
- r = sql.query(ps);
- if (!r.next())
- return null;
- String value = r.getString("Value");
- // Decode & load ảnh
- String json = StringUtils.newStringUtf8(Base64.decodeBase64(value));
- String url = new JsonParser().parse(json).getAsJsonObject().getAsJsonObject("textures")
- .getAsJsonObject("SKIN").get("url").getAsString();
- BufferedImage base = ImageIO.read(new URL(url));
- BufferedImage img2 = new BufferedImage(base.getWidth(), base.getHeight(), BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = img2.createGraphics();
- g.drawImage(base, 0, 0, null);
- g.dispose();
- for (int i = 0; i < 8; ++i)
- for (int j = 0; j < 8; ++j) {
- kq[i][j] = MapPalette.matchColor(new Color(img2.getRGB(i + 8, j + 8), true));
- byte b = MapPalette.matchColor(new Color(img2.getRGB(i + 40, j + 8), true));
- if (b != 0)
- kq[i][j] = b;
- }
- } catch (Exception e) {
- main.getLogger().log(Level.WARNING, "Can't get " + name + "'s skin head", e);
- } finally {
- cleanup(r, ps);
- }
- return kq;
- }
Advertisement
Add Comment
Please, Sign In to add comment