u_general.txt 118 KB

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