SHARE
TWEET

Untitled

a guest Jul 17th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package server;
  2.  
  3. import client.*;
  4. import java.util.*;
  5. import server.maps.MapleMapFactory;
  6. import java.sql.*;
  7.  
  8. /**
  9.  *
  10.  * @author FateJiki
  11.  */
  12. public class PlayerTransfer {
  13.     public static List<MapleCharacter> transferList = new ArrayList<MapleCharacter>();
  14.    // public static HashMap<Integer,MapleCharacter> transferList = new HashMap<Integer,MapleCharacter>(); //CharacterID -> MapleCharacter
  15.  
  16.     public static  void addCharacter(MapleCharacter chr){
  17.         synchronized(transferList){
  18.        if(!transferList.contains(chr)){
  19.             transferList.add(chr);
  20.     //        if(!transferList.containsKey(chr.getId())) {
  21.       //      transferList.put(chr.getId(), chr); //put for haspmap insted of add
  22.         }
  23.         }
  24.     }
  25.  
  26.     public static MapleCharacter retrieveCharacter(int cid, MapleClient c) /*throws SQLException*/ {
  27.  
  28.         MapleCharacter chr = null;
  29.         synchronized(transferList){
  30.         for(MapleCharacter xferList : transferList){
  31.             if(xferList.getId() == cid){
  32.                 chr = xferList;
  33.                 chr.client = c;
  34.                 updateCServer(chr);
  35.         }
  36.         }
  37.         if(chr == null){
  38.             try {
  39.             chr = MapleCharacter.loadCharFromDB(cid, c, true);
  40.         } catch (SQLException e) {
  41.             e.printStackTrace();
  42.             }
  43.         }
  44.         }
  45.         return chr;
  46.     }
  47.  
  48.     public static void removeCharacter(int cid){
  49.         synchronized(transferList){
  50.         for(MapleCharacter removeList : transferList){
  51.             if(removeList.getId() == cid){
  52.                 transferList.remove(removeList);
  53.             }
  54.         }
  55.         }
  56.     }
  57.  
  58.     private synchronized static void updateCServer(MapleCharacter ret){
  59.         MapleClient client = ret.getClient();
  60.         MapleMapFactory mapFactory = client.getChannelServer().getMapFactory();
  61.                 ret.map = mapFactory.getMap(ret.mapid);
  62.                 if (ret.map == null) {
  63.                     ret.map = mapFactory.getMap(ret.mapid);
  64.                 }
  65.     }
  66. }
RAW Paste Data
Top