u_general.txt 107 KB

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