Guest User

Untitled

a guest
Aug 27th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1.     @SuppressWarnings("deprecation")
  2.     public byte[][] getSkinIcon(String name) {
  3.         byte[][] kq = new byte[8][8];
  4.         PreparedStatement ps = null;
  5.         ResultSet r = null;
  6.         try {
  7.  
  8.             // Lấy value từ mysql
  9.             ps = sql.prepare(SKIN_VALUE);
  10.             ps.setString(1, name);
  11.             r = sql.query(ps);
  12.             if (!r.next())
  13.                 return null;
  14.             String value = r.getString("Value");
  15.  
  16.             // Decode & load ảnh
  17.             String json = StringUtils.newStringUtf8(Base64.decodeBase64(value));
  18.             String url = new JsonParser().parse(json).getAsJsonObject().getAsJsonObject("textures")
  19.                     .getAsJsonObject("SKIN").get("url").getAsString();
  20.             BufferedImage base = ImageIO.read(new URL(url));
  21.             BufferedImage img2 = new BufferedImage(base.getWidth(), base.getHeight(), BufferedImage.TYPE_INT_ARGB);
  22.             Graphics2D g = img2.createGraphics();
  23.             g.drawImage(base, 0, 0, null);
  24.             g.dispose();
  25.             for (int i = 0; i < 8; ++i)
  26.                 for (int j = 0; j < 8; ++j) {
  27.                     kq[i][j] = MapPalette.matchColor(new Color(img2.getRGB(i + 8, j + 8), true));
  28.                     byte b = MapPalette.matchColor(new Color(img2.getRGB(i + 40, j + 8), true));
  29.                     if (b != 0)
  30.                         kq[i][j] = b;
  31.                 }
  32.         } catch (Exception e) {
  33.             main.getLogger().log(Level.WARNING, "Can't get " + name + "'s skin head", e);
  34.         } finally {
  35.             cleanup(r, ps);
  36.         }
  37.         return kq;
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment