Excellzone

Forum and disscussions since 2010


You are not connected. Please login or register

View previous topic View next topic Go down Message [Page 1 of 1]

#1
Excell

avatar
Head Administer
Head Administer
Code:
 Code:
 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database.Information.Loading;

import Database.DatabaseConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Jay
 */
public class BeautyDataProvider {
    private static List<Integer> skins = new ArrayList<Integer>();
    private static Map<Integer, CharacterGender> hair = new HashMap<Integer, CharacterGender>();
    private static Map<Integer, CharacterGender> faces = new HashMap<Integer, CharacterGender>();

    public static void loadData() {
        loadSkins();
        loadHair();
        loadFaces();
    }

    public static boolean isValidHair(int gender, int hairId) {
        CharacterGender hairGender = hair.get(hairId);
        if (hairGender != null && hairGender.getGender() == gender) return true;
        return false;
    }

    public static boolean isValidFace(int gender, int faceId) {
        CharacterGender faceGender = faces.get(faceId);
        if (faceGender != null && faceGender.getGender() == gender) return true;
        return false;
    }

    public static boolean isValidSkin(int skinId) {
        return skins.contains(skinId);
    }

    private static void loadSkins() {
        Connection con = DatabaseConnection.getMCDB();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = con.prepareStatement("SELECT * FROM character_skin_data");
            rs = ps.executeQuery();
            while (rs.next()) {
                skins.add(rs.getInt("skinid"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (ps != null && !ps.isClosed()) ps.close();
                if (rs != null && !rs.isClosed()) rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    private static  void loadHair() {
        Connection con = DatabaseConnection.getMCDB();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = con.prepareStatement("SELECT * FROM character_hair_data");
            rs = ps.executeQuery();
            while (rs.next()) {
                hair.put(rs.getInt("faceid"), new CharacterGender(rs.getString("gender")));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (ps != null && !ps.isClosed()) ps.close();
                if (rs != null && !rs.isClosed()) rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    private static  void loadFaces() {
        Connection con = DatabaseConnection.getMCDB();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = con.prepareStatement("SELECT * FROM character_face_data");
            rs = ps.executeQuery();
            while (rs.next()) {
                faces.put(rs.getInt("hairid"), new CharacterGender(rs.getString("gender")));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (ps != null && !ps.isClosed()) ps.close();
                if (rs != null && !rs.isClosed()) rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static class CharacterGender {
        private int gender;

        private CharacterGender(String gender) {
            if (gender.equals("male")) this.gender = 0;
            else if (gender.equals("female")) this.gender = 1;
        }

        public int getGender() {
            return gender;
        }
    }
}

View user profile http://excellzone.mrforum.net

View previous topic View next topic Back to top Message [Page 1 of 1]


Permissions in this forum:
You cannot reply to topics in this forum