<commit_before>package org.dynmap;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.imageio.ImageIO;

import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.dynmap.MapType.ImageFormat;
import org.dynmap.debug.Debug;
import org.dynmap.utils.DynmapBufferedImage;
import org.dynmap.utils.FileLockManager;

/**
 * Listen for player logins, and process player faces by fetching skins *
 */
public class PlayerFaces {
    private DynmapPlugin plugin;
    private File facesdir;
    private File faces8x8dir;
    private File faces16x16dir;
    private File faces32x32dir;

    
    private class LoadPlayerImages implements Runnable {
        public String playername;
        public LoadPlayerImages(String playername) {
            this.playername = playername;
        }
        public void run() {
            BufferedImage img = null;
            try {
                URL url = new URL("http://s3.amazonaws.com/MinecraftSkins/" + playername + ".png");
                img = ImageIO.read(url);    /* Load skin for player */
            } catch (IOException iox) {
                Debug.debug("Error loading skin for '" + playername + "' - " + iox);
            }
            if(img == null) {
                try {
                    InputStream in = getClass().getResourceAsStream("/char.png");
                    img = ImageIO.read(in);    /* Load generic skin for player */
                    in.close();
                } catch (IOException iox) {
                    Debug.debug("Error loading default skin for '" + playername + "' - " + iox);
                }
            }
            if(img == null) {   /* No image to process?  Quit */
                return;
            }
            int[] faceaccessory = new int[64];  /* 8x8 of face accessory */
            /* Get buffered image for face at 8x8 */
            DynmapBufferedImage face8x8 = DynmapBufferedImage.allocateBufferedImage(8, 8);
            int[] bgcolor = new int[1];
            img.getRGB(0, 0, 1, 1, bgcolor, 0, 1);  /* Get BG color (for accessory face) */
            img.getRGB(8, 8, 8, 8, face8x8.argb_buf, 0, 8); /* Read face from image */
            img.getRGB(40, 8, 8, 8, faceaccessory, 0, 8); /* Read face accessory from image */
            /* Apply accessory to face: first element is transparency color so only ones not matching it */
            for(int i = 0; i < 64; i++) {
                if(faceaccessory[i] != bgcolor[0]) 
                    face8x8.argb_buf[i] = faceaccessory[i];
                else if(face8x8.argb_buf[i] == bgcolor[0])
                    face8x8.argb_buf[i] = 0;
            }
            /* Write 8x8 file */
            File img_8x8 = new File(faces8x8dir, playername + ".png");
            FileLockManager.getWriteLock(img_8x8);
            try {<commit_msg>Yet another face fix - hopefully got the rules on accessories right this time...<commit_after>package org.dynmap;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.imageio.ImageIO;

import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.dynmap.MapType.ImageFormat;
import org.dynmap.debug.Debug;
import org.dynmap.utils.DynmapBufferedImage;
import org.dynmap.utils.FileLockManager;

/**
 * Listen for player logins, and process player faces by fetching skins *
 */
public class PlayerFaces {
    private DynmapPlugin plugin;
    private File facesdir;
    private File faces8x8dir;
    private File faces16x16dir;
    private File faces32x32dir;

    
    private class LoadPlayerImages implements Runnable {
        public String playername;
        public LoadPlayerImages(String playername) {
            this.playername = playername;
        }
        public void run() {
            BufferedImage img = null;
            try {
                URL url = new URL("http://s3.amazonaws.com/MinecraftSkins/" + playername + ".png");
                img = ImageIO.read(url);    /* Load skin for player */
            } catch (IOException iox) {
                Debug.debug("Error loading skin for '" + playername + "' - " + iox);
            }
            if(img == null) {
                try {
                    InputStream in = getClass().getResourceAsStream("/char.png");
                    img = ImageIO.read(in);    /* Load generic skin for player */
                    in.close();
                } catch (IOException iox) {
                    Debug.debug("Error loading default skin for '" + playername + "' - " + iox);
                }
            }
            if(img == null) {   /* No image to process?  Quit */
                return;
            }
            int[] faceaccessory = new int[64];  /* 8x8 of face accessory */
            /* Get buffered image for face at 8x8 */
            DynmapBufferedImage face8x8 = DynmapBufferedImage.allocateBufferedImage(8, 8);
            img.getRGB(8, 8, 8, 8, face8x8.argb_buf, 0, 8); /* Read face from image */
            img.getRGB(40, 8, 8, 8, faceaccessory, 0, 8); /* Read face accessory from image */
            /* Apply accessory to face: see if anything is transparent (if so, apply accessory */
            boolean transp = false;
            for(int i = 0; i < 64; i++) {
            	if((faceaccessory[i] & 0xFF000000) == 0) {
            		transp = true;
            		break;
            	}
            }
            if(transp) {
                for(int i = 0; i < 64; i++) {
                	if((faceaccessory[i] & 0xFF000000) != 0)
                		face8x8.argb_buf[i] = faceaccessory[i];
                }
            }
            /* Write 8x8 file */
            File img_8x8 = new File(faces8x8dir, playername + ".png");
            FileLockManager.getWriteLock(img_8x8);
            try {
{'fraction_non_alphanumeric': 0.10808594390683943, 'fraction_numerical': 0.021485976709857305, 'mean_word_length': 1.8832151300236406, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7047055', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1733, 'n_words': 469}