u_general.txt 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163
  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. function player.getValid(player_or_id) {
  1377. if(isPlayer(player_or_id)) {
  1378. return player_or_id;
  1379. }
  1380. player = player.get(player.getUuidFromId(player_or_id));
  1381. if(player == null) {
  1382. return null;
  1383. }
  1384. return player;
  1385. }
  1386. //--------------------------------------------------
  1387. //Msg-Utils
  1388. //--------------------------------------------------
  1389. function msg.quest(player, speaker, line_now, line_max, message) {
  1390. msg(player, concat("[§b", text.number(line_now), "§r/§b", text.number(line_max), "§r] §a", speaker, " §r| ", concat("§e", message)));
  1391. }
  1392. function sendMessageToWorld(world, message) {
  1393. world_name = world.getName(world);
  1394. if(isSurvWorldName(world_name)) {
  1395. worldlist = players.toWorldList(world.getOverWorld());
  1396. for(i = 0; i < list.getSize(worldlist); i++) {
  1397. msg(list.getIndex(worldlist, i), message);
  1398. }
  1399. worldlist = players.toWorldList(world.get("the_end"));
  1400. for(i = 0; i < list.getSize(worldlist); i++) {
  1401. msg(list.getIndex(worldlist, i), message);
  1402. }
  1403. worldlist = players.toWorldList(world.get("the_nether"));
  1404. for(i = 0; i < list.getSize(worldlist); i++) {
  1405. msg(list.getIndex(worldlist, i), message);
  1406. }
  1407. return;
  1408. }
  1409. worldlist = players.toWorldList(world);
  1410. for(i = 0; i < list.getSize(worldlist); i++) {
  1411. msg(list.getIndex(worldlist, i), message);
  1412. }
  1413. }
  1414. function sendMessageToWorld2(world, message1, message2) {
  1415. world_name = world.getName(world);
  1416. if(isSurvWorldName(world_name)) {
  1417. worldlist = players.toWorldList(world.getOverWorld());
  1418. for(i = 0; i < list.getSize(worldlist); i++) {
  1419. msg(list.getIndex(worldlist, i), message1, message2);
  1420. }
  1421. worldlist = players.toWorldList(world.get("the_end"));
  1422. for(i = 0; i < list.getSize(worldlist); i++) {
  1423. msg(list.getIndex(worldlist, i), message1, message2);
  1424. }
  1425. worldlist = players.toWorldList(world.get("the_nether"));
  1426. for(i = 0; i < list.getSize(worldlist); i++) {
  1427. msg(list.getIndex(worldlist, i), message1, message2);
  1428. }
  1429. return;
  1430. }
  1431. worldlist = players.toWorldList(world);
  1432. for(i = 0; i < list.getSize(worldlist); i++) {
  1433. msg(list.getIndex(worldlist, i), message1, message2);
  1434. }
  1435. }
  1436. function sendOnlineMessage(player, message) {
  1437. nickname = player.getNickName(player);
  1438. rank = getRank(player);
  1439. colorcode = text.subString(rank, 0, 2);
  1440. player_id = player.getId(player);
  1441. if(player_id == 35 || player_id == 62) {
  1442. nickname = concat(nickname, "§r][§e§l★");
  1443. rank = concat(rank, "\n§eSpecial VIP for Special Services");
  1444. }
  1445. live_tag = "";
  1446. if(player.isLive(player)) {
  1447. live_tag = "§f[§dLive§f]";
  1448. }
  1449. online_list = players.toList();
  1450. iter = list.iterator(online_list);
  1451. while(hasNext(iter)) {
  1452. p = next(iter);
  1453. if(player.hasMinigame(p) && player.isMuted(p)) {
  1454. continue;
  1455. }
  1456. msg(p, live_tag, "[", text.hover(concat(colorcode, nickname), rank), "§r] §r", message);
  1457. }
  1458. }
  1459. function msg.send(from_player, to_name, prefix, message, send_mail) {
  1460. p = read.player(to_name);
  1461. if(p == null) {
  1462. if(send_mail) {
  1463. mail.send(player.getName(from_player), to_name, message);
  1464. }
  1465. } else {
  1466. msg.prefix(p, prefix, message);
  1467. }
  1468. }
  1469. function msg.prefix(player, prefix, message) {
  1470. msg(player, concat("§r[", prefix, "§r] ", message));
  1471. }
  1472. function msg.radius(prefix, message, location, radius) {
  1473. list = players.near(location, radius);
  1474. iter = list.iterator(list);
  1475. while(hasNext(iter)) {
  1476. msg.prefix(next(iter), prefix, message);
  1477. }
  1478. }
  1479. //--------------------------------------------------
  1480. //Player-Utils
  1481. //--------------------------------------------------
  1482. function player.hasClearInventory(player) {
  1483. inv = player.getInv(player);
  1484. for(slot = 0; slot < 36; slot++) {
  1485. if(item.getType(inv.getItem(inv, slot)) != "minecraft:air") {
  1486. return false;
  1487. }
  1488. }
  1489. if(item.getType(entity.getEquip(player, "head")) != "minecraft:air") {
  1490. return false;
  1491. }
  1492. if(item.getType(entity.getEquip(player, "chest")) != "minecraft:air") {
  1493. return false;
  1494. }
  1495. if(item.getType(entity.getEquip(player, "legs")) != "minecraft:air") {
  1496. return false;
  1497. }
  1498. if(item.getType(entity.getEquip(player, "feet")) != "minecraft:air") {
  1499. return false;
  1500. }
  1501. if(item.getType(entity.getEquip(player, "offhand")) != "minecraft:air") {
  1502. return false;
  1503. }
  1504. return true;
  1505. }
  1506. function player.getJoinMessage(player_or_id) {
  1507. config = playerdata.getSurvival(player_or_id);
  1508. temp = config.getString(config, "message.join", "null");
  1509. if(temp == "null") {
  1510. return null;
  1511. }
  1512. return temp;
  1513. }
  1514. function player.setJoinMessage(player_or_id, message) {
  1515. config = playerdata.getSurvival(player_or_id);
  1516. config.set(config, "message.join", message);
  1517. config.saveAsync(config);
  1518. }
  1519. function player.getLeaveMessage(player_or_id) {
  1520. config = playerdata.getSurvival(player_or_id);
  1521. temp = config.getString(config, "message.leave", "null");
  1522. if(temp == "null") {
  1523. return null;
  1524. }
  1525. return temp;
  1526. }
  1527. function player.setLeaveMessage(player_or_id, message) {
  1528. config = playerdata.getSurvival(player_or_id);
  1529. config.set(config, "message.leave", message);
  1530. config.saveAsync(config);
  1531. }
  1532. function player.isLive(player) {
  1533. player_uuid = player.getUuid(player);
  1534. live_set = getScriptVar("live_set");
  1535. return set.contains(live_set, player_uuid);
  1536. }
  1537. function player.setLive(player, boolean) {
  1538. player_uuid = player.getUuid(player);
  1539. live_set = getScriptVar("live_set");
  1540. if(boolean) {
  1541. set.add(live_set, player_uuid);
  1542. } else {
  1543. set.remove(live_set, player_uuid);
  1544. }
  1545. }
  1546. function player.getFullName(player) {
  1547. player_name = player.getName(player);
  1548. nickname = removeFormat(player.getNickname(player));
  1549. if(nickname == player_name) {
  1550. personally_messages = true;
  1551. } else {
  1552. personally_messages = false;
  1553. }
  1554. if(personally_messages) {
  1555. full_name = concat("[", getRank(player), "§r] ", nickname);
  1556. } else {
  1557. full_name = concat("[§3User§r] ", nickname);
  1558. }
  1559. return full_name;
  1560. }
  1561. function player.setTabName(player) {
  1562. nickname = player.getNickname(player);
  1563. if(player.isAfk(player)) {
  1564. tab_name = concat("§7§m", nickname);
  1565. } else {
  1566. rank = getRank(player);
  1567. if(text.startswith(rank, "§", 0)) {
  1568. colorcode = text.subString(rank, 0, 2);
  1569. tab_name = concat(colorcode, nickname);
  1570. } else {
  1571. tab_name = nickname;
  1572. }
  1573. }
  1574. if(player.isLive(player)) {
  1575. tab_name = concat(tab_name, " §f[§dLive§f]");
  1576. }
  1577. player.setDisplayName(player, tab_name);
  1578. }
  1579. function player.removeItem2(player, itemstack) {
  1580. item_type = item.getType(itemstack);
  1581. amount = item.getAmount(itemstack);
  1582. my_item = read.item(item_type, amount); //Kopie erstellen
  1583. item.setAmount(my_item, 1);
  1584. for(slot = 0; slot <= 35; slot++) {
  1585. item = player.getInvSlot(player, slot);
  1586. if(item.getType(item) == item_type) {
  1587. amount2 = item.getAmount(item);
  1588. diff = amount - amount2;
  1589. if(diff > 0) {
  1590. amount = diff;
  1591. item.setAmount(item, 0);
  1592. } else {
  1593. item.setAmount(item, math.abs(diff));
  1594. return null;
  1595. }
  1596. }
  1597. }
  1598. item.setAmount(my_item, amount);
  1599. return my_item;
  1600. }
  1601. function player.showDebug(player, boolean) {
  1602. player_uuid = player.getUuid(player);
  1603. if(boolean) {
  1604. perm.registerPlayer(player_uuid, 16);
  1605. } else {
  1606. perm.unregisterPlayer(player_uuid, 16);
  1607. }
  1608. }
  1609. function player.showDefaultStacks(player) {
  1610. player_loc = entity.getLocation(player);
  1611. world_name = world.getName(loc.getWorld(player_loc));
  1612. stacks.clear(player);
  1613. if(isSurvWorldName(world_name)) {
  1614. stacks.set(player, 0, "km:gear");
  1615. stacks.set(player, 1, "km:golden_scepter");
  1616. stacks.set(player, 2, "minecraft:red_bed");
  1617. } elseif(world_name == "games") {
  1618. stacks.set(player, 0, "km:gear");
  1619. } elseif(world_name == "story") {
  1620. stacks.set(player, 0, "km:gear");
  1621. stacks.set(player, 1, "km:golden_scepter");
  1622. }
  1623. stacks.setActive(player, true);
  1624. }
  1625. function player.setSpeed(player, speed) {
  1626. living.setPersistentMovementSpeed(player, speed / 10);
  1627. living.setPersistentFlyingSpeed(player, speed / 10 * 4);
  1628. }
  1629. function player.hasBigPlotCreated(player_or_id) {
  1630. config = playerdata.getSurvival(player_or_id);
  1631. return config.getBool(config, "plot.big", false);
  1632. }
  1633. function player.setBigPlotCreated(player_or_id, boolean) {
  1634. config = playerdata.getSurvival(player_or_id);
  1635. config.set(config, "plot.big", boolean);
  1636. config.saveAsync(config);
  1637. }
  1638. function player.hasPlotRaised(player_or_id) {
  1639. config = playerdata.getSurvival(player_or_id);
  1640. return config.getBool(config, "plot.raised", false);
  1641. }
  1642. function player.setPlotRaised(player_or_id, boolean) {
  1643. config = playerdata.getSurvival(player_or_id);
  1644. config.set(config, "plot.raised", boolean);
  1645. config.saveAsync(config);
  1646. }
  1647. function player.usedHisFreePlot(player_or_id) {
  1648. config = playerdata.getSurvival(player_or_id);
  1649. return config.getBool(config, "plot.usedFree", false);
  1650. }
  1651. function player.setUsedFreePlot(player_or_id, boolean) {
  1652. config = playerdata.getSurvival(player_or_id);
  1653. config.set(config, "plot.usedFree", boolean);
  1654. config.saveAsync(config);
  1655. }
  1656. function player.activateSitting(player_or_id, boolean) {
  1657. config = playerdata.getSurvival(player_or_id);
  1658. config.set(config, "sitting", boolean);
  1659. config.saveAsync(config);
  1660. }
  1661. function player.hasSittingActivated(player_or_id) {
  1662. config = playerdata.getSurvival(player_or_id);
  1663. return config.getBool(config, "sitting", true);
  1664. }
  1665. function player.acceptTpaRequests(player_or_id, boolean) {
  1666. config = playerdata.getSurvival(player_or_id);
  1667. config.set(config, "tptoggle", boolean);
  1668. config.saveAsync(config);
  1669. }
  1670. function player.doesAcceptTpaRequests(player_or_id) {
  1671. config = playerdata.getSurvival(player_or_id);
  1672. return config.getBool(config, "tptoggle", true);
  1673. }
  1674. function player.getBackPos(player) {
  1675. config = playerdata.getSurvival(player);
  1676. location = config.getString(config, "backpos", "null");
  1677. if(location == "null") {
  1678. return null;
  1679. }
  1680. return read.location(location);
  1681. }
  1682. function player.setBackPos(player) {
  1683. config = playerdata.getSurvival(player);
  1684. config.set(config, "backpos", text.location(entity.getLocation(player)));
  1685. config.saveAsync(config);
  1686. }
  1687. function player.setBackPosLoc(player, location) {
  1688. config = playerdata.getSurvival(player);
  1689. config.set(config, "backpos", text.location(location));
  1690. config.saveAsync(config);
  1691. }
  1692. function player.clearBackPos(player) {
  1693. config = playerdata.getSurvival(player);
  1694. config.set(config, "backpos", "null");
  1695. config.saveAsync(config);
  1696. }
  1697. function player.getFromDamageSource(damage_source) {
  1698. entity = damage.getImmediateSource(damage_source);
  1699. if(isPlayer(entity)) {
  1700. return entity;
  1701. }
  1702. entity = damage.getTrueSource(damage_source);
  1703. if(isPlayer(entity)) {
  1704. return entity;
  1705. }
  1706. return null;
  1707. }
  1708. function player.getJoins(player_or_id) {
  1709. if(isPlayer(player_or_id)) {
  1710. player_id = player.getId(player_or_id);
  1711. } else {
  1712. player_id = player_or_id;
  1713. }
  1714. stmt = databank.prepare("SELECT COUNT(join_time) FROM playtime WHERE player_id = ?;");
  1715. databank.setInt(stmt, 1, player_id);
  1716. result = databank.execute(stmt);
  1717. if(databank.next(result)) {
  1718. amount = databank.getLong(result, 1);
  1719. }
  1720. databank.close(result);
  1721. databank.close(stmt);
  1722. return amount;
  1723. }
  1724. function player.getTotalPlaytime(player_or_id) {
  1725. if(isPlayer(player_or_id)) {
  1726. player_id = player.getId(player_or_id);
  1727. } else {
  1728. player_id = player_or_id;
  1729. }
  1730. //Online seit
  1731. since_minutes = 0;
  1732. if(isOnline(player.getNameFromId(player_id))) {
  1733. stmt = databank.prepare("SELECT join_time FROM playtime WHERE player_id = ? AND leave_time IS NULL;");
  1734. databank.setInt(stmt, 1, player_id);
  1735. result = databank.execute(stmt);
  1736. while(databank.next(result)) {
  1737. since_minutes = (time.getMillis() - databank.getLong(result, 1)) / 1000 / 60;
  1738. }
  1739. databank.close(result);
  1740. databank.close(stmt);
  1741. }
  1742. //Spielzeit gesamt
  1743. stmt2 = databank.prepare("SELECT SUM(leave_time - join_time) FROM playtime WHERE player_id = ?;");
  1744. databank.setInt(stmt2, 1, player_id);
  1745. result = databank.execute(stmt2);
  1746. while(databank.next(result)) {
  1747. minutes = databank.getLong(result, 1) / 1000 / 60 + since_minutes;
  1748. }
  1749. databank.close(result);
  1750. databank.close(stmt2);
  1751. return minutes;
  1752. }
  1753. function player.hasInvIgnore(player_or_id) {
  1754. config = playerdata.getSurvival(player_or_id);
  1755. return config.getBool(config, "invignore", false);
  1756. }
  1757. function player.invIgnore(player_or_id, boolean) {
  1758. config = playerdata.getSurvival(player_or_id);
  1759. config.set(config, "invignore", boolean);
  1760. config.saveAsync(config);
  1761. }
  1762. function player.getClanId(player_or_id) {
  1763. config = playerdata.getSurvival(player_or_id);
  1764. return config.getDouble(config, "clan_id", -1);
  1765. }
  1766. function player.setClanId(player_or_id, clan_id) {
  1767. config = playerdata.getSurvival(player_or_id);
  1768. config.set(config, "clan_id", clan_id);
  1769. config.saveAsync(config);
  1770. }
  1771. function player.getClanRole(player_or_id) {
  1772. config = playerdata.getSurvival(player_or_id);
  1773. temp = config.getString(config, "clan_role", "null");
  1774. if(temp == "null") {
  1775. return null;
  1776. }
  1777. return temp;
  1778. }
  1779. function player.setClanRole(player_or_id, clan_id) {
  1780. config = playerdata.getSurvival(player_or_id);
  1781. config.set(config, "clan_role", clan_id);
  1782. config.saveAsync(config);
  1783. }
  1784. function player.isInClan(player_or_id) {
  1785. return player.getClanId(player_or_id) >= 0;
  1786. }
  1787. function player.isClanLeader(player_or_id) {
  1788. return player.getClanRole(player_or_id) == "leader";
  1789. }
  1790. function player.isClanMod(player_or_id) {
  1791. return player.getClanRole(player_or_id) == "mod";
  1792. }
  1793. function player.isClanMember(player_or_id) {
  1794. return player.getClanRole(player_or_id) == "member";
  1795. }
  1796. function player.isSameClan(player_or_id_1, player_or_id_2) {
  1797. id_1 = player.getClanId(player_or_id_1);
  1798. id_2 = player.getClanId(player_or_id_2);
  1799. if(id_1 < 0 || id_2 < 0) {
  1800. return false;
  1801. }
  1802. return id_1 == id_2;
  1803. }
  1804. function player.setHeadName(player) {
  1805. player_name = player.getName(player);
  1806. clan_string = "";
  1807. if(player.isInClan(player)) {
  1808. clan_id = player.getClanId(player);
  1809. clan_string = text.concat(" [§6", clan.getTag(clan_id), "§r]");
  1810. }
  1811. live_string = "";
  1812. if(player.isLive(player)) {
  1813. live_string = "§f[§dLive§f] ";
  1814. }
  1815. entity.setName(player, text.concat(live_string, player_name, clan_string));
  1816. }
  1817. function player.setAdventureAmounts(player_or_id, amount) {
  1818. config = playerdata.getSurvival(player_or_id);
  1819. config.set(config, "adventures", amount);
  1820. config.saveAsync(config);
  1821. }
  1822. function player.getAdventureAmounts(player_or_id) {
  1823. config = playerdata.getSurvival(player_or_id);
  1824. return config.getDouble(config, "adventures", 0);
  1825. }
  1826. function player.isOnAdventure(player_or_id) {
  1827. config = playerdata.getSurvival(player_or_id);
  1828. return config.getBool(config, "onadventure", false);
  1829. }
  1830. function player.setAdventure(player_or_id, boolean) {
  1831. config = playerdata.getSurvival(player_or_id);
  1832. config.set(config, "onadventure", boolean);
  1833. config.saveAsync(config);
  1834. }
  1835. function player.getAdventureStart(player_or_id) {
  1836. config = playerdata.getSurvival(player_or_id);
  1837. location = config.getString(config, "adventureloc", "null");
  1838. if(location == "null") {
  1839. return world.getServerSpawn();
  1840. }
  1841. return read.location(location);
  1842. }
  1843. function player.setAdventureStart(player_or_id, location) {
  1844. config = playerdata.getSurvival(player_or_id);
  1845. config.set(config, "adventureloc", text.location(location));
  1846. config.saveAsync(config);
  1847. }
  1848. function player.isMuted(player_or_id) {
  1849. config = playerdata.getSurvival(player_or_id);
  1850. return config.getBool(config, "muted", false);
  1851. }
  1852. function player.mute(player_or_id, boolean) {
  1853. config = playerdata.getSurvival(player_or_id);
  1854. config.set(config, "muted", boolean);
  1855. config.saveAsync(config);
  1856. }
  1857. function player.getSilentJoin(player_or_id) {
  1858. config = playerdata.getSurvival(player_or_id);
  1859. return config.getBool(config, "silentjoin", false);
  1860. }
  1861. function player.setSilentJoin(player_or_id, boolean) {
  1862. config = playerdata.getSurvival(player_or_id);
  1863. config.set(config, "silentjoin", boolean);
  1864. config.saveAsync(config);
  1865. }
  1866. function player.getAutoCloseDoor(player_or_id) {
  1867. config = playerdata.getSurvival(player_or_id);
  1868. return config.getBool(config, "door_auto_close", true);
  1869. }
  1870. function player.setAutoCloseDoor(player_or_id, boolean) {
  1871. config = playerdata.getSurvival(player_or_id);
  1872. config.set(config, "door_auto_close", boolean);
  1873. config.saveAsync(config);
  1874. }
  1875. function player.getNoPetDamage(player_or_id) {
  1876. config = playerdata.getSurvival(player_or_id);
  1877. return config.getBool(config, "pet_damage", true);
  1878. }
  1879. function player.setNoPetDamage(player_or_id, boolean) {
  1880. config = playerdata.getSurvival(player_or_id);
  1881. config.set(config, "pet_damage", boolean);
  1882. config.saveAsync(config);
  1883. }
  1884. function player.setVotePoints(player_or_id, amount) {
  1885. config = playerdata.getSurvival(player_or_id);
  1886. config.set(config, "votepoints", amount);
  1887. config.saveAsync(config);
  1888. }
  1889. function player.getVotePoints(player_or_id) {
  1890. config = playerdata.getSurvival(player_or_id);
  1891. return config.getDouble(config, "votepoints", 0);
  1892. }
  1893. function player.hasFirstJoin(player_or_id) {
  1894. config = playerdata.getSurvival(player_or_id);
  1895. return config.getBool(config, "firstjoin", true);
  1896. }
  1897. function player.setFirstJoin(player_or_id, boolean) {
  1898. config = playerdata.getSurvival(player_or_id);
  1899. config.set(config, "firstjoin", !boolean);
  1900. config.saveAsync(config);
  1901. }
  1902. function player.getFirstJoin(player_or_id) {
  1903. if(isPlayer(player_or_id)) {
  1904. player_id = player.getId(player_or_id);
  1905. } else {
  1906. player_id = player_or_id;
  1907. }
  1908. stmt = databank.prepare("SELECT MIN(join_time) FROM playtime WHERE player_id = ?;");
  1909. databank.setInt(stmt, 1, player_id);
  1910. result = databank.execute(stmt);
  1911. if(databank.next(result)) {
  1912. time = databank.getLong(result, 1);
  1913. }
  1914. databank.close(result);
  1915. databank.close(stmt);
  1916. return time;
  1917. }
  1918. function player.getLastJoin(player_or_id) {
  1919. if(isPlayer(player_or_id)) {
  1920. player_id = player.getId(player_or_id);
  1921. } else {
  1922. player_id = player_or_id;
  1923. }
  1924. stmt = databank.prepare("SELECT MAX(join_time) FROM playtime WHERE player_id = ?;");
  1925. databank.setInt(stmt, 1, player_id);
  1926. result = databank.execute(stmt);
  1927. if(databank.next(result)) {
  1928. time = databank.getLong(result, 1);
  1929. }
  1930. databank.close(result);
  1931. databank.close(stmt);
  1932. return time;
  1933. }
  1934. function player.blockCommands(player) {
  1935. list = getScriptVar("block_commands_list");
  1936. list.add(list, player.getUuid(player));
  1937. }
  1938. function player.unblockCommands(player) {
  1939. list = getScriptVar("block_commands_list");
  1940. player_uuid = player.getUuid(player);
  1941. while(list.contains(list, player_uuid)) {
  1942. list.remove(list, player_uuid);
  1943. }
  1944. }
  1945. function player.isCommandBlocked(player) {
  1946. list = getScriptVar("block_commands_list");
  1947. return list.contains(list, player.getUuid(player));
  1948. }
  1949. function player.checkHandsForItem(player, item) {
  1950. hand = entity.getEquip(player, "hand");
  1951. if(item.getType(hand) == item.getType(item)) {
  1952. return true;
  1953. }
  1954. offhand = entity.getEquip(player, "offhand");
  1955. return item.getType(offhand) == item.getType(item);
  1956. }
  1957. function player.checkHandsForTag(player, tag) {
  1958. hand = entity.getEquip(player, "hand");
  1959. if(item.hasTag(tag, hand)) {
  1960. return true;
  1961. }
  1962. offhand = entity.getEquip(player, "offhand");
  1963. return item.hasTag(tag, offhand);
  1964. }
  1965. //--------------------------------------------------
  1966. //Block-Utils
  1967. //--------------------------------------------------
  1968. function block.getSecondDoor(door_loc_1) {
  1969. prop_h_facing = block.getProperty("horizontal_facing");
  1970. state_facing = block.getState(door_loc_1, prop_h_facing);
  1971. prop_hinge = block.getProperty("hinge");
  1972. state_hinge = block.getState(door_loc_1, prop_hinge);
  1973. if(state_facing == "north") {
  1974. if(state_hinge == "right") {
  1975. door_loc_2 = loc.mod(door_loc_1, -1, 0, 0);
  1976. } else {
  1977. door_loc_2 = loc.mod(door_loc_1, 1, 0, 0);
  1978. }
  1979. } elseif(state_facing == "east") {
  1980. if(state_hinge == "right") {
  1981. door_loc_2 = loc.mod(door_loc_1, 0, 0, -1);
  1982. } else {
  1983. door_loc_2 = loc.mod(door_loc_1, 0, 0, 1);
  1984. }
  1985. } elseif(state_facing == "south") {
  1986. if(state_hinge == "right") {
  1987. door_loc_2 = loc.mod(door_loc_1, 1, 0, 0);
  1988. } else {
  1989. door_loc_2 = loc.mod(door_loc_1, -1, 0, 0);
  1990. }
  1991. } else {
  1992. if(state_hinge == "right") {
  1993. door_loc_2 = loc.mod(door_loc_1, 0, 0, 1);
  1994. } else {
  1995. door_loc_2 = loc.mod(door_loc_1, 0, 0, -1);
  1996. }
  1997. }
  1998. if(block.isDoor(door_loc_2)) {
  1999. if(block.isSameDoorHalf(door_loc_1, door_loc_2)) {
  2000. state_hinge_2 = block.getState(door_loc_2, prop_hinge);
  2001. if(state_hinge == "left" && state_hinge_2 == "right" || state_hinge == "right" && state_hinge_2 == "left") {
  2002. return door_loc_2;
  2003. }
  2004. }
  2005. }
  2006. return null;
  2007. }
  2008. function block.isSameDoorHalf(door_loc_1, door_loc_2) {
  2009. prop_d_half = block.getProperty("double_block_half");
  2010. state_half = block.getState(door_loc_1, prop_d_half);
  2011. state_half_2 = block.getState(door_loc_2, prop_d_half);
  2012. return state_half == state_half_2;
  2013. }
  2014. //--------------------------------------------------
  2015. //Money-Utils
  2016. //--------------------------------------------------
  2017. function hasEnoughMoney(player_or_id, price) {
  2018. return getMoney(player_or_id) >= price;
  2019. }
  2020. function getMoney(player_or_id) {
  2021. config = playerdata.getSurvival(player_or_id);
  2022. return config.getDouble(config, "money", 0);
  2023. }
  2024. function setMoney(player_or_id, money) {
  2025. config = playerdata.getSurvival(player_or_id);
  2026. config.set(config, "money", money);
  2027. config.saveAsync(config);
  2028. player = player.getValid(player_or_id);
  2029. if(player == null) {
  2030. return;
  2031. }
  2032. displayMoney(player, new_money);
  2033. }
  2034. function money.getBoostFactor() {
  2035. return getScriptVar("money_factor");
  2036. }
  2037. function money.setBoostFactor(factor) {
  2038. setScriptVar("money_factor", factor);
  2039. }
  2040. function money.addBoost(player_or_id, money) {
  2041. money *= money.getBoostFactor();
  2042. player = player.getValid(player_or_id);
  2043. if(player == null) {
  2044. return;
  2045. }
  2046. if(money.getBoostFactor() > 1) {
  2047. money.popUp(player, money, true);
  2048. }
  2049. addMoney(player, money);
  2050. }
  2051. function addMoney(player_or_id, money) {
  2052. if(money == 0) {
  2053. return;
  2054. }
  2055. config = playerdata.getSurvival(player_or_id);
  2056. new_money = config.getDouble(config, "money", 0) + money;
  2057. config.set(config, "money", new_money);
  2058. config.saveAsync(config);
  2059. player = player.getValid(player_or_id);
  2060. if(player == null) {
  2061. return;
  2062. }
  2063. displayMoney(player, new_money);
  2064. money.popUp(player, money, false);
  2065. }
  2066. function subMoney(player_or_id, money) {
  2067. if(money == 0) {
  2068. return;
  2069. }
  2070. config = playerdata.getSurvival(player_or_id);
  2071. new_money = config.getDouble(config, "money", 0) - money;
  2072. config.set(config, "money", new_money);
  2073. config.saveAsync(config);
  2074. player = player.getValid(player_or_id);
  2075. if(player == null) {
  2076. return;
  2077. }
  2078. displayMoney(player, new_money);
  2079. money.popUp(player, money, false);
  2080. }
  2081. function money.popUp(player, money, boosted) {
  2082. if($boost_blocker == null) {
  2083. $boost_blocker = false;
  2084. }
  2085. if($boost_blocker) {
  2086. $boost_blocker = false;
  2087. return;
  2088. }
  2089. if(money == 0) {
  2090. return;
  2091. }
  2092. if(money > 0) {
  2093. pre = "+";
  2094. }
  2095. if(money < 0) {
  2096. pre = "-";
  2097. }
  2098. if(boosted) {
  2099. $boost_blocker = true;
  2100. post = " §6§k#§rBoosted§6§k#";
  2101. } else {
  2102. post = "";
  2103. }
  2104. player.action(player, concat(pre, "§6", text.number(money), " §rsnuvi", post));
  2105. }
  2106. function displayMoney(player, money) {
  2107. a = money.split(money);
  2108. display.add(player, 0, concat("#23-1- ", text.number(a[0])));
  2109. display.add(player, 1, concat("#24-1- ", text.number(a[1])));
  2110. display.add(player, 2, concat("#25-1- ", text.number(a[2])));
  2111. }
  2112. function money.split(money) {
  2113. array = array.new(3);
  2114. gold = math.roundDown(money / 4096);
  2115. pre_silver = money % 4096;;
  2116. silver = math.roundDown(pre_silver / 64);
  2117. bronze = pre_silver % 64;
  2118. array[0] = gold;
  2119. array[1] = silver;
  2120. array[2] = bronze;
  2121. return array;
  2122. }
  2123. //--------------------------------------------------
  2124. //Plot-Utils
  2125. //--------------------------------------------------
  2126. function plot.getFromId(plot_id, world) {
  2127. iter = plot.iterator(world);
  2128. while(hasNext(iter)) {
  2129. plot = next(iter);
  2130. if(plot.getId(plot) == plot_id) {
  2131. return plot;
  2132. }
  2133. }
  2134. return null;
  2135. }
  2136. function plot.calcCost(world, arg1, arg2) {
  2137. //function plot.calcCost(world, length, width) {
  2138. //function plot.calcCost(world, loc1, loc2) {
  2139. if(isDouble(arg1)) {
  2140. length = arg1;
  2141. width = arg2;
  2142. } else {
  2143. x1 = loc.getX(arg1);
  2144. z1 = loc.getZ(arg1);
  2145. x2 = loc.getX(arg2);
  2146. z2 = loc.getZ(arg2);
  2147. length = math.abs(x1 - x2) + 1;
  2148. width = math.abs(z1 - z2) + 1;
  2149. }
  2150. if(world.getName(world) == "creative") {
  2151. factor = 1;
  2152. } else {
  2153. factor = 3;
  2154. }
  2155. return length * width * factor;
  2156. }
  2157. function plot.getIdFromLocation(location) {
  2158. list = plot.get(location);
  2159. if(list.getSize(list) == 0) {
  2160. plot_id = null;
  2161. } else {
  2162. plot = list.getIndex(list, 0);
  2163. plot_id = plot.getId(plot);
  2164. }
  2165. return plot_id;
  2166. }
  2167. function plot.getIdListFromLocation(location) {
  2168. list = plot.get(location);
  2169. for(i = 0; i < list.getSize(list); i++) {
  2170. plot = list.getIndex(list, i);
  2171. list.setIndex(list, i, plot.getId(plot));
  2172. }
  2173. return list;
  2174. }
  2175. function plot.addPlayer(plot, player_name) {
  2176. list = plot.getOwners(plot);
  2177. uuid = player.getUuid(player_name);
  2178. if(!list.contains(list, uuid)) {
  2179. list.add(list, uuid);
  2180. }
  2181. }
  2182. function plot.removePlayer(plot, player_name) {
  2183. list = plot.getOwners(plot);
  2184. uuid = player.getUuid(player_name);
  2185. list.remove(list, uuid);
  2186. player_id = player.getId(player.getUuid(player_name));
  2187. plot.removeRank(plot, player_id);
  2188. }
  2189. function plot.getOwnersString(plot) {
  2190. list = plot.getOwners(plot);
  2191. if(list.getSize(list) == 0) {
  2192. return "";
  2193. }
  2194. owners_list = list.new();
  2195. for(i = 0; i < list.getSize(list); i++) {
  2196. list.add(owners_list, player.getName(list.getIndex(list, i)));
  2197. }
  2198. return text.concatList(owners_list, " / ", 0, list.getSize(owners_list) - 1);
  2199. }
  2200. function plot.isLeader(plot, player_or_id) {
  2201. return plot.getRank(plot, player_or_id) == "leader";
  2202. }
  2203. function plot.getLeaderName(plot) {
  2204. plot_leader_id = plot.getLeaderId(plot);
  2205. if(plot_leader_id == null) {
  2206. return "";
  2207. }
  2208. return player.getNameFromId(plot_leader_id);
  2209. }
  2210. function plot.getLeaderId(plot) {
  2211. plot_id = plot.getId(plot);
  2212. stmt = databank.prepare("SELECT player_id FROM plotranks WHERE plot_id = ? AND rank = ?;");
  2213. databank.setInt(stmt, 1, plot_id);
  2214. databank.setString(stmt, 2, "leader");
  2215. result = databank.execute(stmt);
  2216. while(databank.next(result)) {
  2217. player_id = databank.getInt(result, 1);
  2218. }
  2219. databank.close(result);
  2220. databank.close(stmt);
  2221. return player_id;
  2222. }
  2223. function plot.setLeader(plot, player_or_id) {
  2224. plot.setRank(plot, player_or_id, "leader");
  2225. }
  2226. function plot.isMod(plot, player_or_id) {
  2227. return plot.getRank(plot, player_or_id) == "mod";
  2228. }
  2229. function plot.getMods(plot) {
  2230. list = list.new();
  2231. plot_id = plot.getId(plot);
  2232. stmt = databank.prepare("SELECT player_id FROM plotranks WHERE plot_id = ? AND rank = ?;");
  2233. databank.setInt(stmt, 1, plot_id);
  2234. databank.setString(stmt, 2, "mod");
  2235. result = databank.execute(stmt);
  2236. while(databank.next(result)) {
  2237. list.add(list, databank.getInt(result, 1));
  2238. }
  2239. databank.close(result);
  2240. databank.close(stmt);
  2241. return list;
  2242. }
  2243. function plot.setMod(plot, player_or_id) {
  2244. plot.setRank(plot, player_or_id, "mod");
  2245. }
  2246. function plot.canOpenChests(plot, player_or_id) {
  2247. return plot.getRank(plot, player_or_id) == "chest";
  2248. }
  2249. function plot.setChest(plot, player_or_id) {
  2250. plot.setRank(plot, player_or_id, "chest");
  2251. }
  2252. function plot.getChestRanks(plot) {
  2253. list = list.new();
  2254. plot_id = plot.getId(plot);
  2255. stmt = databank.prepare("SELECT player_id FROM plotranks WHERE plot_id = ? AND rank = ?;");
  2256. databank.setInt(stmt, 1, plot_id);
  2257. databank.setString(stmt, 2, "chest");
  2258. result = databank.execute(stmt);
  2259. while(databank.next(result)) {
  2260. list.add(list, databank.getInt(result, 1));
  2261. }
  2262. databank.close(result);
  2263. databank.close(stmt);
  2264. return list;
  2265. }
  2266. function plot.getRank(plot, player_or_id) {
  2267. if(isPlayer(player_or_id)) {
  2268. player_id = player.getId(player_or_id);
  2269. } else {
  2270. player_id = player_or_id;
  2271. }
  2272. plot_id = plot.getId(plot);
  2273. stmt = databank.prepare("SELECT rank FROM plotranks WHERE player_id = ? AND plot_id = ?;");
  2274. databank.setInt(stmt, 1, player_id);
  2275. databank.setInt(stmt, 2, plot_id);
  2276. result = databank.execute(stmt);
  2277. while(databank.next(result)) {
  2278. rank = databank.getString(result, 1);
  2279. }
  2280. databank.close(result);
  2281. databank.close(stmt);
  2282. return rank;
  2283. }
  2284. function plot.setRank(plot, player_or_id, rank) {
  2285. if(isPlayer(player_or_id)) {
  2286. player_id = player.getId(player_or_id);
  2287. } else {
  2288. player_id = player_or_id;
  2289. }
  2290. plot_id = plot.getId(plot);
  2291. stmt = databank.prepare("INSERT INTO plotranks (plot_id, player_id, rank) VALUES (?,?,?) ON DUPLICATE KEY UPDATE rank = ?");
  2292. databank.setInt(stmt, 1, plot_id);
  2293. databank.setInt(stmt, 2, player_id);
  2294. databank.setString(stmt, 3, rank);
  2295. databank.setString(stmt, 4, rank);
  2296. databank.workerExecute(stmt);
  2297. }
  2298. function plot.removeRank(plot, player_or_id) {
  2299. if(isPlayer(player_or_id)) {
  2300. player_id = player.getId(player_or_id);
  2301. } else {
  2302. player_id = player_or_id;
  2303. }
  2304. plot_id = plot.getId(plot);
  2305. stmt = databank.prepare("DELETE FROM plotranks WHERE player_id = ? AND plot_id = ?;");
  2306. databank.setInt(stmt, 1, player_id);
  2307. databank.setInt(stmt, 2, plot_id);
  2308. databank.workerExecute(stmt);
  2309. }
  2310. function plot.transferRanks(old_plot_id, new_plot_id) {
  2311. stmt = databank.prepare("UPDATE plotranks SET plot_id = ? WHERE plot_id = ?;");
  2312. databank.setInt(stmt, 1, new_plot_id);
  2313. databank.setInt(stmt, 2, old_plot_id);
  2314. databank.workerExecute(stmt);
  2315. }
  2316. function plot.removeAllPlayers(plot) {
  2317. list = plot.getOwners(plot);
  2318. iter = list.iterator(list);
  2319. while(hasNext(iter)) {
  2320. plot.removeRank(plot, player.getId(next(iter)));
  2321. }
  2322. }
  2323. function plot.setEdges(plot, location1, location2) {
  2324. //Alte Daten abrufen
  2325. plot_name = plot.getName(plot);
  2326. list = plot.getOwners(plot);
  2327. flags = plot.getFlags(plot);
  2328. //Neues Plot erstellen und altes Plot löschen
  2329. new_plot = plot.add(location1, location2);
  2330. plot.remove(plot, loc.getWorld(location1));
  2331. //Alte Daten auf neuem Plot setzen
  2332. plot.transferRanks(plot.getId(plot), plot.getId(new_plot));
  2333. plot.setName(new_plot, plot_name);
  2334. new_list = plot.getOwners(new_plot);
  2335. for(i = 0; i < list.getSize(list); i++) {
  2336. list.add(new_list, list.getIndex(list, i));
  2337. }
  2338. plot.setFlags(new_plot, flags, true);
  2339. return new_plot;
  2340. }
  2341. function getFlags(plot, getActive) { //getActive = true means getActiveFlags
  2342. flags = plot.getFlags(plot);
  2343. flags_true = list.new();
  2344. flags_false = list.new();
  2345. array = array.new(2);
  2346. array[0] = 512;
  2347. array[1] = "SUB_PLOT_FLAG";
  2348. if(flags >= 512) {
  2349. list.add(flags_true, array);
  2350. flags -= 512;
  2351. } else {
  2352. list.add(flags_false, array);
  2353. }
  2354. array = array.new(2);
  2355. array[0] = 256;
  2356. array[1] = "FREE_FLAG";
  2357. if(flags >= 256) {
  2358. list.add(flags_true, array);
  2359. flags -= 256;
  2360. } else {
  2361. list.add(flags_false, array);
  2362. }
  2363. array = array.new(2);
  2364. array[0] = 128;
  2365. array[1] = "CITY_FLAG";
  2366. if(flags >= 128) {
  2367. list.add(flags_true, array);
  2368. flags -= 128;
  2369. } else {
  2370. list.add(flags_false, array);
  2371. }
  2372. array = array.new(2);
  2373. array[0] = 64;
  2374. array[1] = "EXPLOSION_FLAG";
  2375. if(flags >= 64) {
  2376. list.add(flags_true, array);
  2377. flags -= 64;
  2378. } else {
  2379. list.add(flags_false, array);
  2380. }
  2381. array = array.new(2);
  2382. array[0] = 32;
  2383. array[1] = "ENTITY_INTERACT_FLAG";
  2384. if(flags >= 32) {
  2385. list.add(flags_true, array);
  2386. flags -= 32;
  2387. } else {
  2388. list.add(flags_false, array);
  2389. }
  2390. array = array.new(2);
  2391. array[0] = 16;
  2392. array[1] = "BLOCK_INTERACT_FLAG";
  2393. if(flags >= 16) {
  2394. list.add(flags_true, array);
  2395. flags -= 16;
  2396. } else {
  2397. list.add(flags_false, array);
  2398. }
  2399. array = array.new(2);
  2400. array[0] = 8;
  2401. array[1] = "HIT_AMBIENT_FLAG";
  2402. if(flags >= 8) {
  2403. list.add(flags_true, array);
  2404. flags -= 8;
  2405. } else {
  2406. list.add(flags_false, array);
  2407. }
  2408. array = array.new(2);
  2409. array[0] = 4;
  2410. array[1] = "BUCKET_FLAG";
  2411. if(flags >= 4) {
  2412. list.add(flags_true, array);
  2413. flags -= 4;
  2414. } else {
  2415. list.add(flags_false, array);
  2416. }
  2417. array = array.new(2);
  2418. array[0] = 2;
  2419. array[1] = "BREAK_FLAG";
  2420. if(flags >= 2) {
  2421. list.add(flags_true, array);
  2422. flags -= 2;
  2423. } else {
  2424. list.add(flags_false, array);
  2425. }
  2426. array = array.new(2);
  2427. array[0] = 1;
  2428. array[1] = "PLACE_FLAG";
  2429. if(flags >= 1) {
  2430. list.add(flags_true, array);
  2431. } else {
  2432. list.add(flags_false, array);
  2433. }
  2434. if(getActive) {
  2435. return flags_true;
  2436. } else {
  2437. return flags_false;
  2438. }
  2439. }
  2440. function plot.getType(plot) {
  2441. if(plot.isCity(plot)) {
  2442. type = "§4[§cCity§4]";
  2443. } elseif(plot.isFree(plot)) {
  2444. type = "§3[§bFree§3]";
  2445. } elseif(plot.isSub(plot)) {
  2446. type = "§6[§eSubPlot§6]";
  2447. } else {
  2448. type = "§6[§ePlot§6]";
  2449. }
  2450. return type;
  2451. }
  2452. function plot.isPlot(plot) {
  2453. return !plot.isCity(plot) && !plot.isFree(plot) && !plot.isSub(plot);
  2454. }
  2455. function plot.isExplosive(plot) {
  2456. return plot.hasFlags(plot, 64);
  2457. }
  2458. function plot.isCity(plot) {
  2459. return plot.hasFlags(plot, 128);
  2460. }
  2461. function plot.isFree(plot) {
  2462. return plot.hasFlags(plot, 256);
  2463. }
  2464. function plot.isSub(plot) {
  2465. return plot.hasFlags(plot, 512);
  2466. }
  2467. function plot.setCity(plot, boolean) {
  2468. plot.setFlags(plot, 128, boolean);
  2469. }
  2470. function plot.setFree(plot, boolean) {
  2471. plot.setFlags(plot, 256, boolean);
  2472. plot.setFlags(plot, 512, !boolean); //Sub-Plot entfernen
  2473. }
  2474. function plot.setSub(plot, boolean) {
  2475. plot.setFlags(plot, 512, boolean);
  2476. plot.setFlags(plot, 256, !boolean); //Free-Plot entfernen
  2477. }
  2478. //--------------------------------------------------
  2479. //Skill-Utils
  2480. //--------------------------------------------------
  2481. function skill.getAmount(player_or_id, tech_name) {
  2482. config = playerdata.getSurvival(player_or_id);
  2483. return config.getDouble(config, tech_name, 0);
  2484. }
  2485. function skill.setAmount(player_or_id, tech_name, amount) {
  2486. config = playerdata.getSurvival(player_or_id);
  2487. config.set(config, tech_name, amount);
  2488. config.saveAsync(config);
  2489. }
  2490. function skill.addAmount(player_or_id, tech_name, amount) {
  2491. config = playerdata.getSurvival(player_or_id);
  2492. config.set(config, tech_name, config.getDouble(config, tech_name, 0) + amount);
  2493. config.saveAsync(config);
  2494. }
  2495. function skill.isActivated(player_or_id, tech_name) {
  2496. config = playerdata.getSurvival(player_or_id);
  2497. return config.getBool(config, concat(tech_name, ".active"), true);
  2498. }
  2499. function skill.setActivated(player_or_id, tech_name, bool) {
  2500. config = playerdata.getSurvival(player_or_id);
  2501. config.set(config, concat(tech_name, ".active"), bool);
  2502. }
  2503. function skill.add(skill_name, tech_name, item, description, cost, permanent, active, toggleable) {
  2504. skill = array.new(8);
  2505. skill[0] = skill_name;
  2506. skill[1] = tech_name;
  2507. skill[2] = item;
  2508. skill[3] = description;
  2509. skill[4] = cost;
  2510. skill[5] = permanent;
  2511. skill[6] = active;
  2512. skill[7] = toggleable;
  2513. list.add(getScriptVar("skills"), skill);
  2514. }
  2515. function skill.get(tech_name) {
  2516. skill_list = getScriptVar("skills");
  2517. for(i = 0; i < list.getSize(skill_list); i++) {
  2518. array = list.getIndex(skill_list, i);
  2519. temp_tech_name = array[1];
  2520. if(temp_tech_name == tech_name) {
  2521. return array;
  2522. }
  2523. }
  2524. }
  2525. function skill.getShopItem(player, tech_name) {
  2526. if(tech_name == null) {
  2527. return read.item("minecraft:air");
  2528. }
  2529. skill = skill.get(tech_name);
  2530. amount = skill.getAmount(player, tech_name);
  2531. permanent = skill[5];
  2532. if(permanent) {
  2533. if(amount == 0) {
  2534. text_property = concat("§fBought: §cNo §f(Permanent)");
  2535. } else {
  2536. text_property = concat("§fBought: §aYes §f(Permanent)");
  2537. }
  2538. } else {
  2539. text_property = concat("§fAmount you have: §e", text.number(amount));
  2540. }
  2541. active = skill[6];
  2542. if(active) {
  2543. type = "§fActive skill";
  2544. } else {
  2545. type = "§fPassive skill";
  2546. }
  2547. toggleable = skill[7];
  2548. if(toggleable) {
  2549. if(skill.isActivated(player, tech_name)) {
  2550. tog = "§fToggleable: §aActive";
  2551. } else {
  2552. tog = "§fToggleable: §cInactive";
  2553. }
  2554. } else {
  2555. tog = "§fNot toggleable";
  2556. }
  2557. skill_name = skill.getName(tech_name);
  2558. item = read.item(skill[2], 1, concat("§e§o", skill_name), concat("§fCost: §e", text.number(skill[4])), skill[3], type, tog, text_property);
  2559. return item;
  2560. }
  2561. function skill.getName(tech_name) {
  2562. skill_list = getScriptVar("skills");
  2563. for(i = 0; i < list.getSize(skill_list); i++) {
  2564. array = list.getIndex(skill_list, i);
  2565. temp_tech_name = array[1];
  2566. if(temp_tech_name == tech_name) {
  2567. return array[0];
  2568. }
  2569. }
  2570. }
  2571. function skill.getTechName(skill_name) {
  2572. skill_list = getScriptVar("skills");
  2573. for(i = 0; i < list.getSize(skill_list); i++) {
  2574. array = list.getIndex(skill_list, i);
  2575. temp_skill_name = array[0];
  2576. if(temp_skill_name == skill_name) {
  2577. return array[1];
  2578. }
  2579. }
  2580. }
  2581. function skill.getItem(skill_name) {
  2582. skill_list = getScriptVar("skills");
  2583. for(i = 0; i < list.getSize(skill_list); i++) {
  2584. array = list.getIndex(skill_list, i);
  2585. temp_skill_name = array[0];
  2586. if(temp_skill_name == skill_name) {
  2587. return array[2];
  2588. }
  2589. }
  2590. }
  2591. function skill.getDescription(skill_name) {
  2592. skill_list = getScriptVar("skills");
  2593. for(i = 0; i < list.getSize(skill_list); i++) {
  2594. array = list.getIndex(skill_list, i);
  2595. temp_skill_name = array[0];
  2596. if(temp_skill_name == skill_name) {
  2597. return array[3];
  2598. }
  2599. }
  2600. }
  2601. function skill.getCost(skill_name) {
  2602. skill_list = getScriptVar("skills");
  2603. for(i = 0; i < list.getSize(skill_list); i++) {
  2604. array = list.getIndex(skill_list, i);
  2605. temp_skill_name = array[0];
  2606. if(temp_skill_name == skill_name) {
  2607. return array[4];
  2608. }
  2609. }
  2610. }
  2611. function skill.isPermanent(skill_name) {
  2612. skill_list = getScriptVar("skills");
  2613. for(i = 0; i < list.getSize(skill_list); i++) {
  2614. array = list.getIndex(skill_list, i);
  2615. temp_skill_name = array[0];
  2616. if(temp_skill_name == skill_name) {
  2617. return array[5];
  2618. }
  2619. }
  2620. }
  2621. function skill.isActive(skill_name) {
  2622. skill_list = getScriptVar("skills");
  2623. for(i = 0; i < list.getSize(skill_list); i++) {
  2624. array = list.getIndex(skill_list, i);
  2625. temp_skill_name = array[0];
  2626. if(temp_skill_name == skill_name) {
  2627. return array[6];
  2628. }
  2629. }
  2630. }
  2631. function skill.isToggleable(skill_name) {
  2632. skill_list = getScriptVar("skills");
  2633. for(i = 0; i < list.getSize(skill_list); i++) {
  2634. array = list.getIndex(skill_list, i);
  2635. temp_skill_name = array[0];
  2636. if(temp_skill_name == skill_name) {
  2637. return array[7];
  2638. }
  2639. }
  2640. }
  2641. 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) {
  2642. inv = inv.new("333333333333333333");
  2643. inv.setItem(inv, 0, skill.getShopItem(player, tech_name1));
  2644. inv.setItem(inv, 1, skill.getShopItem(player, tech_name2));
  2645. inv.setItem(inv, 2, skill.getShopItem(player, tech_name3));
  2646. inv.setItem(inv, 3, skill.getShopItem(player, tech_name4));
  2647. inv.setItem(inv, 4, skill.getShopItem(player, tech_name5));
  2648. inv.setItem(inv, 5, skill.getShopItem(player, tech_name6));
  2649. inv.setItem(inv, 6, skill.getShopItem(player, tech_name7));
  2650. inv.setItem(inv, 7, skill.getShopItem(player, tech_name8));
  2651. inv.setItem(inv, 8, skill.getShopItem(player, tech_name9));
  2652. inv.setItem(inv, 9, skill.getShopItem(player, tech_name10));
  2653. inv.setItem(inv, 10, skill.getShopItem(player, tech_name11));
  2654. inv.setItem(inv, 11, skill.getShopItem(player, tech_name12));
  2655. inv.setItem(inv, 12, skill.getShopItem(player, tech_name13));
  2656. inv.setItem(inv, 13, skill.getShopItem(player, tech_name14));
  2657. inv.setItem(inv, 14, skill.getShopItem(player, tech_name15));
  2658. inv.setItem(inv, 15, skill.getShopItem(player, tech_name16));
  2659. inv.setItem(inv, 16, skill.getShopItem(player, tech_name17));
  2660. inv.setItem(inv, 17, skill.getShopItem(player, tech_name18));
  2661. inv.open(inv, player, "Skillshop");
  2662. }
  2663. function skill.showAll(player) {
  2664. inv = inv.new("333333333333333333333333333");
  2665. skill_list = getScriptVar("skills");
  2666. for(i = 0; i < list.getSize(skill_list); i++) {
  2667. a = list.getIndex(skill_list, i);
  2668. tech_name = a[1];
  2669. inv.setItem(inv, i, skill.getShopItem(player, tech_name));
  2670. }
  2671. inv.open(inv, player, "Skills");
  2672. }
  2673. //--------------------------------------------------
  2674. //Loc-Utils
  2675. //--------------------------------------------------
  2676. function loc.getStringColon(loc) {
  2677. world_name = world.getName(loc.getWorld(loc));
  2678. x = text.number(loc.getX(loc));
  2679. y = text.number(loc.getY(loc));
  2680. z = text.number(loc.getZ(loc));
  2681. return concat(world_name, ":", x, ":", y, ":", z);
  2682. }
  2683. function loc.getStringSpace(loc) {
  2684. world_name = world.getName(loc.getWorld(loc));
  2685. x = text.number(loc.getX(loc));
  2686. y = text.number(loc.getY(loc));
  2687. z = text.number(loc.getZ(loc));
  2688. return concat(world_name, " ", x, " ", y, " ", z);
  2689. }
  2690. function loc.isSameWorld(loc1, loc2) {
  2691. return world.getName(loc.getWorld(loc1)) == world.getName(loc.getWorld(loc2));
  2692. }
  2693. function loc.getSubPlot(location) {
  2694. list = plot.get(location);
  2695. iter = list.iterator(list);
  2696. while(hasNext(iter)) {
  2697. plot = next(iter);
  2698. if(plot.isSub(plot)) {
  2699. return plot;
  2700. }
  2701. }
  2702. return null;
  2703. }
  2704. function loc.isCity(location) {
  2705. list = plot.get(location);
  2706. iter = list.iterator(list);
  2707. while(hasNext(iter)) {
  2708. plot = next(iter);
  2709. if(plot.isCity(plot)) {
  2710. return true;
  2711. }
  2712. }
  2713. return false;
  2714. }
  2715. function loc.hasPlotId(location, plot_id) {
  2716. return list.contains(plot.getIdListFromLocation(location), plot_id);
  2717. }
  2718. function loc.hasPlotName(location, plot_name) {
  2719. list = plot.get(location);
  2720. iter = list.iterator(list);
  2721. while(hasNext(iter)) {
  2722. plot = next(iter);
  2723. if(plot.getName(plot) == plot_name) {
  2724. return true;
  2725. }
  2726. }
  2727. return false;
  2728. }
  2729. function loc.isAir(location) {
  2730. type = block.getType(location);
  2731. return type == "minecraft:air" || type == "minecraft:cave_air";
  2732. }
  2733. function loc.isInSurvWorld(location) {
  2734. world_name = world.getName(loc.getWorld(location));
  2735. if(world_name == "overworld") {
  2736. return true;
  2737. } elseif(world_name == "the_end") {
  2738. return true;
  2739. } elseif(world_name == "the_nether") {
  2740. return true;
  2741. }
  2742. return false;
  2743. }
  2744. function loc.isInGamesWorld(location) {
  2745. return loc.getWorld(location) == world.getGames();
  2746. }
  2747. function loc.isInCreativeWorld(location) {
  2748. return loc.getWorld(location) == world.getCreative();
  2749. }
  2750. function loc.isInStoryWorld(location) {
  2751. return loc.getWorld(location) == world.getStory();
  2752. }
  2753. function loc.round(location) {
  2754. world = loc.getWorld(location);
  2755. x = math.round(loc.getX(location));
  2756. y = math.round(loc.getY(location));
  2757. z = math.round(loc.getZ(location));
  2758. return loc.new(world, x, y, z);
  2759. }
  2760. //--------------------------------------------------
  2761. //Survival-Utils
  2762. //--------------------------------------------------
  2763. function living.setAi(bool) {
  2764. config = getScriptVar("server_config");
  2765. config.set(config, "spawnWithAi", bool);
  2766. config.saveAsync(config);
  2767. }
  2768. function living.getAi() {
  2769. config = getScriptVar("server_config");
  2770. return config.getBool(config, "spawnWithAi", true);
  2771. }
  2772. //--------------------------------------------------
  2773. //Afk-Utils
  2774. //--------------------------------------------------
  2775. function player.isAfk(player) {
  2776. player_uuid = player.getUuid(player);
  2777. afk_map = getScriptVar("afk_map");
  2778. return map.contains(afk_map, player_uuid);
  2779. }
  2780. function player.setAfk(player, boolean) {
  2781. player_uuid = player.getUuid(player);
  2782. afk_map = getScriptVar("afk_map");
  2783. if(boolean) {
  2784. map.add(afk_map, player_uuid, loc.getYaw(entity.getLocation(player)));
  2785. } else {
  2786. map.remove(afk_map, player_uuid);
  2787. }
  2788. }
  2789. //--------------------------------------------------
  2790. //PvP-Utils
  2791. //--------------------------------------------------
  2792. function hasPvpOn(player_or_id) {
  2793. config = playerdata.getSurvival(player_or_id);
  2794. return config.getBool(config, "pvp", false);
  2795. }
  2796. function setPvp(player_or_id, bool) {
  2797. config = playerdata.getSurvival(player_or_id);
  2798. config.set(config, "pvp", bool);
  2799. config.saveAsync(config);
  2800. }
  2801. //--------------------------------------------------
  2802. //Rank-Utils
  2803. //--------------------------------------------------
  2804. function getRank(player_or_id) {
  2805. config = playerdata.getSurvival(player_or_id);
  2806. return config.getString(config, "rank", "§3User");
  2807. }
  2808. function setRank(player_or_id, rank) {
  2809. rank = text.replace(rank, "&", "§");
  2810. config = playerdata.getSurvival(player_or_id);
  2811. config.set(config, "rank", rank);
  2812. config.saveAsync(config);
  2813. }
  2814. function offerRank(player, tech_name) {
  2815. rank = rank.getFromTechName(tech_name);
  2816. player.speak(player, "§6Commands", "New rank available: ", text.hover(text.click(concat("[§", rank, "§r]"), concat("/setrank ", player.getName(player), " &", rank)), "Click to set"));
  2817. }
  2818. function rank.offerClan(clan_id, tech_name) {
  2819. leader_uuid = clan.getLeader(clan_id);
  2820. leader = player.get(leader_uuid);
  2821. if(leader == null) {
  2822. mail.send("marvinius", player.getName(leader_uuid), concat("New rank available: ", tech_name));
  2823. } else {
  2824. offerRank(leader, tech_name);
  2825. }
  2826. }
  2827. function rank.checkCriteria(player, tech_name) {
  2828. //Playtime
  2829. if(tech_name == "rank.newcomer") {
  2830. return player.getTotalPlaytime(player) >= 1200; //20 Stunden
  2831. }
  2832. if(tech_name == "rank.frequenter") {
  2833. return player.getTotalPlaytime(player) >= 6000; //100 Stunden
  2834. }
  2835. if(tech_name == "rank.legend") {
  2836. return player.getTotalPlaytime(player) >= 42000; //700 Stunden
  2837. }
  2838. //Adventure
  2839. if(tech_name == "rank.adventurer") {
  2840. return player.getAdventureAmounts(player) >= 1;
  2841. }
  2842. if(tech_name == "rank.explorer") {
  2843. return player.getAdventureAmounts(player) >= 5;
  2844. }
  2845. if(tech_name == "rank.pioneer") {
  2846. return player.getAdventureAmounts(player) >= 10;
  2847. }
  2848. //Clans
  2849. if(tech_name == "rank.commander") {
  2850. if(player.isClanLeader(player)) {
  2851. clan_id = player.getClanId(player);
  2852. return clan.getMembersAmount(clan_id) >= 5;
  2853. }
  2854. }
  2855. if(tech_name == "rank.chief") {
  2856. if(player.isClanLeader(player)) {
  2857. clan_id = player.getClanId(player);
  2858. return clan.getMembersAmount(clan_id) >= 10;
  2859. }
  2860. }
  2861. if(tech_name == "rank.lord") {
  2862. if(player.isClanLeader(player)) {
  2863. clan_id = player.getClanId(player);
  2864. return clan.getMembersAmount(clan_id) >= 15;
  2865. }
  2866. }
  2867. //Quests
  2868. if(tech_name == "rank.volunteer") {
  2869. return quest.getCounter(player) >= 15;
  2870. }
  2871. if(tech_name == "rank.friend") {
  2872. return quest.getCounter(player) >= 50;
  2873. }
  2874. if(tech_name == "rank.altruist") {
  2875. return quest.getCounter(player) >= 500;
  2876. }
  2877. //Plots
  2878. if(tech_name == "rank.settler") {
  2879. return player.usedHisFreePlot(player);
  2880. }
  2881. if(tech_name == "rank.colonizer") {
  2882. return player.hasBigPlotCreated(player);
  2883. }
  2884. if(tech_name == "rank.major") {
  2885. return player.hasPlotRaised(player);
  2886. }
  2887. //Team
  2888. if(tech_name == "rank.owner") {
  2889. return perm.has(player, "isOwner");
  2890. }
  2891. if(tech_name == "rank.admin") {
  2892. return perm.has(player, "isAdmin");
  2893. }
  2894. if(tech_name == "rank.builder") {
  2895. return perm.has(player, "isBuilder");
  2896. }
  2897. if(tech_name == "rank.dev") {
  2898. return perm.has(player, "isDev");
  2899. }
  2900. if(tech_name == "rank.moderator") {
  2901. return perm.has(player, "isMod");
  2902. }
  2903. if(tech_name == "rank.supporter") {
  2904. return perm.has(player, "isSupporter");
  2905. }
  2906. //Other
  2907. if(tech_name == "rank.vip") {
  2908. return perm.has(player, "isVIP");
  2909. }
  2910. if(tech_name == "rank.influencer") {
  2911. return perm.has(player, "isYT") || perm.has(player, "isStreamer");
  2912. }
  2913. if(tech_name == "rank.sponsor") {
  2914. return perm.has(player, "isSponsor");
  2915. }
  2916. if(tech_name == "rank.user") {
  2917. return true;
  2918. }
  2919. return perm.has(player, "setrank.other");
  2920. }
  2921. function rank.getRankArray() {
  2922. return getScriptVar("ranks");
  2923. }
  2924. function rank.getFromTechName(tech_name) {
  2925. a = rank.getRankArray();
  2926. a_size = array.getSize(a);
  2927. for(i = 0; i < a_size; i++) {
  2928. if(a[i, 0] == tech_name) {
  2929. return a[i, 1];
  2930. }
  2931. }
  2932. return null;
  2933. }
  2934. function rank.getTechName(rank) {
  2935. a = rank.getRankArray();
  2936. a_size = array.getSize(a);
  2937. for(i = 0; i < a_size; i++) {
  2938. if(a[i, 1] == rank) {
  2939. return a[i, 0];
  2940. }
  2941. }
  2942. return null;
  2943. }
  2944. function rank.choose(player, tech_name) {
  2945. rank = rank.getFromTechName(tech_name);
  2946. msg(player, text.click(concat(" [§", rank, "§r]"), concat("/setrank ", player.getName(player), " &", rank)));
  2947. }
  2948. function rank.showAll(player) {
  2949. a = rank.getRankArray();
  2950. a_size = array.getSize(a);
  2951. for(i = 0; i < a_size; i++) {
  2952. tech_name = a[i, 0];
  2953. if(rank.checkCriteria(player, tech_name)) {
  2954. rank.choose(player, tech_name);
  2955. }
  2956. }
  2957. }
  2958. //--------------------------------------------------
  2959. //Perm-Utils
  2960. //--------------------------------------------------
  2961. function givePerm(player_id, perm_id) {
  2962. stmt = databank.prepare("INSERT INTO playerperms (player_id, perm_id) VALUES (?,?);");
  2963. databank.setInt(stmt, 1, player_id);
  2964. databank.setInt(stmt, 2, perm_id);
  2965. databank.workerExecute(stmt);
  2966. perm.registerPlayer(player.getUuidFromID(player_id), perm_id);
  2967. }
  2968. function removePerm(player_id, perm_id) {
  2969. stmt = databank.prepare("DELETE FROM playerperms WHERE player_id = ? AND perm_id = ?;");
  2970. databank.setInt(stmt, 1, player_id);
  2971. databank.setInt(stmt, 2, perm_id);
  2972. databank.workerExecute(stmt);
  2973. perm.unregisterPlayer(player.getUuidFromID(player_id), perm_id);
  2974. }
  2975. function removeAllPermsTemporarly(player_id) {
  2976. perm.registerPlayer(player.getUuidFromID(player_id), 8);
  2977. permslist = getPermsFromPlayer(player_id);
  2978. for(i = 0; i < list.getSize(permslist); i++) {
  2979. perm_id = list.getIndex(permslist, i);
  2980. perm.unregisterPlayer(player.getUuidFromID(player_id), perm_id);
  2981. }
  2982. }
  2983. function reloadAllPerms(player_id) {
  2984. perm.unregisterPlayer(player.getUuidFromID(player_id), 8);
  2985. permslist = getPermsFromPlayer(player_id);
  2986. for(i = 0; i < list.getSize(permslist); i++) {
  2987. perm_id = list.getIndex(permslist, i);
  2988. perm.registerPlayer(player.getUuidFromID(player_id), perm_id);
  2989. }
  2990. }
  2991. function removeAllPerms(player_id) {
  2992. permslist = getPermsFromPlayer(player_id);
  2993. for(i = 0; i < list.getSize(permslist); i++) {
  2994. removePerm(player_id, list.getIndex(permslist, i));
  2995. }
  2996. }
  2997. function isAPermGroup(permstring) {
  2998. if(map.contains($permgroupsmap, text.toLowerCase(permstring))) {
  2999. return true;
  3000. }
  3001. return false;
  3002. }
  3003. function getPermsFromPlayer(player_id) {
  3004. permslist = list.new();
  3005. stmt = databank.prepare("SELECT perm_id FROM playerperms WHERE player_id = ?;");
  3006. databank.setInt(stmt, 1, player_id);
  3007. result = databank.execute(stmt);
  3008. while(databank.next(result)) {
  3009. list.add(permslist, databank.getInt(result, 1));
  3010. }
  3011. databank.close(result);
  3012. databank.close(stmt);
  3013. return permslist;
  3014. }
  3015. function hasPermAlready(player_id, perm_id) {
  3016. permslist = getPermsFromPlayer(player_id);
  3017. if(list.contains(permslist, perm_id)) {
  3018. return true;
  3019. } else {
  3020. return false;
  3021. }
  3022. }
  3023. function registerAllPerms() {
  3024. stmt = databank.prepare("SELECT * FROM playerperms;");
  3025. result = databank.execute(stmt);
  3026. while(databank.next(result)) {
  3027. player_id = databank.getInt(result, 1);
  3028. perm_id = databank.getInt(result, 2);
  3029. perm.registerPlayer(player.getUuidFromID(player_id), perm_id);
  3030. }
  3031. databank.close(result);
  3032. databank.close(stmt);
  3033. }
  3034. //--------------------------------------------------
  3035. //Nickname-Utils
  3036. //--------------------------------------------------
  3037. function player.setNickName(player, nickname) {
  3038. map.add(getScriptVar("nicknames"), player.getUuid(player), nickname);
  3039. }
  3040. function player.getNickName(player) {
  3041. return map.getOrDefault(getScriptVar("nicknames"), player.getUuid(player), player.getName(player));
  3042. }
  3043. function player.removeNickName(player) {
  3044. map.remove(getScriptVar("nicknames"), player.getUuid(player));
  3045. }
  3046. //--------------------------------------------------
  3047. //Mail-Utils
  3048. //--------------------------------------------------
  3049. function mail.send(from_name, to_name, message) {
  3050. server_config = getScriptVar("server_config");
  3051. mail_id = config.getDouble(server_config, "mail_id", 0) + 1;
  3052. config.set(server_config, "mail_id", mail_id);
  3053. config.saveAsync(server_config);
  3054. from_id = player.getId(player.getUuid(from_name));
  3055. to_id = player.getId(player.getUuid(to_name));
  3056. stmt = databank.prepare("INSERT INTO mails (mail_id, from_id, to_id, readed, time, message) VALUES (?, ?, ?, ?, ?, ?);");
  3057. databank.setInt(stmt, 1, mail_id);
  3058. databank.setInt(stmt, 2, from_id);
  3059. databank.setInt(stmt, 3, to_id);
  3060. databank.setBool(stmt, 4, false);
  3061. databank.setLong(stmt, 5, time.getMillis());
  3062. databank.setString(stmt, 6, message);
  3063. databank.workerExecute(stmt);
  3064. //Wenn Spieler online, dann Pushmeldung veranlassen
  3065. p = read.player(to_name);
  3066. if(p != null) {
  3067. msg.prefix(p, "§bMail", concat("§rYou´ve got a new mail from §b", from_name, "."));
  3068. }
  3069. }
  3070. function mail.checkForNew(player) {
  3071. stmt = databank.prepare("SELECT mail_id, from_id, time, message FROM mails WHERE to_id = ? AND readed = false;");
  3072. to_id = player.getId(player);
  3073. databank.setInt(stmt, 1, to_id);
  3074. result = databank.execute(stmt);
  3075. nextrow = databank.next(result);
  3076. if(!nextrow) {
  3077. databank.close(result);
  3078. databank.close(stmt);
  3079. return;
  3080. }
  3081. newmails = 0;
  3082. while(nextrow) {
  3083. newmails++;
  3084. nextrow = databank.next(result);
  3085. }
  3086. databank.close(result);
  3087. databank.close(stmt);
  3088. if(newmails > 0) {
  3089. if(newmails > 1) {
  3090. msg.prefix(player, "§bMail", concat("§rYou´ve got §b", text.number(newmails), "§r new mails."));
  3091. } else {
  3092. msg.prefix(player, "§bMail", "§rYou´ve got §b1 §rnew mail.");
  3093. }
  3094. }
  3095. }
  3096. //--------------------------------------------------
  3097. //Friend-Utils
  3098. //--------------------------------------------------
  3099. function friend.check(player_id, friend_id) {
  3100. stmt = databank.prepare("SELECT friend_id FROM friends WHERE player_id = ? AND friend_id = ?;");
  3101. databank.setInt(stmt, 1, player_id);
  3102. databank.setInt(stmt, 2, friend_id);
  3103. result = databank.execute(stmt);
  3104. temp = false;
  3105. while(databank.next(result)) {
  3106. temp = true;
  3107. }
  3108. databank.close(result);
  3109. databank.close(stmt);
  3110. return temp;
  3111. }
  3112. function friend.add(player_id, friend_id) {
  3113. nowtime = time.getMillis();
  3114. stmt1 = databank.prepare("INSERT INTO friends (player_id, friend_id, time) VALUES (?, ?, ?);");
  3115. databank.setInt(stmt1, 1, player_id);
  3116. databank.setInt(stmt1, 2, friend_id);
  3117. databank.setLong(stmt1, 3, nowtime);
  3118. databank.workerExecute(stmt1);
  3119. stmt2 = databank.prepare("INSERT INTO friends (player_id, friend_id, time) VALUES (?, ?, ?);");
  3120. databank.setInt(stmt2, 1, friend_id);
  3121. databank.setInt(stmt2, 2, player_id);
  3122. databank.setLong(stmt2, 3, nowtime);
  3123. databank.workerExecute(stmt2);
  3124. }
  3125. function friend.delete(player_id, friend_id) {
  3126. stmt1 = databank.prepare("DELETE FROM friends WHERE player_id = ? AND friend_id = ?;");
  3127. databank.setInt(stmt1, 1, player_id);
  3128. databank.setInt(stmt1, 2, friend_id);
  3129. databank.workerExecute(stmt1);
  3130. stmt2 = databank.prepare("DELETE FROM friends WHERE player_id = ? AND friend_id = ?;");
  3131. databank.setInt(stmt2, 1, friend_id);
  3132. databank.setInt(stmt2, 2, player_id);
  3133. databank.workerExecute(stmt2);
  3134. }
  3135. function friend.getList(player_id) {
  3136. list = list.new();
  3137. stmt = databank.prepare("SELECT friend_id FROM friends WHERE player_id = ?;");
  3138. databank.setInt(stmt, 1, player_id);
  3139. result = databank.execute(stmt);
  3140. while(databank.next(result)) {
  3141. friend_id = databank.getInt(result, 1);
  3142. list.add(list, player.getNameFromId(friend_id));
  3143. }
  3144. databank.close(result);
  3145. databank.close(stmt);
  3146. return list;
  3147. }
  3148. //--------------------------------------------------
  3149. //Clan-Utils
  3150. //--------------------------------------------------
  3151. function clan.getIdList() {
  3152. file = file.new("scripts/configs/clan_data");
  3153. if(file.exists(file) && file.isDirectory(file)) {
  3154. list = file.getList(file);
  3155. }
  3156. id_list = list.new();
  3157. iter = list.iterator(list);
  3158. while(hasNext(iter)) {
  3159. element = next(iter);
  3160. file_name = file.getName(element);
  3161. file_name = text.replace(file_name, ".0.snuvic", "");
  3162. list.add(id_list, read.number(file_name));
  3163. }
  3164. return id_list;
  3165. }
  3166. function clan.loadData() {
  3167. list = clan.getIdList();
  3168. iter = list.iterator(list);
  3169. map = map.new();
  3170. while(hasNext(iter)) {
  3171. clan_id = next(iter);
  3172. config = config.new("scripts/configs/clan_data", clan_id);
  3173. if(config.exists(config)) {
  3174. config.load(config);
  3175. }
  3176. map.add(map, clan_id, config);
  3177. }
  3178. setScriptVar("clan_data", map);
  3179. }
  3180. function clan.getData(clan_id) {
  3181. if(clan_id == null) {
  3182. snuvi.debug("script termed. clan_id was null");
  3183. term();
  3184. }
  3185. map = getScriptVar("clan_data");
  3186. config = map.get(map, clan_id);
  3187. if(config == null) {
  3188. config = config.new("scripts/configs/clan_data", clan_id);
  3189. if(config.exists(config)) {
  3190. config.load(config);
  3191. }
  3192. map.add(map, clan_id, config);
  3193. }
  3194. return config;
  3195. }
  3196. function clan.setName(clan_id, name) {
  3197. config = clan.getData(clan_id);
  3198. config.set(config, "name", name);
  3199. config.saveAsync(config);
  3200. }
  3201. function clan.getName(clan_id) {
  3202. config = clan.getData(clan_id);
  3203. temp = config.getString(config, "name", "null");
  3204. if(temp == "null") {
  3205. return null;
  3206. }
  3207. return temp;
  3208. }
  3209. function clan.setTag(clan_id, tag) {
  3210. config = clan.getData(clan_id);
  3211. config.set(config, "tag", tag);
  3212. config.saveAsync(config);
  3213. }
  3214. function clan.getTag(clan_id) {
  3215. config = clan.getData(clan_id);
  3216. temp = config.getString(config, "tag", "null");
  3217. if(temp == "null") {
  3218. return null;
  3219. }
  3220. return temp;
  3221. }
  3222. function clan.setMoney(clan_id, money) {
  3223. config = clan.getData(clan_id);
  3224. config.set(config, "money", money);
  3225. config.saveAsync(config);
  3226. }
  3227. function clan.getMoney(clan_id) {
  3228. config = clan.getData(clan_id);
  3229. return config.getDouble(config, "money", 0);
  3230. }
  3231. function clan.addMoney(clan_id, money) {
  3232. config = clan.getData(clan_id);
  3233. new_money = config.getDouble(config, "money", 0) + money;
  3234. config.set(config, "money", new_money);
  3235. config.saveAsync(config);
  3236. }
  3237. function clan.subMoney(clan_id, money) {
  3238. config = clan.getData(clan_id);
  3239. new_money = config.getDouble(config, "money", 0) - money;
  3240. config.set(config, "money", new_money);
  3241. config.saveAsync(config);
  3242. }
  3243. function clan.setSpawn(clan_id, location) {
  3244. config = clan.getData(clan_id);
  3245. config.set(config, "spawn", text.location(location));
  3246. config.saveAsync(config);
  3247. }
  3248. function clan.getSpawn(clan_id) {
  3249. config = clan.getData(clan_id);
  3250. location = config.getString(config, "spawn", "null");
  3251. if(location == "null") {
  3252. return null;
  3253. }
  3254. return read.location(location);
  3255. }
  3256. function clan.getIdFromName(name) {
  3257. list = clan.getIdList();
  3258. iter = list.iterator(list);
  3259. while(hasNext(iter)) {
  3260. clan_id = next(iter);
  3261. if(clan.getName(clan_id) == name) {
  3262. return clan_id;
  3263. }
  3264. }
  3265. return null;
  3266. }
  3267. function clan.getIdFromTag(clan_tag) {
  3268. list = clan.getIdList();
  3269. iter = list.iterator(list);
  3270. while(hasNext(iter)) {
  3271. clan_id = next(iter);
  3272. if(clan.getTag(clan_id) == clan_tag) {
  3273. return clan_id;
  3274. }
  3275. }
  3276. return null;
  3277. }
  3278. function clan.isExistingTag(clan_tag) {
  3279. return !(clan.getIdFromTag(clan_tag) == null);
  3280. }
  3281. function clan.isExistingName(name) {
  3282. return !(clan.getIdFromName(name) == null);
  3283. }
  3284. function clan.getNextFreeId() {
  3285. server_config = getScriptVar("server_config");
  3286. id = config.getDouble(server_config, "clan.id.next", 0) + 1;
  3287. config.set(server_config, "clan.id.next", id);
  3288. config.saveAsync(server_config);
  3289. return id;
  3290. }
  3291. function clan.create(name, tag) {
  3292. clan_id = clan.getNextFreeId();
  3293. config = clan.getData(clan_id);
  3294. config.set(config, "name", name);
  3295. config.set(config, "tag", tag);
  3296. config.set(config, "members", 0);
  3297. config.save(config);
  3298. return clan_id;
  3299. }
  3300. function clan.getLeader(clan_id) {
  3301. list = clan.getMembersList(clan_id);
  3302. iter = list.iterator(list);
  3303. while(hasNext(iter)) {
  3304. player_uuid = next(iter);
  3305. player_id = player.getId(player_uuid);
  3306. if(player.isClanLeader(player_id)) {
  3307. return player_uuid;
  3308. }
  3309. }
  3310. return null;
  3311. }
  3312. function clan.getMembersAmount(clan_id) {
  3313. config = clan.getData(clan_id);
  3314. return config.getDouble(config, "members", 0);
  3315. }
  3316. function clan.setMembersAmount(clan_id, amount) {
  3317. config = clan.getData(clan_id);
  3318. config.set(config, "members", amount);
  3319. config.saveAsync(config);
  3320. }
  3321. function clan.addMember(clan_id, player_or_id, role) {
  3322. //Player
  3323. player.setClanId(player_or_id, clan_id);
  3324. player.setClanRole(player_or_id, role);
  3325. //Clan
  3326. new_amount = clan.getMembersAmount(clan_id) + 1;
  3327. if(isPlayer(player_or_id)) {
  3328. player_uuid = player.getUuid(player_or_id);
  3329. } else {
  3330. player_uuid = player.getUuidFromId(player_or_id);
  3331. }
  3332. config = clan.getData(clan_id);
  3333. config.set(config, text.concat("player_", new_amount), text(player_uuid));
  3334. config.set(config, "members", new_amount);
  3335. config.saveAsync(config);
  3336. }
  3337. function clan.removeMember(clan_id, player_or_id) {
  3338. //Player
  3339. player.setClanId(player_or_id, -1);
  3340. player.setClanRole(player_or_id, "null");
  3341. if(isPlayer(player_or_id)) {
  3342. player_uuid = player.getUuid(player_or_id);
  3343. } else {
  3344. player_uuid = player.getUuidFromId(player_or_id);
  3345. }
  3346. //Clan
  3347. config = clan.getData(clan_id);
  3348. amount = config.getDouble(config, "members", 0);
  3349. for(i = 1; i <= amount; i++) {
  3350. if(config.getString(config, text.concat("player_", i), "null") == text(player_uuid)) {
  3351. break;
  3352. }
  3353. }
  3354. if(i != amount) {
  3355. config.set(config, text.concat("player_", i), config.getString(config, text.concat("player_", amount), "null"));
  3356. }
  3357. config.set(config, text.concat("player_", amount), "null");
  3358. config.set(config, "members", amount - 1);
  3359. config.saveAsync(config);
  3360. }
  3361. function clan.delete(clan_id) {
  3362. //Members
  3363. list = clan.getMembersList(clan_id);
  3364. iter = list.iterator(list);
  3365. while(hasNext(iter)) {
  3366. player_uuid = next(iter);
  3367. player_id = player.getId(player_uuid);
  3368. player.setClanId(player_id, -1);
  3369. player.setClanRole(player_id, "null");
  3370. }
  3371. //Clan
  3372. config.delete(clan.getData(clan_id));
  3373. map.remove(getScriptVar("clan_data"), clan_id);
  3374. }
  3375. function clan.getMembersList(clan_id) {
  3376. list = list.new();
  3377. config = clan.getData(clan_id);
  3378. amount = config.getDouble(config, "members", 0);
  3379. for(i = 1; i <= amount; i++) {
  3380. player_uuid = read.uuid(config.getString(config, text.concat("player_", i), "null"));
  3381. list.add(list, player_uuid);
  3382. }
  3383. return list;
  3384. }
  3385. function clan.updateHeadNames(clan_id) {
  3386. list = clan.getMembersList(clan_id);
  3387. iter = list.iterator(list);
  3388. while(hasNext(iter)) {
  3389. p = player.get(next(iter));
  3390. if(p != null) {
  3391. player.setHeadName(p);
  3392. }
  3393. }
  3394. }
  3395. function clan.msg(clan_id, message) {
  3396. list = clan.getMembersList(clan_id);
  3397. iter = list.iterator(list);
  3398. while(hasNext(iter)) {
  3399. p = player.get(next(iter));
  3400. if(p != null) {
  3401. msg.prefix(p, "§2Clan", message);
  3402. }
  3403. }
  3404. }
  3405. function clan.mail(clan_id, from_name, message) {
  3406. list = clan.getMembersList(clan_id);
  3407. iter = list.iterator(list);
  3408. while(hasNext(iter)) {
  3409. to_name = player.getName(next(iter));
  3410. mail.send(from_name, to_name, message);
  3411. }
  3412. }
  3413. //--------------------------------------------------
  3414. //Party-Utils
  3415. //--------------------------------------------------
  3416. function player.isInParty(player) {
  3417. return player.getPartyId(player) != null;
  3418. }
  3419. function party.same(player1, player2) {
  3420. return player.getPartyId(player1) == player.getPartyId(player2);
  3421. }
  3422. function player.isPartyLeader(player) {
  3423. return player.getPartyRank(player) == "Leader";
  3424. }
  3425. function player.isPartyLeaderOrMod(player) {
  3426. return player.getPartyRank(player) != "Player";
  3427. }
  3428. function player.getPartyId(player) {
  3429. return map.get(getScriptVar("party_ids"), player.getUuid(player));
  3430. }
  3431. function player.setPartyId(player, party_id) {
  3432. map.add(getScriptVar("party_ids"), player.getUuid(player), party_id);
  3433. }
  3434. function player.delPartyId(player) {
  3435. map.remove(getScriptVar("party_ids"), player.getUuid(player));
  3436. }
  3437. function player.getPartyRank(player) {
  3438. return map.get(getScriptVar("party_ranks"), player.getUuid(player));
  3439. }
  3440. function player.setPartyRank(player, rank) {
  3441. map.add(getScriptVar("party_ranks"), player.getUuid(player), rank);
  3442. }
  3443. function player.delPartyRank(player) {
  3444. map.remove(getScriptVar("party_ranks"), player.getUuid(player));
  3445. }
  3446. function party.getList(party_id) {
  3447. return map.get(getScriptVar("party_lists"), party_id);
  3448. }
  3449. function party.setList(party_id, list) {
  3450. map = getScriptVar("party_lists");
  3451. map.add(map, party_id, list);
  3452. setScriptVar("party_lists", map);
  3453. }
  3454. function party.addPlayer(party_id, player) {
  3455. list.add(party.getList(party_id), player.getUuid(player));
  3456. player.setPartyId(player, party_id);
  3457. }
  3458. //--------------------------------------------------
  3459. //Scheduler-Utils
  3460. //--------------------------------------------------
  3461. function scheduler.add(data_array) {
  3462. list.add(getScriptVar("scheduler_list"), data_array);
  3463. }
  3464. function scheduler.addFly(ticks, player, bool) {
  3465. a = array.new(4);
  3466. a[0] = 0;
  3467. a[1] = ticks;
  3468. a[2] = player;
  3469. a[3] = bool;
  3470. scheduler.add(a);
  3471. }
  3472. function scheduler.msgPrefix(ticks, player, prefix, message) {
  3473. a = array.new(5);
  3474. a[0] = 1;
  3475. a[1] = ticks;
  3476. a[2] = player;
  3477. a[3] = prefix;
  3478. a[4] = message;
  3479. scheduler.add(a);
  3480. }
  3481. function scheduler.msg(ticks, player, message) {
  3482. a = array.new(4);
  3483. a[0] = 2;
  3484. a[1] = ticks;
  3485. a[2] = player;
  3486. a[3] = message;
  3487. scheduler.add(a);
  3488. }
  3489. function scheduler.setBlock(ticks, location, item_string, block_update) {
  3490. a = array.new(5);
  3491. a[0] = 3;
  3492. a[1] = ticks;
  3493. a[2] = location;
  3494. a[3] = item_string;
  3495. a[4] = block_update;
  3496. scheduler.add(a);
  3497. }
  3498. function scheduler.questFinish(ticks, script, player) {
  3499. a = array.new(4);
  3500. a[0] = 4;
  3501. a[1] = ticks;
  3502. a[2] = script;
  3503. a[3] = player;
  3504. scheduler.add(a);
  3505. }
  3506. function scheduler.setBurning(ticks, entity, seconds) {
  3507. a = array.new(4);
  3508. a[0] = 5;
  3509. a[1] = ticks;
  3510. a[2] = entity;
  3511. a[3] = seconds;
  3512. scheduler.add(a);
  3513. }
  3514. function scheduler.spawnEntity(ticks, type, location) {
  3515. a = array.new(4);
  3516. a[0] = 6;
  3517. a[1] = ticks;
  3518. a[2] = type;
  3519. a[3] = location;
  3520. scheduler.add(a);
  3521. }
  3522. function scheduler.removeEntity(ticks, entity) {
  3523. a = array.new(3);
  3524. a[0] = 7;
  3525. a[1] = ticks;
  3526. a[2] = entity;
  3527. scheduler.add(a);
  3528. }
  3529. function scheduler.giveItem(ticks, player, item) {
  3530. a = array.new(4);
  3531. a[0] = 8;
  3532. a[1] = ticks;
  3533. a[2] = player;
  3534. a[3] = item;
  3535. scheduler.add(a);
  3536. }
  3537. function scheduler.giveSingleItem(ticks, player, item, boolean) {
  3538. a = array.new(5);
  3539. a[0] = 9;
  3540. a[1] = ticks;
  3541. a[2] = player;
  3542. a[3] = item;
  3543. a[4] = boolean;
  3544. scheduler.add(a);
  3545. }
  3546. //--------------------------------------------------
  3547. //Hawkeye-Utils
  3548. //--------------------------------------------------
  3549. function hawkeye.getData(timeFrom, timeTo, location, radius, events, players, order) {
  3550. base_query = "SELECT * FROM hawkeye WHERE ";
  3551. and_query = " AND ";
  3552. //Events
  3553. where_query = hawkeye.getEventQuery(events);
  3554. if(where_query == -1) {
  3555. return "False input at e:";
  3556. }
  3557. //Players
  3558. player_query = hawkeye.getPlayerQuery(players);
  3559. if(player_query == -1) {
  3560. return "False input at p:";
  3561. }
  3562. if(text.length(where_query) == 0) {
  3563. where_query = player_query;
  3564. } elseif(text.length(player_query) != 0) {
  3565. where_query = concat(where_query, and_query, player_query);
  3566. }
  3567. //Location
  3568. location_query = hawkeye.getLocationQuery(location, radius);
  3569. if(text.length(where_query) == 0) {
  3570. where_query = location_query;
  3571. } elseif(text.length(location_query) != 0) {
  3572. where_query = concat(where_query, and_query, location_query);
  3573. }
  3574. //Time
  3575. time_query = hawkeye.getTimeQuery(timeFrom, timeTo);
  3576. if(text.length(where_query) == 0) {
  3577. where_query = time_query;
  3578. } elseif(text.length(time_query) != 0) {
  3579. where_query = concat(where_query, and_query, time_query);
  3580. }
  3581. //Safety check
  3582. if(text.length(where_query) == 0) {
  3583. return "No parameters found";
  3584. }
  3585. //Final Statement
  3586. stmt = databank.prepare(concat(base_query, where_query, " ORDER BY time ", order, ";"));
  3587. index = 1;
  3588. if(events != null) {
  3589. iter = list.iterator(events);
  3590. while(hasNext(iter)) {
  3591. databank.setString(stmt, index, next(iter));
  3592. index++;
  3593. }
  3594. }
  3595. if(players != null) {
  3596. iter = list.iterator(players);
  3597. while(hasNext(iter)) {
  3598. databank.setInt(stmt, index, player.getId(player.getUuid(next(iter))));
  3599. index++;
  3600. }
  3601. }
  3602. if(location != null && radius != null) {
  3603. databank.setInt(stmt, index++, loc.getX(location));
  3604. databank.setInt(stmt, index++, loc.getY(location));
  3605. databank.setInt(stmt, index++, loc.getZ(location));
  3606. databank.setInt(stmt, index++, radius);
  3607. }
  3608. if(timeFrom != null && timeTo != null) {
  3609. databank.setLong(stmt, index++, timeFrom);
  3610. databank.setLong(stmt, index++, timeTo);
  3611. }
  3612. l = list.new();
  3613. result = databank.execute(stmt);
  3614. while(databank.next(result)) {
  3615. a = array.new(6);
  3616. id = databank.getInt(result, 1);
  3617. a[0] = id; //id
  3618. a[1] = databank.getInt(result, 2); //player_id
  3619. a[2] = databank.getString(result, 3); //event
  3620. a[3] = loc.new(world.get(databank.getString(result, 4)), databank.getInt(result, 5), databank.getInt(result, 6), databank.getInt(result, 7)); //location
  3621. a[4] = databank.getLong(result, 8); //time
  3622. a[5] = hawkeye.getDetailData(id);
  3623. list.add(l, a);
  3624. }
  3625. databank.close(result);
  3626. databank.close(stmt);
  3627. return l;
  3628. }
  3629. function hawkeye.getEventQuery(events) {
  3630. if(events == null) {
  3631. return "";
  3632. }
  3633. query = "event IN(";
  3634. c = 0;
  3635. iter = list.iterator(events);
  3636. while(hasNext(iter)) {
  3637. event = next(iter);
  3638. if(event != "block_break" && event != "block_place") {
  3639. return -1;
  3640. }
  3641. if(c == 0) {
  3642. query = concat(query, "?");
  3643. } else {
  3644. query = concat(query, ",?");
  3645. }
  3646. c++;
  3647. }
  3648. return concat(query, ")");
  3649. }
  3650. function hawkeye.getPlayerQuery(players) {
  3651. if(players == null) {
  3652. return "";
  3653. }
  3654. query = "player_id IN(";
  3655. c = 0;
  3656. iter = list.iterator(players);
  3657. while(hasNext(iter)) {
  3658. player_name = next(iter);
  3659. player_uuid = player.getUuid(player_name);
  3660. if(player_uuid == null) {
  3661. return -1;
  3662. }
  3663. if(c == 0) {
  3664. query = concat(query, "?");
  3665. } else {
  3666. query = concat(query, ",?");
  3667. }
  3668. c++;
  3669. }
  3670. return concat(query, ")");
  3671. }
  3672. function hawkeye.getLocationQuery(player_loc, radius) {
  3673. if(player_loc == null || radius == null) {
  3674. return "";
  3675. }
  3676. return "POWER(x - ?, 2) + POWER(y - ?, 2) + POWER(z - ?, 2) < POWER(?, 2)";
  3677. }
  3678. function hawkeye.getTimeQuery(timeFrom, timeTo) {
  3679. if(timeFrom == null || timeTo == null) {
  3680. return "";
  3681. }
  3682. return "time > ? AND time < ?";
  3683. }
  3684. function hawkeye.getDetailData(hawkeye_id) {
  3685. stmt = databank.prepare("SELECT name,value FROM hawkeye_data WHERE hawkeye_id = ?;");
  3686. databank.setInt(stmt, 1, hawkeye_id);
  3687. l = list.new();
  3688. result = databank.execute(stmt);
  3689. while(databank.next(result)) {
  3690. a = array.new(2);
  3691. a[0] = databank.getString(result, 1); //name
  3692. a[1] = databank.getString(result, 2); //value
  3693. list.add(l, a);
  3694. }
  3695. databank.close(result);
  3696. databank.close(stmt);
  3697. return l;
  3698. }
  3699. function hawkeye.print(player, list, side) {
  3700. amount = list.getSize(list);
  3701. a = list.getIndex(list, side - 1);
  3702. msg.prefix(player, "§cHawkeye", concat("§7----- Page (§c", text.number(side), "§7/§c", text.number(amount), "§7) -----"));
  3703. msg(player, concat("§7| ID:", text.number(a[0]), " ", getTimeString(a[4])));
  3704. msg(player, concat("§7| §c", a[2], " ", player.getNameFromId(a[1])));
  3705. msg(player, concat("§7| ", loc.getStringSpace(a[3])));
  3706. detail_l = a[5];
  3707. detail_iter = list.iterator(detail_l);
  3708. while(hasNext(detail_iter)) {
  3709. detail_a = next(detail_iter);
  3710. msg(player, concat("§7| - ", detail_a[0], ": ", detail_a[1]));
  3711. }
  3712. if(side == 1) {
  3713. backward = "§7<<<<";
  3714. if(amount == 1) {
  3715. forward = "§7>>>>";
  3716. } else {
  3717. forward = text.click("§c>>>>", concat("/hawkeye print ", side + 1));
  3718. }
  3719. } elseif(side >= amount) {
  3720. backward = text.click("§c<<<<", concat("/hawkeye print ", side - 1));
  3721. forward = "§7>>>>";
  3722. } else {
  3723. backward = text.click("§c<<<<", concat("/hawkeye print ", side - 1));
  3724. forward = text.click("§c>>>>", concat("/hawkeye print ", side + 1));
  3725. }
  3726. msg(player, backward, " ", forward);
  3727. msg(player, "§7-----------------------------");
  3728. }
  3729. function hawkeye.setDataList(player, list) {
  3730. map.add(getScriptVar("ha_data_lists"), player.getUuid(player), list);
  3731. }
  3732. function hawkeye.getDataList(player) {
  3733. return map.get(getScriptVar("ha_data_lists"), player.getUuid(player));
  3734. }
  3735. function hawkeye.setUndoList(player, list) {
  3736. map.add(getScriptVar("ha_undo_lists"), player.getUuid(player), list);
  3737. }
  3738. function hawkeye.getUndoList(player) {
  3739. return map.get(getScriptVar("ha_undo_lists"), player.getUuid(player));
  3740. }
  3741. function hawkeye.rollback(list) {
  3742. counter = 0;
  3743. for(i = 0; i < list.getSize(list); i++) {
  3744. a = list.getIndex(list, i);
  3745. event = a[2];
  3746. loc = a[3];
  3747. detail_l = a[5];
  3748. str = "";
  3749. detail_iter = list.iterator(detail_l);
  3750. while(hasNext(detail_iter)) {
  3751. detail_a = next(detail_iter);
  3752. name = detail_a[0];
  3753. value = detail_a[1];
  3754. if(name == "block_type") {
  3755. block_type = value;
  3756. } else {
  3757. str = concat(str, name, "=", value,",");
  3758. }
  3759. }
  3760. if(event == "block_place") {
  3761. block.set(loc, "minecraft:air", true);
  3762. counter++;
  3763. } elseif(event == "block_break") {
  3764. block.set(loc, concat(block_type, "[", str, "]"), true);
  3765. counter++;
  3766. }
  3767. }
  3768. return counter;
  3769. }
  3770. function hawkeye.undo(list) {
  3771. for(i = list.getSize(list) - 1; i >= 0; i--) {
  3772. a = list.getIndex(list, i);
  3773. event = a[2];
  3774. loc = a[3];
  3775. detail_l = a[5];
  3776. str = "";
  3777. detail_iter = list.iterator(detail_l);
  3778. while(hasNext(detail_iter)) {
  3779. detail_a = next(detail_iter);
  3780. name = detail_a[0];
  3781. value = detail_a[1];
  3782. if(name == "block_type") {
  3783. block_type = value;
  3784. } else {
  3785. str = concat(str, name, "=", value,",");
  3786. }
  3787. }
  3788. if(event == "block_place") {
  3789. block.set(loc, concat(block_type, "[", str, "]"), true);
  3790. } elseif(event == "block_break") {
  3791. block.set(loc, "minecraft:air", true);
  3792. }
  3793. }
  3794. }