u_general.txt 113 KB

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