u_general.txt 96 KB

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