private static Npc spawnInstance( int instanceIndex, SpawnGroup spawnGroup, SpawnTemplate spawnTemplate, RiftController riftController) { NpcTemplate masterObjectTemplate = DataManager.NPC_DATA.getNpcTemplate(spawnGroup.getNpcid()); Npc npc = new Npc( IDFactory.getInstance().nextId(), riftController, spawnTemplate, masterObjectTemplate); npc.setKnownlist(new NpcKnownList(npc)); npc.setEffectController(new EffectController(npc)); npc.getController().onRespawn(); World world = World.getInstance(); world.storeObject(npc); world.setPosition( npc, spawnTemplate.getWorldId(), instanceIndex, spawnTemplate.getX(), spawnTemplate.getY(), spawnTemplate.getZ(), spawnTemplate.getHeading()); world.spawn(npc); rifts.add(npc); scheduleDespawn(npc); riftController.sendAnnounce(); return npc; }
@Override public void executeCommand(Player admin, String[] params) { if (admin.getAccessLevel() < AdminConfig.COMMAND_RELOAD) { PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command"); return; } if (params == null || params.length != 1) { sendSyntax(admin); return; } ReloadType reloadType = ReloadType.UNKNOWN; try { reloadType = ReloadType.valueOf(params[0].toUpperCase()); } catch (Exception e) { } switch (reloadType) { case COMMAND: try { ChatHandlers.getInstance().reloadChatHandlers(); PacketSendUtility.sendMessage(admin, "Admin/user commands reloaded successfully!"); } catch (GameServerError e) { PacketSendUtility.sendMessage( admin, "Admin/user commands failed to reload! Keeping last version ..."); } break; case NPC: File npcXml = new File("./data/static_data/npcs/npc_templates.xml"); List<NpcTemplate> npcTemplates = new ArrayList<NpcTemplate>(); try { JAXBContext jc = JAXBContext.newInstance(StaticData.class); Unmarshaller un = jc.createUnmarshaller(); un.setSchema(getSchema("./data/static_data/static_data.xsd")); NpcData data = (NpcData) un.unmarshal(npcXml); if (data != null && data.getTemplates() != null) npcTemplates.addAll(data.getTemplates()); } catch (Exception e) { PacketSendUtility.sendMessage( admin, "NPC templates reload failed! Keeping last version ..."); log.error(e); return; } if (npcTemplates.size() > 0) { DataManager.NPC_DATA.setTemplates(npcTemplates); PacketSendUtility.sendMessage( admin, "NPC templates reloaded successfuly, now updating World to reflect changes ...!"); World.getInstance() .doOnAllNpcs( new Executor<Npc>() { @Override public boolean run(Npc object) { NpcTemplate newTemplate = DataManager.NPC_DATA.getNpcTemplate(object.getNpcId()); if (newTemplate != null) { object.setObjectTemplate(newTemplate); } return true; } }, true); PacketSendUtility.sendMessage(admin, "Complete !"); } else PacketSendUtility.sendMessage( admin, "NPC templates reload failed! Keeping last version ..."); break; case PORTAL: File portalDir = new File("./data/static_data/portals"); List<PortalTemplate> portalTemplates = new ArrayList<PortalTemplate>(); try { JAXBContext jc = JAXBContext.newInstance(StaticData.class); Unmarshaller un = jc.createUnmarshaller(); un.setSchema(getSchema("./data/static_data/static_data.xsd")); for (File file : listFiles(portalDir, true)) { PortalData data = (PortalData) un.unmarshal(file); if (data != null && data.getPortals() != null) portalTemplates.addAll(data.getPortals()); } } catch (Exception e) { PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ..."); log.error(e); return; } if (portalTemplates.size() > 0) { DataManager.PORTAL_DATA.setPortals(portalTemplates); PacketSendUtility.sendMessage(admin, "Portals reloaded successfuly!"); } else PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ..."); break; case QUEST: File questXml = new File("./data/static_data/quest_data/quest_data.xml"); File questDir = new File("./data/static_data/quest_script_data"); QuestsData newQuestData; ArrayList<QuestScriptsData> newScriptData = new ArrayList<QuestScriptsData>(); try { JAXBContext jc = JAXBContext.newInstance(StaticData.class); Unmarshaller un = jc.createUnmarshaller(); un.setSchema(getSchema("./data/static_data/static_data.xsd")); newQuestData = (QuestsData) un.unmarshal(questXml); for (File file : listFiles(questDir, true)) { QuestScriptsData data = ((QuestScriptsData) un.unmarshal(file)); if (data != null) if (data.getData() != null) newScriptData.add(data); } } catch (Exception e) { PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ..."); log.error(e); return; } if (newQuestData != null) { try { DataManager.QUEST_DATA.setQuestsData(newQuestData.getQuestsData()); QuestScriptsData questScriptsData = DataManager.QUEST_SCRIPTS_DATA; questScriptsData.getData().clear(); for (QuestScriptsData qsd : newScriptData) { questScriptsData.getData().addAll(qsd.getData()); } QuestEngine.getInstance().load(true); PacketSendUtility.sendMessage(admin, "Quests reloaded successfuly!"); } catch (GameServerError e) { PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ..."); log.error(e); return; } } break; case SKILL: File skillDir = new File("./data/static_data/skills"); List<SkillTemplate> skillTemplates = new ArrayList<SkillTemplate>(); try { JAXBContext jc = JAXBContext.newInstance(StaticData.class); Unmarshaller un = jc.createUnmarshaller(); un.setSchema(getSchema("./data/static_data/static_data.xsd")); for (File file : listFiles(skillDir, true)) { SkillData data = (SkillData) un.unmarshal(file); if (data != null) skillTemplates.addAll(data.getSkillTemplates()); } } catch (Exception e) { PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ..."); log.error(e); return; } if (skillTemplates.size() > 0) { DataManager.SKILL_DATA.setSkillTemplates(skillTemplates); PacketSendUtility.sendMessage(admin, "Skills reloaded successfuly!"); } else PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ..."); break; case SPAWN: File spawnDir = new File("./data/static_data/spawns"); List<SpawnGroup> spawnTemplates = new ArrayList<SpawnGroup>(); try { JAXBContext jc = JAXBContext.newInstance(StaticData.class); Unmarshaller un = jc.createUnmarshaller(); un.setSchema(getSchema("./data/static_data/static_data.xsd")); for (File file : listFiles(spawnDir, true)) { SpawnsData data = (SpawnsData) un.unmarshal(file); if (data != null && data.getSpawnGroups() != null) spawnTemplates.addAll(data.getSpawnGroups()); } } catch (Exception e) { PacketSendUtility.sendMessage(admin, "Spawns reload failed! Keeping last version ..."); log.error(e); return; } if (spawnTemplates.size() > 0) { DataManager.SPAWNS_DATA.setSpawns(spawnTemplates); PacketSendUtility.sendMessage(admin, "Spawns reloaded successfuly!"); } else PacketSendUtility.sendMessage( admin, "Spawns reload failed with empty object! Keeping last version ..."); break; default: sendSyntax(admin); return; } }