Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release] Skin/Hair/Face loading from MCDB

Skilled Illusionist
Joined
Jul 28, 2009
Messages
339
Reaction score
200
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;
        }
    }
}
Pre-release for Orion.
 
Back
Top