u_general.txt 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285
  1. function calcLeftShift(bit) { //Deprecated, kaje soll << einbauen
  2. a = 1;
  3. a <<= bit;
  4. return a;
  5. }
  6. function sb.getSpacer() {
  7. return("§0------------------");
  8. }
  9. function isString(anything) {
  10. return string.class(anything) == "String";
  11. }
  12. function isBlock(anything) {
  13. return string.class(anything) == "CraftBlock";
  14. }
  15. function getServerConfig() {
  16. return getScriptVar("server_config");
  17. }
  18. function snuvi.debug(string) {
  19. msg.string("dev", string.concat("[§eDebug§r] ", string));
  20. }
  21. function perm.no(perm, player) {
  22. msg.prefix(player, "§6Perms", string.concat("You have no permission for §c", perm, "§r."));
  23. }
  24. function checkIfEverOnline(player_name) {
  25. if(player.getUuid(player_name) == null) {
  26. return false;
  27. }
  28. return true;
  29. }
  30. function isOnline(player_name) {
  31. if(read.player(player_name) == null) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. function list.copy(list) {
  37. list_new = list.new();
  38. iter = iterator(list);
  39. while(hasNext(iter)) {
  40. list.add(list_new, next(iter));
  41. }
  42. return list_new;
  43. }
  44. function list.transfer(from_list, to_list) {
  45. iter = iterator(from_list);
  46. while(hasNext(iter)) {
  47. list.add(to_list, next(iter));
  48. }
  49. }
  50. function array.sort(my_array, ascending) {
  51. size = array.getSize(my_array);
  52. if(ascending) {
  53. for(i = 0; i < size - 1; i++) {
  54. for(j = i + 1; j < size; j++) {
  55. if(my_array[j] < my_array[i]) {
  56. temp = my_array[i];
  57. my_array[i] = my_array[j];
  58. my_array[j] = temp;
  59. }
  60. }
  61. }
  62. } else {
  63. for(i = 0; i < size - 1; i++) {
  64. for(j = i + 1; j < size; j++) {
  65. if(my_array[j] > my_array[i]) {
  66. temp = my_array[i];
  67. my_array[i] = my_array[j];
  68. my_array[j] = temp;
  69. }
  70. }
  71. }
  72. }
  73. return my_array;
  74. }
  75. function array.contains(array, element) {
  76. for(i = 0; i < array.getSize(array); i++) {
  77. if(array[i] == element) {
  78. return true;
  79. }
  80. }
  81. return false;
  82. }
  83. function array.getIndexOf(array, element) {
  84. for(i = 0; i < array.getSize(array); i++) {
  85. if(array[i] == element) {
  86. return i;
  87. }
  88. }
  89. return -1;
  90. }
  91. function map.sort(map, ascending) {
  92. size = map.getSize(map);
  93. my_array = array.new(size, 2);
  94. //Map in Array umwandeln
  95. i = 0;
  96. iter = map.iterator(map);
  97. while(hasNext(iter)) {
  98. element = next(iter);
  99. key = map.getKey(element);
  100. value = map.getValue(element);
  101. my_array[i, 0] = key;
  102. my_array[i, 1] = value;
  103. i++;
  104. }
  105. //Array sortieren
  106. if(ascending) {
  107. for(i = 0; i < size - 1; i++) {
  108. for(j = i + 1; j < size; j++) {
  109. if(my_array[j, 1] < my_array[i, 1]) {
  110. g = my_array[i, 0];
  111. h = my_array[i, 1];
  112. my_array[i, 0] = my_array[j, 0];
  113. my_array[i, 1] = my_array[j, 1];
  114. my_array[j, 0] = g;
  115. my_array[j, 1] = h;
  116. }
  117. }
  118. }
  119. } else {
  120. for(i = 0; i < size - 1; i++) {
  121. for(j = i + 1; j < size; j++) {
  122. if(my_array[j, 1] > my_array[i, 1]) {
  123. g = my_array[i, 0];
  124. h = my_array[i, 1];
  125. my_array[i, 0] = my_array[j, 0];
  126. my_array[i, 1] = my_array[j, 1];
  127. my_array[j, 0] = g;
  128. my_array[j, 1] = h;
  129. }
  130. }
  131. }
  132. }
  133. return my_array;
  134. }
  135. function getDirection(yaw) {
  136. while(yaw < 0) {
  137. yaw += 360;
  138. }
  139. while(yaw >= 360) {
  140. yaw -= 360;
  141. }
  142. if(yaw > 60 && yaw < 120) {
  143. direction = "west";
  144. } elseif(yaw > 150 && yaw < 210) {
  145. direction = "north";
  146. } elseif(yaw > 240 && yaw < 300) {
  147. direction = "east";
  148. } elseif(yaw > 330 || yaw < 30) {
  149. direction = "south";
  150. } else {
  151. return null;
  152. }
  153. return direction;
  154. }
  155. function getDirectionExact(yaw) {
  156. while(yaw < 0) {
  157. yaw += 360;
  158. }
  159. while(yaw >= 360) {
  160. yaw -= 360;
  161. }
  162. if(yaw > 67.5 && yaw <= 112.5) {
  163. direction = "West";
  164. } elseif(yaw > 112.5 && yaw <= 157.5) {
  165. direction = "North-West";
  166. } elseif(yaw > 157.5 && yaw <= 202.5) {
  167. direction = "North";
  168. } elseif(yaw > 202.5 && yaw <= 247.5) {
  169. direction = "North-East";
  170. } elseif(yaw > 247.5 && yaw <= 292.5) {
  171. direction = "East";
  172. } elseif(yaw > 292.5 && yaw <= 337.5) {
  173. direction = "South-East";
  174. }elseif(yaw > 337.5 || yaw <= 22.5) {
  175. direction = "South";
  176. } elseif(yaw > 22.5 && yaw <= 67.5) {
  177. direction = "South-West";
  178. }else {
  179. return null;
  180. }
  181. return direction;
  182. }
  183. function correctTimeFormat(textnumber) {
  184. if(string.length(textnumber) == 1) {
  185. textnumber = string.concat("0", textnumber);
  186. }
  187. return textnumber;
  188. }
  189. function player.giveSingleItem(player, item) {
  190. amount = inv.getItemAmount(player.getInv(player), item.getType(item));
  191. if(amount == 0) {
  192. player.safeGiveItem(player, item);
  193. }
  194. }
  195. function player.splitGiveItem(player, item, safe_give) {
  196. amount = item.getAmount(item);
  197. max_amount = item.getMaxAmount(item);
  198. max_item = item.clone(item);
  199. item.setAmount(max_item, max_amount);
  200. while(amount > max_amount) {
  201. if(safe_give) {
  202. player.safeGiveItem(player, max_item);
  203. } else {
  204. player.giveItem(player, max_item);
  205. }
  206. amount -= max_amount;
  207. }
  208. item.setAmount(item, amount);
  209. if(safe_give) {
  210. player.safeGiveItem(player, item);
  211. } else {
  212. player.safeGiveItem(player, item);
  213. }
  214. }
  215. function player.safeGiveItem(player, item) {
  216. rest_amount = player.giveItem(player, item);
  217. if(rest_amount > 0) {
  218. item.setAmount(item, rest_amount);
  219. item.drop(item, entity.getLocation(player));
  220. }
  221. }
  222. function block.setIfAir(block, type) {
  223. if(block.isAir(block)) {
  224. block.setMaterial(block, material.get(type));
  225. return true;
  226. }
  227. return false;
  228. }
  229. //Gesamte Spielzeit eines Spielers inkl. der Online-Spielzeit
  230. function playtime.getPlayerTotal(player_or_id) {
  231. player_id = player.getValidId(player_or_id);
  232. minutes = playtime.getPlayerOnlineMinutes(player_id);
  233. stmt = databank.prepare("SELECT SUM(leave_time - join_time) FROM playtime WHERE player_id = ?;");
  234. databank.setInt(stmt, 1, player_id);
  235. result = databank.execute(stmt);
  236. if(databank.next(result)) {
  237. minutes += databank.getLong(result, 1) / 1000 / 60;
  238. }
  239. databank.close(result);
  240. databank.close(stmt);
  241. return minutes;
  242. }
  243. //Spielzeit eines Online-Spielers
  244. function playtime.getPlayerOnlineMinutes(player_id) {
  245. stmt = databank.prepare("SELECT join_time FROM playtime WHERE player_id = ? AND leave_time IS NULL;");
  246. databank.setInt(stmt, 1, player_id);
  247. result = databank.execute(stmt);
  248. if(databank.next(result)) {
  249. minutes = (time.getMillis() - databank.getLong(result, 1)) / 1000 / 60;
  250. } else {
  251. minutes = 0;
  252. }
  253. databank.close(result);
  254. databank.close(stmt);
  255. return minutes;
  256. }
  257. function grow(center_loc, radius) {
  258. crops_tag = block.getTag("minecraft:crops");
  259. for(x = radius * -1; x <= radius; x++) {
  260. for(z = radius * -1; z <= radius; z++) {
  261. for(y = radius * -1; y <= radius; y++) {
  262. length = math.hypot(x, math.hypot(y, z));
  263. if(length <= radius) {
  264. block = block.get(loc.mod(center_loc, x, y, z));
  265. if(block.hasTag(block, crops_tag)) {
  266. if(block.isType(block, "minecraft:beetroots")) {
  267. block.setData(block, read.blockData(string.replace(string.blockData(block.getData(block)), "age=.", "age=3")));
  268. } else {
  269. block.setData(block, read.blockData(string.replace(string.blockData(block.getData(block)), "age=.", "age=7")));
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. function getBlockLocation(location) {
  278. world = loc.getWorld(location);
  279. bx = loc.getBlockX(location);
  280. by = loc.getBlockY(location);
  281. bz = loc.getBlockZ(location);
  282. return loc.new(world, bx, by, bz);
  283. }
  284. function time.getDateString(time) {
  285. calendar = time.new(time);
  286. day = time.getStringFromNumber(time.getDay(calendar));
  287. month = time.getStringFromNumber(time.getMonth(calendar));
  288. year = string.number(time.getYear(calendar));
  289. return string.concat(day, ".", month, ".", year);
  290. }
  291. function time.getCal(year, month, day, hour, minute, second) {
  292. second = time.getStringFromNumber(second);
  293. minute = time.getStringFromNumber(minute);
  294. hour = time.getStringFromNumber(hour);
  295. day = time.getStringFromNumber(day);
  296. month = time.getStringFromNumber(month);
  297. year = string.number(year);
  298. return time.parse("yyyyMMddHHmmss", string.concat(year, month, day, hour, minute, second));
  299. }
  300. function time.getStringFromNumber(number) {
  301. if(number > 9) {
  302. return string.number(number);
  303. }
  304. return string.concat("0", string.number(number));
  305. }
  306. function time.getClockString(time) { //s
  307. return string.concat(string.number(math.roundDown(time / 60)), " min ", string.number(math.round(time % 60)), " s");
  308. }
  309. function time.getString(millis) {
  310. calendar = time.new(millis);
  311. day = time.getStringFromNumber(time.getDay(calendar));
  312. month = time.getStringFromNumber(time.getMonth(calendar));
  313. year = time.getYear(calendar);
  314. hour = time.getStringFromNumber(time.getHour(calendar));
  315. minute = time.getStringFromNumber(time.getMinute(calendar));
  316. timestring = string.concat(day, ".", month, ".", string.number(year), " ", hour, ":", minute);
  317. return timestring;
  318. }
  319. function isFollowingDay(timestamp_1, timestamp_2) {
  320. cal_1 = time.new(timestamp_1);
  321. time.nextDay(cal_1);
  322. mid_1 = time.from(cal_1);
  323. diff = timestamp_2 - mid_1;
  324. return diff > 0 && diff < 86400000;
  325. }
  326. function isSameDay(timestamp_1, timestamp_2) {
  327. cal_1 = time.new(timestamp_1);
  328. cal_2 = time.new(timestamp_2);
  329. time.nextDay(cal_1);
  330. time.nextDay(cal_2);
  331. mid_1 = time.from(cal_1);
  332. mid_2 = time.from(cal_2);
  333. return mid_1 == mid_2;
  334. }
  335. function player.hasMinigame(player) {
  336. id_set = player.getMinigameIds(player);
  337. if(set.getSize(id_set) > 0) {
  338. return true;
  339. }
  340. return false;
  341. }
  342. function player.getMinigameIds(player) {
  343. set = data.get(player, "minigames_set");
  344. if(set == null) {
  345. set = set.new();
  346. data.set(player, "minigames_set", set);
  347. }
  348. return set;
  349. }
  350. function player.resetMinigames(player) {
  351. id_set = player.getMinigameIds(player);
  352. set.clear(id_set);
  353. }
  354. function tjr.getWholeModule(player_or_id) {
  355. return ranking.getPoints("tjrranks", player_or_id);
  356. }
  357. function tjr.getWholeTime(player_or_id) {
  358. return ranking.getSecPoints("tjrranks", player_or_id);
  359. }
  360. function ranking.getPoints(rankingtable, player_or_id) {
  361. player_id = player.getValidId(player_or_id);
  362. stmt = databank.prepare(string.concat("SELECT points FROM ", rankingtable, " WHERE player_id = ?;"));
  363. databank.setInt(stmt, 1, player_id);
  364. result = databank.execute(stmt);
  365. if(databank.next(result)) {
  366. points = databank.getInt(result, 1);
  367. } else {
  368. points = 0;
  369. }
  370. databank.close(result);
  371. databank.close(stmt);
  372. return points;
  373. }
  374. function ranking.getSecPoints(rankingtable, player_or_id) {
  375. player_id = player.getValidId(player_or_id);
  376. stmt = databank.prepare(string.concat("SELECT sec_points FROM ", rankingtable, " WHERE player_id = ?;"));
  377. databank.setInt(stmt, 1, player_id);
  378. result = databank.execute(stmt);
  379. if(databank.next(result)) {
  380. sec_points = databank.getInt(result, 1);
  381. } else {
  382. sec_points = 0;
  383. }
  384. databank.close(result);
  385. databank.close(stmt);
  386. return sec_points;
  387. }
  388. function registerNewbie(id, time) {
  389. stmt = databank.prepare("INSERT INTO newbies (player_id, time) VALUES(?,?);");
  390. databank.setInt(stmt, 1, id);
  391. databank.setLong(stmt, 2, time);
  392. databank.workerExecute(stmt);
  393. }
  394. //--------------------------------------------------
  395. //ModTimer-Utils
  396. //--------------------------------------------------
  397. function modTimer.scriptCallEvent(event, script) {
  398. modTimer(-20);
  399. if(script == null) {
  400. script.callEvent(event);
  401. return;
  402. }
  403. script.callEvent(event, script);
  404. }
  405. function modTimer.entityTeleport(entity, location) {
  406. modTimer(-15);
  407. entity.teleport(entity, location);
  408. }
  409. //--------------------------------------------------
  410. //World-Utils
  411. //--------------------------------------------------
  412. function read.location(string) {
  413. a = string.split(":", string);
  414. w = world.get(a[0]);
  415. x = read.number(a[1]);
  416. y = read.number(a[2]);
  417. z = read.number(a[3]);
  418. if(array.getSize(a) > 4) {
  419. yaw = read.number(a[4]);
  420. pitch = read.number(a[5]);
  421. } else {
  422. yaw = 0;
  423. pitch = 0;
  424. }
  425. return loc.new(w, x, y, z, yaw, pitch);
  426. }
  427. function string.location(location) {
  428. w = world.getName(loc.getWorld(location));
  429. x = loc.getX(location);
  430. y = loc.getY(location);
  431. z = loc.getZ(location);
  432. yaw = loc.getYaw(location);
  433. pitch = loc.getPitch(location);
  434. return string.concat(w, ":", x, ":", y, ":", z, ":", yaw, ":", pitch);
  435. }
  436. function world.getServerSpawn() {
  437. return read.location(config.getString(getServerConfig(), "serverspawn", "world:0:0:0"));
  438. }
  439. function world.getGamesSpawn() {
  440. return read.location(config.getString(getServerConfig(), "gamesspawn", "world:0:0:0"));
  441. }
  442. function world.getCreativeSpawn() {
  443. return read.location(config.getString(getServerConfig(), "creativespawn", "world:0:0:0"));
  444. }
  445. function world.getOverWorld() {
  446. return world.get("world");
  447. }
  448. function world.getTheEnd() {
  449. return world.get("world_the_end");
  450. }
  451. function world.getTheNether() {
  452. return world.get("world_nether");
  453. }
  454. function world.getGames() {
  455. return world.get("games");
  456. }
  457. function world.getCreative() {
  458. return world.get("creative");
  459. }
  460. function world.isCreativeName(world_name) {
  461. return world_name == "creative";
  462. }
  463. function world.isGamesName(world_name) {
  464. return world_name == "games";
  465. }
  466. function world.isOverworld(world_name) {
  467. return world_name == "world";
  468. }
  469. function world.isSurvName(world_name) {
  470. if(world_name == "world") {
  471. return true;
  472. } elseif(world_name == "world_the_end") {
  473. return true;
  474. } elseif(world_name == "world_nether") {
  475. return true;
  476. }
  477. return false;
  478. }
  479. function world.canUsePlots(world) {
  480. world_name = world.getName(world);
  481. if(world.isSurvName(world_name)) {
  482. return true;
  483. }
  484. if(world.isCreativeName(world_name)) {
  485. return true;
  486. }
  487. return false;
  488. }
  489. function world.addTimedStatus(world, index, time, message) {
  490. return;
  491. world_name = world.getName(world);
  492. if(world.isSurvName(world_name)) {
  493. worldlist = world.getPlayers(world.getOverWorld());
  494. for(i = 0; i < list.getSize(worldlist); i++) {
  495. status.addTimed(list.getIndex(worldlist, i), index, time, message);
  496. }
  497. worldlist = world.getPlayers(world.getTheEnd());
  498. for(i = 0; i < list.getSize(worldlist); i++) {
  499. status.addTimed(list.getIndex(worldlist, i), index, time, message);
  500. }
  501. worldlist = world.getPlayers(world.getTheNether());
  502. for(i = 0; i < list.getSize(worldlist); i++) {
  503. status.addTimed(list.getIndex(worldlist, i), index, time, message);
  504. }
  505. return;
  506. }
  507. worldlist = world.getPlayers(world);
  508. for(i = 0; i < list.getSize(worldlist); i++) {
  509. status.addTimed(list.getIndex(worldlist, i), index, time, message);
  510. }
  511. }
  512. function world.giveItem(world, item) {
  513. world_list = woorld.getPlayers(world);
  514. iter = iterator(world_list);
  515. while(hasNext(iter)) {
  516. player.safeGiveItem(next(iter), item);
  517. }
  518. }
  519. //--------------------------------------------------
  520. //Inv-Utils
  521. //--------------------------------------------------
  522. function player.checkForWorldChange(player, location) {
  523. from_world = loc.getWorld(entity.getLocation(player));
  524. to_world = loc.getWorld(location);
  525. //Wenn ignore aktiviert --> kein Wechsel
  526. if(player.hasInvIgnore(player)) {
  527. return false;
  528. }
  529. from_world_name = world.getName(from_world);
  530. to_world_name = world.getName(to_world);
  531. //Wenn in selber Welt --> kein Wechsel
  532. if(from_world == to_world) {
  533. return false;
  534. }
  535. //Wenn beide Welten in derselben Liste sind --> kein Wechsel
  536. if(world.isSurvName(from_world_name) && world.isSurvName(to_world_name)) {
  537. return false;
  538. }
  539. return true;
  540. }
  541. function player.changeInv(player, from_world, to_world) {
  542. from_world_name = world.getName(from_world);
  543. to_world_name = world.getName(to_world);
  544. //Inventory
  545. inv.saveForPlayer(player, player, from_world);
  546. inv.loadFromPlayer(player, player, to_world);
  547. if(perm.has("isTeam", player)) {
  548. if(perm.has("isSupporter", player) && !perm.has("isAdmin", player) && !perm.has("isMod", player)) {
  549. player.changeGamemode(player, to_world_name);
  550. }
  551. } else {
  552. player.changeGamemode(player, to_world_name);
  553. }
  554. if(world.isSurvName(to_world_name)) {
  555. if(player.hasFly(player)) {
  556. scheduler.addFly(5, player, true);
  557. }
  558. }
  559. }
  560. function player.changeGamemode(player, to_world_name) {
  561. if(!player.isSpectator(player)) {
  562. if(to_world_name == "creative") {
  563. if(perm.has("creative.gm1", player)) {
  564. gm = "CREATIVE";
  565. } else {
  566. gm = "ADVENTURE";
  567. scheduler.addFly(5, player, true);
  568. }
  569. } else {
  570. gm = "SURVIVAL";
  571. }
  572. player.setGamemode(player, gm);
  573. duration = data.getTimer(player, "fly");
  574. if(world.isSurvName(to_world_name) && duration > 0) {
  575. scheduler.addFly(5, player, true);
  576. }
  577. }
  578. }
  579. function inv.backup(p_or_id) {
  580. player_id = player.getValidId(p_or_id);
  581. from_file = file.new(string.concat("scripts/configs/inv_data/survival/", player_id, ".snuvic"));
  582. if(!file.exists(from_file)) {
  583. return;
  584. }
  585. dir = file.new(string.concat("scripts/configs/inv_data/backup/", player_id));
  586. if(!file.exists(dir)) {
  587. file.createFolder(dir);
  588. }
  589. f_map = map.new();
  590. file_list = file.getList(dir);
  591. iter = iterator(file_list);
  592. while(hasNext(iter)) {
  593. f = next(iter);
  594. f_name = file.getName(f);
  595. split_array = string.split("_", f_name);
  596. number = read.number(split_array[1]);
  597. a = array.new(2);
  598. a[0] = f;
  599. a[1] = split_array[2];
  600. map.add(f_map, number, a);
  601. }
  602. number_of_backups = 10;
  603. for(i = number_of_backups; i > 0; i--) {
  604. a = map.get(f_map, i);
  605. if(a == null) {
  606. continue;
  607. }
  608. f = a[0];
  609. timestamp = a[1];
  610. if(i == number_of_backups) {
  611. file.delete(f);
  612. continue;
  613. }
  614. new_f_name = string.concat("backup_", string.number(i + 1), "_", timestamp);
  615. file.rename(f, file.new(string.concat("scripts/configs/inv_data/backup/", player_id, "/", new_f_name)));
  616. }
  617. cal = time.new(time.getMillis());
  618. year = string.number(time.getYear(cal));
  619. month = string.number(time.getMonth(cal));
  620. day = string.number(time.getDay(cal));
  621. hour = string.number(time.getHour(cal));
  622. min = string.number(time.getMinute(cal));
  623. sec = string.number(time.getSecond(cal));
  624. new_f = file.new(string.concat(dir, "/backup_", string.number(1), "_", year, "-", month, "-", day, "-", hour, "-", min, "-", sec));
  625. f_list = file.read(from_file);
  626. file.write(new_f, f_list);
  627. }
  628. function inv.saveForPlayer(sec_player, for_player_or_id, world) {
  629. if(isPlayer(for_player_or_id)) {
  630. for_player_or_id = player.getId(for_player_or_id);
  631. }
  632. world_name = world.getName(world);
  633. if(world.isSurvName(world_name)) {
  634. inv.backup(for_player_or_id);
  635. pfad = "scripts/configs/inv_data/survival";
  636. } else {
  637. pfad = string.concat("scripts/configs/inv_data/", world_name);
  638. }
  639. config = config.new(pfad, for_player_or_id);
  640. //Allgemeine Daten
  641. if(for_player_or_id == player.getId(sec_player)) {
  642. config.set(config, "health", living.getHealth(sec_player));
  643. config.set(config, "hunger", player.getHunger(sec_player));
  644. config.set(config, "saturation", player.getSaturation(sec_player));
  645. config.set(config, "xp", player.getExp(sec_player));
  646. config.set(config, "lvl", player.getLevel(sec_player));
  647. }
  648. //Inventare
  649. inv = player.getInv(sec_player);
  650. for(i = 0; i < 36; i++) {
  651. item_string = string.item(inv.getItem(inv, i));
  652. config.set(config, string.concat("slot-", i), item_string);
  653. }
  654. ender_inv = player.getEnderInv(sec_player);
  655. for(i = 0; i < 27; i++) {
  656. item_string = string.item(inv.getItem(ender_inv, i));
  657. config.set(config, string.concat("eslot-", i), item_string);
  658. }
  659. config.set(config, "offhand", string.item(living.getOffHand(sec_player)));
  660. config.set(config, "head", string.item(living.getEquip(sec_player, read.slot("HEAD"))));
  661. config.set(config, "chest", string.item(living.getEquip(sec_player, read.slot("CHEST"))));
  662. config.set(config, "legs", string.item(living.getEquip(sec_player, read.slot("LEGS"))));
  663. config.set(config, "feet", string.item(living.getEquip(sec_player, read.slot("FEET"))));
  664. config.saveAsync(config);
  665. }
  666. function inv.loadFromPlayer(sec_player, from_player_or_id, world) {
  667. if(isPlayer(from_player_or_id)) {
  668. from_player_or_id = player.getId(from_player_or_id);
  669. }
  670. world_name = world.getName(world);
  671. if(world.isSurvName(world_name)) {
  672. pfad = "scripts/configs/inv_data/survival";
  673. } else {
  674. pfad = string.concat("scripts/configs/inv_data/", world_name);
  675. }
  676. config = config.new(pfad, from_player_or_id);
  677. if(config.exists(config)) {
  678. config.load(config);
  679. }
  680. //Allgemeine Daten
  681. if(from_player_or_id == player.getId(sec_player)) {
  682. health = config.getDouble(config, "health", 20);
  683. if(health > 20) {
  684. health = 20;
  685. }
  686. living.setHealth(sec_player, health);
  687. player.setHunger(sec_player, config.getDouble(config, "hunger", 20));
  688. player.setSaturation(sec_player, config.getDouble(config, "saturation", 5));
  689. player.setExp(sec_player, config.getDouble(config, "xp", 0));
  690. player.setLevel(sec_player, config.getDouble(config, "lvl", 0));
  691. }
  692. //Inventare
  693. air_string = item.getAirString();
  694. for(i = 0; i <= 35; i++) {
  695. item_string = config.getString(config, string.concat("slot-", i), air_string);
  696. item = read.item(item_string);
  697. if(item != null) {
  698. inv = player.getInv(sec_player);
  699. inv.setItem(inv, i, item);
  700. }
  701. }
  702. for(i = 0; i < 27; i++) {
  703. item_string = config.getString(config, string.concat("eslot-", i), air_string);
  704. item = read.item(item_string);
  705. if(item != null) {
  706. ender_inv = player.getEnderInv(sec_player);
  707. inv.setItem(ender_inv, i, item);
  708. }
  709. }
  710. living.setEquip(sec_player, read.slot("OFF_HAND"), read.item(config.getString(config, "offhand", air_string)));
  711. living.setEquip(sec_player, read.slot("HEAD"), read.item(config.getString(config, "head", air_string)));
  712. living.setEquip(sec_player, read.slot("CHEST"), read.item(config.getString(config, "chest", air_string)));
  713. living.setEquip(sec_player, read.slot("LEGS"), read.item(config.getString(config, "legs", air_string)));
  714. living.setEquip(sec_player, read.slot("FEET"), read.item(config.getString(config, "feet", air_string)));
  715. }
  716. function inv.getItemAmount(inv, wusi) {
  717. //wusi: item_stack or item_type or item_tag
  718. c = 0;
  719. if(isMaterial(wusi)) {
  720. for(i = 0; i < inv.getSize(inv); i++) {
  721. item = inv.getItem(inv, i);
  722. if(item == null) {
  723. continue;
  724. }
  725. if(item.getType(item) == wusi) {
  726. c += item.getAmount(item);
  727. }
  728. }
  729. } elseif(isItemstack(wusi)) {
  730. for(i = 0; i < inv.getSize(inv); i++) {
  731. item = inv.getItem(inv, i);
  732. if(item == null) {
  733. continue;
  734. }
  735. if(isSameItem(item, wusi)) {
  736. c += item.getAmount(item);
  737. }
  738. }
  739. } else {
  740. for(i = 0; i < inv.getSize(inv); i++) {
  741. item = inv.getItem(inv, i);
  742. if(item == null) {
  743. continue;
  744. }
  745. if(item.hasTag(item, wusi)) {
  746. c += item.getAmount(item);
  747. }
  748. }
  749. }
  750. return c;
  751. }
  752. function inv.addItem(inv, itemstack) {
  753. //adds an item and returns the amount which could not be added
  754. amount_to_add = item.getAmount(itemstack);
  755. for(i = 0; i < inv.getSize(inv); i++) {
  756. item = inv.getItem(inv, i);
  757. if(item == null) {
  758. space = item.getMaxAmount(itemstack);
  759. item = item.clone(itemstack);
  760. if(space <= amount_to_add) {
  761. item.setAmount(item, space);
  762. inv.setItem(inv, i, item);
  763. amount_to_add -= space;
  764. if(amount_to_add == 0) {
  765. break;
  766. }
  767. } else {
  768. item.setAmount(item, amount_to_add);
  769. inv.setItem(inv, i, item);
  770. amount_to_add = 0;
  771. break;
  772. }
  773. }
  774. elseif(isSameItem(item, itemstack)) {
  775. a = item.getAmount(item);
  776. max_a = item.getMaxAmount(item);
  777. space = max_a - a;
  778. if(space > 0) {
  779. if(space <= amount_to_add) {
  780. item.setAmount(item, max_a);
  781. amount_to_add -= space;
  782. if(amount_to_add == 0) {
  783. break;
  784. }
  785. } else {
  786. item.setAmount(item, a + amount_to_add);
  787. amount_to_add = 0;
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. return amount_to_add;
  794. }
  795. function inv.removeItem(inv, itemstack) {
  796. //removes items and returns the amount which could not be removed
  797. amount_to_remove = item.getAmount(itemstack);
  798. for(i = 0; i < inv.getSize(inv); i++) {
  799. item = inv.getItem(inv, i);
  800. if(item == null) {
  801. continue;
  802. }
  803. if(isSameItem(item, itemstack)) {
  804. a = item.getAmount(item);
  805. if(a <= amount_to_remove) {
  806. inv.setItem(inv, i, null);
  807. amount_to_remove -= a;
  808. if(amount_to_remove == 0) {
  809. break;
  810. }
  811. } else {
  812. item.setAmount(item, a - amount_to_remove);
  813. amount_to_remove = 0;
  814. break;
  815. }
  816. }
  817. }
  818. return amount_to_remove;
  819. }
  820. function inv.removeItem2(inv, wusi, amount_to_remove) {
  821. //wusi: item_type or item_tag
  822. //removes items and returns the amount which could not be removed
  823. if(isMaterial(wusi)) {
  824. for(i = 0; i < inv.getSize(inv); i++) {
  825. item = inv.getItem(inv, i);
  826. if(item == null) {
  827. continue;
  828. }
  829. if(item.getType(item) == wusi) {
  830. a = item.getAmount(item);
  831. if(a <= amount_to_remove) {
  832. inv.setItem(inv, i, null);
  833. amount_to_remove -= a;
  834. if(amount_to_remove == 0) {
  835. break;
  836. }
  837. } else {
  838. item.setAmount(item, a - amount_to_remove);
  839. amount_to_remove = 0;
  840. break;
  841. }
  842. }
  843. }
  844. } else {
  845. for(i = 0; i < inv.getSize(inv); i++) {
  846. item = inv.getItem(inv, i);
  847. if(item == null) {
  848. continue;
  849. }
  850. if(item.hasTag(item, wusi)) {
  851. a = item.getAmount(item);
  852. if(a <= amount_to_remove) {
  853. inv.setItem(inv, i, null);
  854. amount_to_remove -= a;
  855. if(amount_to_remove == 0) {
  856. break;
  857. }
  858. } else {
  859. item.setAmount(item, a - amount_to_remove);
  860. amount_to_remove = 0;
  861. break;
  862. }
  863. }
  864. }
  865. }
  866. return c;
  867. }
  868. //--------------------------------------------------
  869. //Text-Utils
  870. //--------------------------------------------------
  871. function text.getClickText(show_text, execute_string) {
  872. return text.click(show_text, execute_string);
  873. }
  874. function text.getHoverText(show_text, execute_string) {
  875. return text.hover(show_text, text.new(execute_string));
  876. }
  877. //--------------------------------------------------
  878. //String-Utils
  879. //--------------------------------------------------
  880. function string.getHoverText(show_string, execute_string) {
  881. return text.hover(text.new(show_string), text.new(execute_string));
  882. }
  883. function string.getClipBoardText(show_string, copy_string) {
  884. return text.clipBoard(text.new(show_string), copy_string);
  885. }
  886. function string.getInterpretedText(string) {
  887. start_index = string.indexOf(string, "%link", 0);
  888. if(start_index == -1) {
  889. return text.new(string);
  890. }
  891. start_text = text.new(string.subString(string, 0, start_index));
  892. show_index = start_index + 6;
  893. link_index = string.indexOf(string, " ", show_index) + 1;
  894. show_string = string.subString(string, show_index, link_index - 1);
  895. end_index = string.indexOf(string, " ", link_index) + 1;
  896. link_string = string.subString(string, link_index, end_index - 1);
  897. rest_string = string.subString(string, end_index, string.length(string));
  898. return text.merge(start_text, string.getLinkText(show_string, link_string), text.new(rest_string));
  899. }
  900. function string.getPrefix(string) {
  901. return string.concat("§r[", string, "§r]");
  902. }
  903. function string.removeFormat(string) {
  904. return string.replace(string, "§.", "");
  905. }
  906. function string.getLinkText(show_string, link_string) {
  907. return text.link(text.new(show_string), link_string);
  908. }
  909. function string.getClickText(show_string, execute_string) {
  910. return text.click(text.new(show_string), execute_string);
  911. }
  912. function string.getSpacer() {
  913. return("§0-------------------------------------------------");
  914. }
  915. function string.concatList(list, connector, from_index, to_index) {
  916. for(i = from_index; i <= to_index; i++) {
  917. element = list.getIndex(list, i);
  918. if(i == from_index) {
  919. string = element;
  920. } else {
  921. string = string.concat(string, connector, element);
  922. }
  923. }
  924. return string;
  925. }
  926. function string.onlyLetters(string) {
  927. a_code = string.charcode("a", 0);
  928. z_code = string.charcode("z", 0);
  929. oe_code = string.charcode("ö", 0);
  930. ae_code = string.charcode("ä", 0);
  931. ue_code = string.charcode("ü", 0);
  932. cap_a_code = string.charcode("A", 0);
  933. cap_z_code = string.charcode("Z", 0);
  934. cap_oe_code = string.charcode("Ö", 0);
  935. cap_ae_code = string.charcode("Ä", 0);
  936. cap_ue_code = string.charcode("Ü", 0);
  937. for(i = 0; i < string.length(string); i++) {
  938. char_code = string.charcode(string, i);
  939. }
  940. if(char_code >= a_code && char_code <= z_code) {
  941. return true;
  942. }
  943. if(char_code >= cap_a_code && char_code <= cap_z_code) {
  944. return true;
  945. }
  946. if(char_code == ae_code || char_code == cap_ae_code) {
  947. return true;
  948. }
  949. if(char_code == oe_code || char_code == cap_oe_code) {
  950. return true;
  951. }
  952. if(char_code == ue_code || char_code == cap_ue_code) {
  953. return true;
  954. }
  955. return false;
  956. }
  957. function string.upperFirstLetter(string) {
  958. length = string.length(string);
  959. first_letter = string.subString(string, 0, 1);
  960. rest = string.substring(string, 1, length);
  961. return string.concat(string.toUpperCase(first_letter), rest);
  962. }
  963. function string.getTextWithLink(string) {
  964. if(string.contains(string, "https://")) {
  965. https_index = string.indexOf(string, "https://", 0);
  966. space_index = string.indexOf(string, " ", https_index);
  967. length = string.length(string);
  968. if(https_index == 0) {
  969. msg_before = "";
  970. } else {
  971. msg_before = string.subString(string, 0, https_index);
  972. }
  973. if(space_index == -1) {
  974. string_link = string.subString(string, https_index, length);
  975. msg_after = "";
  976. } else {
  977. string_link = string.subString(string, https_index, space_index);
  978. msg_after = string.subString(string, space_index, length);
  979. }
  980. text_link = string.getLinkText(string_link, string_link);
  981. return text.merge(text.new(msg_before), text_link, text.new(msg_after));
  982. }
  983. return text.new(string);
  984. }
  985. function string.intelligentSplit(string) {
  986. list = list.new();
  987. from_index = 0;
  988. to_index = 0;
  989. split_after = 25;
  990. split_index = split_after;
  991. whole_length = string.length(string);
  992. while(true) {
  993. to_index = string.indexOf(string, " ", split_index);
  994. if(to_index == -1) {
  995. sub_string = string.subString(string, from_index, string.length(string));
  996. list.add(list, text.new(sub_string));
  997. break;
  998. }
  999. sub_string = string.subString(string, from_index, to_index);
  1000. list.add(list, text.new(sub_string));
  1001. from_index = to_index + 1;
  1002. split_index += split_after;
  1003. }
  1004. return list;
  1005. }
  1006. //--------------------------------------------------
  1007. //Quest-Utils
  1008. //--------------------------------------------------
  1009. function quest.display(player, quest_name, stage, all_stages) {
  1010. sb.add(player, 10, string.concat("§dQuest: ", quest_name, " [", string.number(stage), "/", string.number(all_stages), "]"));
  1011. }
  1012. function quest.removeDisplay(player) {
  1013. sb.remove(player, 10);
  1014. }
  1015. function quest.getIds() {
  1016. return getScriptVar("quest_ids");
  1017. }
  1018. function quest.addPlayer(script, player) {
  1019. quest_ids = quest.getIds();
  1020. map.add(quest_ids, player.getUuid(player), script.getId(script));
  1021. }
  1022. function quest.removePlayer(player) {
  1023. quest_ids = quest.getIds();
  1024. map.remove(quest_ids, player.getUuid(player));
  1025. }
  1026. function player.hasQuest(player) {
  1027. quest_ids = quest.getIds();
  1028. return map.contains(quest_ids, player.getUuid(player));
  1029. }
  1030. function quest.getFromPlayer(player) {
  1031. quest_ids = quest.getIds();
  1032. return map.get(quest_ids, player.getUuid(player));
  1033. }
  1034. function player.isQuester(player, script) {
  1035. if(player == null) {
  1036. return false;
  1037. }
  1038. if(script == null) {
  1039. return false;
  1040. }
  1041. script_id = script.getId(script);
  1042. quest_ids = quest.getIds();
  1043. return map.get(quest_ids, player.getUuid(player)) == script_id;
  1044. }
  1045. function quest.getCounter(player_or_id) {
  1046. config = playerdata.getSurvival(player_or_id);
  1047. return config.getDouble(config, "quests_solved", 0);
  1048. }
  1049. function quest.setCounter(player_or_id, amount) {
  1050. config = playerdata.getSurvival(player_or_id);
  1051. config.set(config, "quests_solved", amount);
  1052. config.saveAsync(config);
  1053. }
  1054. function quest.addCounter(player, amount) {
  1055. config = playerdata.getSurvival(player);
  1056. new_amount = config.getDouble(config, "quests_solved", 0) + amount;
  1057. config.set(config, "quests_solved", new_amount);
  1058. config.saveAsync(config);
  1059. if(new_amount == 500) {
  1060. offerRank(player, "rank.altruist");
  1061. perm.addGroupToPlayer(player.getId(player), 17);
  1062. waitfor(20);
  1063. } elseif(new_amount == 50) {
  1064. offerRank(player, "rank.friend");
  1065. } elseif(new_amount == 15) {
  1066. offerRank(player, "rank.volunteer");
  1067. }
  1068. }
  1069. function quest.finish(script, player) {
  1070. sound = sound.get("ENTITY_EXPERIENCE_ORB_PICKUP");
  1071. category = sound.getCategory("MASTER");
  1072. sound.spawnForPlayer(player, sound, category);
  1073. quest.addCounter(player, 1);
  1074. quest.term(script, player);
  1075. }
  1076. function quest.finishReward(script, player, reward) {
  1077. msg.string(player, string.concat("§dQuest finished. §rReward: ", money.getString(reward)));
  1078. money.addBoost(player, reward);
  1079. sound = sound.get("ENTITY_EXPERIENCE_ORB_PICKUP");
  1080. category = sound.getCategory("MASTER");
  1081. sound.spawnForPlayer(player, sound, category);
  1082. quest.addCounter(player, 1);
  1083. quest.term(script, player);
  1084. }
  1085. function quest.term(script, player) {
  1086. quest.removeDisplay(player);
  1087. quest.removePlayer(player);
  1088. script.term(script);
  1089. }
  1090. function script.isActiveName(script_name) {
  1091. script = script.get(script_name);
  1092. if(script == null) {
  1093. return false;
  1094. }
  1095. return true;
  1096. }
  1097. //--------------------------------------------------
  1098. //Slot-Utils
  1099. //--------------------------------------------------
  1100. function slot.getHand() {
  1101. return read.slot("HAND");
  1102. }
  1103. function slot.getOffHand() {
  1104. return read.slot("OFF_HAND");
  1105. }
  1106. function slot.getHead() {
  1107. return read.slot("HEAD");
  1108. }
  1109. function slot.getChest() {
  1110. return read.slot("CHEST");
  1111. }
  1112. function slot.getLegs() {
  1113. return read.slot("LEGS");
  1114. }
  1115. function slot.getFeet() {
  1116. return read.slot("FEET");
  1117. }
  1118. function slot.isHand(slot) {
  1119. return slot == slot.getHand();
  1120. }
  1121. function slot.isOffHand(slot) {
  1122. return slot == slot.getOffHand();
  1123. }
  1124. function slot.isHead(slot) {
  1125. return slot == slot.getHead();
  1126. }
  1127. function slot.isChest(slot) {
  1128. return slot == slot.getChest();
  1129. }
  1130. function slot.isLegs(slot) {
  1131. return slot == slot.getLegs();
  1132. }
  1133. function slot.isFeet(slot) {
  1134. return slot == slot.getFeet();
  1135. }
  1136. //--------------------------------------------------
  1137. //Player-Data-Utils
  1138. //--------------------------------------------------
  1139. function player.teleport(player, location, setBackPos) {
  1140. player_uuid = player.getUuid(player);
  1141. if(player.isOnAdventure(player)) {
  1142. msg.string(player, "[§5Adventure§r] Teleport blocked. ", string.getClickText("[§5Cancel Adventure?§r]", string.concat("/stopadventure ", player)));
  1143. return false;
  1144. }
  1145. if(player.hasMinigame(player)) {
  1146. return false;
  1147. }
  1148. passengers = entity.getPassengers(player);
  1149. iter = iterator(passengers);
  1150. while(hasNext(iter)) {
  1151. entity.unmount(next(iter));
  1152. }
  1153. if(setBackPos) {
  1154. player.setBackPos(player);
  1155. }
  1156. player_loc = entity.getLocation(player);
  1157. from_world = loc.getWorld(player_loc);
  1158. from_world_name = world.getName(from_world);
  1159. to_world = loc.getWorld(location);
  1160. to_world_name = world.getName(to_world);
  1161. world_change = player.checkForWorldChange(player, location);
  1162. if(world_change) {
  1163. //Inventory
  1164. player.changeInv(player, from_world, to_world);
  1165. living.clearEffects(player);
  1166. //Party
  1167. if(player.isInParty(player) && player.isPartyLeader(player)) {
  1168. party_id = player.getPartyId(player);
  1169. party_list = party.getList(party_id);
  1170. iter = iterator(party_list);
  1171. while(hasNext(iter)) {
  1172. p = player.get(next(iter));
  1173. if(player_uuid == player.getUuid(p)) {
  1174. continue;
  1175. }
  1176. p_name = player.getName(p);
  1177. if(!loc.isSameWorld(player_loc, entity.getLocation(p))) {
  1178. msg.prefix(player, "§5Party", string.concat(p_name, "§c is in another world."));
  1179. continue;
  1180. }
  1181. if(player.hasMinigame(p)) {
  1182. msg.prefix(player, "§5Party", string.concat(p_name, "§c is in a game."));
  1183. continue;
  1184. }
  1185. if(player.hasQuest(p)) {
  1186. msg.prefix(player, "§5Party", string.concat(p_name, "§c is doing a quest."));
  1187. continue;
  1188. }
  1189. if(player.isOnAdventure(p)) {
  1190. msg.prefix(player, "§5Party", string.concat(p_name, "§c is on an adventure."));
  1191. continue;
  1192. }
  1193. if(player.isAfk(p)) {
  1194. msg.prefix(player, "§5Party", string.concat(p_name, "§c is afk."));
  1195. continue;
  1196. }
  1197. player.teleport(p, location, setBackPos);
  1198. }
  1199. }
  1200. //Quests
  1201. script_id = quest.getFromPlayer(player);
  1202. if(script_id != null) {
  1203. script = script.getFromId(script_id);
  1204. if(script != null) {
  1205. setScriptVar("player", player);
  1206. script.callEvent("quest_term", script);
  1207. quest.term(script, player);
  1208. msg.prefix(player, "§dQuest", "Quest termed.");
  1209. }
  1210. }
  1211. }
  1212. modTimer(-50);
  1213. entity.teleport(player, location);
  1214. player.setHeadName(player);
  1215. if(world.isGamesName(to_world_name)) {
  1216. player.clearInventory(player);
  1217. inv = player.getInv(player);
  1218. inv.setItem(inv, 0, item.create("COMPASS", 1, null, null));
  1219. }
  1220. player.setTabName(player);
  1221. return true;
  1222. }
  1223. function playerdata.getSurvival(player_or_id) {
  1224. player_id = player.getValidId(player_or_id);
  1225. if(player_id == null) {
  1226. snuvi.debug(string.concat("invalid player_id ", player_id, " on playerdata.getSurvival"));
  1227. return;
  1228. }
  1229. map = getScriptVar("survival_data");
  1230. config = map.get(map, player_id);
  1231. if(config == null) {
  1232. playerdata.load(player_id, map, "survival_data");
  1233. config = map.get(map, player_id);
  1234. }
  1235. return config;
  1236. }
  1237. function playerdata.getGames(player_or_id) {
  1238. player_id = player.getValidId(player_or_id);
  1239. if(player_id == null) {
  1240. snuvi.debug(string.concat("invalid player_id ", player_id, " on playerdata.getGames"));
  1241. return;
  1242. }
  1243. map = getScriptVar("games_data");
  1244. config = map.get(map, player_id);
  1245. if(config == null) {
  1246. playerdata.load(player_id, map, "games_data");
  1247. config = map.get(map, player_id);
  1248. }
  1249. return config;
  1250. }
  1251. function playerdata.load(player_or_id, map, name) {
  1252. player_id = player.getValidId(player_or_id);
  1253. if(player_id == null) {
  1254. snuvi.debug(string.concat("invalid player_id ", player_id, " on playerdata.load"));
  1255. return;
  1256. }
  1257. config = map.get(map, player_id);
  1258. if(config == null) {
  1259. config = config.new(string.concat("scripts/configs/player_data/", name), player_id);
  1260. if(config.exists(config)) {
  1261. config.load(config);
  1262. }
  1263. map.add(map, player_id, config);
  1264. }
  1265. }
  1266. function player.getValidId(player_or_id) {
  1267. if(isPlayer(player_or_id)) {
  1268. return player.getId(player_or_id);
  1269. }
  1270. if(isDouble(player_or_id)) {
  1271. if(player.getNameFromId(player_or_id) != null) {
  1272. return player_or_id;
  1273. }
  1274. }
  1275. return null;
  1276. }
  1277. function player.getValid(player_or_id) {
  1278. if(isPlayer(player_or_id)) {
  1279. return player_or_id;
  1280. }
  1281. player = player.get(player.getUuidFromId(player_or_id));
  1282. if(player == null) {
  1283. return null;
  1284. }
  1285. return player;
  1286. }
  1287. //--------------------------------------------------
  1288. //Msg-Utils
  1289. //--------------------------------------------------
  1290. function getMessage(text_or_string) {
  1291. if(isString(text_or_string)) {
  1292. message = getMessageFromString(text_or_string);
  1293. } else {
  1294. message = text_or_string;
  1295. }
  1296. return message;
  1297. }
  1298. function getMessageFromString(string) {
  1299. string = string.replace(string, "&", "§");
  1300. message = string.getTextWithLink(string);
  1301. return message;
  1302. }
  1303. function msg.action(receiver, text_or_string) {
  1304. player.action(receiver, getMessage(text_or_string));
  1305. }
  1306. function msg.string(receiver, string) {
  1307. msg(receiver, text.new(string));
  1308. }
  1309. function msg.prefix(receiver, prefix, text_or_string) {
  1310. msg(receiver, text.merge(text.new(string.concat(string.getPrefix(prefix), " ")), getMessage(text_or_string)));
  1311. }
  1312. function msg.online(prefix, text_or_string) {
  1313. msg.prefix("online", prefix, text_or_string);
  1314. }
  1315. function msg.quest(player, speaker, line_now, line_max, string) {
  1316. msg.string(player, string.concat("[§b", string.number(line_now), "§r/§b", string.number(line_max), "§r] §a", speaker, " §r| ", string.concat("§e", string)));
  1317. }
  1318. function msg.chat(player, text_or_string) {
  1319. nickname = player.getNickName(player);
  1320. rank = getRank(player);
  1321. colorcode = string.subString(rank, 0, 2);
  1322. if(player.isLive(player)) {
  1323. live_tag = "§dLive §f| ";
  1324. } else {
  1325. live_tag = "";
  1326. }
  1327. online_list = players.toList();
  1328. iter = iterator(online_list);
  1329. while(hasNext(iter)) {
  1330. p = next(iter);
  1331. if(player.hasMinigame(p) && player.isMuted(p)) {
  1332. continue;
  1333. }
  1334. msg(p, text.merge(text.new("<"), text.new(live_tag), string.getHoverText(string.concat(colorcode, nickname), rank), text.new("§r> §r"), getMessage(text_or_string)));
  1335. }
  1336. }
  1337. function msg.send(from_player, to_name, prefix, string_message, send_mail) {
  1338. p = read.player(to_name);
  1339. if(p == null) {
  1340. if(send_mail) {
  1341. mail.send(player.getName(from_player), to_name, string_message);
  1342. }
  1343. } else {
  1344. msg.prefix(p, prefix, string_message);
  1345. }
  1346. }
  1347. function msg.team(from, text_or_string) {
  1348. if(isString(from)) {
  1349. from_name = from;
  1350. } else {
  1351. from_name = player.getName(from);
  1352. }
  1353. pre_text = text.new(string.concat("§c", from_name, "§r: "));
  1354. message = getMessage(text_or_string);
  1355. online_list = players.toList();
  1356. iter = iterator(online_list);
  1357. while(hasNext(iter)) {
  1358. p = next(iter);
  1359. if(perm.has("isTeam", p)) {
  1360. if(player.isLive(p)) {
  1361. msg.prefix(p, "§4Team", text.merge(pre_text, text.hover(text.new("§7§oHidden"), message)));
  1362. } else {
  1363. msg.prefix(p, "§4Team", text.merge(pre_text, message));
  1364. }
  1365. }
  1366. }
  1367. msg.prefix("SERVER", "§4Team", text.merge(pre_text, message));
  1368. }
  1369. function msg.radius(prefix, text_or_string, location, radius) {
  1370. list = players.near(location, radius);
  1371. iter = iterator(list);
  1372. while(hasNext(iter)) {
  1373. msg.prefix(next(iter), prefix, text_or_string);
  1374. }
  1375. }
  1376. function msg.world(world, text_or_string) {
  1377. if(world == null) {
  1378. return;
  1379. }
  1380. world_list = world.getPlayers(world);
  1381. iter = iterator(world_list);
  1382. while(hasNext(iter)) {
  1383. msg(next(iter), getMessage(text_or_string));
  1384. }
  1385. }
  1386. function msg.survival(text_or_string) {
  1387. msg.world(world.getOverWorld(), text_or_string);
  1388. msg.world(world.getTheEnd(), text_or_string);
  1389. msg.world(world.getTheNether(), text_or_string);
  1390. }
  1391. function msg.creative(text_or_string) {
  1392. msg.world(world.getCreative(), text_or_string);
  1393. }
  1394. function msg.games(text_or_string) {
  1395. msg.world(world.getGames(), text_or_string);
  1396. }
  1397. //--------------------------------------------------
  1398. //Material-Utils
  1399. //--------------------------------------------------
  1400. function isMaterial(anything) {
  1401. return string.class(anything) == "Material";
  1402. }
  1403. function material.getAir() {
  1404. return material.get("AIR");
  1405. }
  1406. function material.equals(type, type_string) {
  1407. return type == material.get(type_string);
  1408. }
  1409. //--------------------------------------------------
  1410. //Item-Utils
  1411. //--------------------------------------------------
  1412. function item.isType(item, type_string) {
  1413. return item.getType(item) == material.get(type_string);
  1414. }
  1415. function isSameItem(itemstack_1, itemstack_2) {
  1416. itemstack_1 = item.clone(itemstack_1);
  1417. itemstack_2 = item.clone(itemstack_2);
  1418. item.setAmount(itemstack_1, 1);
  1419. item.setAmount(itemstack_2, 1);
  1420. return itemstack_1 == itemstack_2;
  1421. }
  1422. function isItemstack(anything) {
  1423. type = string.class(anything);
  1424. return type == "ItemStack" || type == "CraftItemStack";
  1425. }
  1426. function item.isAir(itemstack) {
  1427. if(itemstack == null) {
  1428. return true;
  1429. }
  1430. return item.getType(itemstack) == material.getAir();
  1431. }
  1432. function item.custom.isType(item, custom) {
  1433. return item.getCustom(item) == custom;
  1434. }
  1435. function item.custom.create(type, amount, name, wusi) {
  1436. //wusi: lore_list or lore_string
  1437. item = item.custom.new(item.custom.get(type), amount);
  1438. if(name != null) {
  1439. item.setName(item, text.new(name));
  1440. }
  1441. if(wusi != null) {
  1442. if(isString(wusi)) {
  1443. lore_list = list.new();
  1444. list.add(lore_list, text.new(wusi));
  1445. item.setLore(item, lore_list);
  1446. } else {
  1447. item.setLore(item, wusi);
  1448. }
  1449. }
  1450. return item;
  1451. }
  1452. function item.create(type, amount, name, wusi) {
  1453. //wusi: lore_list or lore_string
  1454. item = item.new(material.get(type), amount);
  1455. if(name != null) {
  1456. item.setName(item, text.new(name));
  1457. }
  1458. if(wusi != null) {
  1459. if(isString(wusi)) {
  1460. lore_list = list.new();
  1461. list.add(lore_list, text.new(wusi));
  1462. item.setLore(item, lore_list);
  1463. } else {
  1464. item.setLore(item, wusi);
  1465. }
  1466. }
  1467. return item;
  1468. }
  1469. function item.createLore(string) {
  1470. lore = list.new();
  1471. list.add(lore, text.new(string));
  1472. return lore;
  1473. }
  1474. function item.addLore(item, string) {
  1475. lore = item.getLore(item);
  1476. if(lore == null) {
  1477. lore = list.new();
  1478. }
  1479. list.add(lore, text.new(string));
  1480. item.setLore(item, lore);
  1481. }
  1482. function item.getAir() {
  1483. return item.new(material.get("AIR"));
  1484. }
  1485. function item.getAirString() {
  1486. return "{id:\"minecraft:air\",Count:1b}";
  1487. }
  1488. function item.isAmber(item) {
  1489. return item.custom.get("AMBER") == item.getCustom(item);
  1490. }
  1491. function item.isSapphire(item) {
  1492. return item.custom.get("SAPPHIRE") == item.getCustom(item);
  1493. }
  1494. function item.isRuby(item) {
  1495. return item.custom.get("RUBY") == item.getCustom(item);
  1496. }
  1497. function item.getAmber() {
  1498. return item.custom.new(item.custom.get("AMBER"));
  1499. }
  1500. function item.getSapphire() {
  1501. return item.custom.new(item.custom.get("SAPPHIRE"));
  1502. }
  1503. function item.getRuby() {
  1504. return item.custom.new(item.custom.get("RUBY"));
  1505. }
  1506. function item.isDigit(item) {
  1507. c = item.getCustom(item);
  1508. set = getScriptVar("digits");
  1509. return set.contains(set, c);
  1510. }
  1511. function drops.containsMaterial(drops_list, material) {
  1512. for(i = 0; i < list.getSize(drops_list); i++) {
  1513. item_entity = list.getIndex(drops_list, i);
  1514. item = item.entity.get(item_entity);
  1515. item_type = item.getType(item);
  1516. if(item_type == material) {
  1517. return true;
  1518. }
  1519. }
  1520. return false;
  1521. }
  1522. //--------------------------------------------------
  1523. //Entity-Utils
  1524. //--------------------------------------------------
  1525. function entity.isArmorstand(entity) {
  1526. if(entity == null) {
  1527. return false;
  1528. }
  1529. return entity.getType(entity) == "armor_stand";
  1530. }
  1531. //--------------------------------------------------
  1532. //Player-Utils
  1533. //--------------------------------------------------
  1534. function player.hasBypass(player) {
  1535. return perm.has("plot.bypass", player);
  1536. }
  1537. function player.clearInventory(player) {
  1538. inv = player.getInv(player);
  1539. inv.clear(inv);
  1540. }
  1541. function player.toggleFly(player) {
  1542. new_state = !player.hasFly(player);
  1543. player.setFly(player, new_state);
  1544. return new_state;
  1545. }
  1546. function player.canTeleport(player) {
  1547. if(player.hasMinigame(player)) {
  1548. return false;
  1549. }
  1550. if(player.isOnAdventure(player)) {
  1551. return false;
  1552. }
  1553. return true;
  1554. }
  1555. function player.hasClearInventory(player) {
  1556. air = item.getAir();
  1557. inv = player.getInv(player);
  1558. for(slot = 0; slot < 36; slot++) {
  1559. if(item.getType(inv.getItem(inv, slot)) != air) {
  1560. return false;
  1561. }
  1562. }
  1563. if(item.getType(living.getEquip(player, read.slot("HEAD"))) != air) {
  1564. return false;
  1565. }
  1566. if(item.getType(living.getEquip(player, read.slot("CHEST"))) != air) {
  1567. return false;
  1568. }
  1569. if(item.getType(living.getEquip(player, read.slot("LEGS"))) != air) {
  1570. return false;
  1571. }
  1572. if(item.getType(living.getEquip(player, read.slot("FEET"))) != air) {
  1573. return false;
  1574. }
  1575. if(item.getType(living.getOffHand(player)) != air) {
  1576. return false;
  1577. }
  1578. return true;
  1579. }
  1580. function player.getJoinMessage(player_or_id) {
  1581. config = playerdata.getSurvival(player_or_id);
  1582. temp = config.getString(config, "message.join", "null");
  1583. if(temp == "null") {
  1584. return null;
  1585. }
  1586. return temp;
  1587. }
  1588. function player.setJoinMessage(player_or_id, message) {
  1589. config = playerdata.getSurvival(player_or_id);
  1590. config.set(config, "message.join", message);
  1591. config.saveAsync(config);
  1592. }
  1593. function player.getLeaveMessage(player_or_id) {
  1594. config = playerdata.getSurvival(player_or_id);
  1595. temp = config.getString(config, "message.leave", "null");
  1596. if(temp == "null") {
  1597. return null;
  1598. }
  1599. return temp;
  1600. }
  1601. function player.setLeaveMessage(player_or_id, message) {
  1602. config = playerdata.getSurvival(player_or_id);
  1603. config.set(config, "message.leave", message);
  1604. config.saveAsync(config);
  1605. }
  1606. function player.getDeathMessage(player_or_id) {
  1607. config = playerdata.getSurvival(player_or_id);
  1608. temp = config.getString(config, "message.death", "null");
  1609. if(temp == "null") {
  1610. return null;
  1611. }
  1612. return temp;
  1613. }
  1614. function player.setDeathMessage(player_or_id, message) {
  1615. config = playerdata.getSurvival(player_or_id);
  1616. config.set(config, "message.death", message);
  1617. config.saveAsync(config);
  1618. }
  1619. function player.usesCustomMessage(player_or_id) {
  1620. config = playerdata.getSurvival(player_or_id);
  1621. return config.getBool(config, "message.use", true);
  1622. }
  1623. function player.activateCustomMessage(player_or_id, boolean) {
  1624. config = playerdata.getSurvival(player_or_id);
  1625. config.set(config, "message.use", boolean);
  1626. config.saveAsync(config);
  1627. }
  1628. function player.setLoggedIp(player_or_id, ip) {
  1629. config = playerdata.getSurvival(player_or_id);
  1630. config.set(config, "ip", ip);
  1631. config.saveAsync(config);
  1632. }
  1633. function player.getLoggedIp(player_or_id) {
  1634. config = playerdata.getSurvival(player_or_id);
  1635. return config.getString(config, "ip", "-");
  1636. }
  1637. function player.resetDeathLoc(player) {
  1638. config = playerdata.getSurvival(player);
  1639. config.set(config, "deathloc", "null");
  1640. config.saveAsync(config);
  1641. }
  1642. function player.setDeathLoc(player) {
  1643. config = playerdata.getSurvival(player);
  1644. config.set(config, "deathloc", string.location(entity.getLocation(player)));
  1645. config.saveAsync(config);
  1646. }
  1647. function player.getDeathLoc(player) {
  1648. config = playerdata.getSurvival(player);
  1649. loc = config.getString(config, "deathloc", "null");
  1650. if(loc == "null") {
  1651. return null;
  1652. }
  1653. return read.location(loc);
  1654. }
  1655. function player.isLive(player) {
  1656. player_uuid = player.getUuid(player);
  1657. live_set = getScriptVar("live_set");
  1658. return set.contains(live_set, player_uuid);
  1659. }
  1660. function player.setLive(player, boolean) {
  1661. player_uuid = player.getUuid(player);
  1662. live_set = getScriptVar("live_set");
  1663. if(boolean) {
  1664. set.add(live_set, player_uuid);
  1665. } else {
  1666. set.remove(live_set, player_uuid);
  1667. }
  1668. }
  1669. function player.getFullName(player) {
  1670. nickname = player.getNickname(player);
  1671. if(player.isNicked(player)) {
  1672. full_name = string.concat("[§3User§r] ", nickname);
  1673. } else {
  1674. full_name = string.concat("[", getRank(player), "§r] ", nickname);
  1675. }
  1676. return full_name;
  1677. }
  1678. function player.setTabName(player) {
  1679. nickname = player.getNickname(player);
  1680. rank = getRank(player);
  1681. if(string.startswith(rank, "§", 0)) {
  1682. colorcode = string.subString(rank, 0, 2);
  1683. tab_name = string.concat(colorcode, nickname);
  1684. } else {
  1685. tab_name = nickname;
  1686. }
  1687. if(player.isAfk(player)) {
  1688. tab_name = string.concat(tab_name, " §5§o[Afk]");
  1689. }
  1690. if(player.isLive(player)) {
  1691. tab_name = string.concat(tab_name, " §f[§dLive§f]");
  1692. }
  1693. player.setDisplayName(player, text.new(tab_name));
  1694. }
  1695. function player.removeItemNbt(player, itemstack) { //Might be deprecated
  1696. //Make a copy
  1697. item_type = item.getType(itemstack);
  1698. amount = item.getAmount(itemstack);
  1699. my_item = item.new(item_type, amount);
  1700. //Loop the inventory
  1701. inv = player.getInv(player);
  1702. for(slot = 0; slot < inv.getSize(inv); slot++) {
  1703. item = inv.getItem(inv, slot);
  1704. if(item == null) {
  1705. continue;
  1706. }
  1707. if(item.getType(item) == item_type) {
  1708. diff = amount - item.getAmount(item);
  1709. if(diff > 0) {
  1710. amount = diff;
  1711. item.setAmount(item, 0);
  1712. } else {
  1713. item.setAmount(item, math.abs(diff));
  1714. air = item.getAir();
  1715. item.setAmount(air, 0);
  1716. return air;
  1717. }
  1718. }
  1719. }
  1720. item.setAmount(my_item, amount);
  1721. return my_item;
  1722. }
  1723. function player.removeItemTag(player, tag, amount) {
  1724. air = item.getAir();
  1725. inv = player.getInv(player);
  1726. for(slot = 0; slot < inv.getSize(inv); slot++) {
  1727. item = inv.getItem(inv, slot);
  1728. if(item == null) {
  1729. continue;
  1730. }
  1731. if(item.hasTag(item, tag)) {
  1732. diff = amount - item.getAmount(item);
  1733. if(diff > 0) {
  1734. item.setAmount(item, 0);
  1735. amount = diff;
  1736. } else {
  1737. item.setAmount(item, math.abs(diff));
  1738. amount = 0;
  1739. break;
  1740. }
  1741. }
  1742. }
  1743. item.setAmount(air, amount);
  1744. return air;
  1745. }
  1746. function player.setSpeed(player, speed) {
  1747. speed = 4/5/9 * speed + 1/9;
  1748. player.setWalkSpeed(player, speed);
  1749. player.setFlySpeed(player, speed / 2);
  1750. }
  1751. function player.hasBigPlotCreated(player_or_id) {
  1752. config = playerdata.getSurvival(player_or_id);
  1753. return config.getBool(config, "plot.big", false);
  1754. }
  1755. function player.setBigPlotCreated(player_or_id, boolean) {
  1756. config = playerdata.getSurvival(player_or_id);
  1757. config.set(config, "plot.big", boolean);
  1758. config.saveAsync(config);
  1759. }
  1760. function player.hasPlotRaised(player_or_id) {
  1761. config = playerdata.getSurvival(player_or_id);
  1762. return config.getBool(config, "plot.raised", false);
  1763. }
  1764. function player.setPlotRaised(player_or_id, boolean) {
  1765. config = playerdata.getSurvival(player_or_id);
  1766. config.set(config, "plot.raised", boolean);
  1767. config.saveAsync(config);
  1768. }
  1769. function player.usedHisFreePlot(player_or_id) {
  1770. config = playerdata.getSurvival(player_or_id);
  1771. return config.getBool(config, "plot.usedFree", false);
  1772. }
  1773. function player.setUsedFreePlot(player_or_id, boolean) {
  1774. config = playerdata.getSurvival(player_or_id);
  1775. config.set(config, "plot.usedFree", boolean);
  1776. config.saveAsync(config);
  1777. }
  1778. function player.activateSitting(player_or_id, boolean) {
  1779. config = playerdata.getSurvival(player_or_id);
  1780. config.set(config, "sitting", boolean);
  1781. config.saveAsync(config);
  1782. }
  1783. function player.hasSittingActivated(player_or_id) {
  1784. config = playerdata.getSurvival(player_or_id);
  1785. return config.getBool(config, "sitting", true);
  1786. }
  1787. function player.acceptTpaRequests(player_or_id, boolean) {
  1788. config = playerdata.getSurvival(player_or_id);
  1789. config.set(config, "tptoggle", boolean);
  1790. config.saveAsync(config);
  1791. }
  1792. function player.doesAcceptTpaRequests(player_or_id) {
  1793. config = playerdata.getSurvival(player_or_id);
  1794. return config.getBool(config, "tptoggle", true);
  1795. }
  1796. function player.getBackPos(player) {
  1797. config = playerdata.getSurvival(player);
  1798. location = config.getString(config, "backpos", "null");
  1799. if(location == "null") {
  1800. return null;
  1801. }
  1802. return read.location(location);
  1803. }
  1804. function player.setBackPos(player) {
  1805. config = playerdata.getSurvival(player);
  1806. config.set(config, "backpos", string.location(entity.getLocation(player)));
  1807. config.saveAsync(config);
  1808. }
  1809. function player.setBackPosLoc(player, location) {
  1810. config = playerdata.getSurvival(player);
  1811. config.set(config, "backpos", string.location(location));
  1812. config.saveAsync(config);
  1813. }
  1814. function player.clearBackPos(player) {
  1815. config = playerdata.getSurvival(player);
  1816. config.set(config, "backpos", "null");
  1817. config.saveAsync(config);
  1818. }
  1819. function entity.getFromDamageSource(damage_source) {
  1820. entity = damage.getImmediateSource(damage_source);
  1821. if(entity == null) {
  1822. return damage.getTrueSource(damage_source);
  1823. }
  1824. return entity;
  1825. }
  1826. function player.getFromDamageSource(damage_source) {
  1827. entity = damage.getImmediateSource(damage_source);
  1828. if(isPlayer(entity)) {
  1829. return entity;
  1830. }
  1831. entity = damage.getTrueSource(damage_source);
  1832. if(isPlayer(entity)) {
  1833. return entity;
  1834. }
  1835. return null;
  1836. }
  1837. function player.getJoins(player_or_id) {
  1838. if(isPlayer(player_or_id)) {
  1839. player_id = player.getId(player_or_id);
  1840. } else {
  1841. player_id = player_or_id;
  1842. }
  1843. stmt = databank.prepare("SELECT COUNT(join_time) FROM playtime WHERE player_id = ?;");
  1844. databank.setInt(stmt, 1, player_id);
  1845. result = databank.execute(stmt);
  1846. if(databank.next(result)) {
  1847. amount = databank.getLong(result, 1);
  1848. }
  1849. databank.close(result);
  1850. databank.close(stmt);
  1851. return amount;
  1852. }
  1853. function player.getTotalPlaytime(player_or_id) {
  1854. if(isPlayer(player_or_id)) {
  1855. player_id = player.getId(player_or_id);
  1856. } else {
  1857. player_id = player_or_id;
  1858. }
  1859. //Online seit
  1860. since_minutes = 0;
  1861. if(isOnline(player.getNameFromId(player_id))) {
  1862. stmt = databank.prepare("SELECT join_time FROM playtime WHERE player_id = ? AND leave_time IS NULL;");
  1863. databank.setInt(stmt, 1, player_id);
  1864. result = databank.execute(stmt);
  1865. while(databank.next(result)) {
  1866. since_minutes = (time.getMillis() - databank.getLong(result, 1)) / 1000 / 60;
  1867. }
  1868. databank.close(result);
  1869. databank.close(stmt);
  1870. }
  1871. //Spielzeit gesamt
  1872. stmt2 = databank.prepare("SELECT SUM(leave_time - join_time) FROM playtime WHERE player_id = ?;");
  1873. databank.setInt(stmt2, 1, player_id);
  1874. result = databank.execute(stmt2);
  1875. while(databank.next(result)) {
  1876. minutes = databank.getLong(result, 1) / 1000 / 60 + since_minutes;
  1877. }
  1878. databank.close(result);
  1879. databank.close(stmt2);
  1880. return minutes;
  1881. }
  1882. function player.hasInvIgnore(player_or_id) {
  1883. config = playerdata.getSurvival(player_or_id);
  1884. return config.getBool(config, "invignore", false);
  1885. }
  1886. function player.invIgnore(player_or_id, boolean) {
  1887. config = playerdata.getSurvival(player_or_id);
  1888. config.set(config, "invignore", boolean);
  1889. config.saveAsync(config);
  1890. }
  1891. function player.getClanId(player_or_id) {
  1892. config = playerdata.getSurvival(player_or_id);
  1893. return config.getDouble(config, "clan_id", -1);
  1894. }
  1895. function player.setClanId(player_or_id, clan_id) {
  1896. config = playerdata.getSurvival(player_or_id);
  1897. config.set(config, "clan_id", clan_id);
  1898. config.saveAsync(config);
  1899. }
  1900. function player.getClanRole(player_or_id) {
  1901. config = playerdata.getSurvival(player_or_id);
  1902. temp = config.getString(config, "clan_role", "null");
  1903. if(temp == "null") {
  1904. return null;
  1905. }
  1906. return temp;
  1907. }
  1908. function player.setClanRole(player_or_id, clan_id) {
  1909. config = playerdata.getSurvival(player_or_id);
  1910. config.set(config, "clan_role", clan_id);
  1911. config.saveAsync(config);
  1912. }
  1913. function player.isInClan(player_or_id) {
  1914. return player.getClanId(player_or_id) >= 0;
  1915. }
  1916. function player.isClanLeader(player_or_id) {
  1917. return player.getClanRole(player_or_id) == "leader";
  1918. }
  1919. function player.isClanMod(player_or_id) {
  1920. return player.getClanRole(player_or_id) == "mod";
  1921. }
  1922. function player.isClanMember(player_or_id) {
  1923. return player.getClanRole(player_or_id) == "member";
  1924. }
  1925. function player.isSameClan(player_or_id_1, player_or_id_2) {
  1926. id_1 = player.getClanId(player_or_id_1);
  1927. id_2 = player.getClanId(player_or_id_2);
  1928. if(id_1 < 0 || id_2 < 0) {
  1929. return false;
  1930. }
  1931. return id_1 == id_2;
  1932. }
  1933. function player.setHeadName(player) {
  1934. nickname = player.getNickname(player);
  1935. clan_string = "";
  1936. if(player.isInClan(player)) {
  1937. clan_id = player.getClanId(player);
  1938. clan_string = string.concat(" [§6", clan.getTag(clan_id), "§r]");
  1939. }
  1940. live_string = "";
  1941. if(player.isLive(player)) {
  1942. live_string = "§f[§dLive§f] ";
  1943. }
  1944. entity.setName(player, text.new(string.concat(live_string, nickname, clan_string)));
  1945. }
  1946. function player.setAIChallengeAmounts(player_or_id, amount) {
  1947. config = playerdata.getSurvival(player_or_id);
  1948. config.set(config, "cha.ai.amount", amount);
  1949. config.saveAsync(config);
  1950. }
  1951. function player.getAIhallengeAmounts(player_or_id) {
  1952. config = playerdata.getSurvival(player_or_id);
  1953. return config.getDouble(config, "cha.ai.amount", 0);
  1954. }
  1955. function player.setAEChallengeAmounts(player_or_id, amount) {
  1956. config = playerdata.getSurvival(player_or_id);
  1957. config.set(config, "cha.ae.amount", amount);
  1958. config.saveAsync(config);
  1959. }
  1960. function player.getAEChallengeAmounts(player_or_id) {
  1961. config = playerdata.getSurvival(player_or_id);
  1962. return config.getDouble(config, "cha.ae.amount", 0);
  1963. }
  1964. function player.setADTChallengeAmounts(player_or_id, amount) {
  1965. config = playerdata.getSurvival(player_or_id);
  1966. config.set(config, "cha.dtype.amount", amount);
  1967. config.saveAsync(config);
  1968. }
  1969. function player.getADTChallengeAmounts(player_or_id) {
  1970. config = playerdata.getSurvival(player_or_id);
  1971. return config.getDouble(config, "cha.dtype.amount", 0);
  1972. }
  1973. function player.setAdventureAmounts(player_or_id, amount) {
  1974. config = playerdata.getSurvival(player_or_id);
  1975. config.set(config, "adventures", amount);
  1976. config.saveAsync(config);
  1977. }
  1978. function player.getAdventureAmounts(player_or_id) {
  1979. config = playerdata.getSurvival(player_or_id);
  1980. return config.getDouble(config, "adventures", 0);
  1981. }
  1982. function player.isOnAdventure(player_or_id) {
  1983. config = playerdata.getSurvival(player_or_id);
  1984. return config.getBool(config, "onadventure", false);
  1985. }
  1986. function player.setAdventure(player_or_id, boolean) {
  1987. config = playerdata.getSurvival(player_or_id);
  1988. config.set(config, "onadventure", boolean);
  1989. config.saveAsync(config);
  1990. }
  1991. function player.getAdventureStart(player_or_id) {
  1992. config = playerdata.getSurvival(player_or_id);
  1993. location = config.getString(config, "adventureloc", "null");
  1994. if(location == "null") {
  1995. return world.getServerSpawn();
  1996. }
  1997. return read.location(location);
  1998. }
  1999. function player.setAdventureStart(player_or_id, location) {
  2000. config = playerdata.getSurvival(player_or_id);
  2001. config.set(config, "adventureloc", string.location(location));
  2002. config.saveAsync(config);
  2003. }
  2004. function player.isMuted(player_or_id) {
  2005. config = playerdata.getSurvival(player_or_id);
  2006. return config.getBool(config, "muted", false);
  2007. }
  2008. function player.mute(player_or_id, boolean) {
  2009. config = playerdata.getSurvival(player_or_id);
  2010. config.set(config, "muted", boolean);
  2011. config.saveAsync(config);
  2012. }
  2013. function player.isGameMuted(player_or_id) {
  2014. config = playerdata.getGames(player_or_id);
  2015. return config.getBool(config, "game_muted", false);
  2016. }
  2017. function player.gameMute(player_or_id, boolean) {
  2018. config = playerdata.getGames(player_or_id);
  2019. config.set(config, "game_muted", boolean);
  2020. config.saveAsync(config);
  2021. }
  2022. function player.getSilentJoin(player_or_id) {
  2023. config = playerdata.getSurvival(player_or_id);
  2024. return config.getBool(config, "silentjoin", false);
  2025. }
  2026. function player.setSilentJoin(player_or_id, boolean) {
  2027. config = playerdata.getSurvival(player_or_id);
  2028. config.set(config, "silentjoin", boolean);
  2029. config.saveAsync(config);
  2030. }
  2031. function player.getAutoCloseDoor(player_or_id) {
  2032. config = playerdata.getSurvival(player_or_id);
  2033. return config.getBool(config, "door_auto_close", true);
  2034. }
  2035. function player.setAutoCloseDoor(player_or_id, boolean) {
  2036. config = playerdata.getSurvival(player_or_id);
  2037. config.set(config, "door_auto_close", boolean);
  2038. config.saveAsync(config);
  2039. }
  2040. function player.getNoPetDamage(player_or_id) {
  2041. config = playerdata.getSurvival(player_or_id);
  2042. return config.getBool(config, "pet_damage", true);
  2043. }
  2044. function player.setNoPetDamage(player_or_id, boolean) {
  2045. config = playerdata.getSurvival(player_or_id);
  2046. config.set(config, "pet_damage", boolean);
  2047. config.saveAsync(config);
  2048. }
  2049. function player.getTipLoop(player_or_id) {
  2050. config = playerdata.getSurvival(player_or_id);
  2051. return config.getBool(config, "tip_loop", true);
  2052. }
  2053. function player.setTipLoop(player_or_id, boolean) {
  2054. config = playerdata.getSurvival(player_or_id);
  2055. config.set(config, "tip_loop", boolean);
  2056. config.saveAsync(config);
  2057. }
  2058. function player.setVoteStreak(player_or_id, millis) {
  2059. config = playerdata.getSurvival(player_or_id);
  2060. config.set(config, "votestreak", millis);
  2061. config.saveAsync(config);
  2062. }
  2063. function player.getVoteStreak(player_or_id) {
  2064. config = playerdata.getSurvival(player_or_id);
  2065. return config.getDouble(config, "votestreak", 0);
  2066. }
  2067. function player.setLastVoteTime(player_or_id, millis) {
  2068. config = playerdata.getSurvival(player_or_id);
  2069. config.set(config, "lastvotetime", millis);
  2070. config.saveAsync(config);
  2071. }
  2072. function player.getLastVoteTime(player_or_id) {
  2073. config = playerdata.getSurvival(player_or_id);
  2074. return config.getDouble(config, "lastvotetime", 0);
  2075. }
  2076. function player.setVotePoints(player_or_id, amount) {
  2077. config = playerdata.getSurvival(player_or_id);
  2078. config.set(config, "votepoints", amount);
  2079. config.saveAsync(config);
  2080. }
  2081. function player.getVotePoints(player_or_id) {
  2082. config = playerdata.getSurvival(player_or_id);
  2083. return config.getDouble(config, "votepoints", 0);
  2084. }
  2085. function player.addVotePoints(player_or_id, amount) {
  2086. config = playerdata.getSurvival(player_or_id);
  2087. points = config.getDouble(config, "votepoints", 0) + amount;
  2088. config.set(config, "votepoints", points);
  2089. config.saveAsync(config);
  2090. }
  2091. function player.isFirstJoin(player_or_id) {
  2092. config = playerdata.getSurvival(player_or_id);
  2093. return config.getBool(config, "firstjoin", true);
  2094. }
  2095. function player.setFirstJoin(player_or_id, boolean) {
  2096. config = playerdata.getSurvival(player_or_id);
  2097. config.set(config, "firstjoin", !boolean);
  2098. config.saveAsync(config);
  2099. }
  2100. function player.getShowcoords(player_or_id) {
  2101. config = playerdata.getSurvival(player_or_id);
  2102. return config.getBool(config, "showcoords", true);
  2103. }
  2104. function player.setShowcoords(player_or_id, bool) {
  2105. config = playerdata.getSurvival(player_or_id);
  2106. config.set(config, "showcoords", bool);
  2107. config.saveAsync(config);
  2108. }
  2109. function player.getFirstJoin(player_or_id) {
  2110. if(isPlayer(player_or_id)) {
  2111. player_id = player.getId(player_or_id);
  2112. } else {
  2113. player_id = player_or_id;
  2114. }
  2115. stmt = databank.prepare("SELECT MIN(join_time) FROM playtime WHERE player_id = ?;");
  2116. databank.setInt(stmt, 1, player_id);
  2117. result = databank.execute(stmt);
  2118. if(databank.next(result)) {
  2119. time = databank.getLong(result, 1);
  2120. }
  2121. databank.close(result);
  2122. databank.close(stmt);
  2123. return time;
  2124. }
  2125. function player.getLastJoin(player_or_id) {
  2126. if(isPlayer(player_or_id)) {
  2127. player_id = player.getId(player_or_id);
  2128. } else {
  2129. player_id = player_or_id;
  2130. }
  2131. stmt = databank.prepare("SELECT MAX(join_time) FROM playtime WHERE player_id = ?;");
  2132. databank.setInt(stmt, 1, player_id);
  2133. result = databank.execute(stmt);
  2134. if(databank.next(result)) {
  2135. time = databank.getLong(result, 1);
  2136. }
  2137. databank.close(result);
  2138. databank.close(stmt);
  2139. return time;
  2140. }
  2141. function player.blockCommands(player) {
  2142. list = getScriptVar("block_commands_list");
  2143. list.add(list, player.getUuid(player));
  2144. }
  2145. function player.unblockCommands(player) {
  2146. list = getScriptVar("block_commands_list");
  2147. player_uuid = player.getUuid(player);
  2148. while(list.contains(list, player_uuid)) {
  2149. list.remove(list, player_uuid);
  2150. }
  2151. }
  2152. function player.isCommandBlocked(player) {
  2153. list = getScriptVar("block_commands_list");
  2154. return list.contains(list, player.getUuid(player));
  2155. }
  2156. function player.checkHandForType(player, item_type) {
  2157. return item.getType(living.getHand(player)) == item_type;
  2158. }
  2159. function player.checkHandsForItem(player, item_or_type) {
  2160. if(string.class(item_or_type) != "String") {
  2161. item_or_type = item.getType(item_or_type);
  2162. }
  2163. hand = living.getHand(player);
  2164. if(item.getType(hand) == item_or_type) {
  2165. return true;
  2166. }
  2167. offhand = living.getOffHand(player);
  2168. return item.getType(offhand) == item_or_type;
  2169. }
  2170. function player.checkHandsForTag(player, tag) {
  2171. hand = living.getHand(player);
  2172. if(item.hasTag(hand, tag)) {
  2173. return true;
  2174. }
  2175. offhand = living.getOffHand(player);
  2176. return item.hasTag(offhand, tag);
  2177. }
  2178. function player.hideOnline(player) {
  2179. list = players.toList();
  2180. iter = iterator(list);
  2181. while(hasNext(iter)) {
  2182. p = next(iter);
  2183. player.hide(p, player);
  2184. }
  2185. }
  2186. function player.showOnline(player) {
  2187. list = players.toList();
  2188. iter = iterator(list);
  2189. while(hasNext(iter)) {
  2190. p = next(iter);
  2191. player.show(p, player);
  2192. }
  2193. }
  2194. //--------------------------------------------------
  2195. //Chestshop-Utils
  2196. //--------------------------------------------------
  2197. function shop.getOwner(sign_block) {
  2198. owner_id = read.number(sign.getString(sign_block, 3));
  2199. if(owner_id == null) {
  2200. return null;
  2201. }
  2202. return owner_id;
  2203. }
  2204. function shop.isOwner(player, sign_block) {
  2205. if(player.hasBypass(player)) {
  2206. return true;
  2207. }
  2208. owner_id = shop.getOwner(sign_block);
  2209. if(owner_id == null) {
  2210. return false;
  2211. }
  2212. owner_name = player.getNameFromId(owner_id);
  2213. if(owner_name == null) {
  2214. return false;
  2215. }
  2216. return owner_id == player.getId(player);
  2217. }
  2218. //--------------------------------------------------
  2219. //Block-Utils
  2220. //--------------------------------------------------
  2221. function block.isChest(block) {
  2222. return block.isType(block, "minecraft:chest");
  2223. }
  2224. function block.isWallSign(block) {
  2225. if(block == null) {
  2226. return false;
  2227. }
  2228. return block.hasTag(block, block.getTag("minecraft:wall_signs"));
  2229. }
  2230. function sign.getString(block, row) {
  2231. return string.text(block.getSign(block, row));
  2232. }
  2233. function sign.setString(block, row, string) {
  2234. block.setSign(block, row, text.new(string));
  2235. }
  2236. function block.isType(block, type_string) {
  2237. return block.getType(block) == material.get(type_string);
  2238. }
  2239. function block.isAir(block) {
  2240. type = block.getType(block);
  2241. return type == material.getAir() || type == material.get("CAVE_AIR");
  2242. }
  2243. function block.mod(block, x, y, z) {
  2244. return block.get(loc.mod(block.getLocation(block), x, y, z));
  2245. }
  2246. function block.gotWater(block) {
  2247. if(block.canHaveWater(block)) {
  2248. return block.isWaterlogged(block);
  2249. }
  2250. return false;
  2251. }
  2252. //--------------------------------------------------
  2253. //Money-Utils
  2254. //--------------------------------------------------
  2255. function hasEnoughMoney(player_or_id, price) {
  2256. return money.get(player_or_id) >= price;
  2257. }
  2258. function money.get(player_or_id) {
  2259. config = playerdata.getSurvival(player_or_id);
  2260. return config.getDouble(config, "money", 0);
  2261. }
  2262. function money.set(player_or_id, money) {
  2263. config = playerdata.getSurvival(player_or_id);
  2264. config.set(config, "money", money);
  2265. config.saveAsync(config);
  2266. player = player.getValid(player_or_id);
  2267. if(player == null) {
  2268. return;
  2269. }
  2270. money.display(player, money);
  2271. }
  2272. function money.getBoostFactor() {
  2273. return getScriptVar("money_factor");
  2274. }
  2275. function money.setBoostFactor(factor) {
  2276. setScriptVar("money_factor", factor);
  2277. }
  2278. function money.addBoost(player_or_id, money) {
  2279. money *= money.getBoostFactor();
  2280. player = player.getValid(player_or_id);
  2281. if(player == null) {
  2282. return;
  2283. }
  2284. if(money.getBoostFactor() > 1) {
  2285. money.popUp(player, money, true);
  2286. }
  2287. money.add(player, money);
  2288. }
  2289. function money.add(player_or_id, money) {
  2290. if(money == 0) {
  2291. return;
  2292. }
  2293. config = playerdata.getSurvival(player_or_id);
  2294. new_money = config.getDouble(config, "money", 0) + money;
  2295. config.set(config, "money", new_money);
  2296. config.saveAsync(config);
  2297. player = player.getValid(player_or_id);
  2298. if(player == null) {
  2299. return;
  2300. }
  2301. money.display(player, new_money);
  2302. money.popUp(player, money, false);
  2303. }
  2304. function money.sub(player_or_id, money) {
  2305. if(money == 0) {
  2306. return;
  2307. }
  2308. config = playerdata.getSurvival(player_or_id);
  2309. new_money = config.getDouble(config, "money", 0) - money;
  2310. config.set(config, "money", new_money);
  2311. config.saveAsync(config);
  2312. player = player.getValid(player_or_id);
  2313. if(player == null) {
  2314. return;
  2315. }
  2316. money.display(player, new_money);
  2317. money.popUp(player, money * -1, false);
  2318. }
  2319. function money.subWithoutPopUp(player_or_id, money) {
  2320. if(money == 0) {
  2321. return;
  2322. }
  2323. config = playerdata.getSurvival(player_or_id);
  2324. new_money = config.getDouble(config, "money", 0) - money;
  2325. config.set(config, "money", new_money);
  2326. config.saveAsync(config);
  2327. player = player.getValid(player_or_id);
  2328. if(player == null) {
  2329. return;
  2330. }
  2331. money.display(player, new_money);
  2332. }
  2333. function money.popUp(player, money, boosted) {
  2334. if($boost_blocker == null) {
  2335. $boost_blocker = false;
  2336. }
  2337. if($boost_blocker) {
  2338. $boost_blocker = false;
  2339. return;
  2340. }
  2341. if(money == 0) {
  2342. return;
  2343. }
  2344. if(money > 0) {
  2345. pre = "+";
  2346. }
  2347. if(money < 0) {
  2348. pre = "-";
  2349. money *= -1;
  2350. }
  2351. if(boosted) {
  2352. $boost_blocker = true;
  2353. post = " §6§k#§rBoosted§6§k#";
  2354. } else {
  2355. post = "";
  2356. }
  2357. //player.action(player, string.concat(pre, "§6", string.number(money), " §rsnuvi", post));
  2358. player.action(player, text.new(string.concat(pre, " ", money.getString(money), " ", post)));
  2359. }
  2360. function money.display(player, money) {
  2361. a = money.split(money);
  2362. gold = string.number(a[0]);
  2363. silver = string.number(a[1]);
  2364. copper = string.number(a[2]);
  2365. sb.add(player, 1, string.concat(icon.getGoldCoin(), gold, " ", icon.getSilverCoin(), silver, " ", icon.getCopperCoin(), copper));
  2366. }
  2367. function money.getString(money) {
  2368. return money.getStringColor(money, "§f");
  2369. }
  2370. function money.getStringColor(money, color) {
  2371. a = money.split(money);
  2372. gold = a[0];
  2373. silver = a[1];
  2374. copper = a[2];
  2375. if(gold == 0) {
  2376. gold_string = "";
  2377. } else {
  2378. gold_string = string.concat(icon.getGoldCoin(), color, string.number(gold));;
  2379. }
  2380. if(silver == 0) {
  2381. silver_string = "";
  2382. } else {
  2383. silver_string = string.concat(icon.getSilverCoin(), color, string.number(silver));;
  2384. }
  2385. if(copper == 0) {
  2386. copper_string = "";
  2387. } else {
  2388. copper_string = string.concat(icon.getCopperCoin(), color, string.number(copper));;
  2389. }
  2390. if(gold == 0 && silver == 0 && copper == 0) {
  2391. copper_string = string.concat(icon.getCopperCoin(), color, string.number(0));;
  2392. }
  2393. return string.concat(gold_string, silver_string, copper_string);
  2394. }
  2395. function money.split(money) {
  2396. array = array.new(3);
  2397. gold = math.roundDown(money / 4096);
  2398. pre_silver = money % 4096;;
  2399. silver = math.roundDown(pre_silver / 64);
  2400. bronze = pre_silver % 64;
  2401. array[0] = gold;
  2402. array[1] = silver;
  2403. array[2] = bronze;
  2404. return array;
  2405. }
  2406. function money.splitCap(money) {
  2407. //cap liegt bei 266304 (64 gold + 64 silver + 64 bronze)
  2408. if(money > 266304) {
  2409. snuvi.debug("error on money.splitCap");
  2410. return null;
  2411. }
  2412. gold = math.roundDown(money / 4096);
  2413. if(gold > 64) {
  2414. gold = 64;
  2415. }
  2416. money -= gold * 4096;
  2417. silver = math.roundDown(money / 64);
  2418. if(silver > 64) {
  2419. silver = 64;
  2420. }
  2421. money -= silver * 64;
  2422. array = array.new(3);
  2423. array[0] = gold;
  2424. array[1] = silver;
  2425. array[2] = money;
  2426. return array;
  2427. }
  2428. //--------------------------------------------------
  2429. //Plot-Utils
  2430. //--------------------------------------------------
  2431. function plot.getFromId(plot_id, world) {
  2432. iter = plot.iterator(world);
  2433. while(hasNext(iter)) {
  2434. plot = next(iter);
  2435. if(plot.getId(plot) == plot_id) {
  2436. return plot;
  2437. }
  2438. }
  2439. return null;
  2440. }
  2441. function plot.calcCost(world, arg1, arg2) {
  2442. //function plot.calcCost(world, length, width) {
  2443. //function plot.calcCost(world, loc1, loc2) {
  2444. if(isDouble(arg1)) {
  2445. length = arg1;
  2446. width = arg2;
  2447. } else {
  2448. x1 = loc.getX(arg1);
  2449. z1 = loc.getZ(arg1);
  2450. x2 = loc.getX(arg2);
  2451. z2 = loc.getZ(arg2);
  2452. length = math.abs(x1 - x2) + 1;
  2453. width = math.abs(z1 - z2) + 1;
  2454. }
  2455. if(world.getName(world) == "creative") {
  2456. factor = 1;
  2457. } else {
  2458. factor = 3;
  2459. }
  2460. return length * width * factor;
  2461. }
  2462. function plot.getIdFromLocation(location) {
  2463. list = plot.get(location);
  2464. if(list.getSize(list) == 0) {
  2465. plot_id = null;
  2466. } else {
  2467. plot = list.getIndex(list, 0);
  2468. plot_id = plot.getId(plot);
  2469. }
  2470. return plot_id;
  2471. }
  2472. function plot.getIdListFromLocation(location) {
  2473. list = plot.get(location);
  2474. for(i = 0; i < list.getSize(list); i++) {
  2475. plot = list.getIndex(list, i);
  2476. list.setIndex(list, i, plot.getId(plot));
  2477. }
  2478. return list;
  2479. }
  2480. function plot.getHighestId(location) {
  2481. list = plot.get(location);
  2482. iter = iterator(list);
  2483. highest = -1;
  2484. while(hasNext(iter)) {
  2485. plot_id = plot.getId(next(iter));
  2486. if(plot_id > highest) {
  2487. highest = plot_id;
  2488. }
  2489. }
  2490. return highest;
  2491. }
  2492. function plot.addPlayer(plot, player_name) {
  2493. list = plot.getOwners(plot);
  2494. uuid = player.getUuid(player_name);
  2495. if(!list.contains(list, uuid)) {
  2496. list.add(list, uuid);
  2497. }
  2498. }
  2499. function plot.removePlayer(plot, player_name) {
  2500. list = plot.getOwners(plot);
  2501. uuid = player.getUuid(player_name);
  2502. list.remove(list, uuid);
  2503. player_id = player.getId(player.getUuid(player_name));
  2504. plot.removeRank(plot, player_id);
  2505. }
  2506. function plot.getOwnersString(plot) {
  2507. list = plot.getOwners(plot);
  2508. if(list.getSize(list) == 0) {
  2509. return "";
  2510. }
  2511. owners_list = list.new();
  2512. for(i = 0; i < list.getSize(list); i++) {
  2513. list.add(owners_list, player.getName(list.getIndex(list, i)));
  2514. }
  2515. return string.concatList(owners_list, " / ", 0, list.getSize(owners_list) - 1);
  2516. }
  2517. function plot.isLeader(plot, player_or_id) {
  2518. return plot.getRank(plot, player_or_id) == "leader";
  2519. }
  2520. function plot.getLeaderName(plot) {
  2521. plot_leader_id = plot.getLeaderId(plot);
  2522. if(plot_leader_id == null) {
  2523. return "";
  2524. }
  2525. return player.getNameFromId(plot_leader_id);
  2526. }
  2527. function plot.getLeaderId(plot) {
  2528. map = plot.getRanksMap(plot);
  2529. iter = map.iterator(map);
  2530. while(hasNext(iter)) {
  2531. element = next(iter);
  2532. rank = map.getValue(element);
  2533. if(rank == "leader") {
  2534. p_id = map.getKey(element);
  2535. }
  2536. }
  2537. return p_id;
  2538. }
  2539. function plot.setLeader(plot, player_or_id) {
  2540. plot.setRank(plot, player_or_id, "leader");
  2541. }
  2542. function plot.isMod(plot, player_or_id) {
  2543. return plot.getRank(plot, player_or_id) == "mod";
  2544. }
  2545. function plot.getMods(plot) {
  2546. list = list.new();
  2547. map = plot.getRanksMap(plot);
  2548. iter = map.iterator(map);
  2549. while(hasNext(iter)) {
  2550. element = next(iter);
  2551. rank = map.getValue(element);
  2552. if(rank == "mod") {
  2553. list.add(list, map.getKey(element));
  2554. }
  2555. }
  2556. return list;
  2557. }
  2558. function plot.setMod(plot, player_or_id) {
  2559. plot.setRank(plot, player_or_id, "mod");
  2560. }
  2561. function plot.canOpenChests(plot, player_or_id) {
  2562. return plot.getRank(plot, player_or_id) == "chest";
  2563. }
  2564. function plot.setChest(plot, player_or_id) {
  2565. plot.setRank(plot, player_or_id, "chest");
  2566. }
  2567. function plot.getAllRanks() {
  2568. return getScriptVar("plot_ranks");
  2569. }
  2570. function plot.getRanksMap(plot) {
  2571. plot_id = plot.getId(plot);
  2572. plot_ranks_map = plot.getAllRanks();
  2573. map = map.get(plot_ranks_map, plot_id);
  2574. if(map == null) {
  2575. map = map.new();
  2576. }
  2577. return map;
  2578. }
  2579. function plot.getChestRanks(plot) {
  2580. list = list.new();
  2581. map = plot.getRanksMap(plot);
  2582. iter = map.iterator(map);
  2583. while(hasNext(iter)) {
  2584. element = next(iter);
  2585. rank = map.getValue(element);
  2586. if(rank == "chest") {
  2587. list.add(list, map.getKey(element));
  2588. }
  2589. }
  2590. return list;
  2591. }
  2592. function plot.getRank(plot, player_or_id) {
  2593. map = plot.getRanksMap(plot);
  2594. player_id = player.getValidId(player_or_id);
  2595. rank = map.get(map, player_id);
  2596. return rank;
  2597. }
  2598. function plot.setRank(plot, player_or_id, rank) {
  2599. player_id = player.getValidId(player_or_id);
  2600. plot_id = plot.getId(plot);
  2601. //Cache
  2602. plot_ranks_map = plot.getAllRanks();
  2603. map = plot.getRanksMap(plot);
  2604. map.add(map, player_id, rank);
  2605. map.add(plot_ranks_map, plot_id, map);
  2606. //DB
  2607. stmt = databank.prepare("INSERT INTO new_plotranks (plot_id, player_id, rank) VALUES (?,?,?) ON DUPLICATE KEY UPDATE rank = ?");
  2608. databank.setInt(stmt, 1, plot_id);
  2609. databank.setInt(stmt, 2, player_id);
  2610. databank.setString(stmt, 3, rank);
  2611. databank.setString(stmt, 4, rank);
  2612. databank.workerExecute(stmt);
  2613. }
  2614. function plot.removeRank(plot, player_or_id) {
  2615. player_id = player.getValidId(player_or_id);
  2616. plot_id = plot.getId(plot);
  2617. //Cache
  2618. plot_ranks_map = plot.getAllRanks();
  2619. map = plot.getRanksMap(plot);
  2620. map.remove(map, player_id);
  2621. map.add(plot_ranks_map, plot_id, map);
  2622. //DB
  2623. stmt = databank.prepare("DELETE FROM new_plotranks WHERE player_id = ? AND plot_id = ?;");
  2624. databank.setInt(stmt, 1, player_id);
  2625. databank.setInt(stmt, 2, plot_id);
  2626. databank.workerExecute(stmt);
  2627. }
  2628. function plot.removeAllPlayers(plot) {
  2629. list = plot.getOwners(plot);
  2630. iter = iterator(list);
  2631. while(hasNext(iter)) {
  2632. plot.removeRank(plot, player.getId(next(iter)));
  2633. }
  2634. }
  2635. function plot.setEdges(plot, location1, location2) {
  2636. //Alte Daten abrufen
  2637. plot_name = plot.getName(plot);
  2638. plot_id = plot.getId(plot);
  2639. list = plot.getOwners(plot);
  2640. flags = plot.getFlags(plot);
  2641. //Neues Plot erstellen und altes Plot löschen
  2642. plot.remove(plot, loc.getWorld(location1));
  2643. new_plot = plot.add(location1, location2, plot_id);
  2644. //Alte Daten auf neuem Plot setzen
  2645. plot.setName(new_plot, plot_name);
  2646. new_list = plot.getOwners(new_plot);
  2647. for(i = 0; i < list.getSize(list); i++) {
  2648. list.add(new_list, list.getIndex(list, i));
  2649. }
  2650. plot.setFlags(new_plot, flags, true);
  2651. return new_plot;
  2652. }
  2653. function plot.getType(plot) {
  2654. if(plot.isCity(plot)) {
  2655. type = "§4[§cCity§4]";
  2656. } elseif(plot.isFree(plot)) {
  2657. type = "§3[§bFree§3]";
  2658. } elseif(plot.isSub(plot)) {
  2659. type = "§6[§eSubPlot§6]";
  2660. } else {
  2661. type = "§6[§ePlot§6]";
  2662. }
  2663. return type;
  2664. }
  2665. function plot.isPlot(plot) {
  2666. return !plot.isCity(plot) && !plot.isFree(plot) && !plot.isSub(plot);
  2667. }
  2668. function plot.isExplosive(plot) {
  2669. return plot.hasFlags(plot, calcLeftShift(27));
  2670. }
  2671. function plot.isCity(plot) {
  2672. return plot.hasFlags(plot, calcLeftShift(28));
  2673. }
  2674. function plot.isFree(plot) {
  2675. return plot.hasFlags(plot, calcLeftShift(29));
  2676. }
  2677. function plot.isSub(plot) {
  2678. return plot.hasFlags(plot, calcLeftShift(30));
  2679. }
  2680. function plot.setCity(plot, boolean) {
  2681. plot.setFlags(plot, calcLeftShift(28), boolean);
  2682. }
  2683. function plot.setFree(plot, boolean) {
  2684. plot.setFlags(plot, calcLeftShift(29), boolean);
  2685. plot.setFlags(plot, calcLeftShift(30), !boolean); //Sub-Plot entfernen
  2686. }
  2687. function plot.setSub(plot, boolean) {
  2688. plot.setFlags(plot, calcLeftShift(30), boolean);
  2689. plot.setFlags(plot, calcLeftShift(29), !boolean); //Free-Plot entfernen
  2690. }
  2691. //--------------------------------------------------
  2692. //Loc-Utils
  2693. //--------------------------------------------------
  2694. function loc.getHighestPoint(loc) {
  2695. y = 319;
  2696. loc.setY(loc, y);
  2697. while(y > 0 && block.isAir(block.get(loc))) {
  2698. loc.setY(loc, y);
  2699. y = y - 10;
  2700. }
  2701. while(!block.isAir(block.get(loc))) {
  2702. loc.setY(loc, y);
  2703. y++;
  2704. }
  2705. return loc;
  2706. }
  2707. function loc.getStringColon(loc) {
  2708. world_name = world.getName(loc.getWorld(loc));
  2709. x = string.number(loc.getX(loc));
  2710. y = string.number(loc.getY(loc));
  2711. z = string.number(loc.getZ(loc));
  2712. return string.concat(world_name, ":", x, ":", y, ":", z);
  2713. }
  2714. function loc.getStringSpace(loc) {
  2715. world_name = world.getName(loc.getWorld(loc));
  2716. x = string.number(loc.getX(loc));
  2717. y = string.number(loc.getY(loc));
  2718. z = string.number(loc.getZ(loc));
  2719. return string.concat(world_name, " ", x, " ", y, " ", z);
  2720. }
  2721. function loc.getStringRounded(loc, separator) {
  2722. x = string.number(math.round(loc.getX(loc)));
  2723. y = string.number(math.round(loc.getY(loc)));
  2724. z = string.number(math.round(loc.getZ(loc)));
  2725. return string.concat(separator, x, separator, y, separator, z);
  2726. }
  2727. function loc.isSameWorld(loc1, loc2) {
  2728. return world.getName(loc.getWorld(loc1)) == world.getName(loc.getWorld(loc2));
  2729. }
  2730. function loc.getSubPlot(location) {
  2731. list = plot.get(location);
  2732. iter = iterator(list);
  2733. while(hasNext(iter)) {
  2734. plot = next(iter);
  2735. if(plot.isSub(plot)) {
  2736. return plot;
  2737. }
  2738. }
  2739. return null;
  2740. }
  2741. function loc.isCity(location) {
  2742. list = plot.get(location);
  2743. iter = iterator(list);
  2744. while(hasNext(iter)) {
  2745. plot = next(iter);
  2746. if(plot.isCity(plot)) {
  2747. return true;
  2748. }
  2749. }
  2750. return false;
  2751. }
  2752. function loc.hasPlotId(location, plot_id) {
  2753. return list.contains(plot.getIdListFromLocation(location), plot_id);
  2754. }
  2755. function loc.hasPlotName(location, plot_name) {
  2756. list = plot.get(location);
  2757. iter = iterator(list);
  2758. while(hasNext(iter)) {
  2759. plot = next(iter);
  2760. if(plot.getName(plot) == plot_name) {
  2761. return true;
  2762. }
  2763. }
  2764. return false;
  2765. }
  2766. function loc.isInSurvWorld(location) {
  2767. world_name = world.getName(loc.getWorld(location));
  2768. if(world_name == "world") {
  2769. return true;
  2770. } elseif(world_name == "world_the_end") {
  2771. return true;
  2772. } elseif(world_name == "world_nether") {
  2773. return true;
  2774. }
  2775. return false;
  2776. }
  2777. function loc.isInGamesWorld(location) {
  2778. return loc.getWorld(location) == world.getGames();
  2779. }
  2780. function loc.isInCreativeWorld(location) {
  2781. return loc.getWorld(location) == world.getCreative();
  2782. }
  2783. function loc.round(location) {
  2784. world = loc.getWorld(location);
  2785. x = math.round(loc.getX(location));
  2786. y = math.round(loc.getY(location));
  2787. z = math.round(loc.getZ(location));
  2788. return loc.new(world, x, y, z);
  2789. }
  2790. //--------------------------------------------------
  2791. //Survival-Utils
  2792. //--------------------------------------------------
  2793. function living.setAi(bool) {
  2794. config = getServerConfig();
  2795. config.set(config, "spawnWithAi", bool);
  2796. config.saveAsync(config);
  2797. }
  2798. function living.getAi() {
  2799. config = getServerConfig();
  2800. return config.getBool(config, "spawnWithAi", true);
  2801. }
  2802. function living.setHand(living, item) {
  2803. living.setEquip(living, slot.getHand(), item);
  2804. }
  2805. function living.getHand(living) {
  2806. return living.getEquip(living, slot.getHand());
  2807. }
  2808. function living.getOffHand(living) {
  2809. return living.getEquip(living, slot.getOffHand());
  2810. }
  2811. //--------------------------------------------------
  2812. //Afk-Utils
  2813. //--------------------------------------------------
  2814. function player.isAfk(player) {
  2815. player_uuid = player.getUuid(player);
  2816. afk_map = getScriptVar("afk_map");
  2817. return map.contains(afk_map, player_uuid);
  2818. }
  2819. function player.setAfk(player, boolean) {
  2820. player_uuid = player.getUuid(player);
  2821. afk_map = getScriptVar("afk_map");
  2822. if(boolean) {
  2823. map.add(afk_map, player_uuid, loc.getYaw(entity.getLocation(player)));
  2824. } else {
  2825. map.remove(afk_map, player_uuid);
  2826. }
  2827. }
  2828. //--------------------------------------------------
  2829. //PvP-Utils
  2830. //--------------------------------------------------
  2831. function hasPvpOn(player_or_id) {
  2832. config = playerdata.getSurvival(player_or_id);
  2833. return config.getBool(config, "pvp", false);
  2834. }
  2835. function setPvp(player_or_id, bool) {
  2836. config = playerdata.getSurvival(player_or_id);
  2837. config.set(config, "pvp", bool);
  2838. config.saveAsync(config);
  2839. }
  2840. //--------------------------------------------------
  2841. //Rank-Utils
  2842. //--------------------------------------------------
  2843. function getRank(player_or_id) {
  2844. config = playerdata.getSurvival(player_or_id);
  2845. return config.getString(config, "rank", "§3User");
  2846. }
  2847. function setRank(player_or_id, rank) {
  2848. rank = string.replace(rank, "&", "§");
  2849. config = playerdata.getSurvival(player_or_id);
  2850. config.set(config, "rank", rank);
  2851. config.saveAsync(config);
  2852. }
  2853. function offerRank(player, tech_name) {
  2854. rank = rank.getFromTechName(tech_name);
  2855. msg(player, text.merge(text.new(string.getPrefix("§6Commands")), text.new(" "), text.new("New rank available: "), text.getHoverText(string.getClickText(string.concat("[§", rank, "§r]"), string.concat("/setrank ", player.getName(player), " &", rank)), "Click to set")));
  2856. }
  2857. function rank.offerClan(clan_id, tech_name) {
  2858. leader_uuid = clan.getLeader(clan_id);
  2859. leader = player.get(leader_uuid);
  2860. if(leader == null) {
  2861. mail.send("marvinius", player.getName(leader_uuid), string.concat("New rank available: ", tech_name));
  2862. } else {
  2863. offerRank(leader, tech_name);
  2864. }
  2865. }
  2866. function rank.checkCriteria(player, tech_name) {
  2867. //Playtime
  2868. if(tech_name == "rank.newcomer") {
  2869. return player.getTotalPlaytime(player) >= 1200; //20 Stunden
  2870. }
  2871. if(tech_name == "rank.frequenter") {
  2872. return player.getTotalPlaytime(player) >= 6000; //100 Stunden
  2873. }
  2874. if(tech_name == "rank.legend") {
  2875. return player.getTotalPlaytime(player) >= 42000; //700 Stunden
  2876. }
  2877. //Challenges
  2878. if(tech_name == "rank.challenger") {
  2879. return player.getADTChallengeAmounts(player) >= 1;
  2880. }
  2881. if(tech_name == "rank.mobhunter") {
  2882. return player.getAEChallengeAmounts(player) >= 1;
  2883. }
  2884. if(tech_name == "rank.collector") {
  2885. return player.getAIhallengeAmounts(player) >= 1;
  2886. }
  2887. //Adventure
  2888. /*if(tech_name == "rank.adventurer") {
  2889. return player.getAdventureAmounts(player) >= 1;
  2890. }
  2891. if(tech_name == "rank.explorer") {
  2892. return player.getAdventureAmounts(player) >= 5;
  2893. }
  2894. if(tech_name == "rank.pioneer") {
  2895. return player.getAdventureAmounts(player) >= 10;
  2896. }*/
  2897. //Clans
  2898. /*if(tech_name == "rank.commander") {
  2899. if(player.isClanLeader(player)) {
  2900. clan_id = player.getClanId(player);
  2901. return clan.getMembersAmount(clan_id) >= 5;
  2902. }
  2903. return false;
  2904. }
  2905. if(tech_name == "rank.chief") {
  2906. if(player.isClanLeader(player)) {
  2907. clan_id = player.getClanId(player);
  2908. return clan.getMembersAmount(clan_id) >= 10;
  2909. }
  2910. return false;
  2911. }
  2912. if(tech_name == "rank.lord") {
  2913. if(player.isClanLeader(player)) {
  2914. clan_id = player.getClanId(player);
  2915. return clan.getMembersAmount(clan_id) >= 15;
  2916. }
  2917. return false;
  2918. }*/
  2919. //Quests
  2920. if(tech_name == "rank.volunteer") {
  2921. return quest.getCounter(player) >= 15;
  2922. }
  2923. if(tech_name == "rank.friend") {
  2924. return quest.getCounter(player) >= 50;
  2925. }
  2926. if(tech_name == "rank.altruist") {
  2927. return quest.getCounter(player) >= 500;
  2928. }
  2929. //Plots
  2930. if(tech_name == "rank.settler") {
  2931. return player.usedHisFreePlot(player);
  2932. }
  2933. if(tech_name == "rank.colonizer") {
  2934. return player.hasBigPlotCreated(player);
  2935. }
  2936. if(tech_name == "rank.major") {
  2937. return player.hasPlotRaised(player);
  2938. }
  2939. //Team
  2940. if(tech_name == "rank.owner") {
  2941. return perm.has("isOwner", player);
  2942. }
  2943. if(tech_name == "rank.admin") {
  2944. return perm.has("isAdmin", player);
  2945. }
  2946. if(tech_name == "rank.builder") {
  2947. return perm.has("isBuilder", player);
  2948. }
  2949. if(tech_name == "rank.dev") {
  2950. return perm.has("isDev", player);
  2951. }
  2952. if(tech_name == "rank.moderator") {
  2953. return perm.has("isMod", player);
  2954. }
  2955. if(tech_name == "rank.supporter") {
  2956. return perm.has("isSupporter", player);
  2957. }
  2958. //Other
  2959. if(tech_name == "rank.vip") {
  2960. return perm.has("isVIP", player);
  2961. }
  2962. if(tech_name == "rank.influencer") {
  2963. return perm.has("isYT", player) || perm.has("isStreamer", player);
  2964. }
  2965. if(tech_name == "rank.sponsor") {
  2966. return perm.has("isSponsor", player);
  2967. }
  2968. if(tech_name == "rank.user") {
  2969. return true;
  2970. }
  2971. return perm.has("setrank.other", player);
  2972. }
  2973. function rank.getRankArray() {
  2974. return getScriptVar("ranks");
  2975. }
  2976. function rank.getFromTechName(tech_name) {
  2977. a = rank.getRankArray();
  2978. a_size = array.getSize(a);
  2979. for(i = 0; i < a_size; i++) {
  2980. if(a[i, 0] == tech_name) {
  2981. return a[i, 1];
  2982. }
  2983. }
  2984. return null;
  2985. }
  2986. function rank.getTechName(rank) {
  2987. a = rank.getRankArray();
  2988. a_size = array.getSize(a);
  2989. for(i = 0; i < a_size; i++) {
  2990. if(a[i, 1] == rank) {
  2991. return a[i, 0];
  2992. }
  2993. }
  2994. return null;
  2995. }
  2996. function rank.choose(player, tech_name) {
  2997. rank = rank.getFromTechName(tech_name);
  2998. msg(player, string.getClickText(string.concat(" [§", rank, "§r]"), string.concat("/setrank ", player.getName(player), " &", rank)));
  2999. }
  3000. function rank.showAll(player) {
  3001. a = rank.getRankArray();
  3002. a_size = array.getSize(a);
  3003. for(i = 0; i < a_size; i++) {
  3004. tech_name = a[i, 0];
  3005. if(rank.checkCriteria(player, tech_name)) {
  3006. rank.choose(player, tech_name);
  3007. }
  3008. }
  3009. }
  3010. //--------------------------------------------------
  3011. //Perm-Utils
  3012. //--------------------------------------------------
  3013. function perm.addGroupToPlayer(player_id, perm_id) {
  3014. stmt = databank.prepare("INSERT INTO new_playerperms (player_id, perm_id) VALUES (?,?);");
  3015. databank.setInt(stmt, 1, player_id);
  3016. databank.setInt(stmt, 2, perm_id);
  3017. databank.workerExecute(stmt);
  3018. list = player.getPerms(player_id);
  3019. list.add(list, perm_id);
  3020. perm.initPlayer(player_id);
  3021. }
  3022. function perm.removeGroupFromPlayer(player_id, perm_id) {
  3023. stmt = databank.prepare("DELETE FROM new_playerperms WHERE player_id = ? AND perm_id = ?;");
  3024. databank.setInt(stmt, 1, player_id);
  3025. databank.setInt(stmt, 2, perm_id);
  3026. databank.workerExecute(stmt);
  3027. list = player.getPerms(player_id);
  3028. list.remove(list, perm_id);
  3029. player_uuid = player.getUuidFromId(player_id);
  3030. player = player.get(player_uuid);
  3031. if(player != null) {
  3032. perm.unloadGroupFromPlayer(perm_id, player);
  3033. }
  3034. }
  3035. function perm.simUser(player) {
  3036. perm.clear(player);
  3037. perm.loadGroupToPlayer(0, player);
  3038. perm.loadGroupToPlayer(14, player);
  3039. perm.update(player);
  3040. }
  3041. function player.removeAllPerms(player_id) {
  3042. stmt = databank.prepare("DELETE FROM new_playerperms WHERE player_id = ?;");
  3043. databank.setInt(stmt, 1, player_id);
  3044. databank.workerExecute(stmt);
  3045. perm.initPlayer(player_id);
  3046. }
  3047. function perm.getAll() {
  3048. return getScriptVar("player_perms");
  3049. }
  3050. function player.getPerms(player_or_id) {
  3051. player_id = player.getValidId(player_or_id);
  3052. map = perm.getAll();
  3053. list = map.get(map, player_id);
  3054. if(list == null) {
  3055. list = list.new();
  3056. map.add(map, player_id, list);
  3057. }
  3058. return map.getOrDefault(perm.getAll(), player_id, list.new());
  3059. }
  3060. function player.getPermsFromDatabank(player_or_id) {
  3061. player_id = player.getValidId(player_or_id);
  3062. permslist = list.new();
  3063. stmt = databank.prepare("SELECT perm_id FROM new_playerperms WHERE player_id = ?;");
  3064. databank.setInt(stmt, 1, player_id);
  3065. result = databank.execute(stmt);
  3066. while(databank.next(result)) {
  3067. list.add(permslist, databank.getInt(result, 1));
  3068. }
  3069. databank.close(result);
  3070. databank.close(stmt);
  3071. return permslist;
  3072. }
  3073. function perm.setGroups(permgroups) {
  3074. setScriptVar("permgroups", permgroups);
  3075. }
  3076. function perm.getGroups() {
  3077. return getScriptVar("permgroups");
  3078. }
  3079. function perm.getNameFromId(permgroup_id) {
  3080. a = perm.getGroups();
  3081. for(i = 0; i < array.getSize(a); i++) {
  3082. if(i == permgroup_id) {
  3083. return a[i, 0];
  3084. }
  3085. }
  3086. return null;
  3087. }
  3088. function perm.getRankFromId(permgroup_id) {
  3089. a = perm.getGroups();
  3090. for(i = 0; i < array.getSize(a); i++) {
  3091. if(i == permgroup_id) {
  3092. return a[i, 1];
  3093. }
  3094. }
  3095. return null;
  3096. }
  3097. function perm.getIdFromGroupname(permgroup_name) {
  3098. a = perm.getGroups();
  3099. for(i = 0; i < array.getSize(a); i++) {
  3100. if(a[i, 0] == permgroup_name) {
  3101. return i;
  3102. }
  3103. }
  3104. return null;
  3105. }
  3106. function perm.getRankFromGroupname(permgroup_name) {
  3107. a = perm.getGroups();
  3108. for(i = 0; i < array.getSize(a); i++) {
  3109. if(a[i, 0] == permgroup_name) {
  3110. return a[i, 1];
  3111. }
  3112. }
  3113. return null;
  3114. }
  3115. function perm.isGroupName(permgroup_name) {
  3116. a = perm.getGroups();
  3117. for(i = 0; i < array.getSize(a); i++) {
  3118. if(a[i, 0] == permgroup_name) {
  3119. return true;
  3120. }
  3121. }
  3122. return false;
  3123. }
  3124. function player.hasPermGroup(player_id, perm_id) {
  3125. permslist = player.getPerms(player_id);
  3126. return list.contains(permslist, perm_id);
  3127. }
  3128. function perm.loadGroupToPlayer(group_id, player) {
  3129. list = perm.getGroupList(group_id);
  3130. iter = iterator(list);
  3131. while(hasNext(iter)) {
  3132. perm = next(iter);
  3133. perm.add(perm, player);
  3134. }
  3135. }
  3136. function perm.unloadGroupFromPlayer(group_id, player) {
  3137. list = perm.getGroupList(group_id);
  3138. iter = iterator(list);
  3139. while(hasNext(iter)) {
  3140. perm = next(iter);
  3141. perm.remove(perm, player);
  3142. }
  3143. }
  3144. function perm.getGroupList(group_id) {
  3145. a = perm.getGroups();
  3146. for(i = 0; i < array.getSize(a); i++) {
  3147. if(i == group_id) {
  3148. return a[i, 2];
  3149. }
  3150. }
  3151. return null;
  3152. }
  3153. function perm.isAwardable(group_id) {
  3154. a = perm.getGroups();
  3155. for(i = 0; i < array.getSize(a); i++) {
  3156. if(i == group_id) {
  3157. return a[i, 3];
  3158. }
  3159. }
  3160. return null;
  3161. }
  3162. function perm.initPlayer(player_or_id) {
  3163. player = player.getValid(player_or_id);
  3164. if(player == null) {
  3165. return;
  3166. }
  3167. perm.clear(player);
  3168. perm.loadGroupToPlayer(0, player);
  3169. permslist = player.getPerms(player);
  3170. iter = iterator(permslist);
  3171. while(hasNext(iter)) {
  3172. perm.loadGroupToPlayer(next(iter), player);
  3173. }
  3174. perm.update(player);
  3175. command.sendHelp(player);
  3176. }
  3177. //--------------------------------------------------
  3178. //Nickname-Utils
  3179. //--------------------------------------------------
  3180. function player.setNickName(player, nickname) {
  3181. map.add(getScriptVar("nicknames"), player.getUuid(player), nickname);
  3182. }
  3183. function player.getNickName(player) {
  3184. return map.getOrDefault(getScriptVar("nicknames"), player.getUuid(player), player.getName(player));
  3185. }
  3186. function player.removeNickName(player) {
  3187. map.remove(getScriptVar("nicknames"), player.getUuid(player));
  3188. }
  3189. function player.isNicked(player) {
  3190. return map.contains(getScriptVar("nicknames"), player.getUuid(player));
  3191. }
  3192. //--------------------------------------------------
  3193. //Mail-Utils
  3194. //--------------------------------------------------
  3195. function mail.send(from_name, to_name, string_message) {
  3196. server_config = getServerConfig();
  3197. mail_id = config.getDouble(server_config, "mail_id", 0) + 1;
  3198. config.set(server_config, "mail_id", mail_id);
  3199. config.saveAsync(server_config);
  3200. from_id = player.getId(player.getUuid(from_name));
  3201. to_id = player.getId(player.getUuid(to_name));
  3202. stmt = databank.prepare("INSERT INTO mails (mail_id, from_id, to_id, readed, time, message) VALUES (?, ?, ?, ?, ?, ?);");
  3203. databank.setInt(stmt, 1, mail_id);
  3204. databank.setInt(stmt, 2, from_id);
  3205. databank.setInt(stmt, 3, to_id);
  3206. databank.setBool(stmt, 4, false);
  3207. databank.setLong(stmt, 5, time.getMillis());
  3208. databank.setString(stmt, 6, string_message);
  3209. databank.workerExecute(stmt);
  3210. //Wenn Spieler online, dann Pushmeldung veranlassen
  3211. p = read.player(to_name);
  3212. if(p != null) {
  3213. msg(p, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got a new mail from §b", from_name, ". ")), string.getClickText("[§cClick§r]", "/mail new")));
  3214. }
  3215. }
  3216. function mail.checkForNew(player) {
  3217. stmt = databank.prepare("SELECT mail_id, from_id, time, message FROM mails WHERE to_id = ? AND readed = false;");
  3218. to_id = player.getId(player);
  3219. databank.setInt(stmt, 1, to_id);
  3220. result = databank.execute(stmt);
  3221. nextrow = databank.next(result);
  3222. if(!nextrow) {
  3223. databank.close(result);
  3224. databank.close(stmt);
  3225. return;
  3226. }
  3227. newmails = 0;
  3228. while(nextrow) {
  3229. newmails++;
  3230. nextrow = databank.next(result);
  3231. }
  3232. databank.close(result);
  3233. databank.close(stmt);
  3234. if(newmails > 0) {
  3235. if(newmails > 1) {
  3236. msg(player, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got §b", string.number(newmails), "§r new mails. ")), string.getClickText("[§cClick§r]", "/mail new")));;
  3237. } else {
  3238. msg(player, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got §b1 §rnew mail. ")), string.getClickText("[§cClick§r]", "/mail new")));;
  3239. }
  3240. }
  3241. }
  3242. //--------------------------------------------------
  3243. //Friend-Utils
  3244. //--------------------------------------------------
  3245. function friend.check(player_id, friend_id) {
  3246. stmt = databank.prepare("SELECT friend_id FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?);");
  3247. databank.setInt(stmt, 1, player_id);
  3248. databank.setInt(stmt, 2, friend_id);
  3249. databank.setInt(stmt, 3, friend_id);
  3250. databank.setInt(stmt, 4, player_id);
  3251. result = databank.execute(stmt);
  3252. if(databank.next(result)) {
  3253. temp = true;
  3254. } else {
  3255. temp = false;
  3256. }
  3257. databank.close(result);
  3258. databank.close(stmt);
  3259. return temp;
  3260. }
  3261. function friend.add(player_id, friend_id) {
  3262. stmt = databank.prepare("INSERT INTO friends (player_id, friend_id, time) VALUES (?, ?, ?);");
  3263. databank.setInt(stmt, 1, player_id);
  3264. databank.setInt(stmt, 2, friend_id);
  3265. databank.setLong(stmt, 3, time.getMillis());
  3266. databank.workerExecute(stmt);
  3267. }
  3268. function friend.delete(player_id, friend_id) {
  3269. stmt = databank.prepare("DELETE FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?);");
  3270. databank.setInt(stmt, 1, player_id);
  3271. databank.setInt(stmt, 2, friend_id);
  3272. databank.workerExecute(stmt);
  3273. }
  3274. function friend.getList(player_id) {
  3275. list = list.new();
  3276. stmt = databank.prepare("SELECT friend_id FROM friends WHERE player_id = ?;");
  3277. databank.setInt(stmt, 1, player_id);
  3278. result = databank.execute(stmt);
  3279. while(databank.next(result)) {
  3280. list.add(list, databank.getInt(result, 1));
  3281. }
  3282. databank.close(result);
  3283. databank.close(stmt);
  3284. stmt = databank.prepare("SELECT player_id FROM friends WHERE friend_id = ?;");
  3285. databank.setInt(stmt, 1, player_id);
  3286. result = databank.execute(stmt);
  3287. while(databank.next(result)) {
  3288. list.add(list, databank.getInt(result, 1));
  3289. }
  3290. databank.close(result);
  3291. databank.close(stmt);
  3292. return list;
  3293. }
  3294. //--------------------------------------------------
  3295. //Clan-Utils
  3296. //--------------------------------------------------
  3297. function clan.getIdList() {
  3298. file = file.new("scripts/configs/clan_data");
  3299. if(file.exists(file) && file.isDirectory(file)) {
  3300. list = file.getList(file);
  3301. } else {
  3302. list = list.new();
  3303. }
  3304. id_list = list.new();
  3305. iter = iterator(list);
  3306. while(hasNext(iter)) {
  3307. element = next(iter);
  3308. file_name = file.getName(element);
  3309. file_name = string.replace(file_name, ".0.snuvic", "");
  3310. list.add(id_list, read.number(file_name));
  3311. }
  3312. return id_list;
  3313. }
  3314. function clan.loadData() {
  3315. list = clan.getIdList();
  3316. iter = iterator(list);
  3317. map = map.new();
  3318. while(hasNext(iter)) {
  3319. clan_id = next(iter);
  3320. config = config.new("scripts/configs/clan_data", clan_id);
  3321. if(config.exists(config)) {
  3322. config.load(config);
  3323. }
  3324. map.add(map, clan_id, config);
  3325. }
  3326. setScriptVar("clan_data", map);
  3327. }
  3328. function clan.getData(clan_id) {
  3329. if(clan_id == null) {
  3330. snuvi.debug("script termed. clan_id was null");
  3331. term();
  3332. }
  3333. map = getScriptVar("clan_data");
  3334. config = map.get(map, clan_id);
  3335. if(config == null) {
  3336. config = config.new("scripts/configs/clan_data", clan_id);
  3337. if(config.exists(config)) {
  3338. config.load(config);
  3339. }
  3340. map.add(map, clan_id, config);
  3341. }
  3342. return config;
  3343. }
  3344. function clan.setName(clan_id, name) {
  3345. config = clan.getData(clan_id);
  3346. config.set(config, "name", name);
  3347. config.saveAsync(config);
  3348. }
  3349. function clan.getName(clan_id) {
  3350. config = clan.getData(clan_id);
  3351. temp = config.getString(config, "name", "null");
  3352. if(temp == "null") {
  3353. return null;
  3354. }
  3355. return temp;
  3356. }
  3357. function clan.setTag(clan_id, tag) {
  3358. config = clan.getData(clan_id);
  3359. config.set(config, "tag", tag);
  3360. config.saveAsync(config);
  3361. }
  3362. function clan.getTag(clan_id) {
  3363. config = clan.getData(clan_id);
  3364. temp = config.getString(config, "tag", "null");
  3365. if(temp == "null") {
  3366. return null;
  3367. }
  3368. return temp;
  3369. }
  3370. function clan.setMoney(clan_id, money) {
  3371. config = clan.getData(clan_id);
  3372. config.set(config, "money", money);
  3373. config.saveAsync(config);
  3374. }
  3375. function clan.getMoney(clan_id) {
  3376. config = clan.getData(clan_id);
  3377. return config.getDouble(config, "money", 0);
  3378. }
  3379. function clan.addMoney(clan_id, money) {
  3380. config = clan.getData(clan_id);
  3381. new_money = config.getDouble(config, "money", 0) + money;
  3382. config.set(config, "money", new_money);
  3383. config.saveAsync(config);
  3384. }
  3385. function clan.subMoney(clan_id, money) {
  3386. config = clan.getData(clan_id);
  3387. new_money = config.getDouble(config, "money", 0) - money;
  3388. config.set(config, "money", new_money);
  3389. config.saveAsync(config);
  3390. }
  3391. function clan.setSpawn(clan_id, location) {
  3392. config = clan.getData(clan_id);
  3393. config.set(config, "spawn", string.location(location));
  3394. config.saveAsync(config);
  3395. }
  3396. function clan.getSpawn(clan_id) {
  3397. config = clan.getData(clan_id);
  3398. location = config.getString(config, "spawn", "null");
  3399. if(location == "null") {
  3400. return null;
  3401. }
  3402. return read.location(location);
  3403. }
  3404. function clan.getIdFromName(name) {
  3405. list = clan.getIdList();
  3406. iter = iterator(list);
  3407. while(hasNext(iter)) {
  3408. clan_id = next(iter);
  3409. if(clan.getName(clan_id) == name) {
  3410. return clan_id;
  3411. }
  3412. }
  3413. return null;
  3414. }
  3415. function clan.getIdFromTag(clan_tag) {
  3416. list = clan.getIdList();
  3417. iter = iterator(list);
  3418. while(hasNext(iter)) {
  3419. clan_id = next(iter);
  3420. if(clan.getTag(clan_id) == clan_tag) {
  3421. return clan_id;
  3422. }
  3423. }
  3424. return null;
  3425. }
  3426. function clan.isExistingTag(clan_tag) {
  3427. return !(clan.getIdFromTag(clan_tag) == null);
  3428. }
  3429. function clan.isExistingName(name) {
  3430. return !(clan.getIdFromName(name) == null);
  3431. }
  3432. function clan.getNextFreeId() {
  3433. server_config = getServerConfig();
  3434. id = config.getDouble(server_config, "clan.id.next", 0) + 1;
  3435. config.set(server_config, "clan.id.next", id);
  3436. config.saveAsync(server_config);
  3437. return id;
  3438. }
  3439. function clan.create(name, tag) {
  3440. clan_id = clan.getNextFreeId();
  3441. config = clan.getData(clan_id);
  3442. config.set(config, "name", name);
  3443. config.set(config, "tag", tag);
  3444. config.set(config, "members", 0);
  3445. config.save(config);
  3446. return clan_id;
  3447. }
  3448. function clan.getLeader(clan_id) {
  3449. list = clan.getMembersList(clan_id);
  3450. iter = iterator(list);
  3451. while(hasNext(iter)) {
  3452. player_uuid = next(iter);
  3453. player_id = player.getId(player_uuid);
  3454. if(player.isClanLeader(player_id)) {
  3455. return player_uuid;
  3456. }
  3457. }
  3458. return null;
  3459. }
  3460. function clan.getMembersAmount(clan_id) {
  3461. config = clan.getData(clan_id);
  3462. return config.getDouble(config, "members", 0);
  3463. }
  3464. function clan.setMembersAmount(clan_id, amount) {
  3465. config = clan.getData(clan_id);
  3466. config.set(config, "members", amount);
  3467. config.saveAsync(config);
  3468. }
  3469. function clan.addMember(clan_id, player_or_id, role) {
  3470. //Player
  3471. player.setClanId(player_or_id, clan_id);
  3472. player.setClanRole(player_or_id, role);
  3473. //Clan
  3474. new_amount = clan.getMembersAmount(clan_id) + 1;
  3475. if(isPlayer(player_or_id)) {
  3476. player_uuid = player.getUuid(player_or_id);
  3477. } else {
  3478. player_uuid = player.getUuidFromId(player_or_id);
  3479. }
  3480. config = clan.getData(clan_id);
  3481. config.set(config, string.concat("player_", new_amount), text(player_uuid));
  3482. config.set(config, "members", new_amount);
  3483. config.saveAsync(config);
  3484. }
  3485. function clan.removeMember(clan_id, player_or_id) {
  3486. //Player
  3487. player.setClanId(player_or_id, -1);
  3488. player.setClanRole(player_or_id, "null");
  3489. if(isPlayer(player_or_id)) {
  3490. player_uuid = player.getUuid(player_or_id);
  3491. } else {
  3492. player_uuid = player.getUuidFromId(player_or_id);
  3493. }
  3494. //Clan
  3495. config = clan.getData(clan_id);
  3496. amount = config.getDouble(config, "members", 0);
  3497. for(i = 1; i <= amount; i++) {
  3498. if(config.getString(config, string.concat("player_", i), "null") == text(player_uuid)) {
  3499. break;
  3500. }
  3501. }
  3502. if(i != amount) {
  3503. config.set(config, string.concat("player_", i), config.getString(config, string.concat("player_", amount), "null"));
  3504. }
  3505. config.set(config, string.concat("player_", amount), "null");
  3506. config.set(config, "members", amount - 1);
  3507. config.saveAsync(config);
  3508. }
  3509. function clan.delete(clan_id) {
  3510. //Members
  3511. list = clan.getMembersList(clan_id);
  3512. iter = iterator(list);
  3513. while(hasNext(iter)) {
  3514. player_uuid = next(iter);
  3515. player_id = player.getId(player_uuid);
  3516. player.setClanId(player_id, -1);
  3517. player.setClanRole(player_id, "null");
  3518. }
  3519. //Clan
  3520. config.delete(clan.getData(clan_id));
  3521. map.remove(getScriptVar("clan_data"), clan_id);
  3522. }
  3523. function clan.getMembersList(clan_id) {
  3524. list = list.new();
  3525. config = clan.getData(clan_id);
  3526. amount = config.getDouble(config, "members", 0);
  3527. for(i = 1; i <= amount; i++) {
  3528. player_uuid = read.uuid(config.getString(config, string.concat("player_", i), "null"));
  3529. list.add(list, player_uuid);
  3530. }
  3531. return list;
  3532. }
  3533. function clan.updateHeadNames(clan_id) {
  3534. list = clan.getMembersList(clan_id);
  3535. iter = iterator(list);
  3536. while(hasNext(iter)) {
  3537. p = player.get(next(iter));
  3538. if(p != null) {
  3539. player.setHeadName(p);
  3540. }
  3541. }
  3542. }
  3543. function clan.msg(clan_id, text_or_string) {
  3544. list = clan.getMembersList(clan_id);
  3545. iter = iterator(list);
  3546. while(hasNext(iter)) {
  3547. p = player.get(next(iter));
  3548. if(p != null) {
  3549. msg.prefix(p, "§2Clan", text_or_string);
  3550. }
  3551. }
  3552. }
  3553. function clan.mail(clan_id, from_name, string_message) {
  3554. list = clan.getMembersList(clan_id);
  3555. iter = iterator(list);
  3556. while(hasNext(iter)) {
  3557. to_name = player.getName(next(iter));
  3558. mail.send(from_name, to_name, string_message);
  3559. }
  3560. }
  3561. //--------------------------------------------------
  3562. //Party-Utils
  3563. //--------------------------------------------------
  3564. function player.isInParty(player) {
  3565. return player.getPartyId(player) != null;
  3566. }
  3567. function party.same(player1, player2) {
  3568. return player.getPartyId(player1) == player.getPartyId(player2);
  3569. }
  3570. function player.isPartyLeader(player) {
  3571. return player.getPartyRank(player) == "Leader";
  3572. }
  3573. function player.isPartyLeaderOrMod(player) {
  3574. return player.getPartyRank(player) != "Player";
  3575. }
  3576. function player.getPartyId(player) {
  3577. return map.get(getScriptVar("party_ids"), player.getUuid(player));
  3578. }
  3579. function player.setPartyId(player, party_id) {
  3580. map.add(getScriptVar("party_ids"), player.getUuid(player), party_id);
  3581. }
  3582. function player.delPartyId(player) {
  3583. map.remove(getScriptVar("party_ids"), player.getUuid(player));
  3584. }
  3585. function player.getPartyRank(player) {
  3586. return map.get(getScriptVar("party_ranks"), player.getUuid(player));
  3587. }
  3588. function player.setPartyRank(player, rank) {
  3589. map.add(getScriptVar("party_ranks"), player.getUuid(player), rank);
  3590. }
  3591. function player.delPartyRank(player) {
  3592. map.remove(getScriptVar("party_ranks"), player.getUuid(player));
  3593. }
  3594. function party.getList(party_id) {
  3595. return map.get(getScriptVar("party_lists"), party_id);
  3596. }
  3597. function party.setList(party_id, list) {
  3598. map = getScriptVar("party_lists");
  3599. map.add(map, party_id, list);
  3600. setScriptVar("party_lists", map);
  3601. }
  3602. function party.addPlayer(party_id, player) {
  3603. list.add(party.getList(party_id), player.getUuid(player));
  3604. player.setPartyId(player, party_id);
  3605. }
  3606. //--------------------------------------------------
  3607. //Scheduler-Utils
  3608. //--------------------------------------------------
  3609. function scheduler.add(data_array) {
  3610. list.add(scheduler.getList(), data_array);
  3611. }
  3612. function scheduler.getList() {
  3613. return getScriptVar("scheduler_list");
  3614. }
  3615. function scheduler.addFly(ticks, player, bool) {
  3616. a = array.new(4);
  3617. a[0] = 0;
  3618. a[1] = ticks;
  3619. a[2] = player;
  3620. a[3] = bool;
  3621. scheduler.add(a);
  3622. }
  3623. function scheduler.msgPrefix(ticks, player, prefix, text_or_string) {
  3624. a = array.new(5);
  3625. a[0] = 1;
  3626. a[1] = ticks;
  3627. a[2] = player;
  3628. a[3] = prefix;
  3629. a[4] = text_or_string;
  3630. scheduler.add(a);
  3631. }
  3632. function scheduler.msg(ticks, player, text_or_string) {
  3633. a = array.new(4);
  3634. a[0] = 2;
  3635. a[1] = ticks;
  3636. a[2] = player;
  3637. a[3] = text_or_string;
  3638. scheduler.add(a);
  3639. }
  3640. function scheduler.setBlockMaterial(ticks, block, material, block_update) {
  3641. a = array.new(5);
  3642. a[0] = 3;
  3643. a[1] = ticks;
  3644. a[2] = block;
  3645. a[3] = material;
  3646. a[4] = block_update;
  3647. scheduler.add(a);
  3648. }
  3649. function scheduler.questFinish(ticks, script, player) {
  3650. a = array.new(4);
  3651. a[0] = 4;
  3652. a[1] = ticks;
  3653. a[2] = script;
  3654. a[3] = player;
  3655. scheduler.add(a);
  3656. }
  3657. function scheduler.setBurning(ticks, entity, seconds) {
  3658. a = array.new(4);
  3659. a[0] = 5;
  3660. a[1] = ticks;
  3661. a[2] = entity;
  3662. a[3] = seconds;
  3663. scheduler.add(a);
  3664. }
  3665. function scheduler.spawnEntity(ticks, type, location) {
  3666. a = array.new(4);
  3667. a[0] = 6;
  3668. a[1] = ticks;
  3669. a[2] = type;
  3670. a[3] = location;
  3671. scheduler.add(a);
  3672. }
  3673. function scheduler.removeEntity(ticks, entity) {
  3674. a = array.new(3);
  3675. a[0] = 7;
  3676. a[1] = ticks;
  3677. a[2] = entity;
  3678. scheduler.add(a);
  3679. }
  3680. function scheduler.giveItem(ticks, player, item) {
  3681. a = array.new(4);
  3682. a[0] = 8;
  3683. a[1] = ticks;
  3684. a[2] = player;
  3685. a[3] = item;
  3686. scheduler.add(a);
  3687. }
  3688. function scheduler.giveSingleItem(ticks, player, item) {
  3689. a = array.new(4);
  3690. a[0] = 9;
  3691. a[1] = ticks;
  3692. a[2] = player;
  3693. a[3] = item;
  3694. scheduler.add(a);
  3695. }
  3696. function scheduler.setBlockData(ticks, block, blockdata, block_update) {
  3697. a = array.new(5);
  3698. a[0] = 10;
  3699. a[1] = ticks;
  3700. a[2] = block;
  3701. a[3] = blockdata;
  3702. a[4] = block_update;
  3703. scheduler.add(a);
  3704. }
  3705. //--------------------------------------------------
  3706. //Icon-Utils
  3707. //--------------------------------------------------
  3708. function icon.getGoldCoin() {
  3709. return string.fromCode(63489);
  3710. }
  3711. function icon.getSilverCoin() {
  3712. return string.fromCode(63490);
  3713. }
  3714. function icon.getCopperCoin() {
  3715. return string.fromCode(63491);
  3716. }
  3717. function icon.getExp() {
  3718. return string.fromCode(63492);
  3719. }
  3720. function icon.getBookshelf() {
  3721. return string.fromCode(63493);
  3722. }
  3723. function icon.getCraftingTable() {
  3724. return string.fromCode(63494);
  3725. }
  3726. function icon.getCompass() {
  3727. return string.fromCode(63495);
  3728. }
  3729. function icon.getCake() {
  3730. return string.fromCode(63496);
  3731. }
  3732. function icon.getEnderpearl() {
  3733. return string.fromCode(63497);
  3734. }
  3735. function icon.getHeart() {
  3736. return string.fromCode(63498);
  3737. }
  3738. function icon.getHalfHeart() {
  3739. return string.fromCode(63499);
  3740. }
  3741. function icon.getEmptyHeart() {
  3742. return string.fromCode(63500);
  3743. }
  3744. //--------------------------------------------------
  3745. //Challenge-Utils
  3746. //--------------------------------------------------
  3747. function challenge.display(player, id, challenge, string_message, stage, all_stages) {
  3748. sb.add(player, id, string.concat("§a", challenge, ": ", string_message, " [", string.number(stage), "/", string.number(all_stages), "]"));
  3749. }
  3750. function challenge.removeDisplay(player, id) {
  3751. sb.remove(player, id);
  3752. }
  3753. function player.addChallenge(player_or_id, challenge) {
  3754. config = playerdata.getSurvival(player_or_id);
  3755. string = config.getString(config, "challenge", "");
  3756. if(string == "") {
  3757. config.set(config, "challenge", challenge);
  3758. } else {
  3759. config.set(config, "challenge", string.concat(string, "%", challenge));
  3760. }
  3761. config.saveAsync(config);
  3762. }
  3763. function player.removeChallenge(player_or_id, challenge) {
  3764. config = playerdata.getSurvival(player_or_id);
  3765. string = config.getString(config, "challenge", "");
  3766. string = string.replace(string, string.concat(challenge, "%"), "");
  3767. string = string.replace(string, string.concat("%", challenge), "");
  3768. string = string.replace(string, challenge, "");
  3769. config.set(config, "challenge", string);
  3770. config.saveAsync(config);
  3771. }
  3772. function player.getChallenges(player_or_id) {
  3773. config = playerdata.getSurvival(player_or_id);
  3774. string = config.getString(config, "challenge", "");
  3775. a = string.split("%", string);
  3776. s = set.new();
  3777. for(i = 0; i < array.getSize(a); i++) {
  3778. set.add(s, a[i]);
  3779. }
  3780. return s;
  3781. }
  3782. function challenge.playerHas(player_or_id, challenge) {
  3783. return set.contains(player.getChallenges(player_or_id), challenge);
  3784. }