Advertisement
iliqbg

for l2jlisvus

Feb 16th, 2013
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 92.06 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Lisvus_DataPack
  3. Index: data/jscript/village_master/__init__.py
  4. ===================================================================
  5. --- data/jscript/village_master/__init__.py (revision 325)
  6. +++ data/jscript/village_master/__init__.py (working copy)
  7. @@ -1,41 +0,0 @@
  8. -__all__ = [
  9. -'7026_bitz_occupation_change',
  10. -'7031_biotin_occupation_change',
  11. -'7037_levian_occupation_change',
  12. -'7066_pabris_occupation_change',
  13. -'7070_sylvain_occupation_change',
  14. -'7109_hannavalt_occupation_change',
  15. -'7115_jurek_occupation_change',
  16. -'7120_maximilian_occupation_change',
  17. -'7154_asterios_occupation_change',
  18. -'7288_rains_occupation_change',
  19. -'7289_raymond_occupation_change',
  20. -'7290_xenos_occupation_change',
  21. -'7297_tobias_occupation_change',
  22. -'7358_thifiell_occupation_change',
  23. -'7373_ramos_occupation_change',
  24. -'7462_tronix_occupation_change',
  25. -'7474_angus_occupation_change',
  26. -'7498_moke_occupation_change',
  27. -'7499_tapoy_occupation_change',
  28. -'7500_osborn_occupation_change',
  29. -'7503_rikadio_occupation_change',
  30. -'7504_mendio_occupation_change',
  31. -'7505_drikus_occupation_change',
  32. -'7508_castor_occupation_change',
  33. -'7511_gesto_occupation_change',
  34. -'7512_kusto_occupation_change',
  35. -'7513_penatus_occupation_change',
  36. -'7520_reed_occupation_change',
  37. -'7525_bronk_occupation_change',
  38. -'7565_kakai_occupation_change',
  39. -'7594_ranspo_occupation_change',
  40. -'7595_opix_occupation_change',
  41. -'9000_clan',
  42. -'9001_alliance'
  43. -]
  44. -for name in __all__ :
  45. -    try :
  46. -        __import__('data.jscript.village_master.'+name,globals(), locals(), ['__init__'], -1)
  47. -    except :
  48. -        print "Failed to import village master : ",name
  49. \ No newline at end of file
  50. Index: data/scripts.cfg
  51. ===================================================================
  52. --- data/scripts.cfg    (revision 0)
  53. +++ data/scripts.cfg    (revision 0)
  54. @@ -0,0 +1,246 @@
  55. +# Author: Micr0 for L2JLisvus
  56. +
  57. +#Quests in Jython /__init__.py
  58. +quests/1_LettersOfLove1/__init__.py
  59. +quests/2_WhatWomenWant1/__init__.py
  60. +quests/3_ReleaseDarkelfElder1/__init__.py
  61. +quests/4_LongLiveLordOfFlame/__init__.py
  62. +quests/5_MinersFavor/__init__.py
  63. +quests/6_StepIntoTheFuture/__init__.py
  64. +quests/7_ATripBegins/__init__.py
  65. +quests/8_AnAdventureBegins/__init__.py
  66. +quests/9_IntoTheCityOfHumans/__init__.py
  67. +quests/10_IntoTheWorld/__init__.py
  68. +quests/19_GoToThePastureland/__init__.py
  69. +quests/31_SecretBuriedInTheSwamp/__init__.py
  70. +quests/32_AnObviousLie/__init__.py
  71. +quests/33_MakeAPairOfDressShoes/__init__.py
  72. +quests/34_InSearchOfClothes/__init__.py
  73. +quests/35_FindGlitteringJewelry/__init__.py
  74. +quests/36_MakeASewingKit/__init__.py
  75. +quests/37_PleaseMakeMeFormalWear/__init__.py
  76. +quests/39_RedEyedInvaders/__init__.py
  77. +quests/42_HelpTheUncle/__init__.py
  78. +quests/43_HelpTheSister/__init__.py
  79. +quests/44_HelpTheSon/__init__.py
  80. +quests/45_ToTalkingIsland/__init__.py
  81. +quests/46_OnceMoreInTheArmsOfTheMotherTree/__init__.py
  82. +quests/47_IntoTheDarkForest/__init__.py
  83. +quests/48_ToTheImmortalPlateau/__init__.py
  84. +quests/49_TheRoadHome/__init__.py
  85. +quests/101_SwordOfSolidarityQuest/__init__.py
  86. +quests/102_FungusFever/__init__.py
  87. +quests/103_SpiritOfCraftsman/__init__.py
  88. +quests/104_SpiritOfMirror/__init__.py
  89. +quests/105_SkirmishWithOrcs/__init__.py
  90. +quests/106_ForgottenTruth/__init__.py
  91. +quests/107_ShowNoMercy/__init__.py
  92. +quests/108_DiamondGambit/__init__.py
  93. +quests/151_SaveMySister1/__init__.py
  94. +quests/152_ShardsOfGolem/__init__.py
  95. +quests/153_WharfOldtimersFavor/__init__.py
  96. +quests/154_SacrificeToSea/__init__.py
  97. +quests/155_FindSirWindawood/__init__.py
  98. +quests/156_MillenniumLove/__init__.py
  99. +quests/157_RecoverSmuggled/__init__.py
  100. +quests/158_SeedOfEvil/__init__.py
  101. +quests/159_ProtectHeadsprings/__init__.py
  102. +quests/160_NerupasFavor/__init__.py
  103. +quests/161_FruitsOfMothertree/__init__.py
  104. +quests/162_CurseOfFortress/__init__.py
  105. +quests/163_LegacyOfPoet/__init__.py
  106. +quests/164_BloodFiend/__init__.py
  107. +quests/165_WildHunt/__init__.py
  108. +quests/166_DarkMass/__init__.py
  109. +quests/167_DwarvenKinship/__init__.py
  110. +quests/168_DeliverSupplies/__init__.py
  111. +quests/169_NightmareChildren/__init__.py
  112. +quests/170_DangerousAllure/__init__.py
  113. +quests/171_ActsOfEvil/__init__.py
  114. +quests/211_TrialOfChallenger/__init__.py
  115. +quests/212_TrialOfDuty/__init__.py
  116. +quests/213_TrialOfSeeker/__init__.py
  117. +quests/214_TrialOfScholar/__init__.py
  118. +quests/215_TrialOfPilgrim/__init__.py
  119. +quests/216_TrialOfGuildsman/__init__.py
  120. +quests/217_TestimonyOfTrust/__init__.py
  121. +quests/218_TestimonyOfLife/__init__.py
  122. +quests/219_TestimonyOfFate/__init__.py
  123. +quests/220_TestimonyOfGlory/__init__.py
  124. +quests/221_TestimonyOfProsperity/__init__.py
  125. +quests/222_TestOfDuelist/__init__.py
  126. +quests/223_TestOfChampion/__init__.py
  127. +quests/224_TestOfSagittarius/__init__.py
  128. +quests/225_TestOfSearcher/__init__.py
  129. +quests/226_TestOfHealer/__init__.py
  130. +quests/227_TestOfReformer/__init__.py
  131. +quests/228_TestOfMagus/__init__.py
  132. +quests/229_TestOfWitchcraft/__init__.py
  133. +quests/230_TestOfSummoner/__init__.py
  134. +quests/231_TestOfMaestro/__init__.py
  135. +quests/232_TestOfLord/__init__.py
  136. +quests/233_TestOfWarspirit/__init__.py
  137. +quests/234_FatesWhisper/__init__.py
  138. +quests/235_MimirsElixir/__init__.py
  139. +quests/241_PossessorOfAPreciousSoul_1/__init__.py
  140. +quests/242_PossessorOfAPreciousSoul_2/__init__.py
  141. +quests/246_PossessorOfAPreciousSoul_3/__init__.py
  142. +quests/247_PossessorOfAPreciousSoul_4/__init__.py
  143. +quests/257_GuardIsBusy1/__init__.py
  144. +quests/258_BringWolfPelt1/__init__.py
  145. +quests/259_RanchersPlea/__init__.py
  146. +quests/260_HuntForOrcs1/__init__.py
  147. +quests/261_DreamOfMoneylender1/__init__.py
  148. +quests/262_BringMeMushrooms1/__init__.py
  149. +quests/263_KillAllSylphs1/__init__.py
  150. +quests/264_KeenClaws/__init__.py
  151. +quests/265_ChainsOfSlavery/__init__.py
  152. +quests/266_PleaOfPixies/__init__.py
  153. +quests/267_WrathOfVerdure/__init__.py
  154. +quests/271_ProofOfValor/__init__.py
  155. +quests/272_WrathOfAncestors/__init__.py
  156. +quests/273_InvadersOfHolyland/__init__.py
  157. +quests/274_AgainstWolfMen/__init__.py
  158. +quests/275_BlackWingedSpies/__init__.py
  159. +quests/276_HestuiTotem/__init__.py
  160. +quests/277_GatekeepersOffering/__init__.py
  161. +quests/291_RedBonnetsRevenge/__init__.py
  162. +quests/292_CrushBrigands/__init__.py
  163. +quests/293_HiddenVein/__init__.py
  164. +quests/294_CovertBusiness/__init__.py
  165. +quests/295_DreamsOfFlight/__init__.py
  166. +quests/296_SilkOfTarantula/__init__.py
  167. +quests/297_GatekeepersFavor/__init__.py
  168. +quests/298_LizardmensConspiracy/__init__.py
  169. +quests/299_GatherIngredientsForPie/__init__.py
  170. +quests/303_CollectArrowheads/__init__.py
  171. +quests/306_CrystalOfFireice/__init__.py
  172. +quests/313_CollectSpores/__init__.py
  173. +quests/316_DestroyPlaguebringers/__init__.py
  174. +quests/317_CatchTheWind/__init__.py
  175. +quests/319_ScentOfDeath/__init__.py
  176. +quests/320_BonesTellFuture/__init__.py
  177. +quests/324_SweetestVenom/__init__.py
  178. +quests/325_GrimCollector/__init__.py
  179. +quests/326_VanquishRemnants/__init__.py
  180. +quests/327_ReclaimTheLand/__init__.py
  181. +quests/328_SenseForBusiness/__init__.py
  182. +quests/329_CuriosityOfDwarf/__init__.py
  183. +quests/330_AdeptOfTaste/__init__.py
  184. +quests/331_ArrowForVengeance/__init__.py
  185. +quests/333_BlackLionHunt/__init__.py
  186. +quests/334_TheWishingPotion/__init__.py
  187. +quests/336_CoinOfMagic/__init__.py
  188. +quests/338_AlligatorHunter/__init__.py
  189. +quests/341_HuntingForWildBeasts/__init__.py
  190. +quests/343_UnderTheShadowOfTheIvoryTower/__init__.py
  191. +quests/345_MethodToRaiseTheDead/__init__.py
  192. +quests/347_GoGetTheCalculator/__init__.py
  193. +quests/348_ArrogantSearch/__init__.py
  194. +quests/350_EnhanceYourWeapon/__init__.py
  195. +quests/351_BlackSwan/__init__.py
  196. +quests/352_HelpRoodRaiseANewPet/__init__.py
  197. +quests/354_ConquestOfAlligatorIsland/__init__.py
  198. +quests/355_FamilyHonor/__init__.py
  199. +quests/356_DigUpTheSeaOfSpores/__init__.py
  200. +quests/357_WarehouseKeepersAmbition/__init__.py
  201. +quests/358_IllegitimateChildOfAGoddess/__init__.py
  202. +quests/359_ForSleeplessDeadmen/__init__.py
  203. +quests/360_PlunderTheirSupplies/__init__.py
  204. +quests/362_BardsMandolin/__init__.py
  205. +quests/363_SorrowfulSoundofFlute/__init__.py
  206. +quests/364_JovialAccordion/__init__.py
  207. +quests/365_DevilsLegacy/__init__.py
  208. +quests/368_TrespassingIntoTheSacredArea/__init__.py
  209. +quests/370_AWisemanSowsSeeds/__init__.py
  210. +quests/372_LegacyOfInsolence/__init__.py
  211. +quests/373_SupplierOfReagents/__init__.py
  212. +quests/374_WhisperOfDreams1/__init__.py
  213. +quests/375_WhisperOfDreams2/__init__.py
  214. +quests/376_GiantsExploration1/__init__.py
  215. +quests/377_GiantsExploration2/__init__.py
  216. +quests/383_SearchingForTreasure/__init__.py
  217. +quests/385_YokeofthePast/__init__.py
  218. +quests/386_StolenDignity/__init__.py
  219. +quests/401_PathToWarrior/__init__.py
  220. +quests/402_PathToKnight/__init__.py
  221. +quests/403_PathToRogue/__init__.py
  222. +quests/404_PathToWizard/__init__.py
  223. +quests/405_PathToCleric/__init__.py
  224. +quests/406_PathToElvenKnight/__init__.py
  225. +quests/407_PathToElvenScout/__init__.py
  226. +quests/408_PathToElvenwizard/__init__.py
  227. +quests/409_PathToOracle/__init__.py
  228. +quests/410_PathToPalusKnight/__init__.py
  229. +quests/411_PathToAssassin/__init__.py
  230. +quests/412_PathToDarkwizard/__init__.py
  231. +quests/413_PathToShillienOracle/__init__.py
  232. +quests/414_PathToOrcRaider/__init__.py
  233. +quests/415_PathToOrcMonk/__init__.py
  234. +quests/416_PathToOrcShaman/__init__.py
  235. +quests/417_PathToScavenger/__init__.py
  236. +quests/418_PathToArtisan/__init__.py
  237. +quests/419_GetAPet/__init__.py
  238. +quests/420_LittleWings/__init__.py
  239. +quests/421_LittleWingAdventures/__init__.py
  240. +quests/426_FishingShot/__init__.py
  241. +quests/431_WeddingMarch/__init__.py
  242. +quests/432_BirthdayPartySong/__init__.py
  243. +quests/501_ProofOfClanAlliance/__init__.py
  244. +quests/503_PursuitClanAmbition/__init__.py
  245. +quests/621_EggDelivery/__init__.py
  246. +quests/622_DeliveryOfSpecialLiquor/__init__.py
  247. +quests/626_ADarkTwilight/__init__.py
  248. +quests/627_HeartInSearchOfPower/__init__.py
  249. +quests/634_InSearchofDimensionalFragments/__init__.py
  250. +quests/999_C3Tutorial/__init__.py
  251. +
  252. +#Custom
  253. +custom/12535_WakeBaium/__init__.py
  254. +custom/3995_echo/__init__.py
  255. +custom/7000_HeroItems/__init__.py
  256. +
  257. +#teleports
  258. +teleports/1100_teleport_with_charm/__init__.py
  259. +teleports/1101_teleport_to_race_track/__init__.py
  260. +teleports/1102_toivortex_blue/__init__.py
  261. +teleports/1102_toivortex_green/__init__.py
  262. +teleports/1102_toivortex_red/__init__.py
  263. +teleports/1103_OracleTeleport/__init__.py
  264. +teleports/2000_NoblesseTeleport/__init__.py
  265. +
  266. +#village master
  267. +village_master/7026_bitz_occupation_change/__init__.py
  268. +village_master/7031_biotin_occupation_change/__init__.py
  269. +village_master/7037_levian_occupation_change/__init__.py
  270. +village_master/7066_pabris_occupation_change/__init__.py
  271. +village_master/7070_sylvain_occupation_change/__init__.py
  272. +village_master/7109_hannavalt_occupation_change/__init__.py
  273. +village_master/7115_jurek_occupation_change/__init__.py
  274. +village_master/7120_maximilian_occupation_change/__init__.py
  275. +village_master/7154_asterios_occupation_change/__init__.py
  276. +village_master/7288_rains_occupation_change/__init__.py
  277. +village_master/7289_raymond_occupation_change/__init__.py
  278. +village_master/7290_xenos_occupation_change/__init__.py
  279. +village_master/7297_tobias_occupation_change/__init__.py
  280. +village_master/7358_thifiell_occupation_change/__init__.py
  281. +village_master/7373_ramos_occupation_change/__init__.py
  282. +village_master/7462_tronix_occupation_change/__init__.py
  283. +village_master/7474_angus_occupation_change/__init__.py
  284. +village_master/7498_moke_occupation_change/__init__.py
  285. +village_master/7499_tapoy_occupation_change/__init__.py
  286. +village_master/7500_osborn_occupation_change/__init__.py
  287. +village_master/7503_rikadio_occupation_change/__init__.py
  288. +village_master/7504_mendio_occupation_change/__init__.py
  289. +village_master/7505_drikus_occupation_change/__init__.py
  290. +village_master/7508_castor_occupation_change/__init__.py
  291. +village_master/7511_gesto_occupation_change/__init__.py
  292. +village_master/7512_kusto_occupation_change/__init__.py
  293. +village_master/7513_penatus_occupation_change/__init__.py
  294. +village_master/7520_reed_occupation_change/__init__.py
  295. +village_master/7525_bronk_occupation_change/__init__.py
  296. +village_master/7565_kakai_occupation_change/__init__.py
  297. +village_master/7594_ranspo_occupation_change/__init__.py
  298. +village_master/7595_opix_occupation_change/__init__.py
  299. +village_master/9000_clan/__init__.py
  300. +village_master/9001_alliance/__init__.py
  301. \ No newline at end of file
  302. Index: data/jscript/teleports/__init__.py
  303. ===================================================================
  304. --- data/jscript/teleports/__init__.py  (revision 325)
  305. +++ data/jscript/teleports/__init__.py  (working copy)
  306. @@ -1,14 +0,0 @@
  307. -__all__ = [
  308. -'1100_teleport_with_charm',
  309. -'1101_teleport_to_race_track',
  310. -'1102_toivortex_green',
  311. -'1102_toivortex_blue',
  312. -'1102_toivortex_red',
  313. -'1103_OracleTeleport',
  314. -'2000_NoblesseTeleport'
  315. -]
  316. -for name in __all__ :
  317. -    try :
  318. -        __import__('data.jscript.teleports.'+name,globals(), locals(), ['__init__'], -1)
  319. -    except :
  320. -        print "Failed to import teleport : ",name
  321. \ No newline at end of file
  322. Index: data/jscript/__init__.py
  323. ===================================================================
  324. --- data/jscript/__init__.py    (revision 325)
  325. +++ data/jscript/__init__.py    (working copy)
  326. @@ -1,10 +0,0 @@
  327. -__all__ = [
  328. -'quests',
  329. -'custom',
  330. -'teleports',
  331. -'village_master'
  332. -]
  333. -import quests
  334. -import custom
  335. -import teleports
  336. -import village_master
  337. Index: data/jscript/custom/__init__.py
  338. ===================================================================
  339. --- data/jscript/custom/__init__.py (revision 325)
  340. +++ data/jscript/custom/__init__.py (working copy)
  341. @@ -1,10 +0,0 @@
  342. -__all__ = [
  343. -'3995_echo',
  344. -'12535_WakeBaium',
  345. -'7000_HeroItems'
  346. -]
  347. -for name in __all__ :
  348. -    try :
  349. -        __import__('data.jscript.custom.'+name,globals(), locals(), ['__init__'], -1)
  350. -    except :
  351. -        print "Failed to import custom : ",name
  352. \ No newline at end of file
  353. Index: data/jscript/quests/__init__.py
  354. ===================================================================
  355. --- data/jscript/quests/__init__.py (revision 325)
  356. +++ data/jscript/quests/__init__.py (working copy)
  357. @@ -1,200 +0,0 @@
  358. -__all__ = [
  359. -'1_LettersOfLove1',
  360. -'2_WhatWomenWant1',
  361. -'3_ReleaseDarkelfElder1',
  362. -'4_LongLiveLordOfFlame',
  363. -'5_MinersFavor',
  364. -'6_StepIntoTheFuture',
  365. -'7_ATripBegins',
  366. -'8_AnAdventureBegins',
  367. -'9_IntoTheCityOfHumans',
  368. -'10_IntoTheWorld',
  369. -'19_GoToThePastureland',
  370. -'31_SecretBuriedInTheSwamp',
  371. -'32_AnObviousLie',
  372. -'33_MakeAPairOfDressShoes',
  373. -'34_InSearchOfClothes',
  374. -'35_FindGlitteringJewelry',
  375. -'36_MakeASewingKit',
  376. -'37_PleaseMakeMeFormalWear',
  377. -'39_RedEyedInvaders',
  378. -'42_HelpTheUncle',
  379. -'43_HelpTheSister',
  380. -'44_HelpTheSon',
  381. -'45_ToTalkingIsland',
  382. -'46_OnceMoreInTheArmsOfTheMotherTree',
  383. -'47_IntoTheDarkForest',
  384. -'48_ToTheImmortalPlateau',
  385. -'49_TheRoadHome',
  386. -'101_SwordOfSolidarityQuest',
  387. -'102_FungusFever',
  388. -'103_SpiritOfCraftsman',
  389. -'104_SpiritOfMirror',
  390. -'105_SkirmishWithOrcs',
  391. -'106_ForgottenTruth',
  392. -'107_ShowNoMercy',
  393. -'108_DiamondGambit',
  394. -'151_SaveMySister1',
  395. -'152_ShardsOfGolem',
  396. -'153_WharfOldtimersFavor',
  397. -'154_SacrificeToSea',
  398. -'155_FindSirWindawood',
  399. -'156_MillenniumLove',
  400. -'157_RecoverSmuggled',
  401. -'158_SeedOfEvil',
  402. -'159_ProtectHeadsprings',
  403. -'160_NerupasFavor',
  404. -'161_FruitsOfMothertree',
  405. -'162_CurseOfFortress',
  406. -'163_LegacyOfPoet',
  407. -'164_BloodFiend',
  408. -'165_WildHunt',
  409. -'166_DarkMass',
  410. -'167_DwarvenKinship',
  411. -'168_DeliverSupplies',
  412. -'169_NightmareChildren',
  413. -'170_DangerousAllure',
  414. -'171_ActsOfEvil',
  415. -'211_TrialOfChallenger',
  416. -'212_TrialOfDuty',
  417. -'213_TrialOfSeeker',
  418. -'214_TrialOfScholar',
  419. -'215_TrialOfPilgrim',
  420. -'216_TrialOfGuildsman',
  421. -'217_TestimonyOfTrust',
  422. -'218_TestimonyOfLife',
  423. -'219_TestimonyOfFate',
  424. -'220_TestimonyOfGlory',
  425. -'221_TestimonyOfProsperity',
  426. -'222_TestOfDuelist',
  427. -'223_TestOfChampion',
  428. -'224_TestOfSagittarius',
  429. -'225_TestOfSearcher',
  430. -'226_TestOfHealer',
  431. -'227_TestOfReformer',
  432. -'228_TestOfMagus',
  433. -'229_TestOfWitchcraft',
  434. -'230_TestOfSummoner',
  435. -'231_TestOfMaestro',
  436. -'232_TestOfLord',
  437. -'233_TestOfWarspirit',
  438. -'234_FatesWhisper',
  439. -'235_MimirsElixir',
  440. -'241_PossessorOfAPreciousSoul_1',
  441. -'242_PossessorOfAPreciousSoul_2',
  442. -'246_PossessorOfAPreciousSoul_3',
  443. -'247_PossessorOfAPreciousSoul_4',
  444. -'257_GuardIsBusy1',
  445. -'258_BringWolfPelt1',
  446. -'259_RanchersPlea',
  447. -'260_HuntForOrcs1',
  448. -'261_DreamOfMoneylender1',
  449. -'262_BringMeMushrooms1',
  450. -'263_KillAllSylphs1',
  451. -'264_KeenClaws',
  452. -'265_ChainsOfSlavery',
  453. -'266_PleaOfPixies',
  454. -'267_WrathOfVerdure',
  455. -'271_ProofOfValor',
  456. -'272_WrathOfAncestors',
  457. -'273_InvadersOfHolyland',
  458. -'274_AgainstWolfMen',
  459. -'275_BlackWingedSpies',
  460. -'276_HestuiTotem',
  461. -'277_GatekeepersOffering',
  462. -'291_RedBonnetsRevenge',
  463. -'292_CrushBrigands',
  464. -'293_HiddenVein',
  465. -'294_CovertBusiness',
  466. -'295_DreamsOfFlight',
  467. -'296_SilkOfTarantula',
  468. -'297_GatekeepersFavor',
  469. -'298_LizardmensConspiracy',
  470. -'299_GatherIngredientsForPie',
  471. -'303_CollectArrowheads',
  472. -'306_CrystalOfFireice',
  473. -'313_CollectSpores',
  474. -'316_DestroyPlaguebringers',
  475. -'317_CatchTheWind',
  476. -'319_ScentOfDeath',
  477. -'320_BonesTellFuture',
  478. -'324_SweetestVenom',
  479. -'325_GrimCollector',
  480. -'326_VanquishRemnants',
  481. -'327_ReclaimTheLand',
  482. -'328_SenseForBusiness',
  483. -'329_CuriosityOfDwarf',
  484. -'330_AdeptOfTaste',
  485. -'331_ArrowForVengeance',
  486. -'333_BlackLionHunt',
  487. -'334_TheWishingPotion',
  488. -'336_CoinOfMagic',
  489. -'338_AlligatorHunter',
  490. -'341_HuntingForWildBeasts',
  491. -'343_UnderTheShadowOfTheIvoryTower',
  492. -'345_MethodToRaiseTheDead',
  493. -'347_GoGetTheCalculator',
  494. -'348_ArrogantSearch',
  495. -'350_EnhanceYourWeapon',
  496. -'351_BlackSwan',
  497. -'352_HelpRoodRaiseANewPet',
  498. -'354_ConquestOfAlligatorIsland',
  499. -'355_FamilyHonor',
  500. -'356_DigUpTheSeaOfSpores',
  501. -'357_WarehouseKeepersAmbition',
  502. -'358_IllegitimateChildOfAGoddess',
  503. -'359_ForSleeplessDeadmen',
  504. -'360_PlunderTheirSupplies',
  505. -'362_BardsMandolin',
  506. -'363_SorrowfulSoundofFlute',
  507. -'364_JovialAccordion',
  508. -'365_DevilsLegacy',
  509. -'368_TrespassingIntoTheSacredArea',
  510. -'370_AWisemanSowsSeeds',
  511. -'372_LegacyOfInsolence',
  512. -'373_SupplierOfReagents',
  513. -'374_WhisperOfDreams1',
  514. -'375_WhisperOfDreams2',
  515. -'376_GiantsExploration1',
  516. -'377_GiantsExploration2',
  517. -'383_SearchingForTreasure',
  518. -'385_YokeofthePast',
  519. -'386_StolenDignity',
  520. -'401_PathToWarrior',
  521. -'402_PathToKnight',
  522. -'403_PathToRogue',
  523. -'404_PathToWizard',
  524. -'405_PathToCleric',
  525. -'406_PathToElvenKnight',
  526. -'407_PathToElvenScout',
  527. -'408_PathToElvenwizard',
  528. -'409_PathToOracle',
  529. -'410_PathToPalusKnight',
  530. -'411_PathToAssassin',
  531. -'412_PathToDarkwizard',
  532. -'413_PathToShillienOracle',
  533. -'414_PathToOrcRaider',
  534. -'415_PathToOrcMonk',
  535. -'416_PathToOrcShaman',
  536. -'417_PathToScavenger',
  537. -'418_PathToArtisan',
  538. -'419_GetAPet',
  539. -'420_LittleWings',
  540. -'421_LittleWingAdventures',
  541. -'426_FishingShot',
  542. -'431_WeddingMarch',
  543. -'432_BirthdayPartySong',
  544. -'501_ProofOfClanAlliance',
  545. -'503_PursuitClanAmbition',
  546. -'621_EggDelivery',
  547. -'622_DeliveryOfSpecialLiquor',
  548. -'626_ADarkTwilight',
  549. -'627_HeartInSearchOfPower',
  550. -'634_InSearchofDimensionalFragments',
  551. -'999_C3Tutorial'
  552. -]
  553. -for name in __all__ :
  554. -    try :
  555. -        __import__('data.jscript.quests.'+name,globals(), locals(), ['__init__'], -1)
  556. -    except :
  557. -        print "Failed to import quest : ",name
  558. \ No newline at end of file
  559. #P Lisvus_GameServer
  560. Index: build/dist/gameserver/config/l2j-version.properties
  561. ===================================================================
  562. --- build/dist/gameserver/config/l2j-version.properties (revision 0)
  563. +++ build/dist/gameserver/config/l2j-version.properties (revision 0)
  564. @@ -0,0 +1,10 @@
  565. +
  566. +       version=svn: E155036: Working copy 'D:\Programs\WorkSpace\micr0\Lisvus_GameServer' is too old (format 10, created by Subversion 1.6)
  567. +       builddate=20130217_0348
  568. +
  569. +   Detailed Info:
  570. +       https://subversion.assembla.com/svn/L2JLisvus/trunk/Lisvus_GameServer
  571. +https://subversion.assembla.com/svn/L2JLisvus
  572. +
  573. +
  574. +
  575. Index: java/net/sf/l2j/gameserver/model/quest/Quest.java
  576. ===================================================================
  577. --- java/net/sf/l2j/gameserver/model/quest/Quest.java   (revision 325)
  578. +++ java/net/sf/l2j/gameserver/model/quest/Quest.java   (working copy)
  579. @@ -27,6 +27,7 @@
  580.  import java.util.logging.Level;
  581.  import java.util.logging.Logger;
  582.  
  583. +import javolution.util.FastList;
  584.  import javolution.util.FastMap;
  585.  import net.sf.l2j.Config;
  586.  import net.sf.l2j.L2DatabaseFactory;
  587. @@ -35,374 +36,509 @@
  588.  import net.sf.l2j.gameserver.model.L2Character;
  589.  import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  590.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  591. +import net.sf.l2j.gameserver.script.scripting.ManagedScript;
  592. +import net.sf.l2j.gameserver.script.scripting.ScriptManager;
  593.  import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  594.  import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  595.  import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  596.  
  597.  /**
  598.   * @author Luis Arias
  599. - *
  600. + *
  601.   */
  602. -public abstract class Quest
  603. +public class Quest extends ManagedScript
  604.  {
  605. -   protected static Logger _log = Logger.getLogger(Quest.class.getName());
  606. +    protected static Logger _log = Logger.getLogger(Quest.class.getName());
  607.  
  608. -   /** HashMap containing events from String value of the event */
  609. -   private static Map<String, Quest> allEventsS = new FastMap<String, Quest>();
  610. +    /** HashMap containing events from String value of the event */
  611. +    private static Map<String, Quest> allEventsS = new FastMap<String, Quest>();
  612. +    private static Map<String, FastList<QuestTimer>> _allEventTimers = new FastMap<>();
  613.  
  614. -   private final int _questId;
  615. -   private final String _name;
  616. -   private final String _descr;
  617. -        private State initialState;
  618. -        private Map<String, State> states;
  619. -  
  620. -   /**
  621. -    * Return collection view of the values contains in the allEventS
  622. -    * @return Collection<Quest>
  623. -    */
  624. -   public static Collection<Quest> findAllEvents()
  625. -        {
  626. -       return allEventsS.values();
  627. -   }
  628. -  
  629. -        /**
  630. -         * (Constructor)Add values to class variables and put the quest in HashMaps.
  631. -         * @param questId : int pointing out the ID of the quest
  632. -         * @param name : String corresponding to the name of the quest
  633. -         * @param descr : String for the description of the quest
  634. -         */
  635. -   public Quest(int questId, String name, String descr)
  636. -        {
  637. +    private final int _questId;
  638. +    private final String _name;
  639. +    private final String _descr;
  640. +    private State initialState;
  641. +    private Map<String, State> states;
  642.  
  643. -       _questId = questId;
  644. -       _name = name;
  645. -       _descr = descr;
  646. +    /**
  647. +     * Return collection view of the values contains in the allEventS
  648. +     *
  649. +     * @return Collection<Quest>
  650. +     */
  651. +    public static Collection<Quest> findAllEvents()
  652. +    {
  653. +        return allEventsS.values();
  654. +    }
  655.  
  656. -                states = new FastMap<String, State>();
  657. -       if (questId != 0)
  658. -                {
  659. -                        QuestManager.getInstance().getQuests().add(Quest.this);
  660. -       }
  661. -                else
  662. -                {
  663. -           allEventsS.put(name, this);
  664. -       }
  665. -        }
  666. +    /**
  667. +     * (Constructor)Add values to class variables and put the quest in HashMaps.
  668. +     *
  669. +     * @param questId : int pointing out the ID of the quest
  670. +     * @param name : String corresponding to the name of the quest
  671. +     * @param descr : String for the description of the quest
  672. +     */
  673. +    public Quest(int questId, String name, String descr)
  674. +    {
  675.  
  676. -   /**
  677. -    * Return ID of the quest
  678. -    * @return int
  679. -    */
  680. -   public int getQuestIntId()
  681. +        _questId = questId;
  682. +        _name = name;
  683. +        _descr = descr;
  684. +
  685. +        states = new FastMap<String, State>();
  686. +        if (questId != 0)
  687.          {
  688. -       return _questId;
  689. -   }
  690. -  
  691. -   /**
  692. -    * Set the initial state of the quest with parameter "state"
  693. -    * @param state
  694. -    */
  695. -   public void setInitialState(State state)
  696. +            QuestManager.getInstance().addQuest(this);
  697. +        }
  698. +        else
  699.          {
  700. -       this.initialState = state;
  701. -   }
  702. -  
  703. -   /**
  704. -    * Add a new QuestState to the database and return it.
  705. -    * @param player
  706. -    * @return QuestState : QuestState created
  707. -    */
  708. -   public QuestState newQuestState(L2PcInstance player)
  709. -        {
  710. -       QuestState qs = new QuestState(this, player, getInitialState(), false);
  711. -       Quest.createQuestInDb(qs);
  712. -       return qs;
  713. -   }
  714. -  
  715. -   /**
  716. -    * Return initial state of the quest
  717. -    * @return State
  718. -    */
  719. -   public State getInitialState()
  720. -        {
  721. -       return initialState;
  722. -   }
  723. -    
  724. -   /**
  725. -    * Return name of the quest
  726. -    * @return String
  727. -    */
  728. -   public String getName()
  729. -        {
  730. -       return _name;
  731. -   }
  732. -  
  733. -   /**
  734. -    * Return description of the quest
  735. -    * @return String
  736. -    */
  737. -   public String getDescr()
  738. -        {
  739. -       return _descr;
  740. -   }
  741. +            allEventsS.put(name, this);
  742. +        }
  743. +        init_LoadGlobalData();
  744. +    }
  745.  
  746. -   /**
  747. -    * Add a state to the quest
  748. -    * @param state
  749. -    * @return state added
  750. -    */
  751. +    /**
  752. +     * The function init_LoadGlobalData is, by default, called by the constructor of all quests.<br> Children
  753. +     * of this class can implement this function in order to define what variables to load and what structures
  754. +     * to save them in.<br> By default, nothing is loaded.
  755. +     */
  756. +    protected void init_LoadGlobalData()
  757. +    {
  758. +
  759. +    }
  760. +
  761. +    /**
  762. +     * The function saveGlobalData is, by default, called at shutdown, for all quests, by the
  763. +     * QuestManager.<br> Children of this class can implement this function in order to convert their
  764. +     * structures<br> into <var, value> tuples and make calls to save them to the database, if needed.<br> By
  765. +     * default, nothing is saved.
  766. +     */
  767. +    public void saveGlobalData()
  768. +    {
  769. +
  770. +    }
  771. +
  772. +    /**
  773. +     * Return ID of the quest
  774. +     *
  775. +     * @return int
  776. +     */
  777. +    public int getQuestIntId()
  778. +    {
  779. +        return _questId;
  780. +    }
  781. +
  782. +    /**
  783. +     * Set the initial state of the quest with parameter "state"
  784. +     *
  785. +     * @param state
  786. +     */
  787. +    public void setInitialState(State state)
  788. +    {
  789. +        this.initialState = state;
  790. +    }
  791. +
  792. +    /**
  793. +     * Add a new QuestState to the database and return it.
  794. +     *
  795. +     * @param player
  796. +     * @return QuestState : QuestState created
  797. +     */
  798. +    public QuestState newQuestState(L2PcInstance player)
  799. +    {
  800. +        QuestState qs = new QuestState(this, player, getInitialState(), false);
  801. +        Quest.createQuestInDb(qs);
  802. +        return qs;
  803. +    }
  804. +
  805. +    /**
  806. +     * Return initial state of the quest
  807. +     *
  808. +     * @return State
  809. +     */
  810. +    public State getInitialState()
  811. +    {
  812. +        return initialState;
  813. +    }
  814. +
  815. +    /**
  816. +     * Return name of the quest
  817. +     *
  818. +     * @return String
  819. +     */
  820. +    public String getName()
  821. +    {
  822. +        return _name;
  823. +    }
  824. +
  825. +    /**
  826. +     * Return description of the quest
  827. +     *
  828. +     * @return String
  829. +     */
  830. +    public String getDescr()
  831. +    {
  832. +        return _descr;
  833. +    }
  834. +
  835. +    /**
  836. +     * Add a state to the quest
  837. +     *
  838. +     * @param state
  839. +     * @return state added
  840. +     */
  841.      public State addState(State state)
  842.      {
  843.          states.put(state.getName(), state);
  844. -       return state;
  845. +        return state;
  846.      }
  847. -    
  848. +
  849.      /**
  850.       * Add the quest to the NPC's startQuest
  851. +     *
  852.       * @param npcId
  853.       * @return L2NpcTemplate : Start NPC
  854.       */
  855.      public L2NpcTemplate addStartNpc(int npcId)
  856.      {
  857. -       L2NpcTemplate t = NpcTable.getInstance().getTemplate(npcId);
  858. -       if (t != null) {
  859. -           t.addStartQuests(this);
  860. -       }
  861. -       return t;
  862. +        L2NpcTemplate t = NpcTable.getInstance().getTemplate(npcId);
  863. +        if (t != null)
  864. +        {
  865. +            t.addStartQuests(this);
  866. +        }
  867. +        return t;
  868.      }
  869. -    
  870. -   // these are methods to call from java
  871. -    public final boolean notifyAttack(L2NpcInstance npc, QuestState qs) {
  872. +
  873. +    // these are methods to call from java
  874. +    public final boolean notifyAttack(L2NpcInstance npc, QuestState qs)
  875. +    {
  876.          String res = null;
  877. -        try { res = onAttack(npc, qs); } catch (Exception e) { return showError(qs, e); }
  878. +        try
  879. +        {
  880. +            res = onAttack(npc, qs);
  881. +        }
  882. +        catch (Exception e)
  883. +        {
  884. +            return showError(qs, e);
  885. +        }
  886.          return showResult(qs, res);
  887. -    }
  888. -    public final boolean notifyDeath(L2NpcInstance npc, L2Character character, QuestState qs) {
  889. +    }
  890. +
  891. +    public final boolean notifyDeath(L2NpcInstance npc, L2Character character, QuestState qs)
  892. +    {
  893.          String res = null;
  894. -        try { res = onDeath(npc, character, qs); } catch (Exception e) { return showError(qs, e); }
  895. +        try
  896. +        {
  897. +            res = onDeath(npc, character, qs);
  898. +        }
  899. +        catch (Exception e)
  900. +        {
  901. +            return showError(qs, e);
  902. +        }
  903.          return showResult(qs, res);
  904. -    }
  905. -    public final boolean notifyEvent(String event, QuestState qs) {
  906. +    }
  907. +
  908. +    public final boolean notifyEvent(String event, QuestState qs)
  909. +    {
  910.          String res = null;
  911. -        try { res = onEvent(event, qs); } catch (Exception e) { return showError(qs, e); }
  912. +        try
  913. +        {
  914. +            res = onEvent(event, qs);
  915. +        }
  916. +        catch (Exception e)
  917. +        {
  918. +            return showError(qs, e);
  919. +        }
  920.          return showResult(qs, res);
  921. -    }
  922. -   public final boolean notifyKill (L2NpcInstance npc, QuestState qs) {
  923. -       String res = null;
  924. -       try { res = onKill(npc, qs); } catch (Exception e) { return showError(qs, e); }
  925. -       return showResult(qs, res);
  926. -   }
  927. -   public final boolean notifyTalk (L2NpcInstance npc, QuestState qs) {
  928. -       String res = null;
  929. -       try { res = onTalk(npc, qs); } catch (Exception e) { return showError(qs, e); }
  930. +    }
  931. +
  932. +    public final boolean notifyKill(L2NpcInstance npc, QuestState qs)
  933. +    {
  934. +        String res = null;
  935. +        try
  936. +        {
  937. +            res = onKill(npc, qs);
  938. +        }
  939. +        catch (Exception e)
  940. +        {
  941. +            return showError(qs, e);
  942. +        }
  943. +        return showResult(qs, res);
  944. +    }
  945. +
  946. +    public final boolean notifyTalk(L2NpcInstance npc, QuestState qs)
  947. +    {
  948. +        String res = null;
  949. +        try
  950. +        {
  951. +            res = onTalk(npc, qs);
  952. +        }
  953. +        catch (Exception e)
  954. +        {
  955. +            return showError(qs, e);
  956. +        }
  957.          qs.getPlayer().setLastQuestNpcObject(npc.getObjectId());
  958. -       return showResult(qs, res);
  959. -   }
  960. +        return showResult(qs, res);
  961. +    }
  962.  
  963. -   // these are methods that java calls to invoke scripts
  964. -    @SuppressWarnings("unused") public String onAttack(L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
  965. -    @SuppressWarnings("unused") public String onDeath (L2NpcInstance npc, L2Character character, QuestState qs) { return onEvent("", qs); }
  966. -    @SuppressWarnings("unused") public String onEvent(String event, QuestState qs) { return null; }
  967. -    @SuppressWarnings("unused") public String onKill (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
  968. -    @SuppressWarnings("unused") public String onTalk (L2NpcInstance npc, QuestState qs) { return onEvent("", qs); }
  969. -  
  970. -   /**
  971. -    * Show message error to player who has an access level greater than 0
  972. -    * @param qs : QuestState
  973. -    * @param t : Throwable
  974. -    * @return boolean
  975. -    */
  976. -   private boolean showError(QuestState qs, Throwable t) {
  977. -       _log.log(Level.WARNING, "", t);
  978. -       if (qs.getPlayer().getAccessLevel() > 0) {
  979. -           StringWriter sw = new StringWriter();
  980. -           PrintWriter pw = new PrintWriter(sw);
  981. -           t.printStackTrace(pw);
  982. -           pw.close();
  983. -           String res = "<html><body><title>Script error</title>"+sw.toString()+"</body></html>";
  984. -           return showResult(qs, res);
  985. -       }
  986. -       return false;
  987. -   }
  988. -  
  989. -   /**
  990. -    * Show a message to player.<BR><BR>
  991. -    * <U><I>Concept : </I></U><BR>
  992. -    * 3 cases are managed according to the value of the parameter "res" :<BR>
  993. -    * <LI><U>"res" ends with string ".html" :</U> an HTML is opened in order to be shown in a dialog box</LI>
  994. -    * <LI><U>"res" starts with "<html>" :</U> the message hold in "res" is shown in a dialog box</LI>
  995. -    * <LI><U>otherwise :</U> the message hold in "res" is shown in chat box</LI>
  996. -    * @param qs : QuestState
  997. -    * @param res : String pointing out the message to show at the player
  998. -    * @return boolean
  999. -    */
  1000. -   private boolean showResult(QuestState qs, String res) {
  1001. -       if (res == null)
  1002. -           return true;
  1003. -       if (res.endsWith(".htm")) {
  1004. -           qs.showHtmlFile(res);
  1005. -       }
  1006. -       else if (res.startsWith("<html>")) {
  1007. -           NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
  1008. -           npcReply.setHtml(res);
  1009. -           qs.getPlayer().sendPacket(npcReply);
  1010. -       }
  1011. -       else {
  1012. -           SystemMessage sm = new SystemMessage(SystemMessage.S1_S2);
  1013. -           sm.addString(res);
  1014. -           qs.getPlayer().sendPacket(sm);
  1015. -       }
  1016. -       return false;
  1017. -   }
  1018. -  
  1019. -   /**
  1020. -    * Add quests to the L2PCInstance of the player.<BR><BR>
  1021. -    * <U><I>Action : </U></I><BR>
  1022. -    * Add state of quests, drops and variables for quests in the HashMap _quest of L2PcInstance
  1023. -    * @param player : Player who is entering the world
  1024. -    */
  1025. -   public static void playerEnter(L2PcInstance player) {
  1026. +    // these are methods that java calls to invoke scripts
  1027. +    public String onAttack(L2NpcInstance npc, QuestState qs)
  1028. +    {
  1029. +        return onEvent("", qs);
  1030. +    }
  1031.  
  1032. +    public String onDeath(L2NpcInstance npc, L2Character character, QuestState qs)
  1033. +    {
  1034. +        return onEvent("", qs);
  1035. +    }
  1036. +
  1037. +    public String onEvent(String event, QuestState qs)
  1038. +    {
  1039. +        return null;
  1040. +    }
  1041. +
  1042. +    public String onKill(L2NpcInstance npc, QuestState qs)
  1043. +    {
  1044. +        return onEvent("", qs);
  1045. +    }
  1046. +
  1047. +    public String onTalk(L2NpcInstance npc, QuestState qs)
  1048. +    {
  1049. +        return onEvent("", qs);
  1050. +    }
  1051. +
  1052. +    /**
  1053. +     * Show message error to player who has an access level greater than 0
  1054. +     *
  1055. +     * @param qs : QuestState
  1056. +     * @param t : Throwable
  1057. +     * @return boolean
  1058. +     */
  1059. +    private boolean showError(QuestState qs, Throwable t)
  1060. +    {
  1061. +        _log.log(Level.WARNING, "", t);
  1062. +        if (qs.getPlayer().getAccessLevel() > 0)
  1063. +        {
  1064. +            StringWriter sw = new StringWriter();
  1065. +            PrintWriter pw = new PrintWriter(sw);
  1066. +            t.printStackTrace(pw);
  1067. +            pw.close();
  1068. +            String res = "<html><body><title>Script error</title>" + sw.toString() + "</body></html>";
  1069. +            return showResult(qs, res);
  1070. +        }
  1071. +        return false;
  1072. +    }
  1073. +
  1074. +    /**
  1075. +     * Show a message to player.<BR><BR> <U><I>Concept : </I></U><BR> 3 cases are managed according to the
  1076. +     * value of the parameter "res" :<BR> <LI><U>"res" ends with string ".html" :</U> an HTML is opened in
  1077. +     * order to be shown in a dialog box</LI> <LI><U>"res" starts with "<html>" :</U> the message hold in
  1078. +     * "res" is shown in a dialog box</LI> <LI><U>otherwise :</U> the message hold in "res" is shown in chat
  1079. +     * box</LI>
  1080. +     *
  1081. +     * @param qs : QuestState
  1082. +     * @param res : String pointing out the message to show at the player
  1083. +     * @return boolean
  1084. +     */
  1085. +    private boolean showResult(QuestState qs, String res)
  1086. +    {
  1087. +        if (res == null) return true;
  1088. +        if (res.endsWith(".htm"))
  1089. +        {
  1090. +            qs.showHtmlFile(res);
  1091. +        }
  1092. +        else if (res.startsWith("<html>"))
  1093. +        {
  1094. +            NpcHtmlMessage npcReply = new NpcHtmlMessage(5);
  1095. +            npcReply.setHtml(res);
  1096. +            qs.getPlayer().sendPacket(npcReply);
  1097. +        }
  1098. +        else
  1099. +        {
  1100. +            SystemMessage sm = new SystemMessage(SystemMessage.S1_S2);
  1101. +            sm.addString(res);
  1102. +            qs.getPlayer().sendPacket(sm);
  1103. +        }
  1104. +        return false;
  1105. +    }
  1106. +
  1107. +    /**
  1108. +     * Add quests to the L2PCInstance of the player.<BR><BR> <U><I>Action : </U></I><BR> Add state of quests,
  1109. +     * drops and variables for quests in the HashMap _quest of L2PcInstance
  1110. +     *
  1111. +     * @param player : Player who is entering the world
  1112. +     */
  1113. +    public static void playerEnter(L2PcInstance player)
  1114. +    {
  1115. +
  1116.          java.sql.Connection con = null;
  1117.          try
  1118.          {
  1119. -       // Get list of quests owned by the player from database
  1120. +            // Get list of quests owned by the player from database
  1121.              con = L2DatabaseFactory.getInstance().getConnection();
  1122.              PreparedStatement statement;
  1123. -            
  1124. -            PreparedStatement invalidQuestData      = con.prepareStatement("DELETE FROM character_quests WHERE char_id=? and name=?");
  1125. -            PreparedStatement invalidQuestDataVar   = con.prepareStatement("delete FROM character_quests WHERE char_id=? and name=? and var=?");
  1126. -            
  1127. +
  1128. +            PreparedStatement invalidQuestData = con.prepareStatement("DELETE FROM character_quests WHERE char_id=? and name=?");
  1129. +            PreparedStatement invalidQuestDataVar = con.prepareStatement("delete FROM character_quests WHERE char_id=? and name=? and var=?");
  1130. +
  1131.              statement = con.prepareStatement("SELECT name,value FROM character_quests WHERE char_id=? AND var=?");
  1132.              statement.setInt(1, player.getObjectId());
  1133.              statement.setString(2, "<state>");
  1134. -           ResultSet rs = statement.executeQuery();
  1135. -           while (rs.next()) {
  1136. -              
  1137. -               // Get ID of the quest and ID of its state
  1138. -               String questId = rs.getString("name");
  1139. -               String stateId = rs.getString("value");
  1140. -              
  1141. -               // Search quest associated with the ID
  1142. -               Quest q = QuestManager.getInstance().getQuest(questId);
  1143. -               if (q == null) {
  1144. -                   _log.finer("Unknown quest "+questId+" for player "+player.getName());
  1145. -                   if (Config.AUTODELETE_INVALID_QUEST_DATA){
  1146. +            ResultSet rs = statement.executeQuery();
  1147. +            while (rs.next())
  1148. +            {
  1149. +
  1150. +                // Get ID of the quest and ID of its state
  1151. +                String questId = rs.getString("name");
  1152. +                String stateId = rs.getString("value");
  1153. +
  1154. +                // Search quest associated with the ID
  1155. +                Quest q = QuestManager.getInstance().getQuest(questId);
  1156. +                if (q == null)
  1157. +                {
  1158. +                    _log.finer("Unknown quest " + questId + " for player " + player.getName());
  1159. +                    if (Config.AUTODELETE_INVALID_QUEST_DATA)
  1160. +                    {
  1161.                          invalidQuestData.setInt(1, player.getObjectId());
  1162.                          invalidQuestData.setString(2, questId);
  1163.                          invalidQuestData.executeUpdate();
  1164. -                   }
  1165. -                   continue;
  1166. -               }
  1167. -              
  1168. -               // Identify the state of the quest for the player
  1169. -               boolean completed = false;
  1170. -               if (stateId.length() > 0 && stateId.charAt(0) == '*') { // probably obsolete check
  1171. -                   completed = true;
  1172. -                   stateId = stateId.substring(1);
  1173. -               }
  1174. -                                if (stateId.equals("Completed"))
  1175. -                                    completed = true;
  1176. +                    }
  1177. +                    continue;
  1178. +                }
  1179.  
  1180. -               // Create an object State containing the state of the quest
  1181. -               State state = q.states.get(stateId);
  1182. -               if (state == null) {
  1183. -                   _log.finer("Unknown state "+state+" in quest "+questId+" for player "+player.getName());
  1184. -                   if (Config.AUTODELETE_INVALID_QUEST_DATA){
  1185. -                       invalidQuestData.setInt(1, player.getObjectId());
  1186. +                // Identify the state of the quest for the player
  1187. +                boolean completed = false;
  1188. +                if (stateId.length() > 0 && stateId.charAt(0) == '*')
  1189. +                { // probably obsolete check
  1190. +                    completed = true;
  1191. +                    stateId = stateId.substring(1);
  1192. +                }
  1193. +                if (stateId.equals("Completed")) completed = true;
  1194. +
  1195. +                // Create an object State containing the state of the quest
  1196. +                State state = q.states.get(stateId);
  1197. +                if (state == null)
  1198. +                {
  1199. +                    _log.finer("Unknown state " + state + " in quest " + questId + " for player "
  1200. +                        + player.getName());
  1201. +                    if (Config.AUTODELETE_INVALID_QUEST_DATA)
  1202. +                    {
  1203. +                        invalidQuestData.setInt(1, player.getObjectId());
  1204.                          invalidQuestData.setString(2, questId);
  1205.                          invalidQuestData.executeUpdate();
  1206. -                   }
  1207. -                   continue;
  1208. -               }
  1209. -               // Create a new QuestState for the player that will be added to the player's list of quests
  1210. -               new QuestState(q, player, state, completed);
  1211. -           }
  1212. -           rs.close();
  1213. +                    }
  1214. +                    continue;
  1215. +                }
  1216. +                // Create a new QuestState for the player that will be added to the player's list of quests
  1217. +                new QuestState(q, player, state, completed);
  1218. +            }
  1219. +            rs.close();
  1220.              invalidQuestData.close();
  1221.              statement.close();
  1222.  
  1223.              // Get list of quests owned by the player from the DB in order to add variables used in the quest.
  1224.              statement = con.prepareStatement("SELECT name,var,value FROM character_quests WHERE char_id=?");
  1225. -            statement.setInt(1,player.getObjectId());
  1226. -           rs = statement.executeQuery();
  1227. -           while (rs.next()) {
  1228. -               String questId = rs.getString("name");
  1229. -               String var     = rs.getString("var");
  1230. -               String value   = rs.getString("value");
  1231. -               // Get the QuestState saved in the loop before
  1232. -               QuestState qs = player.getQuestState(questId);
  1233. -               if (qs == null) {
  1234. -                   _log.finer("Lost variable "+var+" in quest "+questId+" for player "+player.getName());
  1235. -                   if (Config.AUTODELETE_INVALID_QUEST_DATA){
  1236. -                       invalidQuestDataVar.setInt   (1,player.getObjectId());
  1237. -                        invalidQuestDataVar.setString(2,questId);
  1238. -                        invalidQuestDataVar.setString(3,var);
  1239. +            statement.setInt(1, player.getObjectId());
  1240. +            rs = statement.executeQuery();
  1241. +            while (rs.next())
  1242. +            {
  1243. +                String questId = rs.getString("name");
  1244. +                String var = rs.getString("var");
  1245. +                String value = rs.getString("value");
  1246. +                // Get the QuestState saved in the loop before
  1247. +                QuestState qs = player.getQuestState(questId);
  1248. +                if (qs == null)
  1249. +                {
  1250. +                    _log.finer("Lost variable " + var + " in quest " + questId + " for player "
  1251. +                        + player.getName());
  1252. +                    if (Config.AUTODELETE_INVALID_QUEST_DATA)
  1253. +                    {
  1254. +                        invalidQuestDataVar.setInt(1, player.getObjectId());
  1255. +                        invalidQuestDataVar.setString(2, questId);
  1256. +                        invalidQuestDataVar.setString(3, var);
  1257.                          invalidQuestDataVar.executeUpdate();
  1258. -                   }
  1259. -                   continue;
  1260. -               }
  1261. -               // Add parameter to the quest
  1262. -               qs.setInternal(var, value);
  1263. -           }
  1264. -           rs.close();
  1265. +                    }
  1266. +                    continue;
  1267. +                }
  1268. +                // Add parameter to the quest
  1269. +                qs.setInternal(var, value);
  1270. +            }
  1271. +            rs.close();
  1272.              invalidQuestDataVar.close();
  1273.              statement.close();
  1274. -          
  1275. -       } catch (Exception e) {
  1276. -           _log.log(Level.WARNING, "could not insert char quest:", e);
  1277. -        } finally {
  1278. -            try { con.close(); } catch (Exception e) {}
  1279. +
  1280.          }
  1281. -      
  1282. -       // events
  1283. -       for (String name : allEventsS.keySet()) {
  1284. -           player.processQuestEvent(name, "enter");
  1285. -       }
  1286. -   }
  1287. +        catch (Exception e)
  1288. +        {
  1289. +            _log.log(Level.WARNING, "could not insert char quest:", e);
  1290. +        }
  1291. +        finally
  1292. +        {
  1293. +            try
  1294. +            {
  1295. +                con.close();
  1296. +            }
  1297. +            catch (Exception e)
  1298. +            {
  1299. +            }
  1300. +        }
  1301.  
  1302. +        // events
  1303. +        for (String name : allEventsS.keySet())
  1304. +        {
  1305. +            player.processQuestEvent(name, "enter");
  1306. +        }
  1307. +    }
  1308.  
  1309. -   /**
  1310. -    * Insert in the database the quest for the player.
  1311. -    * @param qs : QuestState pointing out the state of the quest
  1312. -    * @param var : String designating the name of the variable for the quest
  1313. -    * @param value : String designating the value of the variable for the quest
  1314. -    */
  1315. -   public static void createQuestVarInDb(QuestState qs, String var, String value) {
  1316. +    /**
  1317. +     * Insert in the database the quest for the player.
  1318. +     *
  1319. +     * @param qs : QuestState pointing out the state of the quest
  1320. +     * @param var : String designating the name of the variable for the quest
  1321. +     * @param value : String designating the value of the variable for the quest
  1322. +     */
  1323. +    public static void createQuestVarInDb(QuestState qs, String var, String value)
  1324. +    {
  1325.          java.sql.Connection con = null;
  1326.          try
  1327.          {
  1328.              con = L2DatabaseFactory.getInstance().getConnection();
  1329.              PreparedStatement statement;
  1330.              statement = con.prepareStatement("INSERT INTO character_quests (char_id,name,var,value) VALUES (?,?,?,?)");
  1331. -            statement.setInt   (1, qs.getPlayer().getObjectId());
  1332. +            statement.setInt(1, qs.getPlayer().getObjectId());
  1333.              statement.setString(2, qs.getQuest().getName());
  1334.              statement.setString(3, var);
  1335.              statement.setString(4, value);
  1336. -       statement.executeUpdate();
  1337. +            statement.executeUpdate();
  1338.              statement.close();
  1339. -        } catch (Exception e) {
  1340. -           _log.log(Level.WARNING, "could not insert char quest:", e);
  1341. -        } finally {
  1342. -            try { con.close(); } catch (Exception e) {}
  1343.          }
  1344. -   }
  1345. -  
  1346. -   /**
  1347. -    * Update the value of the variable "var" for the quest.<BR><BR>
  1348. -    * <U><I>Actions :</I></U><BR>
  1349. -    * The selection of the right record is made with :
  1350. -    * <LI>char_id = qs.getPlayer().getObjectID()</LI>
  1351. -    * <LI>name = qs.getQuest().getName()</LI>
  1352. -    * <LI>var = var</LI>
  1353. -    * <BR><BR>
  1354. -    * The modification made is :
  1355. -    * <LI>value = parameter value</LI>
  1356. -    * @param qs : Quest State
  1357. -    * @param var : String designating the name of the variable for quest
  1358. -    * @param value : String designating the value of the variable for quest
  1359. -    */
  1360. -    public static void updateQuestVarInDb(QuestState qs, String var, String value) {
  1361. +        catch (Exception e)
  1362. +        {
  1363. +            _log.log(Level.WARNING, "could not insert char quest:", e);
  1364. +        }
  1365. +        finally
  1366. +        {
  1367. +            try
  1368. +            {
  1369. +                con.close();
  1370. +            }
  1371. +            catch (Exception e)
  1372. +            {
  1373. +            }
  1374. +        }
  1375. +    }
  1376. +
  1377. +    /**
  1378. +     * Update the value of the variable "var" for the quest.<BR><BR> <U><I>Actions :</I></U><BR> The selection
  1379. +     * of the right record is made with : <LI>char_id = qs.getPlayer().getObjectID()</LI> <LI>name =
  1380. +     * qs.getQuest().getName()</LI> <LI>var = var</LI> <BR><BR> The modification made is : <LI>value =
  1381. +     * parameter value</LI>
  1382. +     *
  1383. +     * @param qs : Quest State
  1384. +     * @param var : String designating the name of the variable for quest
  1385. +     * @param value : String designating the value of the variable for quest
  1386. +     */
  1387. +    public static void updateQuestVarInDb(QuestState qs, String var, String value)
  1388. +    {
  1389.          java.sql.Connection con = null;
  1390.          try
  1391.          {
  1392. @@ -410,95 +546,184 @@
  1393.              PreparedStatement statement;
  1394.              statement = con.prepareStatement("UPDATE character_quests SET value=? WHERE char_id=? AND name=? AND var = ?");
  1395.              statement.setString(1, value);
  1396. -            statement.setInt   (2, qs.getPlayer().getObjectId());
  1397. +            statement.setInt(2, qs.getPlayer().getObjectId());
  1398.              statement.setString(3, qs.getQuest().getName());
  1399.              statement.setString(4, var);
  1400. -           statement.executeUpdate();
  1401. +            statement.executeUpdate();
  1402.              statement.close();
  1403. -        } catch (Exception e) {
  1404. -           _log.log(Level.WARNING, "could not update char quest:", e);
  1405. -        } finally {
  1406. -            try { con.close(); } catch (Exception e) {}
  1407.          }
  1408. -   }
  1409. -  
  1410. +        catch (Exception e)
  1411. +        {
  1412. +            _log.log(Level.WARNING, "could not update char quest:", e);
  1413. +        }
  1414. +        finally
  1415. +        {
  1416. +            try
  1417. +            {
  1418. +                con.close();
  1419. +            }
  1420. +            catch (Exception e)
  1421. +            {
  1422. +            }
  1423. +        }
  1424. +    }
  1425. +
  1426.      /**
  1427.       * Delete a variable of player's quest from the database.
  1428. +     *
  1429.       * @param qs : object QuestState pointing out the player's quest
  1430.       * @param var : String designating the variable characterizing the quest
  1431.       */
  1432. -   public static void deleteQuestVarInDb(QuestState qs, String var) {
  1433. +    public static void deleteQuestVarInDb(QuestState qs, String var)
  1434. +    {
  1435.          java.sql.Connection con = null;
  1436.          try
  1437.          {
  1438.              con = L2DatabaseFactory.getInstance().getConnection();
  1439.              PreparedStatement statement;
  1440.              statement = con.prepareStatement("DELETE FROM character_quests WHERE char_id=? AND name=? AND var=?");
  1441. -            statement.setInt   (1, qs.getPlayer().getObjectId());
  1442. +            statement.setInt(1, qs.getPlayer().getObjectId());
  1443.              statement.setString(2, qs.getQuest().getName());
  1444.              statement.setString(3, var);
  1445. -       statement.executeUpdate();
  1446. +            statement.executeUpdate();
  1447.              statement.close();
  1448. -        } catch (Exception e) {
  1449. -           _log.log(Level.WARNING, "could not delete char quest:", e);
  1450. -        } finally {
  1451. -            try { con.close(); } catch (Exception e) {}
  1452.          }
  1453. -   }
  1454. -  
  1455. -   /**
  1456. -    * Delete the player's quest from database.
  1457. -    * @param qs : QuestState pointing out the player's quest
  1458. -    */
  1459. -   public static void deleteQuestInDb(QuestState qs) {
  1460. +        catch (Exception e)
  1461. +        {
  1462. +            _log.log(Level.WARNING, "could not delete char quest:", e);
  1463. +        }
  1464. +        finally
  1465. +        {
  1466. +            try
  1467. +            {
  1468. +                con.close();
  1469. +            }
  1470. +            catch (Exception e)
  1471. +            {
  1472. +            }
  1473. +        }
  1474. +    }
  1475. +
  1476. +    /**
  1477. +     * Delete the player's quest from database.
  1478. +     *
  1479. +     * @param qs : QuestState pointing out the player's quest
  1480. +     */
  1481. +    public static void deleteQuestInDb(QuestState qs)
  1482. +    {
  1483.          java.sql.Connection con = null;
  1484.          try
  1485.          {
  1486.              con = L2DatabaseFactory.getInstance().getConnection();
  1487.              PreparedStatement statement;
  1488.              statement = con.prepareStatement("DELETE FROM character_quests WHERE char_id=? AND name=?");
  1489. -            statement.setInt   (1, qs.getPlayer().getObjectId());
  1490. +            statement.setInt(1, qs.getPlayer().getObjectId());
  1491.              statement.setString(2, qs.getQuest().getName());
  1492. -           statement.executeUpdate();
  1493. +            statement.executeUpdate();
  1494.              statement.close();
  1495. -        } catch (Exception e) {
  1496. -           _log.log(Level.WARNING, "could not delete char quest:", e);
  1497. -        } finally {
  1498. -            try { con.close(); } catch (Exception e) {}
  1499.          }
  1500. -   }
  1501. -  
  1502. -   /**
  1503. -    * Create a record in database for quest.<BR><BR>
  1504. -    * <U><I>Actions :</I></U><BR>
  1505. -    * Use fucntion createQuestVarInDb() with following parameters :<BR>
  1506. -    * <LI>QuestState : parameter sq that puts in fields of database :
  1507. -    *   <UL type="square">
  1508. -    *     <LI>char_id : ID of the player</LI>
  1509. -    *     <LI>name : name of the quest</LI>
  1510. -    *   </UL>
  1511. -    * </LI>
  1512. -    * <LI>var : string "&lt;state&gt;" as the name of the variable for the quest</LI>
  1513. -    * <LI>val : string corresponding at the ID of the state (in fact, initial state)</LI>
  1514. -    * @param qs : QuestState
  1515. -    */
  1516. -   public static void createQuestInDb(QuestState qs) {
  1517. -       createQuestVarInDb(qs, "<state>", qs.getStateId());
  1518. -   }
  1519. -  
  1520. -   /**
  1521. -    * Update informations regarding quest in database.<BR>
  1522. -    * <U><I>Actions :</I></U><BR>
  1523. -    * <LI>Get ID state of the quest recorded in object qs</LI>
  1524. -    * <LI>Test if quest is completed. If true, add a star (*) before the ID state</LI>
  1525. -    * <LI>Save in database the ID state (with or without the star) for the variable called "&lt;state&gt;" of the quest</LI>
  1526. -    * @param qs : QuestState
  1527. -    */
  1528. -   public static void updateQuestInDb(QuestState qs)
  1529. +        catch (Exception e)
  1530.          {
  1531. -       String val = qs.getStateId();
  1532. -       //if (qs.isCompleted())
  1533. -       //  val = "*" + val;
  1534. -       updateQuestVarInDb(qs, "<state>", val);
  1535. -   }
  1536. +            _log.log(Level.WARNING, "could not delete char quest:", e);
  1537. +        }
  1538. +        finally
  1539. +        {
  1540. +            try
  1541. +            {
  1542. +                con.close();
  1543. +            }
  1544. +            catch (Exception e)
  1545. +            {
  1546. +            }
  1547. +        }
  1548. +    }
  1549. +
  1550. +    /**
  1551. +     * Create a record in database for quest.<BR><BR> <U><I>Actions :</I></U><BR> Use fucntion
  1552. +     * createQuestVarInDb() with following parameters :<BR> <LI>QuestState : parameter sq that puts in fields
  1553. +     * of database : <UL type="square"> <LI>char_id : ID of the player</LI> <LI>name : name of the quest</LI>
  1554. +     * </UL> </LI> <LI>var : string "&lt;state&gt;" as the name of the variable for the quest</LI> <LI>val :
  1555. +     * string corresponding at the ID of the state (in fact, initial state)</LI>
  1556. +     *
  1557. +     * @param qs : QuestState
  1558. +     */
  1559. +    public static void createQuestInDb(QuestState qs)
  1560. +    {
  1561. +        createQuestVarInDb(qs, "<state>", qs.getStateId());
  1562. +    }
  1563. +
  1564. +    /**
  1565. +     * Update informations regarding quest in database.<BR> <U><I>Actions :</I></U><BR> <LI>Get ID state of
  1566. +     * the quest recorded in object qs</LI> <LI>Test if quest is completed. If true, add a star (*) before the
  1567. +     * ID state</LI> <LI>Save in database the ID state (with or without the star) for the variable called
  1568. +     * "&lt;state&gt;" of the quest</LI>
  1569. +     *
  1570. +     * @param qs : QuestState
  1571. +     */
  1572. +    public static void updateQuestInDb(QuestState qs)
  1573. +    {
  1574. +        String val = qs.getStateId();
  1575. +        // if (qs.isCompleted())
  1576. +        // val = "*" + val;
  1577. +        updateQuestVarInDb(qs, "<state>", val);
  1578. +    }
  1579. +
  1580. +    /**
  1581. +     * @see net.sf.l2j.gameserver.scripting.ManagedScript#getScriptName()
  1582. +     */
  1583. +    @Override
  1584. +    public String getScriptName()
  1585. +    {
  1586. +        return this.getName();
  1587. +    }
  1588. +
  1589. +    /**
  1590. +     * @see net.sf.l2j.gameserver.scripting.ManagedScript#setActive(boolean)
  1591. +     */
  1592. +    @Override
  1593. +    public void setActive(boolean status)
  1594. +    {
  1595. +        // TODO implement me
  1596. +    }
  1597. +
  1598. +    /**
  1599. +     * @see net.sf.l2j.gameserver.scripting.ManagedScript#reload()
  1600. +     */
  1601. +    @Override
  1602. +    public boolean reload()
  1603. +    {
  1604. +        unload();
  1605. +        return super.reload();
  1606. +    }
  1607. +
  1608. +    /**
  1609. +     * @see net.sf.l2j.gameserver.scripting.ManagedScript#unload()
  1610. +     */
  1611. +    @Override
  1612. +    public boolean unload()
  1613. +    {
  1614. +        this.saveGlobalData();
  1615. +        // cancel all pending timers before reloading.
  1616. +        // if timers ought to be restarted, the quest can take care of it
  1617. +        // with its code (example: save global data indicating what timer must
  1618. +        // be restarted).
  1619. +        for (FastList<QuestTimer> timers : _allEventTimers.values())
  1620. +        {
  1621. +            for (QuestTimer timer : timers)
  1622. +            {
  1623. +                timer.cancel();
  1624. +            }
  1625. +        }
  1626. +        _allEventTimers.clear();
  1627. +        return QuestManager.getInstance().removeQuest(this);
  1628. +    }
  1629. +
  1630. +    /**
  1631. +     * @see net.sf.l2j.gameserver.scripting.ManagedScript#getScriptManager()
  1632. +     */
  1633. +    @Override
  1634. +    public ScriptManager<?> getScriptManager()
  1635. +    {
  1636. +        return QuestManager.getInstance();
  1637. +    }
  1638.  }
  1639. Index: java/net/sf/l2j/gameserver/script/scripting/ScriptManager.java
  1640. ===================================================================
  1641. --- java/net/sf/l2j/gameserver/script/scripting/ScriptManager.java  (revision 0)
  1642. +++ java/net/sf/l2j/gameserver/script/scripting/ScriptManager.java  (revision 0)
  1643. @@ -0,0 +1,45 @@
  1644. +/*
  1645. + * Copyright (C) 2004-2013 L2J Server
  1646. + *
  1647. + * This file is part of L2J Server.
  1648. + *
  1649. + * L2J Server is free software: you can redistribute it and/or modify
  1650. + * it under the terms of the GNU General Public License as published by
  1651. + * the Free Software Foundation, either version 3 of the License, or
  1652. + * (at your option) any later version.
  1653. + *
  1654. + * L2J Server is distributed in the hope that it will be useful,
  1655. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1656. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1657. + * General Public License for more details.
  1658. + *
  1659. + * You should have received a copy of the GNU General Public License
  1660. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1661. + */
  1662. +package net.sf.l2j.gameserver.script.scripting;
  1663. +
  1664. +/**
  1665. + * @author KenM
  1666. + * @param <S>
  1667. + */
  1668. +public abstract class ScriptManager<S extends ManagedScript>
  1669. +{
  1670. +   public abstract Iterable<S> getAllManagedScripts();
  1671. +  
  1672. +   public boolean reload(S ms)
  1673. +   {
  1674. +       return ms.reload();
  1675. +   }
  1676. +  
  1677. +   public boolean unload(S ms)
  1678. +   {
  1679. +       return ms.unload();
  1680. +   }
  1681. +  
  1682. +   public void setActive(S ms, boolean status)
  1683. +   {
  1684. +       ms.setActive(status);
  1685. +   }
  1686. +  
  1687. +   public abstract String getScriptManagerName();
  1688. +}
  1689. Index: java/net/sf/l2j/gameserver/instancemanager/QuestManager.java
  1690. ===================================================================
  1691. --- java/net/sf/l2j/gameserver/instancemanager/QuestManager.java    (revision 325)
  1692. +++ java/net/sf/l2j/gameserver/instancemanager/QuestManager.java    (working copy)
  1693. @@ -1,55 +1,49 @@
  1694.  /*
  1695. - * This program is free software; you can redistribute it and/or modify
  1696. - * it under the terms of the GNU General Public License as published by
  1697. - * the Free Software Foundation; either version 2, or (at your option)
  1698. - * any later version.
  1699. - *
  1700. - * This program is distributed in the hope that it will be useful,
  1701. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1702. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1703. - * GNU General Public License for more details.
  1704. - *
  1705. - * You should have received a copy of the GNU General Public License
  1706. - * along with this program; if not, write to the Free Software
  1707. - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  1708. - * 02111-1307, USA.
  1709. - *
  1710. - * http://www.gnu.org/copyleft/gpl.html
  1711. + * This program is free software: you can redistribute it and/or modify it under
  1712. + * the terms of the GNU General Public License as published by the Free Software
  1713. + * Foundation, either version 3 of the License, or (at your option) any later
  1714. + * version.
  1715. + *
  1716. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1717. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1718. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1719. + * details.
  1720. + *
  1721. + * You should have received a copy of the GNU General Public License along with
  1722. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1723.   */
  1724.  package net.sf.l2j.gameserver.instancemanager;
  1725.  
  1726. -import java.util.List;
  1727. +import java.util.Map;
  1728.  import java.util.logging.Logger;
  1729.  
  1730. -import javolution.util.FastList;
  1731. -import net.sf.l2j.Config;
  1732. +import javolution.util.FastMap;
  1733.  import net.sf.l2j.gameserver.model.quest.Quest;
  1734. -import net.sf.l2j.gameserver.model.quest.jython.QuestJython;
  1735. +import net.sf.l2j.gameserver.script.scripting.ScriptManager;
  1736.  
  1737. -public class QuestManager
  1738. +
  1739. +public class QuestManager extends ScriptManager<Quest>
  1740.  {
  1741. -    protected static Logger _log = Logger.getLogger(QuestManager.class.getName());
  1742. +    protected static final Logger _log = Logger.getLogger(QuestManager.class.getName());
  1743.  
  1744.      // =========================================================
  1745. -    private static QuestManager _Instance;
  1746. +    private static QuestManager _instance;
  1747.      public static final QuestManager getInstance()
  1748.      {
  1749. -        if (_Instance == null)
  1750. +        if (_instance == null)
  1751.          {
  1752. -           System.out.println("Initializing QuestManager");
  1753. -            _Instance = new QuestManager();
  1754. -            if (!Config.ALT_DEV_NO_QUESTS)
  1755. -                _Instance.load();
  1756. +            _log.info("Initializing QuestManager");
  1757. +            _instance = new QuestManager();
  1758.          }
  1759. -        return _Instance;
  1760. +        return _instance;
  1761.      }
  1762.      // =========================================================
  1763.  
  1764. -    
  1765. +
  1766.      // =========================================================
  1767.      // Data Field
  1768. -    private List<Quest> _Quests;
  1769. -    
  1770. +    private Map<String, Quest> _quests = new FastMap<String, Quest>();
  1771. +
  1772.      // =========================================================
  1773.      // Constructor
  1774.      public QuestManager()
  1775. @@ -58,65 +52,125 @@
  1776.  
  1777.      // =========================================================
  1778.      // Method - Public
  1779. -    // NOT WORKING CORRECTLY BECAUSE BSFMANAGER DOEN'T UNLOAD JYTHON SCRIPT
  1780. -    // NEED TO FIND THE SOLUTION BEFORE THIS WILL WORK CORRECLY
  1781. -    public final void reload()
  1782. +    public final boolean reload(String questFolder)
  1783.      {
  1784. -       /* Re-add later just incase problem exist now
  1785. -        this.getQuests().clear();
  1786. -        this.load();
  1787. -        */
  1788. +        Quest q = getQuest(questFolder);
  1789. +        if (q == null)
  1790. +        {
  1791. +            return false;
  1792. +        }
  1793. +        return q.reload();
  1794.      }
  1795. -
  1796. -    // =========================================================
  1797. -    // Method - Private
  1798. -    private final void load()
  1799. +    
  1800. +    /**
  1801. +     * Reloads a the quest given by questId.<BR>
  1802. +     * <B>NOTICE: Will only work if the quest name is equal the quest folder name</B>
  1803. +     * @param questId The id of the quest to be reloaded
  1804. +     * @return true if reload was succesful, false otherwise
  1805. +     */
  1806. +    public final boolean reload(int questId)
  1807.      {
  1808. -        QuestJython.init();
  1809. -        System.out.println("Loaded: " + getQuests().size() + " quests");
  1810. +        Quest q = this.getQuest(questId);
  1811. +        if (q == null)
  1812. +        {
  1813. +            return false;
  1814. +        }
  1815. +        return q.reload();
  1816.      }
  1817. +    
  1818. +    public final void report()
  1819. +    {
  1820. +        _log.info("Loaded: " + getQuests().size() + " quests");
  1821. +    }
  1822. +    
  1823. +    public final void save()
  1824. +    {
  1825. +        for (Quest q: getQuests().values())
  1826. +        {
  1827. +            q.saveGlobalData();
  1828. +        }
  1829. +    }
  1830.  
  1831.      // =========================================================
  1832.      // Property - Public
  1833.      public final Quest getQuest(String name)
  1834.      {
  1835. -        int index = getQuestIndex(name);
  1836. -        if (index >= 0) return getQuests().get(index);
  1837. -        return null;
  1838. +        return getQuests().get(name);
  1839.      }
  1840.  
  1841.      public final Quest getQuest(int questId)
  1842.      {
  1843. -        int index = getQuestIndex(questId);
  1844. -        if (index >= 0) return getQuests().get(index);
  1845. +        for (Quest q: getQuests().values())
  1846. +        {
  1847. +            if (q.getQuestIntId() == questId)
  1848. +                return q;
  1849. +        }
  1850.          return null;
  1851.      }
  1852.      
  1853. -    public final int getQuestIndex(String name)
  1854. +
  1855. +    public final void addQuest(Quest newQuest)
  1856.      {
  1857. -        Quest quest;
  1858. -        for (int i = 0; i < getQuests().size(); i++)
  1859. +        if (newQuest == null)
  1860.          {
  1861. -            quest = getQuests().get(i);
  1862. -            if (quest != null && quest.getName().equalsIgnoreCase(name)) return i;
  1863. +            throw new IllegalArgumentException("Quest argument cannot be null");
  1864.          }
  1865. -        return -1;
  1866. +        Quest old = this.getQuests().get(newQuest.getName());
  1867. +        
  1868. +        // FIXME: unloading the old quest at this point is a tad too late.
  1869. +        // the new quest has already initialized itself and read the data, starting
  1870. +        // an unpredictable number of tasks with that data.  The old quest will now
  1871. +        // save data which will never be read.
  1872. +        // However, requesting the newQuest to re-read the data is not necessarily a
  1873. +        // good option, since the newQuest may have already started timers, spawned NPCs
  1874. +        // or taken any other action which it might re-take by re-reading the data.
  1875. +        // the current solution properly closes the running tasks of the old quest but
  1876. +        // ignores the data; perhaps the least of all evils...
  1877. +        if (old != null)
  1878. +        {
  1879. +            old.unload();
  1880. +            _log.info("Replaced: ("+old.getName()+") with a new version ("+newQuest.getName()+")");
  1881. +            
  1882. +        }
  1883. +        this.getQuests().put(newQuest.getName(), newQuest);
  1884.      }
  1885.      
  1886. -    public final int getQuestIndex(int questId)
  1887. +    public final boolean removeQuest(Quest q)
  1888.      {
  1889. -        Quest quest;
  1890. -        for (int i = 0; i < getQuests().size(); i++)
  1891. -        {
  1892. -            quest = getQuests().get(i);
  1893. -            if (quest != null && quest.getQuestIntId() == questId) return i;
  1894. -        }
  1895. -        return -1;
  1896. +        return this.getQuests().remove(q.getName()) != null;
  1897.      }
  1898. +    
  1899. +    public final FastMap<String, Quest> getQuests()
  1900. +    {
  1901. +        if (_quests == null) _quests = new FastMap<String, Quest>();
  1902. +        return (FastMap<String, Quest>) _quests;
  1903. +    }
  1904.  
  1905. -    public final List<Quest> getQuests()
  1906. +    /**
  1907. +     * @see net.sf.l2j.gameserver.scripting.ScriptManager#getAllManagedScripts()
  1908. +     */
  1909. +    @Override
  1910. +    public Iterable<Quest> getAllManagedScripts()
  1911.      {
  1912. -        if (_Quests == null) _Quests = new FastList<Quest>();
  1913. -        return _Quests;
  1914. +        return _quests.values();
  1915.      }
  1916. +
  1917. +    /**
  1918. +     * @see net.sf.l2j.gameserver.scripting.ScriptManager#unload(net.sf.l2j.gameserver.scripting.ManagedScript)
  1919. +     */
  1920. +    @Override
  1921. +    public boolean unload(Quest ms)
  1922. +    {
  1923. +        ms.saveGlobalData();
  1924. +        return this.removeQuest(ms);
  1925. +    }
  1926. +
  1927. +    /**
  1928. +     * @see net.sf.l2j.gameserver.scripting.ScriptManager#getScriptManagerName()
  1929. +     */
  1930. +    @Override
  1931. +    public String getScriptManagerName()
  1932. +    {
  1933. +        return "QuestManager";
  1934. +    }
  1935.  }
  1936. Index: lib/jython-engine-2.2.1.jar
  1937. ===================================================================
  1938. Cannot display: file marked as a binary type.
  1939. svn:mime-type = application/octet-stream
  1940.  
  1941. Property changes on: lib\jython-engine-2.2.1.jar
  1942. ___________________________________________________________________
  1943. Added: svn:mime-type
  1944.    + application/octet-stream
  1945.  
  1946. Index: build.xml
  1947. ===================================================================
  1948. --- build.xml   (revision 325)
  1949. +++ build.xml   (working copy)
  1950. @@ -42,6 +42,8 @@
  1951.             <include name="jython.jar"/>
  1952.             <include name="javolution.jar"/>
  1953.             <include name="hibernate3.jar"/>
  1954. +           <include name="jython-engine-2.2.1.jar"/>
  1955. +           <include name="java-engine-1.7.1.jar"/>
  1956.          </fileset>
  1957.      </path>    
  1958. Index: java/net/sf/l2j/gameserver/script/scripting/ManagedScript.java
  1959. ===================================================================
  1960. --- java/net/sf/l2j/gameserver/script/scripting/ManagedScript.java  (revision 0)
  1961. +++ java/net/sf/l2j/gameserver/script/scripting/ManagedScript.java  (revision 0)
  1962. @@ -0,0 +1,98 @@
  1963. +/*
  1964. + * Copyright (C) 2004-2013 L2J Server
  1965. + *
  1966. + * This file is part of L2J Server.
  1967. + *
  1968. + * L2J Server is free software: you can redistribute it and/or modify
  1969. + * it under the terms of the GNU General Public License as published by
  1970. + * the Free Software Foundation, either version 3 of the License, or
  1971. + * (at your option) any later version.
  1972. + *
  1973. + * L2J Server is distributed in the hope that it will be useful,
  1974. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1975. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1976. + * General Public License for more details.
  1977. + *
  1978. + * You should have received a copy of the GNU General Public License
  1979. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  1980. + */
  1981. +package net.sf.l2j.gameserver.script.scripting;
  1982. +
  1983. +import java.io.File;
  1984. +
  1985. +import javax.script.ScriptException;
  1986. +
  1987. +/**
  1988. + * Abstract class for classes that are meant to be implemented by scripts.<BR>
  1989. + * @author KenM
  1990. + */
  1991. +public abstract class ManagedScript
  1992. +{
  1993. +   private final File _scriptFile;
  1994. +   private long _lastLoadTime;
  1995. +   private boolean _isActive;
  1996. +  
  1997. +   public ManagedScript()
  1998. +   {
  1999. +       _scriptFile = L2ScriptEngineManager.getInstance().getCurrentLoadingScript();
  2000. +       setLastLoadTime(System.currentTimeMillis());
  2001. +   }
  2002. +  
  2003. +   /**
  2004. +    * Attempts to reload this script and to refresh the necessary bindings with it ScriptControler.<BR>
  2005. +    * Subclasses of this class should override this method to properly refresh their bindings when necessary.
  2006. +    * @return true if and only if the script was reloaded, false otherwise.
  2007. +    */
  2008. +   public boolean reload()
  2009. +   {
  2010. +       try
  2011. +       {
  2012. +           L2ScriptEngineManager.getInstance().executeScript(getScriptFile());
  2013. +           return true;
  2014. +       }
  2015. +       catch (ScriptException e)
  2016. +       {
  2017. +           return false;
  2018. +       }
  2019. +   }
  2020. +  
  2021. +   public abstract boolean unload();
  2022. +  
  2023. +   public void setActive(boolean status)
  2024. +   {
  2025. +       _isActive = status;
  2026. +   }
  2027. +  
  2028. +   public boolean isActive()
  2029. +   {
  2030. +       return _isActive;
  2031. +   }
  2032. +  
  2033. +   /**
  2034. +    * @return Returns the scriptFile.
  2035. +    */
  2036. +   public File getScriptFile()
  2037. +   {
  2038. +       return _scriptFile;
  2039. +   }
  2040. +  
  2041. +   /**
  2042. +    * @param lastLoadTime The lastLoadTime to set.
  2043. +    */
  2044. +   protected void setLastLoadTime(long lastLoadTime)
  2045. +   {
  2046. +       _lastLoadTime = lastLoadTime;
  2047. +   }
  2048. +  
  2049. +   /**
  2050. +    * @return Returns the lastLoadTime.
  2051. +    */
  2052. +   protected long getLastLoadTime()
  2053. +   {
  2054. +       return _lastLoadTime;
  2055. +   }
  2056. +  
  2057. +   public abstract String getScriptName();
  2058. +  
  2059. +   public abstract ScriptManager<?> getScriptManager();
  2060. +}
  2061. Index: java/net/sf/l2j/gameserver/GameServer.java
  2062. ===================================================================
  2063. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 325)
  2064. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  2065. @@ -20,6 +20,7 @@
  2066.  
  2067.  import java.io.File;
  2068.  import java.io.FileInputStream;
  2069. +import java.io.IOException;
  2070.  import java.io.InputStream;
  2071.  import java.util.Calendar;
  2072.  import java.util.logging.Level;
  2073. @@ -64,6 +65,7 @@
  2074.  import net.sf.l2j.gameserver.model.entity.Hero;
  2075.  import net.sf.l2j.gameserver.pathfinding.geonodes.GeoPathFinding;
  2076.  import net.sf.l2j.gameserver.script.faenor.FaenorScriptEngine;
  2077. +import net.sf.l2j.gameserver.script.scripting.L2ScriptEngineManager;
  2078.  import net.sf.l2j.gameserver.taskmanager.KnownListUpdateTaskManager;
  2079.  import net.sf.l2j.gameserver.taskmanager.TaskManager;
  2080.  import net.sf.l2j.gameserver.util.DynamicExtension;
  2081. @@ -139,8 +141,9 @@
  2082.  
  2083.         new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
  2084.         new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
  2085. +      
  2086. +       L2ScriptEngineManager.getInstance();
  2087.  
  2088. -
  2089.         // start game time control early
  2090.         GameTimeController.getInstance();
  2091.  
  2092. @@ -250,6 +253,17 @@
  2093.  
  2094.  
  2095.  
  2096. +        try
  2097. +        {
  2098. +            _log.info("Loading Server Scripts");
  2099. +            File scripts = new File("data/scripts.cfg");
  2100. +            L2ScriptEngineManager.getInstance().executeScriptList(scripts);
  2101. +        }
  2102. +        catch (IOException ioe)
  2103. +        {
  2104. +            _log.severe("Failed loading scripts.cfg, no script going to be loaded");
  2105. +        }  
  2106. +                
  2107.          if (Config.SAVE_DROPPED_ITEM)
  2108.              ItemsOnGroundManager.getInstance();
  2109.  
  2110. Index: java/net/sf/l2j/Config.java
  2111. ===================================================================
  2112. --- java/net/sf/l2j/Config.java (revision 325)
  2113. +++ java/net/sf/l2j/Config.java (working copy)
  2114. @@ -29,7 +29,6 @@
  2115.  import java.util.logging.Logger;
  2116.  
  2117.  import javolution.util.FastList;
  2118. -import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  2119.  
  2120.  /**
  2121.   * This class containce global server configuration.<br>
  2122. @@ -42,6 +41,12 @@
  2123.  public final class Config
  2124.  {
  2125.     protected static Logger _log = Logger.getLogger(Config.class.getName());
  2126. +
  2127. +   // --------------------------------------------------
  2128. +    // Constants
  2129. +    // --------------------------------------------------
  2130. +    public static final String EOL = System.getProperty("line.separator");
  2131. +    
  2132.     /** Debug/release mode */
  2133.      public static boolean DEBUG;
  2134.      /** Enable/disable assertions */
  2135. @@ -1077,6 +1082,7 @@
  2136.      public static byte BUFFS_MAX_AMOUNT;
  2137.  
  2138.      /** Alt Settings for devs */
  2139. +    public static boolean ALT_DEV_NO_HANDLERS;
  2140.      public static boolean ALT_DEV_NO_QUESTS;
  2141.      public static boolean ALT_DEV_NO_SPAWNS;
  2142.  
  2143. @@ -1648,6 +1654,7 @@
  2144.                  ALT_LOTTERY_2_AND_1_NUMBER_PRIZE = Integer.parseInt(altSettings.getProperty("AltLottery2and1NumberPrize","200"));
  2145.                  BUFFS_MAX_AMOUNT                 = Byte.parseByte(altSettings.getProperty("maxbuffamount","20"));
  2146.                  ALT_DEV_NO_QUESTS                = Boolean.parseBoolean(altSettings.getProperty("AltDevNoQuests", "False"));
  2147. +                ALT_DEV_NO_HANDLERS                = Boolean.parseBoolean(altSettings.getProperty("AltDevNoHandlers", "False"));
  2148.                  ALT_DEV_NO_SPAWNS                = Boolean.parseBoolean(altSettings.getProperty("AltDevNoSpawns", "False"));
  2149.             }
  2150.             catch (Exception e)
  2151. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminQuest.java
  2152. ===================================================================
  2153. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminQuest.java (revision 325)
  2154. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminQuest.java (working copy)
  2155. @@ -28,12 +28,16 @@
  2156.   */
  2157.  package net.sf.l2j.gameserver.handler.admincommandhandlers;
  2158.  
  2159. +import java.io.File;
  2160.  import java.util.StringTokenizer;
  2161.  
  2162. +import javax.script.ScriptException;
  2163. +
  2164.  import net.sf.l2j.Config;
  2165.  import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  2166.  import net.sf.l2j.gameserver.instancemanager.QuestManager;
  2167.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  2168. +import net.sf.l2j.gameserver.script.scripting.L2ScriptEngineManager;
  2169.  
  2170.  public class AdminQuest implements IAdminCommandHandler
  2171.  {
  2172. @@ -61,7 +65,36 @@
  2173.  
  2174.          if (actualCommand.equalsIgnoreCase("admin_quest_reload"))
  2175.          {
  2176. -            QuestManager.getInstance().reload();
  2177. +            String[] parts = command.split(" ");
  2178. +            if (parts.length < 2)
  2179. +            {
  2180. +                // activeChar.sendMessage("Example: //script_load <questFolder>/<questSubFolders...>/<filename>.<ext> ");
  2181. +                activeChar.sendMessage("Example: //script_load quests/SagasSuperclass/__init__.py");
  2182. +            }
  2183. +            else
  2184. +            {
  2185. +                File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, parts[1]);
  2186. +                if (file.isFile())
  2187. +                {
  2188. +                    try
  2189. +                    {
  2190. +                        L2ScriptEngineManager.getInstance().executeScript(file);
  2191. +                    }
  2192. +                    catch (ScriptException e)
  2193. +                    {
  2194. +                        activeChar.sendMessage("Failed loading: " + parts[1]);
  2195. +                        L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  2196. +                    }
  2197. +                    catch (Exception e)
  2198. +                    {
  2199. +                        activeChar.sendMessage("Failed loading: " + parts[1]);
  2200. +                    }
  2201. +                }
  2202. +                else
  2203. +                {
  2204. +                    activeChar.sendMessage("File Not Found: " + parts[1]);
  2205. +                }
  2206. +            }
  2207.          }
  2208.          return true;
  2209.      }
  2210. Index: .classpath
  2211. ===================================================================
  2212. --- .classpath  (revision 325)
  2213. +++ .classpath  (working copy)
  2214. @@ -20,5 +20,7 @@
  2215.     <classpathentry kind="lib" path="lib/cglib-2.1.3.jar"/>
  2216.     <classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
  2217.     <classpathentry kind="lib" path="lib/jta.jar"/>
  2218. +   <classpathentry kind="lib" path="lib/jython-engine-2.2.1.jar"/>
  2219. +   <classpathentry kind="lib" path="lib/java-engine-1.7.1.jar"/>
  2220.     <classpathentry kind="output" path="bin"/>
  2221.  </classpath>
  2222. Index: java/config/altsettings.properties
  2223. ===================================================================
  2224. --- java/config/altsettings.properties  (revision 325)
  2225. +++ java/config/altsettings.properties  (working copy)
  2226. @@ -282,4 +282,6 @@
  2227.  # Don't load quests
  2228.  AltDevNoQuests = False
  2229.  # Don't load spawntable
  2230. -AltDevNoSpawns = False
  2231. \ No newline at end of file
  2232. +AltDevNoSpawns = False
  2233. +# Don't load masterhandler
  2234. +AltDevNoHandlers = False
  2235. \ No newline at end of file
  2236. Index: java/net/sf/l2j/gameserver/script/scripting/L2ScriptEngineManager.java
  2237. ===================================================================
  2238. --- java/net/sf/l2j/gameserver/script/scripting/L2ScriptEngineManager.java  (revision 0)
  2239. +++ java/net/sf/l2j/gameserver/script/scripting/L2ScriptEngineManager.java  (revision 0)
  2240. @@ -0,0 +1,535 @@
  2241. +/*
  2242. + * Copyright (C) 2004-2013 L2J Server
  2243. + *
  2244. + * This file is part of L2J Server.
  2245. + *
  2246. + * L2J Server is free software: you can redistribute it and/or modify
  2247. + * it under the terms of the GNU General Public License as published by
  2248. + * the Free Software Foundation, either version 3 of the License, or
  2249. + * (at your option) any later version.
  2250. + *
  2251. + * L2J Server is distributed in the hope that it will be useful,
  2252. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2253. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2254. + * General Public License for more details.
  2255. + *
  2256. + * You should have received a copy of the GNU General Public License
  2257. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2258. + */
  2259. +package net.sf.l2j.gameserver.script.scripting;
  2260. +
  2261. +import java.io.BufferedReader;
  2262. +import java.io.File;
  2263. +import java.io.FileInputStream;
  2264. +import java.io.FileOutputStream;
  2265. +import java.io.IOException;
  2266. +import java.io.InputStreamReader;
  2267. +import java.io.LineNumberReader;
  2268. +import java.util.LinkedList;
  2269. +import java.util.List;
  2270. +import java.util.Map;
  2271. +import java.util.logging.Level;
  2272. +import java.util.logging.Logger;
  2273. +
  2274. +import javax.script.Compilable;
  2275. +import javax.script.CompiledScript;
  2276. +import javax.script.ScriptContext;
  2277. +import javax.script.ScriptEngine;
  2278. +import javax.script.ScriptEngineFactory;
  2279. +import javax.script.ScriptEngineManager;
  2280. +import javax.script.ScriptException;
  2281. +import javax.script.SimpleScriptContext;
  2282. +
  2283. +import com.l2jserver.script.jython.JythonScriptEngine;
  2284. +
  2285. +import javolution.util.FastMap;
  2286. +
  2287. +import net.sf.l2j.Config;
  2288. +
  2289. +/**
  2290. + * Caches script engines and provides functionality for executing and managing scripts.
  2291. + * @author KenM
  2292. + */
  2293. +public final class L2ScriptEngineManager
  2294. +{
  2295. +   private static final Logger _log = Logger.getLogger(L2ScriptEngineManager.class.getName());
  2296. +  
  2297. +   public static final File SCRIPT_FOLDER = new File(Config.DATAPACK_ROOT.getAbsolutePath(), "data/jscript");
  2298. +  
  2299. +   public static L2ScriptEngineManager getInstance()
  2300. +   {
  2301. +       return SingletonHolder._instance;
  2302. +   }
  2303. +  
  2304. +   private final Map<String, ScriptEngine> _nameEngines = new FastMap<String, ScriptEngine>();
  2305. +   private final Map<String, ScriptEngine> _extEngines = new FastMap<String, ScriptEngine>();
  2306. +   private final List<ScriptManager<?>> _scriptManagers = new LinkedList<ScriptManager<?>>();
  2307. +  
  2308. +   private File _currentLoadingScript;
  2309. +  
  2310. +   // Configs
  2311. +   // TODO move to config file
  2312. +   /**
  2313. +    * Informs(logs) the scripts being loaded.<BR>
  2314. +    * Apply only when executing script from files.<BR>
  2315. +    */
  2316. +   private static final boolean VERBOSE_LOADING = false;
  2317. +  
  2318. +   /**
  2319. +    * If the script engine supports compilation the script is compiled before execution.<BR>
  2320. +    */
  2321. +   private static final boolean ATTEMPT_COMPILATION = true;
  2322. +  
  2323. +   /**
  2324. +    * Clean an previous error log(if such exists) for the script being loaded before trying to load.<BR>
  2325. +    * Apply only when executing script from files.<BR>
  2326. +    */
  2327. +   private static final boolean PURGE_ERROR_LOG = true;
  2328. +  
  2329. +   protected L2ScriptEngineManager()
  2330. +   {
  2331. +       ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
  2332. +       List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories();
  2333. +      
  2334. +       for (ScriptEngineFactory factory : factories)
  2335. +       {
  2336. +           try
  2337. +           {
  2338. +               ScriptEngine engine = factory.getScriptEngine();
  2339. +               boolean reg = false;
  2340. +               for (String name : factory.getNames())
  2341. +               {
  2342. +                   ScriptEngine existentEngine = _nameEngines.get(name);
  2343. +                  
  2344. +                   if (existentEngine != null)
  2345. +                   {
  2346. +                       double engineVer = Double.parseDouble(factory.getEngineVersion());
  2347. +                       double existentEngVer = Double.parseDouble(existentEngine.getFactory().getEngineVersion());
  2348. +                      
  2349. +                       if (engineVer <= existentEngVer)
  2350. +                       {
  2351. +                           continue;
  2352. +                       }
  2353. +                   }
  2354. +                  
  2355. +                   reg = true;
  2356. +                   _nameEngines.put(name, engine);
  2357. +               }
  2358. +              
  2359. +               if (reg)
  2360. +               {
  2361. +                   _log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " - Language Version: " + factory.getLanguageVersion());
  2362. +               }
  2363. +              
  2364. +               for (String ext : factory.getExtensions())
  2365. +               {
  2366. +                   if (!ext.equals("java") || factory.getLanguageName().equals("java"))
  2367. +                   {
  2368. +                       _extEngines.put(ext, engine);
  2369. +                   }
  2370. +               }
  2371. +           }
  2372. +           catch (Exception e)
  2373. +           {
  2374. +               _log.log(Level.WARNING, "Failed initializing factory: " + e.getMessage(), e);
  2375. +           }
  2376. +       }
  2377. +      
  2378. +       preConfigure();
  2379. +   }
  2380. +  
  2381. +   private void preConfigure()
  2382. +   {
  2383. +       // Jython sys.path
  2384. +       String dataPackDirForwardSlashes = SCRIPT_FOLDER.getPath().replaceAll("\\\\", "/");
  2385. +       String configScript = "import sys;sys.path.insert(0,'" + dataPackDirForwardSlashes + "');";
  2386. +       try
  2387. +       {
  2388. +           eval("jython", configScript);
  2389. +       }
  2390. +       catch (ScriptException e)
  2391. +       {
  2392. +           _log.severe("Failed preconfiguring jython: " + e.getMessage());
  2393. +       }
  2394. +   }
  2395. +  
  2396. +   private ScriptEngine getEngineByName(String name)
  2397. +   {
  2398. +       return _nameEngines.get(name);
  2399. +   }
  2400. +  
  2401. +   private ScriptEngine getEngineByExtension(String ext)
  2402. +   {
  2403. +       return _extEngines.get(ext);
  2404. +   }
  2405. +  
  2406. +   public void executeScriptList(File list) throws IOException
  2407. +   {
  2408. +       File file;
  2409. +      
  2410. +       if (!Config.ALT_DEV_NO_HANDLERS && Config.ALT_DEV_NO_QUESTS)
  2411. +       {
  2412. +           file = new File(SCRIPT_FOLDER, "handlers/MasterHandler.java");
  2413. +          
  2414. +           try
  2415. +           {
  2416. +               executeScript(file);
  2417. +               _log.info("Handlers loaded, all other scripts skipped");
  2418. +               return;
  2419. +           }
  2420. +           catch (ScriptException se)
  2421. +           {
  2422. +               _log.log(Level.WARNING, "", se);
  2423. +           }
  2424. +       }
  2425. +      
  2426. +       if (Config.ALT_DEV_NO_QUESTS)
  2427. +       {
  2428. +           return;
  2429. +       }
  2430. +      
  2431. +       if (list.isFile())
  2432. +       {
  2433. +           try (FileInputStream fis = new FileInputStream(list);
  2434. +               InputStreamReader isr = new InputStreamReader(fis);
  2435. +               LineNumberReader lnr = new LineNumberReader(isr))
  2436. +           {
  2437. +               String line;
  2438. +               while ((line = lnr.readLine()) != null)
  2439. +               {
  2440. +                   if (Config.ALT_DEV_NO_HANDLERS && line.contains("MasterHandler.java"))
  2441. +                   {
  2442. +                       continue;
  2443. +                   }
  2444. +                  
  2445. +                   String[] parts = line.trim().split("#");
  2446. +                  
  2447. +                   if ((parts.length > 0) && !parts[0].isEmpty() && (parts[0].charAt(0) != '#'))
  2448. +                   {
  2449. +                       line = parts[0];
  2450. +                      
  2451. +                       if (line.endsWith("/**"))
  2452. +                       {
  2453. +                           line = line.substring(0, line.length() - 3);
  2454. +                       }
  2455. +                       else if (line.endsWith("/*"))
  2456. +                       {
  2457. +                           line = line.substring(0, line.length() - 2);
  2458. +                       }
  2459. +                      
  2460. +                       file = new File(SCRIPT_FOLDER, line);
  2461. +                      
  2462. +                       if (file.isDirectory() && parts[0].endsWith("/**"))
  2463. +                       {
  2464. +                           executeAllScriptsInDirectory(file, true, 32);
  2465. +                       }
  2466. +                       else if (file.isDirectory() && parts[0].endsWith("/*"))
  2467. +                       {
  2468. +                           executeAllScriptsInDirectory(file);
  2469. +                       }
  2470. +                       else if (file.isFile())
  2471. +                       {
  2472. +                           try
  2473. +                           {
  2474. +                               executeScript(file);
  2475. +                           }
  2476. +                           catch (ScriptException e)
  2477. +                           {
  2478. +                               reportScriptFileError(file, e);
  2479. +                           }
  2480. +                       }
  2481. +                       else
  2482. +                       {
  2483. +                           _log.warning("Failed loading: (" + file.getCanonicalPath() + ") @ " + list.getName() + ":" + lnr.getLineNumber() + " - Reason: doesnt exists or is not a file.");
  2484. +                       }
  2485. +                   }
  2486. +               }
  2487. +           }
  2488. +       }
  2489. +       else
  2490. +       {
  2491. +           throw new IllegalArgumentException("Argument must be an file containing a list of scripts to be loaded");
  2492. +       }
  2493. +   }
  2494. +  
  2495. +   public void executeAllScriptsInDirectory(File dir)
  2496. +   {
  2497. +       executeAllScriptsInDirectory(dir, false, 0);
  2498. +   }
  2499. +  
  2500. +   public void executeAllScriptsInDirectory(File dir, boolean recurseDown, int maxDepth)
  2501. +   {
  2502. +       executeAllScriptsInDirectory(dir, recurseDown, maxDepth, 0);
  2503. +   }
  2504. +  
  2505. +   private void executeAllScriptsInDirectory(File dir, boolean recurseDown, int maxDepth, int currentDepth)
  2506. +   {
  2507. +       if (dir.isDirectory())
  2508. +       {
  2509. +           for (File file : dir.listFiles())
  2510. +           {
  2511. +               if (file.isDirectory() && recurseDown && (maxDepth > currentDepth))
  2512. +               {
  2513. +                   if (VERBOSE_LOADING)
  2514. +                   {
  2515. +                       _log.info("Entering folder: " + file.getName());
  2516. +                   }
  2517. +                   executeAllScriptsInDirectory(file, recurseDown, maxDepth, currentDepth + 1);
  2518. +               }
  2519. +               else if (file.isFile())
  2520. +               {
  2521. +                   try
  2522. +                   {
  2523. +                       String name = file.getName();
  2524. +                       int lastIndex = name.lastIndexOf('.');
  2525. +                       String extension;
  2526. +                       if (lastIndex != -1)
  2527. +                       {
  2528. +                           extension = name.substring(lastIndex + 1);
  2529. +                           ScriptEngine engine = getEngineByExtension(extension);
  2530. +                           if (engine != null)
  2531. +                           {
  2532. +                               executeScript(engine, file);
  2533. +                           }
  2534. +                       }
  2535. +                   }
  2536. +                   catch (ScriptException e)
  2537. +                   {
  2538. +                       reportScriptFileError(file, e);
  2539. +                   }
  2540. +               }
  2541. +           }
  2542. +       }
  2543. +       else
  2544. +       {
  2545. +           throw new IllegalArgumentException("The argument directory either doesnt exists or is not an directory.");
  2546. +       }
  2547. +   }
  2548. +  
  2549. +   public void executeScript(File file) throws ScriptException
  2550. +   {
  2551. +       String name = file.getName();
  2552. +       int lastIndex = name.lastIndexOf('.');
  2553. +       String extension;
  2554. +       if (lastIndex != -1)
  2555. +       {
  2556. +           extension = name.substring(lastIndex + 1);
  2557. +       }
  2558. +       else
  2559. +       {
  2560. +           throw new ScriptException("Script file (" + name + ") doesnt has an extension that identifies the ScriptEngine to be used.");
  2561. +       }
  2562. +      
  2563. +       ScriptEngine engine = getEngineByExtension(extension);
  2564. +       if (engine == null)
  2565. +       {
  2566. +           throw new ScriptException("No engine registered for extension (" + extension + ")");
  2567. +       }
  2568. +       executeScript(engine, file);
  2569. +   }
  2570. +  
  2571. +   public void executeScript(String engineName, File file) throws ScriptException
  2572. +   {
  2573. +       ScriptEngine engine = getEngineByName(engineName);
  2574. +       if (engine == null)
  2575. +       {
  2576. +           throw new ScriptException("No engine registered with name (" + engineName + ")");
  2577. +       }
  2578. +       executeScript(engine, file);
  2579. +   }
  2580. +  
  2581. +   public void executeScript(ScriptEngine engine, File file) throws ScriptException
  2582. +   {
  2583. +       if (VERBOSE_LOADING)
  2584. +       {
  2585. +           _log.info("Loading Script: " + file.getAbsolutePath());
  2586. +       }
  2587. +      
  2588. +       if (PURGE_ERROR_LOG)
  2589. +       {
  2590. +           String name = file.getAbsolutePath() + ".error.log";
  2591. +           File errorLog = new File(name);
  2592. +           if (errorLog.isFile())
  2593. +           {
  2594. +               errorLog.delete();
  2595. +           }
  2596. +       }
  2597. +      
  2598. +       final String relativeName = file.getAbsolutePath().substring(SCRIPT_FOLDER.getAbsolutePath().length() + 1).replace('\\', '/');
  2599. +       try (FileInputStream fis = new FileInputStream(file);
  2600. +           InputStreamReader isr = new InputStreamReader(fis);
  2601. +           BufferedReader reader = new BufferedReader(isr))
  2602. +       {
  2603. +           if ((engine instanceof Compilable) && ATTEMPT_COMPILATION)
  2604. +           {
  2605. +               ScriptContext context = new SimpleScriptContext();
  2606. +               context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
  2607. +               context.setAttribute(ScriptEngine.FILENAME, relativeName, ScriptContext.ENGINE_SCOPE);
  2608. +               context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
  2609. +               context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
  2610. +               context.setAttribute(JythonScriptEngine.JYTHON_ENGINE_INSTANCE, engine, ScriptContext.ENGINE_SCOPE);
  2611. +              
  2612. +               setCurrentLoadingScript(file);
  2613. +               ScriptContext ctx = engine.getContext();
  2614. +               try
  2615. +               {
  2616. +                   engine.setContext(context);
  2617. +                   Compilable eng = (Compilable) engine;
  2618. +                   CompiledScript cs = eng.compile(reader);
  2619. +                   cs.eval(context);
  2620. +               }
  2621. +               finally
  2622. +               {
  2623. +                   engine.setContext(ctx);
  2624. +                   setCurrentLoadingScript(null);
  2625. +                   context.removeAttribute(ScriptEngine.FILENAME, ScriptContext.ENGINE_SCOPE);
  2626. +                   context.removeAttribute("mainClass", ScriptContext.ENGINE_SCOPE);
  2627. +               }
  2628. +           }
  2629. +           else
  2630. +           {
  2631. +               ScriptContext context = new SimpleScriptContext();
  2632. +               context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
  2633. +               context.setAttribute(ScriptEngine.FILENAME, relativeName, ScriptContext.ENGINE_SCOPE);
  2634. +               context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
  2635. +               context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
  2636. +               setCurrentLoadingScript(file);
  2637. +               try
  2638. +               {
  2639. +                   engine.eval(reader, context);
  2640. +               }
  2641. +               finally
  2642. +               {
  2643. +                   setCurrentLoadingScript(null);
  2644. +                   engine.getContext().removeAttribute(ScriptEngine.FILENAME, ScriptContext.ENGINE_SCOPE);
  2645. +                   engine.getContext().removeAttribute("mainClass", ScriptContext.ENGINE_SCOPE);
  2646. +               }
  2647. +              
  2648. +           }
  2649. +       }
  2650. +       catch (IOException e)
  2651. +       {
  2652. +           _log.log(Level.WARNING, "Error executing script!", e);
  2653. +       }
  2654. +   }
  2655. +  
  2656. +   public static String getClassForFile(File script)
  2657. +   {
  2658. +       String path = script.getAbsolutePath();
  2659. +       String scpPath = SCRIPT_FOLDER.getAbsolutePath();
  2660. +       if (path.startsWith(scpPath))
  2661. +       {
  2662. +           int idx = path.lastIndexOf('.');
  2663. +           return path.substring(scpPath.length() + 1, idx);
  2664. +       }
  2665. +       return null;
  2666. +   }
  2667. +  
  2668. +   public ScriptContext getScriptContext(ScriptEngine engine)
  2669. +   {
  2670. +       return engine.getContext();
  2671. +   }
  2672. +  
  2673. +   public ScriptContext getScriptContext(String engineName)
  2674. +   {
  2675. +       ScriptEngine engine = getEngineByName(engineName);
  2676. +       if (engine == null)
  2677. +       {
  2678. +           throw new IllegalStateException("No engine registered with name (" + engineName + ")");
  2679. +       }
  2680. +       return getScriptContext(engine);
  2681. +   }
  2682. +  
  2683. +   public Object eval(ScriptEngine engine, String script, ScriptContext context) throws ScriptException
  2684. +   {
  2685. +       if ((engine instanceof Compilable) && ATTEMPT_COMPILATION)
  2686. +       {
  2687. +           Compilable eng = (Compilable) engine;
  2688. +           CompiledScript cs = eng.compile(script);
  2689. +           return context != null ? cs.eval(context) : cs.eval();
  2690. +       }
  2691. +       return context != null ? engine.eval(script, context) : engine.eval(script);
  2692. +   }
  2693. +  
  2694. +   public Object eval(String engineName, String script) throws ScriptException
  2695. +   {
  2696. +       return eval(engineName, script, null);
  2697. +   }
  2698. +  
  2699. +   public Object eval(String engineName, String script, ScriptContext context) throws ScriptException
  2700. +   {
  2701. +       ScriptEngine engine = getEngineByName(engineName);
  2702. +       if (engine == null)
  2703. +       {
  2704. +           throw new ScriptException("No engine registered with name (" + engineName + ")");
  2705. +       }
  2706. +       return eval(engine, script, context);
  2707. +   }
  2708. +  
  2709. +   public Object eval(ScriptEngine engine, String script) throws ScriptException
  2710. +   {
  2711. +       return eval(engine, script, null);
  2712. +   }
  2713. +  
  2714. +   public void reportScriptFileError(File script, ScriptException e)
  2715. +   {
  2716. +       String dir = script.getParent();
  2717. +       String name = script.getName() + ".error.log";
  2718. +       if (dir != null)
  2719. +       {
  2720. +           final File file = new File(dir + "/" + name);
  2721. +           try (FileOutputStream fos = new FileOutputStream(file))
  2722. +           {
  2723. +               String errorHeader = "Error on: " + file.getCanonicalPath() + Config.EOL + "Line: " + e.getLineNumber() + " - Column: " + e.getColumnNumber() + Config.EOL + Config.EOL;
  2724. +               fos.write(errorHeader.getBytes());
  2725. +               fos.write(e.getMessage().getBytes());
  2726. +               _log.warning("Failed executing script: " + script.getAbsolutePath() + ". See " + file.getName() + " for details.");
  2727. +           }
  2728. +           catch (IOException ioe)
  2729. +           {
  2730. +               _log.log(Level.WARNING, "Failed executing script: " + script.getAbsolutePath() + Config.EOL + e.getMessage() + "Additionally failed when trying to write an error report on script directory. Reason: " + ioe.getMessage(), ioe);
  2731. +           }
  2732. +       }
  2733. +       else
  2734. +       {
  2735. +           _log.log(Level.WARNING, "Failed executing script: " + script.getAbsolutePath() + Config.EOL + e.getMessage() + "Additionally failed when trying to write an error report on script directory.", e);
  2736. +       }
  2737. +   }
  2738. +  
  2739. +   public void registerScriptManager(ScriptManager<?> manager)
  2740. +   {
  2741. +       _scriptManagers.add(manager);
  2742. +   }
  2743. +  
  2744. +   public void removeScriptManager(ScriptManager<?> manager)
  2745. +   {
  2746. +       _scriptManagers.remove(manager);
  2747. +   }
  2748. +  
  2749. +   public List<ScriptManager<?>> getScriptManagers()
  2750. +   {
  2751. +       return _scriptManagers;
  2752. +      
  2753. +   }
  2754. +  
  2755. +   /**
  2756. +    * @param currentLoadingScript The currentLoadingScript to set.
  2757. +    */
  2758. +   protected void setCurrentLoadingScript(File currentLoadingScript)
  2759. +   {
  2760. +       _currentLoadingScript = currentLoadingScript;
  2761. +   }
  2762. +  
  2763. +   /**
  2764. +    * @return Returns the currentLoadingScript.
  2765. +    */
  2766. +   protected File getCurrentLoadingScript()
  2767. +   {
  2768. +       return _currentLoadingScript;
  2769. +   }
  2770. +  
  2771. +   private static class SingletonHolder
  2772. +   {
  2773. +       protected static final L2ScriptEngineManager _instance = new L2ScriptEngineManager();
  2774. +   }
  2775. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement