!pnpc npcs dissapear after a server restart

Results 1 to 2 of 2
  1. #1
    Account Upgraded | Title Enabled! natkemon is offline
    MemberRank
    Jul 2008 Join Date
    424Posts

    !pnpc npcs dissapear after a server restart

    !pnpc spawns the npc and places it onto the map but when i restart the server, it disappears but the data is saved in the MYSQL>Spawn. I remember altering my maplemapfactory.java to remove all the npcs that are orginally on the map. but i dont think that should the !pnpc spawned npcs from despawning after a server restart. But this is my java file below.

    This is my MapleMapFactory.Java file.
    PHP Code:
    /*
    This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
    Matthias Butz <matze@odinms.de>
    Jan Christian Meyer <vimes@odinms.de>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation version 3 as published by
    the Free Software Foundation. You may not use, modify or distribute
    this program under any other version of the GNU Affero General Public
    License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */
    package server.maps;

    import java.awt.Rectangle;
    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import provider.MapleData;
    import provider.MapleDataProvider;
    import provider.MapleDataTool;
    import server.PortalFactory;
    import server.life.AbstractLoadedMapleLife;
    import server.life.MapleLifeFactory;
    import server.life.MapleMonster;
    import tools.StringUtil;
    import java.awt.Point;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import tools.DatabaseConnection;

    public class 
    MapleMapFactory {
        private static 
    org.slf4j.Logger log org.slf4j.LoggerFactory.getLogger(MapleMapFactory.class);
        private 
    MapleDataProvider source;
        private 
    MapleData nameData;
        private 
    Map<IntegerMapleMapmaps = new HashMap<IntegerMapleMap>();
        private 
    int channel;

        public 
    MapleMapFactory(MapleDataProvider sourceMapleDataProvider stringSource) {
            
    this.source source;
            
    this.nameData stringSource.getData("Map.img");
        }

        public 
    MapleMap getMap(int mapid) {
            return 
    getMap(mapidtruetruetruetruefalse);
        }

        
    //backwards-compatible
        
    public MapleMap getMap(int mapidboolean respawnsboolean npcs) {
            return 
    getMap(mapidrespawnsnpcstruetruefalse);
        }

        public 
    MapleMap getMap(int mapidboolean respawnsboolean npcsboolean reactorsboolean monstersboolean forceReload) {
            
    Integer omapid Integer.valueOf(mapid);
            
    MapleMap map maps.get(omapid);
            if ((
    map == null) || (forceReload)) {
                
    synchronized (this) {
                    
    map maps.get(omapid);
                    if ((
    map != null) && (!forceReload)) {
                        return 
    map;
                    }
                    if (
    forceReload) {
                        
    maps.remove(omapid);
                    }

                    
    String mapName getMapName(mapid);
                    
    MapleData mapData source.getData(mapName);
                    
    String link MapleDataTool.getString(mapData.getChildByPath("info/link"), "");
                    if (!
    link.equals("")) { //nexon made hundreds of dojo maps so to reduce the size they added links.
                        
    mapName getMapName(Integer.parseInt(link));
                        
    mapData source.getData(mapName);
                    }
                    
    float monsterRate 0;
                    
    MapleData mobRate mapData.getChildByPath("info/mobRate");
                    if (
    mobRate != null) {
                        
    monsterRate = ((Float) mobRate.getData()).floatValue();
                    }
                    
    map = new MapleMap(mapidchannelMapleDataTool.getInt("info/returnMap"mapData), monsterRate);
                    
    map.setOnFirstUserEnter(MapleDataTool.getString(mapData.getChildByPath("info/onFirstUserEnter"), String.valueOf(mapid)));
                    
    map.setOnUserEnter(MapleDataTool.getString(mapData.getChildByPath("info/onUserEnter"), String.valueOf(mapid)));
                    
    map.setTimeMobId(MapleDataTool.getInt(mapData.getChildByPath("info/timeMob/id"), -1));
                    
    map.setTimeMobMessage(MapleDataTool.getString(mapData.getChildByPath("info/timeMob/message"), ""));
                    
    map.setFieldLimit(MapleDataTool.getInt(mapData.getChildByPath("info/fieldLimit"), 0));
                    
    PortalFactory portalFactory = new PortalFactory();
                    for (
    MapleData portal mapData.getChildByPath("portal")) {
                        
    map.addPortal(portalFactory.makePortal(MapleDataTool.getInt(portal.getChildByPath("pt")), portal));
                    }
                    List<
    MapleFootholdallFootholds = new LinkedList<MapleFoothold>();
                    
    Point lBound = new Point();
                    
    Point uBound = new Point();
                    for (
    MapleData footRoot mapData.getChildByPath("foothold")) {
                        for (
    MapleData footCat footRoot) {
                            for (
    MapleData footHold footCat) {
                                
    int x1 MapleDataTool.getInt(footHold.getChildByPath("x1"));
                                
    int y1 MapleDataTool.getInt(footHold.getChildByPath("y1"));
                                
    int x2 MapleDataTool.getInt(footHold.getChildByPath("x2"));
                                
    int y2 MapleDataTool.getInt(footHold.getChildByPath("y2"));
                                
    MapleFoothold fh = new MapleFoothold(new Point(x1y1), new Point(x2y2), Integer.parseInt(footHold.getName()));
                                
    fh.setPrev(MapleDataTool.getInt(footHold.getChildByPath("prev")));
                                
    fh.setNext(MapleDataTool.getInt(footHold.getChildByPath("next")));
                                if (
    fh.getX1() < lBound.x) {
                                    
    lBound.fh.getX1();
                                }
                                if (
    fh.getX2() > uBound.x) {
                                    
    uBound.fh.getX2();
                                }
                                if (
    fh.getY1() < lBound.y) {
                                    
    lBound.fh.getY1();
                                }
                                if (
    fh.getY2() > uBound.y) {
                                    
    uBound.fh.getY2();
                                }
                                
    allFootholds.add(fh);
                            }
                        }
                    }
                    
    MapleFootholdTree fTree = new MapleFootholdTree(lBounduBound);
                    for (
    MapleFoothold fh allFootholds) {
                        
    fTree.insert(fh);
                    }
                    
    map.setFootholds(fTree);
                    if (
    mapData.getChildByPath("area") != null) {
                        for (
    MapleData area mapData.getChildByPath("area")) {
                            
    int x1 MapleDataTool.getInt(area.getChildByPath("x1"));
                            
    int y1 MapleDataTool.getInt(area.getChildByPath("y1"));
                            
    int x2 MapleDataTool.getInt(area.getChildByPath("x2"));
                            
    int y2 MapleDataTool.getInt(area.getChildByPath("y2"));
                            
    map.addMapleArea(new Rectangle(x1y1, (x2 x1), (y2 y1)));
                        }
                    }
                                    try {
                        
    java.sql.Connection con DatabaseConnection.getConnection();
                        
    java.sql.PreparedStatement ps con.prepareStatement("SELECT * FROM spawns WHERE mid = ?");
                        
    ps.setInt(1omapid);
                        
    ResultSet rs ps.executeQuery();
                        while (
    rs.next()) {
                            
    int id rs.getInt("idd");
                            
    int f rs.getInt("f");
                            
    boolean hide false;
                            
    String type rs.getString("type");
                            
    int fh rs.getInt("fh");
                            
    int cy rs.getInt("cy");
                            
    int rx0 rs.getInt("rx0");
                            
    int rx1 rs.getInt("rx1");
                            
    int x rs.getInt("x");
                            
    int y rs.getInt("y");
                            
    int mobTime rs.getInt("mobtime");
                            
    AbstractLoadedMapleLife myLife loadLife(idfhidefhcyrx0rx1xytype);
                            if (
    type.equals("n")) {
                                
                            } else if (
    type.equals("m")) {
                                
    MapleMonster monster = (MapleMonstermyLife;
                                
    map.addMonsterSpawn(monstermobTime);
                            }
                        }
                        
    ps.close();
                        
    rs.close();
                        
    java.sql.PreparedStatement ps2 con.prepareStatement("SELECT * FROM playernpcs WHERE map = ?");
                        
    ps2.setInt(1omapid);
                        
    ResultSet rs2 ps2.executeQuery();
                        while (
    rs2.next()) {
                            
    map.addMapObject(new PlayerNPCs(rs2));
                        }
                        
    rs2.close();
                        
    ps2.close();
                    } catch (
    SQLException e) {
                        
    e.printStackTrace();
                    }
                    for (
    MapleData life mapData.getChildByPath("life")) {
                        
    String id MapleDataTool.getString(life.getChildByPath("id"));
                        
    String type MapleDataTool.getString(life.getChildByPath("type"));
                        
    AbstractLoadedMapleLife myLife loadLife(lifeidtype);
                        if (
    myLife instanceof MapleMonster) {
                            
    MapleMonster monster = (MapleMonstermyLife;
                            
    int mobTime MapleDataTool.getInt("mobTime"life0);
                            if (
    mobTime == -1//does not respawn, force spawn once
                            
    {
                                
    map.spawnMonster(monster);
                            } else {
                                
    map.addMonsterSpawn(monstermobTime);
                            }
                        } else {
                            
                        }
                    }
                    if (
    mapData.getChildByPath("reactor") != null) {
                        for (
    MapleData reactor mapData.getChildByPath("reactor")) {
                            
    String id MapleDataTool.getString(reactor.getChildByPath("id"));
                            if (
    id != null) {
                                
    MapleReactor newReactor loadReactor(reactorid);
                                
    map.spawnReactor(newReactor);
                            }
                        }
                    }
                    try {
                        
    map.setMapName(MapleDataTool.getString("mapName"nameData.getChildByPath(getMapStringName(omapid)), ""));
                        
    map.setStreetName(MapleDataTool.getString("streetName"nameData.getChildByPath(getMapStringName(omapid)), ""));
                    } catch (
    Exception e) {
                        
    map.setMapName("");
                        
    map.setStreetName("");
                    }
                    
    map.setClock(mapData.getChildByPath("clock") != null);
                    
    map.setEverlast(mapData.getChildByPath("everlast") != null);
                    
    map.setTown(mapData.getChildByPath("town") != null);
                    
    map.setHPDec(MapleDataTool.getIntConvert("decHP"mapData0));
                    
    map.setHPDecProtect(MapleDataTool.getIntConvert("protectItem"mapData0));
                    
    map.setForcedReturnMap(MapleDataTool.getInt(mapData.getChildByPath("info/forcedReturn"), 999999999));
                    
    map.setBoat(mapData.getChildByPath("shipObj") != null);
                    
    map.setTimeLimit(MapleDataTool.getIntConvert("timeLimit"mapData.getChildByPath("info"), -1));
                    
    map.setFieldType(MapleDataTool.getIntConvert("info/fieldType"mapData0));
                    
    maps.put(omapidmap);
                }
            }
            return 
    map;
        }

        private 
    AbstractLoadedMapleLife loadLife(int idint fboolean hideint fhint cyint rx0int rx1int xint yString type) {
            
    AbstractLoadedMapleLife myLife MapleLifeFactory.getLife(idtype);
            
    myLife.setCy(cy);
            
    myLife.setF(f);
            
    myLife.setFh(fh);
            
    myLife.setRx0(rx0);
            
    myLife.setRx1(rx1);
            
    myLife.setPosition(new Point(xy));
                    
    myLife.setHide(hide);
            return 
    myLife;
        }

        public 
    boolean isMapLoaded(int mapId) {
            return 
    maps.containsKey(mapId);
        }

        private 
    AbstractLoadedMapleLife loadLife(MapleData lifeString idString type) {
            
    AbstractLoadedMapleLife myLife MapleLifeFactory.getLife(Integer.parseInt(id), type);
            
    myLife.setCy(MapleDataTool.getInt(life.getChildByPath("cy")));
            
    MapleData dF life.getChildByPath("f");
            if (
    dF != null) {
                
    myLife.setF(MapleDataTool.getInt(dF));
            }
            
    myLife.setFh(MapleDataTool.getInt(life.getChildByPath("fh")));
            
    myLife.setRx0(MapleDataTool.getInt(life.getChildByPath("rx0")));
            
    myLife.setRx1(MapleDataTool.getInt(life.getChildByPath("rx1")));
            
    int x MapleDataTool.getInt(life.getChildByPath("x"));
            
    int y MapleDataTool.getInt(life.getChildByPath("y"));
            
    myLife.setPosition(new Point(xy));
            
    int hide MapleDataTool.getInt("hide"life0);
            if (
    hide == 1) {
                
    myLife.setHide(true);
            }
            return 
    myLife;
        }

        private 
    MapleReactor loadReactor(MapleData reactorString id) {
            
    MapleReactor myReactor = new MapleReactor(MapleReactorFactory.getReactor(Integer.parseInt(id)), Integer.parseInt(id));
            
    int x MapleDataTool.getInt(reactor.getChildByPath("x"));
            
    int y MapleDataTool.getInt(reactor.getChildByPath("y"));
            
    myReactor.setPosition(new Point(xy));
            
    myReactor.setDelay(MapleDataTool.getInt(reactor.getChildByPath("reactorTime")) * 1000);
            
    myReactor.setState((byte0);
            
    myReactor.setName(MapleDataTool.getString(reactor.getChildByPath("name"), ""));
            return 
    myReactor;
        }

        private 
    String getMapName(int mapid) {
            
    String mapName StringUtil.getLeftPaddedStr(Integer.toString(mapid), '0'9);
            
    StringBuilder builder = new StringBuilder("Map/Map");
            
    int area mapid 100000000;
            
    builder.append(area);
            
    builder.append("/");
            
    builder.append(mapName);
            
    builder.append(".img");
            
    mapName builder.toString();
            return 
    mapName;
        }

        private 
    String getMapStringName(int mapid) {
            
    StringBuilder builder = new StringBuilder();
            if (
    mapid 100000000) {
                
    builder.append("maple");
            } else if (
    mapid >= 100000000 && mapid 200000000) {
                
    builder.append("victoria");
            } else if (
    mapid >= 200000000 && mapid 300000000) {
                
    builder.append("ossyria");
            } else if (
    mapid >= 540000000 && mapid 541010110) {
                
    builder.append("singapore");
            } else if (
    mapid >= 600000000 && mapid 620000000) {
                
    builder.append("MasteriaGL");
            } else if (
    mapid >= 670000000 && mapid 682000000) {
                
    builder.append("weddingGL");
            } else if (
    mapid >= 682000000 && mapid 683000000) {
                
    builder.append("HalloweenGL");
            } else if (
    mapid >= 800000000 && mapid 900000000) {
                
    builder.append("jp");
            } else {
                
    builder.append("etc");
            }
            
    builder.append("/" mapid);
            return 
    builder.toString();
        }

        public 
    void setChannel(int channel) {
            
    this.channel channel;
        }

        public 
    Map<IntegerMapleMapgetMaps() {
            return 
    maps;
        }

        public 
    void disposeMap(int mapId) {
            
    synchronized (maps) {
                if (
    maps.containsKey(mapId)) {
                    
    maps.remove(mapId);
                }
                    }
        }

    Is there anwyway to fix this?


  2. #2
    Member Dylanaw is offline
    MemberRank
    May 2013 Join Date
    66Posts

    Re: !pnpc npcs dissapear after a server restart




Advertisement